Updated to libmDot 1.0.8-1

Dependencies:   DOGS102 GpsParser ISL29011 MMA845x MPL3115A2 MTS-Serial NCP5623B libmDot mbed-rtos mbed

Fork of MTDOT-BOX-EVB-Factory-Firmware by MultiTech

Committer:
jreiss
Date:
Wed Jul 13 19:14:04 2016 +0000
Revision:
6:ab581c4260e7
Parent:
1:71125aa00e33
Use DR enum values instead of SF values

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mike Fiore 1:71125aa00e33 1 /* Copyright (c) <2016> <MultiTech Systems>, MIT License
Mike Fiore 1:71125aa00e33 2 *
Mike Fiore 1:71125aa00e33 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
Mike Fiore 1:71125aa00e33 4 * and associated documentation files (the "Software"), to deal in the Software without restriction,
Mike Fiore 1:71125aa00e33 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
Mike Fiore 1:71125aa00e33 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Mike Fiore 1:71125aa00e33 7 * furnished to do so, subject to the following conditions:
Mike Fiore 1:71125aa00e33 8 *
Mike Fiore 1:71125aa00e33 9 * The above copyright notice and this permission notice shall be included in all copies or
Mike Fiore 1:71125aa00e33 10 * substantial portions of the Software.
Mike Fiore 1:71125aa00e33 11 *
Mike Fiore 1:71125aa00e33 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
Mike Fiore 1:71125aa00e33 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Mike Fiore 1:71125aa00e33 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
Mike Fiore 1:71125aa00e33 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Mike Fiore 1:71125aa00e33 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Mike Fiore 1:71125aa00e33 17 */
Mike Fiore 1:71125aa00e33 18
Mike Fiore 1:71125aa00e33 19 // mbed headers
Mike Fiore 1:71125aa00e33 20 #include "mbed.h"
Mike Fiore 1:71125aa00e33 21 #include "rtos.h"
Mike Fiore 1:71125aa00e33 22 // MTS headers
Mike Fiore 1:71125aa00e33 23 #include "mDot.h"
Mike Fiore 1:71125aa00e33 24 #include "MTSLog.h"
Mike Fiore 1:71125aa00e33 25 // display headers
Mike Fiore 1:71125aa00e33 26 #include "DOGS102.h"
Mike Fiore 1:71125aa00e33 27 #include "NCP5623B.h"
Mike Fiore 1:71125aa00e33 28 #include "LayoutStartup.h"
Mike Fiore 1:71125aa00e33 29 #include "LayoutScrollSelect.h"
Mike Fiore 1:71125aa00e33 30 #include "LayoutConfig.h"
Mike Fiore 1:71125aa00e33 31 #include "LayoutHelp.h"
Mike Fiore 1:71125aa00e33 32 // button header
Mike Fiore 1:71125aa00e33 33 #include "ButtonHandler.h"
Mike Fiore 1:71125aa00e33 34 // LoRa header
Mike Fiore 1:71125aa00e33 35 #include "LoRaHandler.h"
Mike Fiore 1:71125aa00e33 36 // Sensor header
Mike Fiore 1:71125aa00e33 37 #include "SensorHandler.h"
Mike Fiore 1:71125aa00e33 38 // mode objects
Mike Fiore 1:71125aa00e33 39 #include "ModeJoin.h"
Mike Fiore 1:71125aa00e33 40 #include "ModeSingle.h"
Mike Fiore 1:71125aa00e33 41 #include "ModeSweep.h"
Mike Fiore 1:71125aa00e33 42 #include "ModeDemo.h"
Mike Fiore 1:71125aa00e33 43 #include "ModeConfig.h"
Mike Fiore 1:71125aa00e33 44 // misc heders
Mike Fiore 1:71125aa00e33 45 #include "FileName.h"
Mike Fiore 1:71125aa00e33 46 #include <string>
Mike Fiore 1:71125aa00e33 47
Mike Fiore 1:71125aa00e33 48 // LCD and LED controllers
Mike Fiore 1:71125aa00e33 49 SPI lcd_spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK);
Mike Fiore 1:71125aa00e33 50 I2C led_i2c(I2C_SDA, I2C_SCL);
Mike Fiore 1:71125aa00e33 51 DigitalOut lcd_spi_cs(SPI1_CS, 1);
Mike Fiore 1:71125aa00e33 52 DigitalOut lcd_cd(XBEE_ON_SLEEP, 1);
Mike Fiore 1:71125aa00e33 53 DOGS102* lcd;
Mike Fiore 1:71125aa00e33 54 NCP5623B* led_cont;
Mike Fiore 1:71125aa00e33 55
Mike Fiore 1:71125aa00e33 56 // Thread informaiton
Mike Fiore 1:71125aa00e33 57 osThreadId main_id;
Mike Fiore 1:71125aa00e33 58
Mike Fiore 1:71125aa00e33 59 // Button controller
Mike Fiore 1:71125aa00e33 60 ButtonHandler* buttons;
Mike Fiore 1:71125aa00e33 61
Mike Fiore 1:71125aa00e33 62 // LoRa controller
Mike Fiore 1:71125aa00e33 63 LoRaHandler* lora;
Mike Fiore 1:71125aa00e33 64 mDot* dot;
Mike Fiore 1:71125aa00e33 65
Mike Fiore 1:71125aa00e33 66 // GPS
Mike Fiore 1:71125aa00e33 67 GPSPARSER* gps;
Mike Fiore 1:71125aa00e33 68 MTSSerial gps_serial(XBEE_DOUT, XBEE_DIN, 256, 2048);
Mike Fiore 1:71125aa00e33 69
Mike Fiore 1:71125aa00e33 70 // Sensors
Mike Fiore 1:71125aa00e33 71 SensorHandler* sensors;
Mike Fiore 1:71125aa00e33 72
Mike Fiore 1:71125aa00e33 73 // Modes
Mike Fiore 1:71125aa00e33 74 ModeJoin* modeJoin;
Mike Fiore 1:71125aa00e33 75 ModeSingle* modeSingle;
Mike Fiore 1:71125aa00e33 76 ModeSweep* modeSweep;
Mike Fiore 1:71125aa00e33 77 ModeDemo* modeDemo;
Mike Fiore 1:71125aa00e33 78 ModeConfig* modeConfig;
Mike Fiore 1:71125aa00e33 79
Mike Fiore 1:71125aa00e33 80 // Serial debug port
Mike Fiore 1:71125aa00e33 81 Serial debug(USBTX, USBRX);
Mike Fiore 1:71125aa00e33 82
Mike Fiore 1:71125aa00e33 83 // Survey Data File
Mike Fiore 1:71125aa00e33 84 char* file_name;
Mike Fiore 1:71125aa00e33 85
Mike Fiore 1:71125aa00e33 86 // Prototypes
Mike Fiore 1:71125aa00e33 87 void mainMenu();
Mike Fiore 1:71125aa00e33 88
Mike Fiore 1:71125aa00e33 89 int main() {
Mike Fiore 1:71125aa00e33 90 debug.baud(115200);
Mike Fiore 1:71125aa00e33 91 file_name = "SurveyData.txt";
Mike Fiore 1:71125aa00e33 92
Mike Fiore 1:71125aa00e33 93 lcd = new DOGS102(lcd_spi, lcd_spi_cs, lcd_cd);
Mike Fiore 1:71125aa00e33 94 // NCP5623B::LEDs 1 & 2 are the screen backlight - not used on default build
Mike Fiore 1:71125aa00e33 95 // NCP5623B::LED3 is EVB LED2
Mike Fiore 1:71125aa00e33 96 led_cont = new NCP5623B(led_i2c);
Mike Fiore 1:71125aa00e33 97
Mike Fiore 1:71125aa00e33 98 main_id = Thread::gettid();
Mike Fiore 1:71125aa00e33 99 buttons = new ButtonHandler(main_id);
Mike Fiore 1:71125aa00e33 100 dot = mDot::getInstance();
Mike Fiore 1:71125aa00e33 101 lora = new LoRaHandler(main_id);
Mike Fiore 1:71125aa00e33 102 gps = new GPSPARSER(&gps_serial, led_cont);
Mike Fiore 1:71125aa00e33 103 sensors = new SensorHandler();
Mike Fiore 1:71125aa00e33 104
Mike Fiore 1:71125aa00e33 105 led_cont->setLEDCurrent(16);
Mike Fiore 1:71125aa00e33 106
Mike Fiore 1:71125aa00e33 107 MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
Mike Fiore 1:71125aa00e33 108
Mike Fiore 1:71125aa00e33 109 modeJoin = new ModeJoin(lcd, buttons, dot, lora, gps, sensors);
Mike Fiore 1:71125aa00e33 110 modeSingle = new ModeSingle(lcd, buttons, dot, lora, gps, sensors);
Mike Fiore 1:71125aa00e33 111 modeSweep = new ModeSweep(lcd, buttons, dot, lora, gps, sensors);
Mike Fiore 1:71125aa00e33 112 modeDemo = new ModeDemo(lcd, buttons, dot, lora, gps, sensors);
Mike Fiore 1:71125aa00e33 113 modeConfig = new ModeConfig(lcd, buttons, dot, lora, gps, sensors);
Mike Fiore 1:71125aa00e33 114
Mike Fiore 1:71125aa00e33 115 osDelay(1000);
Mike Fiore 1:71125aa00e33 116 logInfo("%sGPS detected", gps->gpsDetected() ? "" : "no ");
Mike Fiore 1:71125aa00e33 117
Mike Fiore 1:71125aa00e33 118 // display startup screen for 3 seconds
Mike Fiore 1:71125aa00e33 119 LayoutStartup ls(lcd, dot);
Mike Fiore 1:71125aa00e33 120 ls.display();
Mike Fiore 1:71125aa00e33 121 ls.updateGPS(gps->gpsDetected());
Mike Fiore 1:71125aa00e33 122 osDelay(3000);
Mike Fiore 1:71125aa00e33 123
Mike Fiore 1:71125aa00e33 124 logInfo("displaying main menu");
Mike Fiore 1:71125aa00e33 125 mainMenu();
Mike Fiore 1:71125aa00e33 126
Mike Fiore 1:71125aa00e33 127 return 0;
Mike Fiore 1:71125aa00e33 128 }
Mike Fiore 1:71125aa00e33 129
Mike Fiore 1:71125aa00e33 130 void mainMenu() {
Mike Fiore 1:71125aa00e33 131 bool mode_selected = false;
Mike Fiore 1:71125aa00e33 132 std::string selected;
Mike Fiore 1:71125aa00e33 133 std::string product;
Mike Fiore 1:71125aa00e33 134
Mike Fiore 1:71125aa00e33 135 typedef enum {
Mike Fiore 1:71125aa00e33 136 demo = 1,
Mike Fiore 1:71125aa00e33 137 config,
Mike Fiore 1:71125aa00e33 138 single,
Mike Fiore 1:71125aa00e33 139 sweep
Mike Fiore 1:71125aa00e33 140 } menu_items;
Mike Fiore 1:71125aa00e33 141
Mike Fiore 1:71125aa00e33 142 std::string menu_strings[] = {
Mike Fiore 1:71125aa00e33 143 "Select Mode",
Mike Fiore 1:71125aa00e33 144 "LoRa Demo",
Mike Fiore 1:71125aa00e33 145 "Configuration",
Mike Fiore 1:71125aa00e33 146 "Survey Single",
Mike Fiore 1:71125aa00e33 147 "Survey Sweep"
Mike Fiore 1:71125aa00e33 148 };
Mike Fiore 1:71125aa00e33 149
Mike Fiore 1:71125aa00e33 150 std::vector<std::string> items;
Mike Fiore 1:71125aa00e33 151 items.push_back(menu_strings[demo]);
Mike Fiore 1:71125aa00e33 152 items.push_back(menu_strings[config]);
Mike Fiore 1:71125aa00e33 153 items.push_back(menu_strings[single]);
Mike Fiore 1:71125aa00e33 154 items.push_back(menu_strings[sweep]);
Mike Fiore 1:71125aa00e33 155
Mike Fiore 1:71125aa00e33 156 while (true) {
Mike Fiore 1:71125aa00e33 157 product = "MTDOT-BOX/EVB ";
Mike Fiore 1:71125aa00e33 158 product += mDot::FrequencyBandStr(dot->getFrequencyBand()).substr(3);
Mike Fiore 1:71125aa00e33 159
Mike Fiore 1:71125aa00e33 160 // reset session between modes
Mike Fiore 1:71125aa00e33 161 dot->resetNetworkSession();
Mike Fiore 1:71125aa00e33 162 lora->resetActivityLed();
Mike Fiore 1:71125aa00e33 163 LayoutScrollSelect menu(lcd, items, product, menu_strings[0]);
Mike Fiore 1:71125aa00e33 164 menu.display();
Mike Fiore 1:71125aa00e33 165
Mike Fiore 1:71125aa00e33 166 while (! mode_selected) {
Mike Fiore 1:71125aa00e33 167 osEvent e = Thread::signal_wait(buttonSignal);
Mike Fiore 1:71125aa00e33 168 if (e.status == osEventSignal) {
Mike Fiore 1:71125aa00e33 169 ButtonHandler::ButtonEvent ev = buttons->getButtonEvent();
Mike Fiore 1:71125aa00e33 170 switch (ev) {
Mike Fiore 1:71125aa00e33 171 case ButtonHandler::sw1_press:
Mike Fiore 1:71125aa00e33 172 selected = menu.select();
Mike Fiore 1:71125aa00e33 173 mode_selected = true;
Mike Fiore 1:71125aa00e33 174 break;
Mike Fiore 1:71125aa00e33 175 case ButtonHandler::sw2_press:
Mike Fiore 1:71125aa00e33 176 menu.scroll();
Mike Fiore 1:71125aa00e33 177 break;
Mike Fiore 1:71125aa00e33 178 case ButtonHandler::sw1_hold:
Mike Fiore 1:71125aa00e33 179 break;
Mike Fiore 1:71125aa00e33 180 default:
Mike Fiore 1:71125aa00e33 181 break;
Mike Fiore 1:71125aa00e33 182 }
Mike Fiore 1:71125aa00e33 183 }
Mike Fiore 1:71125aa00e33 184 }
Mike Fiore 1:71125aa00e33 185
Mike Fiore 1:71125aa00e33 186 if (selected == menu_strings[demo]) {
Mike Fiore 1:71125aa00e33 187 if (modeJoin->start())
Mike Fiore 1:71125aa00e33 188 modeDemo->start();
Mike Fiore 1:71125aa00e33 189 } else if (selected == menu_strings[config]) {
Mike Fiore 1:71125aa00e33 190 modeConfig->start();
Mike Fiore 1:71125aa00e33 191 } else if (selected == menu_strings[single]) {
Mike Fiore 1:71125aa00e33 192 if (modeJoin->start())
Mike Fiore 1:71125aa00e33 193 modeSingle->start();
Mike Fiore 1:71125aa00e33 194 } else if (selected == menu_strings[sweep]) {
Mike Fiore 1:71125aa00e33 195 if (modeJoin->start())
Mike Fiore 1:71125aa00e33 196 modeSweep->start();
Mike Fiore 1:71125aa00e33 197 }
Mike Fiore 1:71125aa00e33 198
Mike Fiore 1:71125aa00e33 199 mode_selected = false;
Mike Fiore 1:71125aa00e33 200 }
Mike Fiore 1:71125aa00e33 201 }
Mike Fiore 1:71125aa00e33 202