An example project for the Heltec Turtle LoRa board (STM32L4 and SX1276 chips). The projects is only supported for the Nucleo-L432KC board platform in the mbed online and offline compiler environment. Visit www.radioshuttle.de (choose Turtle board) for instructions. Note that most source files and libraries are open source, however some files especially the RadioShuttle core protocol is copyrighted work. Check header for details.

Dependencies:   mbed BufferedSerial SX1276GenericLib OLED_SSD1306 HELIOS_Si7021 NVProperty RadioShuttle-STM32L4 USBDeviceHT

Revision:
3:b5052f3fa638
Parent:
0:3b6c2ce051a6
Child:
5:c6a960febe80
--- a/main.cpp	Sun Jan 20 16:10:59 2019 +0100
+++ b/main.cpp	Sun Jan 20 16:12:01 2019 +0100
@@ -1,28 +1,91 @@
 /*
- * Copyright (c) 2018 HELIOS Software GmbH
+ * Copyright (c) 2019 Helmut Tschemernjak
  * 30826 Garbsen (Hannover) Germany
  * Licensed under the Apache License, Version 2.0);
  */
- #include "main.h"
+
+ /*
+  * TODO:
+  * Compiler Date/Time is not set correctly on startup
+  */
+#include "main.h"
+#include "RadioShuttle.h"
+#include "RadioTest.h"
+#include "GenericPingPong.h"
 
+volatile uint32_t PendingInterrupts;	// global interrupt mask of received interrupts
+DigitalOut statusLED(LED);
+DigitalOut redLED(LED2);
+InterruptIn buttonIntr(USER_BUTTON);
+LowPowerTimeout timeout;
 
-DigitalOut myled(LED);
+void switchInput(void) {
+	InterrruptMSG(INT_BUTTON1);
+}
 
 
+void timerUpdate(void) {
+	if (redLED == 0)
+		timeout.attach_us(&timerUpdate, 20000); // setup to call timerUpdate after 20 millis
+	else
+    	timeout.attach_us(&timerUpdate, 2000000); // setup to call timerUpdate after 2 seconds
+
+	InterrruptMSG(INT_TIMEOUT);
+}
+
 int main() {
-#ifdef HELTEC_STM32L4
-    DigitalOut vext(POWER_VEXT);
-    vext = POWER_VEXT_ON;
-#endif    
     /*
      * inits the Serial or USBSerial when available (230400 baud).
      * If the serial uart is not is not connected it swiches to USB Serial
      * blinking LED means USBSerial detected, waiting for a connect.
      * It waits up to 30 seconds for a USB terminal connections 
      */
-    InitSerial(30*1000, &myled);
-    dprintf("Welcome to the SX1276GenericLib");
-  
-    dprintf("Starting a simple LoRa PingPong");
-    SX1276PingPong();
+    InitSerial(30*1000, &statusLED);
+	dprintf("Welcome to RadioShuttle v%d.%d", RS_MAJOR, RS_MINOR);
+    dprintf("Voltage: %.2f (%s powered)", BatteryVoltage(), BatterySource());
+
+	
+#ifdef FEATURE_LORA
+    InitRadio();
+#endif
+#ifdef FEATURE_LORA_PING_PONG
+    DeInitRadio();
+    SX1276PingPong();	// basic LoRa raw ping/pong without RadioShuttle
+#endif
+    dprintf("InitDefaults Done");
+    timerUpdate(); // start timer
+#if defined (USER_BUTTON_RISE) // attach switchInput function to the rising or falling edge
+	buttonIntr.rise(&switchInput);
+#else
+	buttonIntr.fall(&switchInput);
+#endif
+
+	/*
+	 * Main event loop, process interrupts and go to sleep
+	 * the green statusLED indicates CPU activity
+	 */
+	while(true) {
+        while ((readPendingInterrupts() == 0)) {
+			statusLED = 0;
+			if (!(usb && usb->connected()))
+				sleep();
+			statusLED = 1;
+        }
+
+        uint32_t pendirqs = readclrPendingInterrupts();
+        if (pendirqs & INT_BUTTON1) {
+#ifdef FEATURE_LORA
+			statusLED = !statusLED;
+            RadioUpdate(true); // pass the pressed user button to RadioShuttle
+#endif
+		}
+        if (pendirqs & INT_LORA) {
+#ifdef FEATURE_LORA
+            RadioUpdate(false);
+#endif
+        }
+        if (pendirqs & INT_TIMEOUT) {
+			redLED = ! redLED;
+		}
+	}
 }