diff --git a/src/CollarRx.cpp b/src/CollarRx.cpp index 205ad32..10b10af 100644 --- a/src/CollarRx.cpp +++ b/src/CollarRx.cpp @@ -79,6 +79,10 @@ const char *CollarRx::mode_to_str(collar_mode mode) void CollarRx::rx_start() { + #ifdef ISR_MONITOR_PIN + pinMode(ISR_MONITOR_PIN,OUTPUT); + #endif + _instance = this; pinMode(_rx_pin, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(_rx_pin), CollarRx::s_isr, CHANGE); diff --git a/src/collar.h b/src/collar.h index 7611688..4b53732 100644 --- a/src/collar.h +++ b/src/collar.h @@ -5,6 +5,9 @@ #include #include "Arduino.h" +// show running ISR on defined pin for debug +#define ISR_MONITOR_PIN 5 + enum collar_mode { SHOCK=1, VIBE=2, BEEP=3 }; enum collar_channel { CH1=0, CH2=1, CH3=2 }; diff --git a/src/type1/CollarRxType1.cpp b/src/type1/CollarRxType1.cpp index 0d6c4a4..aca9806 100644 --- a/src/type1/CollarRxType1.cpp +++ b/src/type1/CollarRxType1.cpp @@ -55,6 +55,9 @@ bool CollarRxType1::is_message_valid(const uint8_t buffer[5]) void CollarRxType1::isr() { + #ifdef ISR_MONITOR_PIN + digitalWrite(ISR_MONITOR_PIN,HIGH); + #endif static unsigned long rx_micros =0; static unsigned int high_pulse_len =0; static unsigned int low_pulse_len=0; @@ -66,6 +69,9 @@ void CollarRxType1::isr() { //falling edge high_pulse_len = micros() - rx_micros; rx_micros = micros(); //start measurement of pulse length for low state + #ifdef ISR_MONITOR_PIN + digitalWrite(ISR_MONITOR_PIN,LOW); + #endif return; } else @@ -82,6 +88,9 @@ void CollarRxType1::isr() byte_position = 0; bit_position = 0; memset(buffer, 0, sizeof(buffer)); + #ifdef ISR_MONITOR_PIN + digitalWrite(ISR_MONITOR_PIN,LOW); + #endif return; } else @@ -111,6 +120,9 @@ void CollarRxType1::isr() buffer_to_collar_message(buffer, &_rx_msg); _cb(&_rx_msg, _userdata); byte_position=-1; //done, wait for new start + #ifdef ISR_MONITOR_PIN + digitalWrite(ISR_MONITOR_PIN,LOW); + #endif return; } } @@ -120,9 +132,16 @@ void CollarRxType1::isr() { //transmission error, wait for new start byte_position=-1; + #ifdef ISR_MONITOR_PIN + digitalWrite(ISR_MONITOR_PIN,LOW); + #endif return; } } } } + #ifdef ISR_MONITOR_PIN + digitalWrite(ISR_MONITOR_PIN,LOW); + #endif + }