Skip to content

Commit

Permalink
Ass a pin triggered while ISR is running for debug purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
bemabalu committed Sep 8, 2024
1 parent 4f892ab commit 1514215
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/CollarRx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/collar.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <stdint.h>
#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 };

Expand Down
19 changes: 19 additions & 0 deletions src/type1/CollarRxType1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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

}

0 comments on commit 1514215

Please sign in to comment.