From 1721be5e66758e2bdf580a755259766894257bcd Mon Sep 17 00:00:00 2001 From: Erick Ahmed Date: Wed, 29 Oct 2025 13:51:04 +0100 Subject: [PATCH] Remove triggerMoistureRead() call in ISR and it's trigger variable - This was done at the very beginning when i thought to develop this part of the program in a different way. It is unnecessary with how I actually ended up to structure the program. - WDT should manage TWI only, as per current developement --- firmware/atmega/include/moisture.h | 1 - firmware/atmega/source/main.c | 12 +++--------- firmware/atmega/source/moisture.c | 4 ---- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/firmware/atmega/include/moisture.h b/firmware/atmega/include/moisture.h index f1eeaba..0c7c993 100644 --- a/firmware/atmega/include/moisture.h +++ b/firmware/atmega/include/moisture.h @@ -44,7 +44,6 @@ static const int8_t sensorPins[] = { extern volatile bool readSensors; void sensorsInit(void); -void triggerMoistureRead(void); uint16_t moistureRead(void); #endif diff --git a/firmware/atmega/source/main.c b/firmware/atmega/source/main.c index 057f1ac..75a6fc4 100644 --- a/firmware/atmega/source/main.c +++ b/firmware/atmega/source/main.c @@ -13,10 +13,6 @@ volatile uint16_t lastMoistureVal = 0; volatile uint16_t *pLastMoistureVal = &lastMoistureVal; extern bool respondFlag; -ISR(WDT_vect) { - triggerMoistureRead(); -} - ISR(TWI_vect) { twiListen(); } @@ -50,11 +46,9 @@ int main(void) { pLastMoistureVal = &lastMoistureVal; while(true) { - if (readSensors) { - *pLastMoistureVal = moistureRead(); - // nested if: (result outside range (see config.h)) {waterPlant()} - readSensors = false; - } + *pLastMoistureVal = moistureRead(); + // nested if: (result outside range (see config.h)) {waterPlant()} + if(respondFlag) { twiRespond(); diff --git a/firmware/atmega/source/moisture.c b/firmware/atmega/source/moisture.c index 09a30ff..943b41d 100644 --- a/firmware/atmega/source/moisture.c +++ b/firmware/atmega/source/moisture.c @@ -17,10 +17,6 @@ void sensorsInit(void) { PORTC &= ~sensorMask; } -void triggerMoistureRead(void) { - readSensors = true; -} - static uint16_t moistureAverage(uint8_t sensorPin) { uint16_t sum = 0; for (uint8_t i = 0; i < SENSOR_READINGS; i++) {