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

Change button callback into 3-state

This commit is contained in:
Andrey Pokhilko 2019-08-14 11:04:29 +03:00
parent 544aa82cf5
commit 6ad116fe1c
2 changed files with 9 additions and 2 deletions

View File

@ -34,3 +34,10 @@ def callback(is_pressed):
hub = MoveHub()
hub.button.subscribe(callback)
```
The state for button has 3 possible values:
- `0` - not released
- `1` - pressed
- `2` - pressed
It is for now unknown why Hub always issues notification with `1` and immediately with `2`, after button is pressed.

View File

@ -660,4 +660,4 @@ class Button(Peripheral):
:type msg: MsgHubProperties
"""
if msg.property == MsgHubProperties.BUTTON and msg.operation == MsgHubProperties.UPSTREAM_UPDATE:
self._notify_subscribers(bool(usbyte(msg.parameters, 0)))
self._notify_subscribers(usbyte(msg.parameters, 0))