antonvh / PUPRemote

GNU General Public License v3.0
2 stars 2 forks source link

Add power_m2 option to init() method of PUPRemoteSensor #9

Open ste7anste7an opened 1 year ago

ste7anste7an commented 1 year ago

Pwer on M2 is enabled by using the capability string \x80\x00\x00\x00\x05\x04. It seems that both the PyBricks as well as the Lego Mindstorms Inventor implementation expects this capability string at a fixed offset in the mode_name field.

Only when the length of mode_name is 5, the capability string is on the right place (position 7 in the mode_name field. For longer or shorter names, it is not, and the power is not enabled on pin M2.

So we have the following requirements on the mode_name:

the code becomes:

if self.power:
            mode_name = mode_name.encode('ascii') + b'\x00'*(5-len(mode_name)) + b'\x00\x80\x00\x00\x00\x05\x04'