danielweidman / pixmob-ir-reverse-engineering

Hacking the PixMob infrared (and now also RF!) protocol to enable control of PixMob wristbands at home.
MIT License
594 stars 42 forks source link

Add some tests and refactor conversion functions #22

Closed zacharesmer closed 1 year ago

zacharesmer commented 1 year ago

Renamed rewrote, and wrote tests for the conversion functions for readability and reusability.

Function name changes that might break something in uncommitted code: to_hex -> bits_to_hex to_arduino_string -> bits_to_arduino_string to_data_timings -> bits_to_run_lengths_microseconds to_levels -> bits_to_run_lengths_pulses

Also, the way an exception is raised when trying to send a bit pattern with >9 bits to the arduino has changed. Instead of an exception when attempting to access a non-existent key in the "logic_level_to_data_num" dict, a ValueError is raised in bits_to_arduino_string. For example, I made a change in serial_brute_forcer_class.py to make it work, but this change might cause issues anywhere you're validating some set of bits before sending it to the arduino. The bit_flipirs still work and appropriately check for errors.

With that different error checking in mind, logic_levels_to_data_nums can be achieved with a list comprehension multiplying each element by cfg.PULSE_LENGTH.