Skip to content

Commit

Permalink
wired in the reset and restart op to the on-board user button
Browse files Browse the repository at this point in the history
  • Loading branch information
gigapod committed Dec 13, 2024
1 parent b9b1163 commit be73880
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
49 changes: 49 additions & 0 deletions sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ static const char *kProductName = "SparkFun IoT Node LoRaWAN";
// delay used in loop during startup
const uint32_t kStartupLoopDelayMS = 70;

// Button event increment
#define kButtonPressedIncrement 5

//---------------------------------------------------------------------------
// LoRaWAN Receive message ids
//
Expand Down Expand Up @@ -318,6 +321,13 @@ bool sfeIoTNodeLoRaWAN::onSetup()

flux_add(_boardButton);

// We want an event every 5 seconds
_boardButton.setPressIncrement(kButtonPressedIncrement);

// Button events we're listening on
_boardButton.on_buttonRelease.call(this, &sfeIoTNodeLoRaWAN::onButtonReleased);
_boardButton.on_buttonPressed.call(this, &sfeIoTNodeLoRaWAN::onButtonPressed);

return true;
}
//---------------------------------------------------------------------------
Expand Down Expand Up @@ -546,6 +556,45 @@ void sfeIoTNodeLoRaWAN::onErrorMessage(uint8_t msgType)
else if (msgType == (uint8_t)flxLogWarning)
sfeLED.flash(sfeLED.Yellow);
}

//---------------------------------------------------------------------------
// Button Events - general handler
//---------------------------------------------------------------------------
//
// CAlled when the button is pressed and an increment time passed
void sfeIoTNodeLoRaWAN::onButtonPressed(uint32_t increment)
{

// we need LED on for visual feedback...
sfeLED.setDisabled(false);

if (increment == 1)
sfeLED.blink(sfeLED.Yellow, kLEDFlashSlow);

else if (increment == 2)
sfeLED.blink(kLEDFlashMedium);

else if (increment == 3)
sfeLED.blink(kLEDFlashFast);

else if (increment >= 4)
{
sfeLED.stop();

sfeLED.on(sfeLED.Red);
delay(500);
sfeLED.off();

// Reset time !
_sysSystem.resetDevice();
}
}
//---------------------------------------------------------------------------
void sfeIoTNodeLoRaWAN::onButtonReleased(uint32_t increment)
{
if (increment > 0)
sfeLED.off();
}
// ---------------------------------------------------------------------------
// Log event
// ---------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ class sfeIoTNodeLoRaWAN : public flxApplication

void getStartupProperties(uint32_t &baudRate, uint32_t &startupDelay);

// Board button callbacks
void onButtonPressed(uint32_t);
void onButtonReleased(uint32_t);

// battery level checks
void checkBatteryLevels(void);

Expand Down Expand Up @@ -209,8 +213,6 @@ class sfeIoTNodeLoRaWAN : public flxApplication

// Our system Control
flxSystem _sysSystem;
// for our button events of the board
// sfeDLButton _boardButton;

// Fuel gauge
flxDevMAX17048 *_fuelGauge;
Expand Down

0 comments on commit be73880

Please sign in to comment.