@@ -25,6 +25,9 @@ static const char *kProductName = "SparkFun IoT Node LoRaWAN";
25
25
// delay used in loop during startup
26
26
const uint32_t kStartupLoopDelayMS = 70 ;
27
27
28
+ // Button event increment
29
+ #define kButtonPressedIncrement 5
30
+
28
31
// ---------------------------------------------------------------------------
29
32
// LoRaWAN Receive message ids
30
33
//
@@ -318,6 +321,13 @@ bool sfeIoTNodeLoRaWAN::onSetup()
318
321
319
322
flux_add (_boardButton);
320
323
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
+
321
331
return true ;
322
332
}
323
333
// ---------------------------------------------------------------------------
@@ -546,6 +556,45 @@ void sfeIoTNodeLoRaWAN::onErrorMessage(uint8_t msgType)
546
556
else if (msgType == (uint8_t )flxLogWarning)
547
557
sfeLED.flash (sfeLED.Yellow );
548
558
}
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
+ }
549
598
// ---------------------------------------------------------------------------
550
599
// Log event
551
600
// ---------------------------------------------------------------------------
0 commit comments