diff --git a/drawers/src/main.cpp b/drawers/src/main.cpp index 9d93f7a..68c44d4 100644 --- a/drawers/src/main.cpp +++ b/drawers/src/main.cpp @@ -3,9 +3,12 @@ const uint8_t I2C_ADDR = 0x10; -const uint8_t CMD_POWER_OFF = 0x01; -const uint8_t CMD_LIGHT_INDEX = 0x02; -const uint8_t CMD_DRAWER_INDEX = 0x03; +const uint8_t BITMASK_CMD = 0b00011000; +const uint8_t BITMASK_PAYLOAD = 0b00000111; + +const uint8_t CMD_POWER_OFF = 0b00001000; +const uint8_t CMD_LIGHT_INDEX = 0b00010000; +const uint8_t CMD_DRAWER_INDEX = 0b00011000; struct Schublade { int schlossPin; @@ -47,22 +50,20 @@ void openLock(uint8_t indexOn) { void onI2CReceive(int len) { while (Wire.available()) { - uint8_t cmd = Wire.read(); + uint8_t data = Wire.read(); - switch (cmd) { + switch (data & BITMASK_CMD) { case CMD_POWER_OFF: turnAllLedsOf(); break; case CMD_LIGHT_INDEX: - uint8_t lightIndex = Wire.read(); - turnOnSingleLed(lightIndex); + turnOnSingleLed(data & BITMASK_PAYLOAD); break; case CMD_DRAWER_INDEX: - uint8_t drawerIndex = Wire.read(); - openLock(drawerIndex); + openLock(data & BITMASK_PAYLOAD); break; } }