Refactor TWI response system

- Avoid setting respondFlag in main, instead let it be managed directly
inside twiListen() and read inside twiRespond()
This commit is contained in:
2025-10-29 14:02:25 +01:00
parent 1721be5e66
commit b28b20f46a
2 changed files with 33 additions and 37 deletions
-5
View File
@@ -11,7 +11,6 @@
volatile uint16_t lastMoistureVal = 0; volatile uint16_t lastMoistureVal = 0;
volatile uint16_t *pLastMoistureVal = &lastMoistureVal; volatile uint16_t *pLastMoistureVal = &lastMoistureVal;
extern bool respondFlag;
ISR(TWI_vect) { ISR(TWI_vect) {
twiListen(); twiListen();
@@ -49,11 +48,7 @@ int main(void) {
*pLastMoistureVal = moistureRead(); *pLastMoistureVal = moistureRead();
// nested if: (result outside range (see config.h)) {waterPlant()} // nested if: (result outside range (see config.h)) {waterPlant()}
if(respondFlag) {
twiRespond(); twiRespond();
respondFlag = false;
}
enterSleep(); enterSleep();
} }
+2 -1
View File
@@ -35,7 +35,7 @@ static void twiSendData(uint8_t data) {
} }
void twiRespond(void) { void twiRespond(void) {
//FIXME: refactor this implementation if(respondFlag) {
switch(twiBuffer[0]) { switch(twiBuffer[0]) {
case 0x01: // Send moisture case 0x01: // Send moisture
twiSendData(*pLastMoistureVal); twiSendData(*pLastMoistureVal);
@@ -67,6 +67,7 @@ void twiRespond(void) {
twiSendNack(); twiSendNack();
break; break;
} }
}
} }
void twiListen(void) { void twiListen(void) {