1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Clarify tilt sensor constants

This commit is contained in:
Andrey Pohilko 2017-09-21 21:52:13 +03:00
parent db23dc81a6
commit c4aaa9fd6d
4 changed files with 49 additions and 22 deletions

View File

@ -29,7 +29,7 @@ Demonstrational video:
Install library like this:
```bash
pip install https://github.com/undera/pylgbst/archive/0.3.tar.gz
pip install https://github.com/undera/pylgbst/archive/0.4.tar.gz
```
Then instantiate MoveHub object and start invoking its methods. Following is example to just print peripherals detected on Hub:
@ -128,6 +128,22 @@ hub.tilt_sensor.unsubscribe(callback)
- `MODE_3AXIS_FULL` - use `callback(roll, pitch)` for 2-axis roll&pitch degree values
- `MODE_BUMP_COUNT` - use `callback(count)` to detect bumps
There are tilt sensor constants for "simple" states, for 2-axis mode their names are also available through `TiltSensor.DUO_STATES`:
- `DUO_HORIZ` - "HORIZONTAL"
- `DUO_DOWN` - "DOWN"
- `DUO_LEFT` - "LEFT"
- `DUO_RIGHT` - "RIGHT"
- `DUO_UP` - "UP"
For 3-axis simple mode map name is `TiltSensor.TRI_STATES` with values:
- `TRI_BACK` - "BACK"
- `TRI_UP` - "UP"
- `TRI_DOWN` - "DOWN"
- `TRI_LEFT` - "LEFT"
- `TRI_RIGHT` - "RIGHT"
- `TRI_FRONT` - "FRONT"
### Color & Distance Sensor
Field named `color_distance_sensor` holds instance of `ColorDistanceSensor`, if one is attached to MoveHub. Sensor has number of different modes to subscribe.

View File

@ -73,11 +73,11 @@ def demo_tilt_sensor_simple(movehub):
demo_tilt_sensor_simple.cnt = 0
limit = 10
def callback(param1):
def callback(state):
demo_tilt_sensor_simple.cnt += 1
log.info("Tilt #%s of %s: %s", demo_tilt_sensor_simple.cnt, limit, TiltSensor.TILT_STATES[param1])
log.info("Tilt #%s of %s: %s=%s", demo_tilt_sensor_simple.cnt, limit, TiltSensor.TRI_STATES[state], state)
movehub.tilt_sensor.subscribe(callback, mode=TiltSensor.MODE_2AXIS_SIMPLE)
movehub.tilt_sensor.subscribe(callback, mode=TiltSensor.MODE_3AXIS_SIMPLE)
while demo_tilt_sensor_simple.cnt < limit:
time.sleep(1)
@ -171,4 +171,5 @@ if __name__ == '__main__':
connection = BLEConnection().connect()
hub = MoveHub(connection)
demo_all(hub)

View File

@ -258,24 +258,34 @@ class TiltSensor(Peripheral):
MODE_BUMP_COUNT = 0x03
MODE_3AXIS_FULL = 0x04
HORIZONTAL = 0x00
UP = 0x01
DOWN = 0x02
RIGHT = 0x03
LEFT = 0x04
FRONT = 0x05
SOME1 = 0x07 # TODO
SOME2 = 0x09 # TODO
TRI_BACK = 0x00
TRI_UP = 0x01
TRI_DOWN = 0x02
TRI_LEFT = 0x03
TRI_RIGHT = 0x04
TRI_FRONT = 0x05
TILT_STATES = {
HORIZONTAL: "HORIZONTAL",
UP: "UP",
DOWN: "DOWN",
RIGHT: "RIGHT",
LEFT: "LEFT",
FRONT: "FRONT",
SOME1: "LEFT1",
SOME2: "RIGHT1",
DUO_HORIZ = 0x00
DUO_DOWN = 0x03
DUO_LEFT = 0x05
DUO_RIGHT = 0x07
DUO_UP = 0x09
DUO_STATES = {
DUO_HORIZ: "HORIZONTAL",
DUO_DOWN: "DOWN",
DUO_LEFT: "LEFT",
DUO_RIGHT: "RIGHT",
DUO_UP: "UP",
}
TRI_STATES = {
TRI_BACK: "BACK",
TRI_UP: "UP",
TRI_DOWN: "DOWN",
TRI_LEFT: "LEFT",
TRI_RIGHT: "RIGHT",
TRI_FRONT: "FRONT",
}
def subscribe(self, callback, mode=MODE_3AXIS_SIMPLE, granularity=1, async=False):

View File

@ -83,7 +83,7 @@ class GeneralTest(unittest.TestCase):
def callback(param1, param2=None, param3=None):
if param2 is None:
log.debug("Tilt: %s", TiltSensor.TILT_STATES[param1])
log.debug("Tilt: %s", TiltSensor.TRI_STATES[param1])
else:
log.debug("Tilt: %s %s %s", param1, param2, param3)