Skip to content

Commit be73880

Browse files
committed
wired in the reset and restart op to the on-board user button
1 parent b9b1163 commit be73880

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWAN.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ static const char *kProductName = "SparkFun IoT Node LoRaWAN";
2525
// delay used in loop during startup
2626
const uint32_t kStartupLoopDelayMS = 70;
2727

28+
// Button event increment
29+
#define kButtonPressedIncrement 5
30+
2831
//---------------------------------------------------------------------------
2932
// LoRaWAN Receive message ids
3033
//
@@ -318,6 +321,13 @@ bool sfeIoTNodeLoRaWAN::onSetup()
318321

319322
flux_add(_boardButton);
320323

324+
// We want an event every 5 seconds
325+
_boardButton.setPressIncrement(kButtonPressedIncrement);
326+
327+
// Button events we're listening on
328+
_boardButton.on_buttonRelease.call(this, &sfeIoTNodeLoRaWAN::onButtonReleased);
329+
_boardButton.on_buttonPressed.call(this, &sfeIoTNodeLoRaWAN::onButtonPressed);
330+
321331
return true;
322332
}
323333
//---------------------------------------------------------------------------
@@ -546,6 +556,45 @@ void sfeIoTNodeLoRaWAN::onErrorMessage(uint8_t msgType)
546556
else if (msgType == (uint8_t)flxLogWarning)
547557
sfeLED.flash(sfeLED.Yellow);
548558
}
559+
560+
//---------------------------------------------------------------------------
561+
// Button Events - general handler
562+
//---------------------------------------------------------------------------
563+
//
564+
// CAlled when the button is pressed and an increment time passed
565+
void sfeIoTNodeLoRaWAN::onButtonPressed(uint32_t increment)
566+
{
567+
568+
// we need LED on for visual feedback...
569+
sfeLED.setDisabled(false);
570+
571+
if (increment == 1)
572+
sfeLED.blink(sfeLED.Yellow, kLEDFlashSlow);
573+
574+
else if (increment == 2)
575+
sfeLED.blink(kLEDFlashMedium);
576+
577+
else if (increment == 3)
578+
sfeLED.blink(kLEDFlashFast);
579+
580+
else if (increment >= 4)
581+
{
582+
sfeLED.stop();
583+
584+
sfeLED.on(sfeLED.Red);
585+
delay(500);
586+
sfeLED.off();
587+
588+
// Reset time !
589+
_sysSystem.resetDevice();
590+
}
591+
}
592+
//---------------------------------------------------------------------------
593+
void sfeIoTNodeLoRaWAN::onButtonReleased(uint32_t increment)
594+
{
595+
if (increment > 0)
596+
sfeLED.off();
597+
}
549598
// ---------------------------------------------------------------------------
550599
// Log event
551600
// ---------------------------------------------------------------------------

sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWAN.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ class sfeIoTNodeLoRaWAN : public flxApplication
182182

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

185+
// Board button callbacks
186+
void onButtonPressed(uint32_t);
187+
void onButtonReleased(uint32_t);
188+
185189
// battery level checks
186190
void checkBatteryLevels(void);
187191

@@ -209,8 +213,6 @@ class sfeIoTNodeLoRaWAN : public flxApplication
209213

210214
// Our system Control
211215
flxSystem _sysSystem;
212-
// for our button events of the board
213-
// sfeDLButton _boardButton;
214216

215217
// Fuel gauge
216218
flxDevMAX17048 *_fuelGauge;

0 commit comments

Comments
 (0)