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 nrz-i conversion functions #26

Closed zacharesmer closed 1 year ago

zacharesmer commented 1 year ago

I just checked and the IR signal is encoded in such a way that it contains the same information if all the bits are flipped. The LED of my wristband lights up red both times I send a code in the following test:

import python_tools.pixmob_conversion_funcs as funcs
import python_tools.effect_definitions as effects
from python_tools.send import send_one_code

send_one_code(effects.base_color_effects["RED"], wait=True)
send_one_code(funcs.invert(effects.base_color_effects["RED"]), wait=True)

(It worked because of a bug hehe whoops)

That makes me pretty sure the IR signal is encoded with some kind of NRZ-I (non-return to zero inverted) code. This means that the data in encoded in bits represented by a change in the signal or no change in the signal at clock/pulse/chip boundaries. "NRZ-I Mark" would mean that a one is encoded by a transition, and zero by it remaining the same. "NRZ-I Space" would be the opposite (0 is a transtion, 1 is staying the same). It's possible there is some other encoding scheme that also fits with this new property and the rest of what we've learned, but I haven't found one yet. More information here: https://en.wikipedia.org/wiki/Non-return-to-zero

So, I added a conversion function to make it easier to analyze the signals in this format. Hopefully the structure of the data will be more apparent in this way!

zacharesmer commented 1 year ago

Actually, don't merge this; I should add some other things to make it more useful (namely, update the documentation, write some tests, and add a function to convert from nrz-i back to the raw IR bits).