Skip to content

Commit 0a9772d

Browse files
committed
Allowed Disabling of Manager Timer
If so, the user will need to manually call the service_inputs() method on a periodic basis.
1 parent ac83e9a commit 0a9772d

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Each Input object type has a number of configuration options, all with default v
3232

3333
After the Manager object is created, it automatically starts polling the input objects at the default rate of 480 Hz (a 2x or greater multiple of 60 Hz will help 60 Hz noise to be filtered on Analog lines). Each input is read and processed according to the type of input it is.
3434

35-
At any time, the current values of all the inputs can be read by executing the `values()` method on the Manager object. The return object is a superset of a Python dictionary, also allowing access to values through attributes:
35+
At any time, the current values of all the inputs can be read by executing the `values()` method on the Manager object. The return object is a Python dictionary with the added feature that values can be read as attributes of the object:
3636

3737
```Python
3838
# get all of the current input values
@@ -103,6 +103,10 @@ Arguments include:
103103

104104
`inputs`: This is the list of input objects that the Manager will periodically poll and manage.
105105

106-
`timer_num`: The number of the microcontroller Timer that will be used to generate an interrupt for polling the inputs.
106+
`timer_num`: The number of the microcontroller Timer that will be used to generate an interrupt for polling the inputs. If `None` is passed, no automatic polling of inputs will occur, and you will need to periodically call the `service_inputs()` method of this object, perhaps from your own Timer interrupt routine.
107107

108-
`poll_freq`: The frequency that will be used to poll the inputs in Hz. The default of 480 Hz will poll each sensor every 2.08 ms, which is a convenient value for debounce routines discussed later and analog averaging routines that sample across an exact number of 60 Hz cycles.
108+
`poll_freq`: The frequency that will be used to poll the inputs in Hz. The default of 480 Hz will poll each sensor every 2.08 ms, which is a convenient value for debounce routines discussed later and analog averaging routines that sample across an exact number of 60 Hz cycles.
109+
110+
**Manager.values**()
111+
112+
This returns a snapshot of all of the current inputs. The return object is a Python dictionary with added feature of being able to use an attribute to access a value as well as standard dictionary syntax. If `vals` is the object returned by this method, these two read access means are equivalent: `vals['X1']` and `vals.X1`.

inputs.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def __init__(self, inputs, timer_num=1, poll_freq=480):
1818
'''Arguments are:
1919
inputs: a list or tuple of Inputs objects that derive from InputBase.
2020
time_num: the number of the microcontroller Timer that will be used to
21-
periodically poll the inputs.
21+
periodically poll the inputs. If None is passed, no Timer will be
22+
set up automatically and you will need to periodically call
23+
the 'service_inputs()` method from your own timer.
2224
poll_freq: the frequency in Hz to read the inputs. The default value
2325
of 480 Hz means each input will be read every 2.08 ms (1000 ms / 480).
2426
Be careful about setting this too high as the time required to read
@@ -28,8 +30,9 @@ def __init__(self, inputs, timer_num=1, poll_freq=480):
2830
the process of reading inputs consumes 1.6 / 2.08 or 77% of the CPU cycles.
2931
'''
3032
self.inputs = inputs
31-
self._tim = pyb.Timer(timer_num, freq=poll_freq)
32-
self._tim.callback(self.service_inputs)
33+
if timer_num is not None:
34+
self._tim = pyb.Timer(timer_num, freq=poll_freq)
35+
self._tim.callback(self.service_inputs)
3336

3437
def service_inputs(self, t):
3538
'''This method is called by the timer interrupt and runs the 'service_input'

0 commit comments

Comments
 (0)