mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Fix tilt sensor functioning
This commit is contained in:
parent
8baaac57a0
commit
ab83408dee
@ -283,22 +283,22 @@ class TiltSensor(Peripheral):
|
|||||||
|
|
||||||
def handle_port_data(self, data):
|
def handle_port_data(self, data):
|
||||||
if self._port_subscription_mode == self.MODE_3AXIS_SIMPLE:
|
if self._port_subscription_mode == self.MODE_3AXIS_SIMPLE:
|
||||||
state = data[4]
|
state = unpack("<B", data[4:5])[0]
|
||||||
self._notify_subscribers(state)
|
self._notify_subscribers(state)
|
||||||
elif self._port_subscription_mode == self.MODE_2AXIS_SIMPLE:
|
elif self._port_subscription_mode == self.MODE_2AXIS_SIMPLE:
|
||||||
state = data[4]
|
state = unpack("<B", data[4:5])[0]
|
||||||
self._notify_subscribers(state)
|
self._notify_subscribers(state)
|
||||||
elif self._port_subscription_mode == self.MODE_BUMP_COUNT:
|
elif self._port_subscription_mode == self.MODE_BUMP_COUNT:
|
||||||
bump_count = data[4]
|
bump_count = unpack("<H", data[4:6])[0]
|
||||||
self._notify_subscribers(bump_count)
|
self._notify_subscribers(bump_count)
|
||||||
elif self._port_subscription_mode == self.MODE_2AXIS_FULL:
|
elif self._port_subscription_mode == self.MODE_2AXIS_FULL:
|
||||||
roll = self._byte2deg(data[4])
|
roll = self._byte2deg(unpack("<B", data[4:5])[0])
|
||||||
pitch = self._byte2deg(data[5])
|
pitch = self._byte2deg(unpack("<B", data[5:6])[0])
|
||||||
self._notify_subscribers(roll, pitch)
|
self._notify_subscribers(roll, pitch)
|
||||||
elif self._port_subscription_mode == self.MODE_3AXIS_FULL:
|
elif self._port_subscription_mode == self.MODE_3AXIS_FULL:
|
||||||
roll = self._byte2deg(data[4])
|
roll = self._byte2deg(unpack("<B", data[4:5])[0])
|
||||||
pitch = self._byte2deg(data[5])
|
pitch = self._byte2deg(unpack("<B", data[5:6])[0])
|
||||||
yaw = self._byte2deg(data[6]) # did I get the order right?
|
yaw = self._byte2deg(unpack("<B", data[6:7])[0]) # did I get the order right?
|
||||||
self._notify_subscribers(roll, pitch, yaw)
|
self._notify_subscribers(roll, pitch, yaw)
|
||||||
else:
|
else:
|
||||||
log.debug("Got tilt sensor data while in unexpected mode: %s", self._port_subscription_mode)
|
log.debug("Got tilt sensor data while in unexpected mode: %s", self._port_subscription_mode)
|
||||||
|
1
tests.py
1
tests.py
@ -165,6 +165,7 @@ class GeneralTest(unittest.TestCase):
|
|||||||
def callback(pressed):
|
def callback(pressed):
|
||||||
log.info("Pressed: %s", pressed)
|
log.info("Pressed: %s", pressed)
|
||||||
|
|
||||||
|
hub.notify_mock.append((HANDLE, "1b0e00060001020600"))
|
||||||
hub.button.subscribe(callback)
|
hub.button.subscribe(callback)
|
||||||
|
|
||||||
hub.notify_mock.append((HANDLE, "1b0e00060001020601"))
|
hub.notify_mock.append((HANDLE, "1b0e00060001020601"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user