Skip to content

Commit

Permalink
ESP32 example timer out of interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
pilotak committed May 13, 2023
1 parent 0415106 commit afb156e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion examples/timers/WeatherMeters_ESP32/WeatherMeters_ESP32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ volatile bool got_data = false;

hw_timer_t * timer = NULL;
volatile SemaphoreHandle_t timerSemaphore;
volatile bool do_update = false;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;

WeatherMeters <4> meters(windvane_pin, 8); // filter last 4 directions, refresh data every 8 sec
Expand All @@ -22,7 +23,7 @@ void ICACHE_RAM_ATTR intRaingauge() {

void IRAM_ATTR onTimer() {
xSemaphoreGiveFromISR(timerSemaphore, NULL);
meters.timer();
do_update = true;
}

void readDone(void) {
Expand All @@ -47,6 +48,11 @@ void setup() {
}

void loop() {
if(do_update){
meters.timer();
do_update = false;
}

if (got_data) {
got_data = false;
Serial.print("Wind degrees: ");
Expand Down

0 comments on commit afb156e

Please sign in to comment.