Change message receive implementation to allow for only one action at a
time
This commit is contained in:
@@ -35,53 +35,50 @@ 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];
|
||||||
twiSendData(*pLastMoistureVal);
|
uint8_t param = twiBuffer[1];
|
||||||
break;
|
|
||||||
case 0x02: // Get SENSOR_READINGS
|
switch(cmd) {
|
||||||
twiSendData(eepromRead(SENSOR_READINGS));
|
// READ
|
||||||
break;
|
case 0x01:
|
||||||
case 0x03: // Get MOISTURE_MIN
|
twiSendData(*pLastMoistureVal);
|
||||||
twiSendData(eepromRead(MOISTURE_MIN));
|
break;
|
||||||
break;
|
case 0x02:
|
||||||
case 0x04: // Get MOISTURE_MAX
|
twiSendData(eepromRead(SENSOR_READINGS));
|
||||||
twiSendData(eepromRead(MOISTURE_MAX));
|
break;
|
||||||
break;
|
case 0x03:
|
||||||
case 0x05: // Set SENSOR_READINGS
|
twiSendData(eepromRead(MOISTURE_MIN));
|
||||||
eepromWrite(SENSOR_READINGS, twiBuffer[1]);
|
break;
|
||||||
twiSendAck();
|
case 0x04:
|
||||||
break;
|
twiSendData(eepromRead(MOISTURE_MAX));
|
||||||
case 0x06: // Set parameters
|
break;
|
||||||
eepromWrite(MOISTURE_MIN, twiBuffer[1]);
|
// WRITE
|
||||||
eepromWrite(MOISTURE_MAX, twiBuffer[2]);
|
case 0x05:
|
||||||
eepromWrite(SENSOR_READINGS, twiBuffer[3]);
|
eepromWrite(SENSOR_READINGS, param);
|
||||||
twiSendAck();
|
twiSendAck();
|
||||||
break;
|
break;
|
||||||
case 0x07: // Force water plants (one pumping)
|
case 0x06:
|
||||||
waterPlant();
|
eepromWrite(MOISTURE_MIN, param);
|
||||||
twiSendAck();
|
twiSendAck();
|
||||||
break;
|
break;
|
||||||
default:
|
case 0x07:
|
||||||
twiSendNack();
|
eepromWrite(MOISTURE_MAX, param);
|
||||||
break;
|
twiSendAck();
|
||||||
}
|
break;
|
||||||
|
case 0x08:
|
||||||
|
waterPlant();
|
||||||
|
twiSendAck();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
twiSendNack();
|
||||||
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user