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

Offer alternative fix for start_power commands (#53)

* Offer alternative fix

* Fix test

* Dummy commit

* fix

* Decrease coverage

* fix test

* turn into comments

* Empty it

* Rollback experiment
This commit is contained in:
Andrey Pokhilko 2020-03-07 09:36:30 +03:00 committed by GitHub
parent fef871946a
commit c47fb2326a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -240,8 +240,8 @@ class LEDRGB(Peripheral):
class Motor(Peripheral): class Motor(Peripheral):
SUBCMD_START_POWER = 0x00 SUBCMD_START_POWER = 0x01
SUBCMD_START_POWER_GROUPED = 0x03 SUBCMD_START_POWER_GROUPED = 0x02
SUBCMD_SET_ACC_TIME = 0x05 SUBCMD_SET_ACC_TIME = 0x05
SUBCMD_SET_DEC_TIME = 0x06 SUBCMD_SET_DEC_TIME = 0x06
SUBCMD_START_SPEED = 0x07 SUBCMD_START_SPEED = 0x07
@ -254,8 +254,7 @@ class Motor(Peripheral):
END_STATE_FLOAT = 0 END_STATE_FLOAT = 0
def _speed_abs(self, relative): def _speed_abs(self, relative):
if relative == Motor.END_STATE_BRAKE \ if relative == Motor.END_STATE_BRAKE or relative == Motor.END_STATE_HOLD:
or relative == Motor.END_STATE_HOLD:
# special value for BRAKE # special value for BRAKE
# https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#output-sub-command-startpower-power # https://lego.github.io/lego-ble-wireless-protocol-docs/index.html#output-sub-command-startpower-power
return relative return relative
@ -291,7 +290,7 @@ class Motor(Peripheral):
power_secondary = power_primary power_secondary = power_primary
if self.virtual_ports: if self.virtual_ports:
cmd = self.SUBCMD_START_POWER_GROUPED cmd = self.SUBCMD_START_POWER_GROUPED - 1 # because _send_cmd will do +1
else: else:
cmd = self.SUBCMD_START_POWER cmd = self.SUBCMD_START_POWER
@ -300,7 +299,7 @@ class Motor(Peripheral):
if self.virtual_ports: if self.virtual_ports:
params += pack("<b", self._speed_abs(power_secondary)) params += pack("<b", self._speed_abs(power_secondary))
self._write_direct_mode(cmd, params) self._send_cmd(cmd, params)
def stop(self): def stop(self):
self.timed(0) self.timed(0)

View File

@ -151,7 +151,7 @@ class PeripheralsTest(unittest.TestCase):
hub.connection.notification_delayed('050082030a', 0.1) hub.connection.notification_delayed('050082030a', 0.1)
motor.start_power(1.0) motor.start_power(1.0)
self.assertEqual(b"0800810311510064", hub.writes.pop(1)[1]) self.assertEqual(b"07008103110164", hub.writes.pop(1)[1])
hub.connection.notification_delayed('050082030a', 0.1) hub.connection.notification_delayed('050082030a', 0.1)
motor.stop() motor.stop()