-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathenc.py
60 lines (47 loc) · 1.46 KB
/
enc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
###############################################################################
#
# Copyright (c) 2017-2024 Master AI, Inc.
# ALL RIGHTS RESERVED
#
# Use of this library, in source or binary form, is prohibited without written
# approval from Master AI, Inc.
#
###############################################################################
"""
This module provides a simplified interface to the Encoder sensor.
"""
from auto.asyncio_tools import thread_safe
from auto.capabilities import list_caps, acquire
def num_encoders():
"""
Return the number of Encoders on this controller.
"""
return _get_encoders().num_encoders()
def enable(index):
"""
Enable an encoder. The first encoder is index-0.
"""
return _get_encoders().enable(index)
def read(index):
"""
Read the counts of the encoder. The first encoder is index-0.
The count is reset to zero when the encoder is enabled.
Returns the number of "clicks" (a signed value) that this encoder has seen.
"""
return _get_encoders().read_counts(index)[0]
def disable(index):
"""
Disable an encoder. The first encoder is index-0.
"""
return _get_encoders().disable(index)
@thread_safe
def _get_encoders():
global _ENCODERS
try:
_ENCODERS
except NameError:
caps = list_caps()
if 'Encoders' not in caps:
raise AttributeError('This device has no Encoders!')
_ENCODERS = acquire('Encoders')
return _ENCODERS