From 6ad116fe1c17400f918b41e4eb5627c888774488 Mon Sep 17 00:00:00 2001 From: Andrey Pokhilko Date: Wed, 14 Aug 2019 11:04:29 +0300 Subject: [PATCH] Change button callback into 3-state --- docs/MoveHub.md | 9 ++++++++- pylgbst/peripherals.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/MoveHub.md b/docs/MoveHub.md index 3047d9e..ed855a5 100644 --- a/docs/MoveHub.md +++ b/docs/MoveHub.md @@ -33,4 +33,11 @@ def callback(is_pressed): hub = MoveHub() hub.button.subscribe(callback) -``` \ No newline at end of file +``` + +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. \ No newline at end of file diff --git a/pylgbst/peripherals.py b/pylgbst/peripherals.py index 834adda..db80808 100644 --- a/pylgbst/peripherals.py +++ b/pylgbst/peripherals.py @@ -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))