Compare commits
No commits in common. "876b2f0db6f0728178c6db9dffe3fb53a1ab829f" and "c7e5a92edfec4f4b6d0536dbe7ca182e14e06615" have entirely different histories.
876b2f0db6
...
c7e5a92edf
@ -3,12 +3,9 @@
|
|||||||
|
|
||||||
const uint8_t I2C_ADDR = 0x10;
|
const uint8_t I2C_ADDR = 0x10;
|
||||||
|
|
||||||
const uint8_t BITMASK_CMD = 0b00011000;
|
const uint8_t CMD_POWER_OFF = 0x01;
|
||||||
const uint8_t BITMASK_PAYLOAD = 0b00000111;
|
const uint8_t CMD_LIGHT_INDEX = 0x02;
|
||||||
|
const uint8_t CMD_DRAWER_INDEX = 0x03;
|
||||||
const uint8_t CMD_POWER_OFF = 0b00001000;
|
|
||||||
const uint8_t CMD_LIGHT_INDEX = 0b00010000;
|
|
||||||
const uint8_t CMD_DRAWER_INDEX = 0b00011000;
|
|
||||||
|
|
||||||
struct Schublade {
|
struct Schublade {
|
||||||
int schlossPin;
|
int schlossPin;
|
||||||
@ -50,20 +47,22 @@ void openLock(uint8_t indexOn) {
|
|||||||
|
|
||||||
void onI2CReceive(int len) {
|
void onI2CReceive(int len) {
|
||||||
while (Wire.available()) {
|
while (Wire.available()) {
|
||||||
uint8_t data = Wire.read();
|
uint8_t cmd = Wire.read();
|
||||||
|
|
||||||
switch (data & BITMASK_CMD) {
|
switch (cmd) {
|
||||||
|
|
||||||
case CMD_POWER_OFF:
|
case CMD_POWER_OFF:
|
||||||
turnAllLedsOf();
|
turnAllLedsOf();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_LIGHT_INDEX:
|
case CMD_LIGHT_INDEX:
|
||||||
turnOnSingleLed(data & BITMASK_PAYLOAD);
|
uint8_t lightIndex = Wire.read();
|
||||||
|
turnOnSingleLed(lightIndex);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CMD_DRAWER_INDEX:
|
case CMD_DRAWER_INDEX:
|
||||||
openLock(data & BITMASK_PAYLOAD);
|
uint8_t drawerIndex = Wire.read();
|
||||||
|
openLock(drawerIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,18 +5,15 @@ void resetPuzzles();
|
|||||||
|
|
||||||
/* ========================================================= */
|
/* ========================================================= */
|
||||||
const uint8_t ARCHIV_ADDR = 0x10;
|
const uint8_t ARCHIV_ADDR = 0x10;
|
||||||
|
const uint8_t CMD_POWER_OFF = 0x01;
|
||||||
const uint8_t BITMASK_CMD = 0b00011000;
|
const uint8_t CMD_LIGHT_INDEX = 0x02;
|
||||||
const uint8_t BITMASK_PAYLOAD = 0b00000111;
|
const uint8_t CMD_DRAWER_INDEX = 0x03;
|
||||||
|
|
||||||
const uint8_t CMD_POWER_OFF = 0b00001000;
|
|
||||||
const uint8_t CMD_LIGHT_INDEX = 0b00010000;
|
|
||||||
const uint8_t CMD_DRAWER_INDEX = 0b00011000;
|
|
||||||
|
|
||||||
void setDrawerLight(uint8_t index)
|
void setDrawerLight(uint8_t index)
|
||||||
{
|
{
|
||||||
Wire.beginTransmission(ARCHIV_ADDR);
|
Wire.beginTransmission(ARCHIV_ADDR);
|
||||||
Wire.write(CMD_LIGHT_INDEX | (index & BITMASK_PAYLOAD));
|
Wire.write(CMD_LIGHT_INDEX);
|
||||||
|
Wire.write(index);
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +27,8 @@ void turnLightsOff()
|
|||||||
void openDrawer(uint8_t index)
|
void openDrawer(uint8_t index)
|
||||||
{
|
{
|
||||||
Wire.beginTransmission(ARCHIV_ADDR);
|
Wire.beginTransmission(ARCHIV_ADDR);
|
||||||
Wire.write(CMD_DRAWER_INDEX | (index & BITMASK_PAYLOAD));
|
Wire.write(CMD_DRAWER_INDEX);
|
||||||
|
Wire.write(index);
|
||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
}
|
}
|
||||||
/* ========================================================= */
|
/* ========================================================= */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user