antonvh / PUPRemote

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

Format strings and callback functions for both directions #1

Closed ste7anste7an closed 1 year ago

ste7anste7an commented 1 year ago

https://github.com/antonvh/PUPRemote/blob/7cffd7331b237a5f96c6d25186238bdeab2b913b/LPF2/pupremote.py#L48

When a mode is assigned to e.g. a gyro sensor, the reading could be formatted as HHH (for pitch, rol, yaw). The hub could send data to the sensor to set specific registers in the sensor. This could be e.g. BB for (register, value). return_format not clear for which direction this is.

Proposal: optional format, or use empty string when format is not used.

def add_command(self, command: callable, mode_name: str, format_pup_to_hub: str, *argv):
if argv:
   format_hub_to_pup=argv[0]
   callback = argv[1]

Example:

def gyro():
  p,r,y=read_gyro()
  return p,r,y

def set_gyro(reg,val):
  set_gyro_reg(reg,val)

def led(nr,r,g,b):
   set_neopixel(nr,r,g,b)

pup.add_command(gyro,'gyro','HHH','BB',set_gyro) 
pup.add_command(NULL,'led',','BB',set_led)     

To do: There are also modes that are only used to send messages frpom hub to pup, and not the otherway arround. Make command=Null and format_pup_to_hub=''

ste7anste7an commented 1 year ago

Implemented in new code