Change message receive implementation to allow for only one action at a

time
This commit is contained in:
2025-12-13 12:36:15 +01:00
parent 137814206c
commit dc5c2c751b
+22 -25
View File
@@ -35,31 +35,39 @@ static void twiSendData(uint8_t data) {
} }
void twiRespond(void) { void twiRespond(void) {
if(respondFlag) { if (!respondFlag) return;
switch(twiBuffer[0]) {
case 0x01: // Get moisture uint8_t cmd = twiBuffer[0];
uint8_t param = twiBuffer[1];
switch(cmd) {
// READ
case 0x01:
twiSendData(*pLastMoistureVal); twiSendData(*pLastMoistureVal);
break; break;
case 0x02: // Get SENSOR_READINGS case 0x02:
twiSendData(eepromRead(SENSOR_READINGS)); twiSendData(eepromRead(SENSOR_READINGS));
break; break;
case 0x03: // Get MOISTURE_MIN case 0x03:
twiSendData(eepromRead(MOISTURE_MIN)); twiSendData(eepromRead(MOISTURE_MIN));
break; break;
case 0x04: // Get MOISTURE_MAX case 0x04:
twiSendData(eepromRead(MOISTURE_MAX)); twiSendData(eepromRead(MOISTURE_MAX));
break; break;
case 0x05: // Set SENSOR_READINGS // WRITE
eepromWrite(SENSOR_READINGS, twiBuffer[1]); case 0x05:
eepromWrite(SENSOR_READINGS, param);
twiSendAck(); twiSendAck();
break; break;
case 0x06: // Set parameters case 0x06:
eepromWrite(MOISTURE_MIN, twiBuffer[1]); eepromWrite(MOISTURE_MIN, param);
eepromWrite(MOISTURE_MAX, twiBuffer[2]);
eepromWrite(SENSOR_READINGS, twiBuffer[3]);
twiSendAck(); twiSendAck();
break; break;
case 0x07: // Force water plants (one pumping) case 0x07:
eepromWrite(MOISTURE_MAX, param);
twiSendAck();
break;
case 0x08:
waterPlant(); waterPlant();
twiSendAck(); twiSendAck();
break; break;
@@ -68,20 +76,9 @@ void twiRespond(void) {
break; break;
} }
} }
}
void twiListen(void) { void twiListen(void) {
/*
HOW TO SPEAK MASTER'S LANGUAGE:
Message is saved bit per bit on a buffer array like this:
[ message, param0, param1, param2 ]
So when parsing:
buffer[0] is the message itself
buffer[1] to buffer[3] are parameters
*/
switch (TWSR & 0xF8) { switch (TWSR & 0xF8) {
case 0x60: // SLA+W received case 0x60: // SLA+W received
bufferIndex = 0; bufferIndex = 0;