Helmut Tschemernjak / Mbed 2 deprecated Turtle_RadioShuttle

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002  * Copyright (c) 2019 Helmut Tschemernjak
00003  * 30826 Garbsen (Hannover) Germany
00004  * Licensed under the Apache License, Version 2.0);
00005  */
00006 
00007  /*
00008   * TODO:
00009   * Compiler Date/Time is not set correctly on startup using gcc
00010   * USB Serial block deepsleep
00011   */
00012 #include "main.h"
00013 #include "RadioTest.h"
00014 
00015 DigitalOut statusLED(LED);
00016 DigitalOut redLED(LED2);
00017 InterruptIn buttonIntr(USER_BUTTON);
00018 volatile int pressedCount;
00019 
00020 void switchInput(void) {
00021     InterruptMSG(INT_BUTTON1);
00022 }
00023 
00024 void timerUpdate(void) {
00025     static LowPowerTimeout timeout;
00026     if (redLED == 0)
00027         timeout.attach_us(&timerUpdate, 20000); // setup to call timerUpdate after 20 millis
00028     else
00029         timeout.attach_us(&timerUpdate, 2000000); // setup to call timerUpdate after 2 seconds
00030 
00031     InterruptMSG(INT_TIMEOUT);
00032 }
00033 
00034 
00035 
00036 int main() {
00037     /*
00038      * inits the Serial or USBSerial when available (230400 baud).
00039      * If the serial uart is not is not connected it swiches to USB Serial
00040      * blinking LED means USBSerial detected, waiting for a connect.
00041      * It waits up to 30 seconds for a USB terminal connections 
00042      */
00043     InitSerial(30*1000, &statusLED, &buttonIntr);
00044     RunStartup();
00045     dprintf("Welcome to RadioShuttle v%d.%d", RS_MAJOR, RS_MINOR);
00046     timerUpdate(); // start timer for status blinked, can be disalbed to save energy
00047 #if defined (USER_BUTTON_RISE) // attach switchInput function to the rising or falling edge
00048     buttonIntr.rise(&switchInput);
00049 #else
00050     buttonIntr.fall(&switchInput);
00051 #endif
00052     
00053     RunCommands(10000); // check 10 secs for any commands
00054     
00055 #ifdef FEATURE_LORA
00056     InitRadio();
00057 #endif
00058 
00059     /*
00060      * Main event loop, process interrupts and goes to sleep when idle.
00061      * the green statusLED indicates CPU activity
00062      * the red redLED indicates that low power timerUpdate function is running.
00063      */
00064     while(true) {
00065         while ((readPendingInterrupts() == 0)) {
00066             statusLED = 0;
00067             sleep();
00068             statusLED = 1;
00069         }
00070 
00071         uint32_t pendirqs = readclrPendingInterrupts();
00072         if (pendirqs & INT_BUTTON1) {
00073 #ifdef FEATURE_LORA
00074             statusLED = !statusLED;
00075             RadioUpdate(true); // pass the pressed user button to RadioShuttle
00076 #endif
00077         }
00078         if (pendirqs & INT_LORA) {
00079 #ifdef FEATURE_LORA
00080             RadioUpdate(false);
00081 #endif
00082         }
00083         if (pendirqs & INT_TIMEOUT) {
00084             redLED = ! redLED;
00085         }
00086     }
00087 }