Skip to content

Commit

Permalink
Handle serial counter
Browse files Browse the repository at this point in the history
  • Loading branch information
steadramon authored and steadramon committed Apr 14, 2023
1 parent 45f464c commit 046d3ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ESPGeiger/src/Counter/Counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ void Counter::begin() {
void Counter::loop() {
#if GEIGER_TYPE == GEIGER_TYPE_SERIAL
if (geigerPort.available() > 0) {
if (_handlesecond)
return;
int n = geigerPort.readStringUntil('\r').toInt();
Log::debug(PSTR("Counter loop - %d"), n);
if (n) {
Expand Down
5 changes: 3 additions & 2 deletions ESPGeiger/src/Counter/Counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ static void IRAM_ATTR sendpulse() {
}
}
#endif
static bool _handlesecond = false;

#ifdef ESP32
static portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
Expand All @@ -162,6 +163,7 @@ static void IRAM_ATTR count() {
};

static void IRAM_ATTR handleSecondTick() {
_handlesecond = true;
portENTER_CRITICAL_ISR(&timerMux);
#ifdef USE_PCNT
int16_t pulseCount;
Expand All @@ -171,6 +173,7 @@ static void IRAM_ATTR handleSecondTick() {
#endif
status.geigerTicks.add(eventCounter);
eventCounter = 0;
_handlesecond = false;
portEXIT_CRITICAL_ISR(&timerMux);
unsigned long int secidx = (millis() / 1000) % 60;
if (secidx % 5 == 0) {
Expand All @@ -183,8 +186,6 @@ static void IRAM_ATTR handleSecondTick() {
}
};
#else
static bool _handlesecond = false;

static void ICACHE_RAM_ATTR count() {
if (_handlesecond)
return;
Expand Down

0 comments on commit 046d3ad

Please sign in to comment.