Compare commits

..

No commits in common. "876b2f0db6f0728178c6db9dffe3fb53a1ab829f" and "c7e5a92edfec4f4b6d0536dbe7ca182e14e06615" have entirely different histories.

2 changed files with 16 additions and 19 deletions

View File

@ -3,12 +3,9 @@
const uint8_t I2C_ADDR = 0x10;
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;
const uint8_t CMD_POWER_OFF = 0x01;
const uint8_t CMD_LIGHT_INDEX = 0x02;
const uint8_t CMD_DRAWER_INDEX = 0x03;
struct Schublade {
int schlossPin;
@ -50,20 +47,22 @@ void openLock(uint8_t indexOn) {
void onI2CReceive(int len) {
while (Wire.available()) {
uint8_t data = Wire.read();
uint8_t cmd = Wire.read();
switch (data & BITMASK_CMD) {
switch (cmd) {
case CMD_POWER_OFF:
turnAllLedsOf();
break;
case CMD_LIGHT_INDEX:
turnOnSingleLed(data & BITMASK_PAYLOAD);
uint8_t lightIndex = Wire.read();
turnOnSingleLed(lightIndex);
break;
case CMD_DRAWER_INDEX:
openLock(data & BITMASK_PAYLOAD);
uint8_t drawerIndex = Wire.read();
openLock(drawerIndex);
break;
}
}

View File

@ -5,18 +5,15 @@ void resetPuzzles();
/* ========================================================= */
const uint8_t ARCHIV_ADDR = 0x10;
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;
const uint8_t CMD_POWER_OFF = 0x01;
const uint8_t CMD_LIGHT_INDEX = 0x02;
const uint8_t CMD_DRAWER_INDEX = 0x03;
void setDrawerLight(uint8_t index)
{
Wire.beginTransmission(ARCHIV_ADDR);
Wire.write(CMD_LIGHT_INDEX | (index & BITMASK_PAYLOAD));
Wire.write(CMD_LIGHT_INDEX);
Wire.write(index);
Wire.endTransmission();
}
@ -30,7 +27,8 @@ void turnLightsOff()
void openDrawer(uint8_t index)
{
Wire.beginTransmission(ARCHIV_ADDR);
Wire.write(CMD_DRAWER_INDEX | (index & BITMASK_PAYLOAD));
Wire.write(CMD_DRAWER_INDEX);
Wire.write(index);
Wire.endTransmission();
}
/* ========================================================= */