From cd81084b7518dd179275dd424680c866235859df Mon Sep 17 00:00:00 2001
From: Jan Grewe <jan@faked.org>
Date: Sun, 26 Jul 2020 02:26:55 +0200
Subject: [PATCH] print status on button click

---
 platformio.ini      |  1 +
 src/config.h.sample |  2 ++
 src/main.cpp        | 14 ++++++++++----
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/platformio.ini b/platformio.ini
index cc39e38..478c23f 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -25,3 +25,4 @@ lib_deps =
   AXP202X_Library@1.1.2
   TinyGPSPlus@1.0.2
   MCCI Arduino LoRaWAN Library@0.8.0
+  OneButton@0.0.0-alpha+sha.eb583d713a
diff --git a/src/config.h.sample b/src/config.h.sample
index c6f45b7..a260387 100644
--- a/src/config.h.sample
+++ b/src/config.h.sample
@@ -6,3 +6,5 @@
 #define TTN_DEVEUI { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 }; // LSB / little-endian / "byte order reversed"
 #define TTN_APPEUI { 0x0E, 0x0D, 0x0C, 0x0B, 0x0A, 0xD5, 0xB3, 0x70 }; // LSB / little-endian / "byte order reversed"
 #define TTN_APPKEY { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; // MSB / big-endian / "byte order same as string"
+
+#define BUTTON_PIN 38
diff --git a/src/main.cpp b/src/main.cpp
index b7168f3..3f531ce 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,6 +5,7 @@
 #include <hal/hal.h>
 #include <SPI.h>
 #include <TinyGPS++.h>
+#include <OneButton.h>
 
 class cLoRaWAN : public Arduino_LoRaWAN_ttn
 {
@@ -63,6 +64,7 @@ AXP20X_Class axp;
 HardwareSerial GPS(1);
 TinyGPSPlus gps;
 cLoRaWAN LoRaWAN{};
+OneButton btn = OneButton(BUTTON_PIN, true, true);
 
 static uint8_t mydata[] = "Hello, world!";
 static osjob_t sendjob;
@@ -101,7 +103,7 @@ void printStatus()
   {
     gps.encode(GPS.read());
   }
-  Serial.println("**********************");
+  Serial.println("##############################");
   Serial.println("--- Power ---");
   Serial.printf("DCDC1/OLED Status   : %s\n", axp.isDCDC1Enable() ? "enabled" : "disabled");
   Serial.printf("DCDC1/OLED Voltage  : %g V\n", (float)axp.getDCDC1Voltage() / 1000);
@@ -143,10 +145,14 @@ void printStatus()
   Serial.println(gps.time.second());
   Serial.print("Speed      : ");
   Serial.println(gps.speed.kmph());
-  Serial.println("**********************");
+  Serial.println("##############################");
   axp.setChgLEDMode(AXP20X_LED_OFF);
 }
 
+static void handleClick() {
+  printStatus();
+}
+
 void do_send(osjob_t *j)
 {
   // Check if there is not a current TX/RX job running
@@ -278,6 +284,7 @@ void setup()
   setupPower();
   setupGps();
   LoRaWAN.begin(pinMap);
+  btn.attachClick(handleClick);
   printStatus();
   do_send(&sendjob);
 }
@@ -285,6 +292,5 @@ void setup()
 void loop()
 {
   LoRaWAN.loop();
-  //printStatus();
-  //delay(1000);
+  btn.tick();
 }
-- 
GitLab