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 *pLastMoistureVal = &lastMoistureVal;
extern bool respondFlag;
ISR(TWI_vect) {
twiListen();
@@ -49,11 +48,7 @@ int main(void) {
*pLastMoistureVal = moistureRead();
// nested if: (result outside range (see config.h)) {waterPlant()}
if(respondFlag) {
twiRespond();
respondFlag = false;
}
enterSleep();
}
+2 -1
View File
@@ -35,7 +35,7 @@ static void twiSendData(uint8_t data) {
}
void twiRespond(void) {
//FIXME: refactor this implementation
if(respondFlag) {
switch(twiBuffer[0]) {
case 0x01: // Send moisture
twiSendData(*pLastMoistureVal);
@@ -68,6 +68,7 @@ void twiRespond(void) {
break;
}
}
}
void twiListen(void) {