|
36 | 36 |
|
37 | 37 | //| .. currentmodule:: rotaryio |
38 | 38 | //| |
39 | | -//| :class:`IncrementalEncoder` -- Read the position of the incremental encoder |
40 | | -//| ============================================================================ |
| 39 | +//| :class:`IncrementalEncoder` -- Track the relative position of an incremental encoder |
| 40 | +//| ==================================================================================== |
41 | 41 | //| |
42 | 42 | //| IncrementalEncoder determines the relative rotational position based on two series of pulses. |
43 | 43 | //| |
|
47 | 47 | //| state of an incremental rotary encoder (also known as a quadrature encoder.) Position is |
48 | 48 | //| relative to the position when the object is contructed. |
49 | 49 | //| |
50 | | -//| :param ~microcontroller.Pin pin: First pin to read pulses from. |
51 | | -//| :param ~microcontroller.Pin pin: Second pin to read pulses from. |
| 50 | +//| :param ~microcontroller.Pin pin_a: First pin to read pulses from. |
| 51 | +//| :param ~microcontroller.Pin pin_b: Second pin to read pulses from. |
52 | 52 | //| |
53 | 53 | //| For example:: |
54 | 54 | //| |
@@ -94,7 +94,7 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, |
94 | 94 |
|
95 | 95 | //| .. method:: deinit() |
96 | 96 | //| |
97 | | -//| Deinitialises the IncrementalEncoder and releases any hardware resources for reuse. |
| 97 | +//| Deinitializes the IncrementalEncoder and releases any hardware resources for reuse. |
98 | 98 | //| |
99 | 99 | STATIC mp_obj_t rotaryio_incrementalencoder_deinit(mp_obj_t self_in) { |
100 | 100 | rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in); |
@@ -135,10 +135,19 @@ STATIC mp_obj_t rotaryio_incrementalencoder_obj_get_position(mp_obj_t self_in) { |
135 | 135 | } |
136 | 136 | MP_DEFINE_CONST_FUN_OBJ_1(rotaryio_incrementalencoder_get_position_obj, rotaryio_incrementalencoder_obj_get_position); |
137 | 137 |
|
| 138 | +STATIC mp_obj_t rotaryio_incrementalencoder_obj_set_position(mp_obj_t self_in, mp_obj_t new_position) { |
| 139 | + rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in); |
| 140 | + raise_error_if_deinited(common_hal_rotaryio_incrementalencoder_deinited(self)); |
| 141 | + |
| 142 | + common_hal_rotaryio_incrementalencoder_set_position(self, mp_obj_get_int(new_position)); |
| 143 | + return mp_const_none; |
| 144 | +} |
| 145 | +MP_DEFINE_CONST_FUN_OBJ_2(rotaryio_incrementalencoder_set_position_obj, rotaryio_incrementalencoder_obj_set_position); |
| 146 | + |
138 | 147 | const mp_obj_property_t rotaryio_incrementalencoder_position_obj = { |
139 | 148 | .base.type = &mp_type_property, |
140 | 149 | .proxy = {(mp_obj_t)&rotaryio_incrementalencoder_get_position_obj, |
141 | | - (mp_obj_t)&mp_const_none_obj, |
| 150 | + (mp_obj_t)&rotaryio_incrementalencoder_set_position_obj, |
142 | 151 | (mp_obj_t)&mp_const_none_obj}, |
143 | 152 | }; |
144 | 153 |
|
|
0 commit comments