this is using the mbed os version 5-13-1
Diff: source/main-https.cpp
- Branch:
- PassingRegression
- Revision:
- 114:b11bb96c09f3
- Parent:
- 113:888e262ff0a9
- Child:
- 115:8054dbadfaa0
--- a/source/main-https.cpp Sat May 18 10:50:49 2019 +0000
+++ b/source/main-https.cpp Sat May 18 15:44:48 2019 +0000
@@ -27,7 +27,7 @@
DigitalOut led3(LED3);
#define FILE_CODE "main"
-
+main_states_t mainLoop;
static RawSerial *device; // tx, rx
// wifi configuration
@@ -37,6 +37,10 @@
// wifi manager pointer
static WiFiManager *wiFiManager;
+// BLE instance
+//BLE& _ble;
+BLE& _ble = BLE::Instance();
+
// BLE configuration
static ble_config_t ble_config;
const uint8_t pairingPassword[6] = "1101";
@@ -215,21 +219,9 @@
led3 = !led3;
}
-#define PAUSE_SECONDS 0
-#define PAUSE_SECONDS_BLE 0
-int main() {
- device = new RawSerial(USBTX, USBRX, 2*DEFAULT_BAUD_RATE);
- uint8_t debug_level = (LOG | ERR | TXT | DBG);
- initialise_debug(debug_level);
-#ifdef MBED_MAJOR_VERSION
- dbg_printf(LOG, "Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
-#endif
-
- reset_counter++;
- dbg_printf(LOG, "\r\n ++++++ PROGRAM STARTING -- reset count = %d ++++++ \r\n", reset_counter);
- setupDefaultWiFiConfig();
- setupDefaultBleConfig();
- BLE& _ble = BLE::Instance();
+void start_BLE()
+{
+ //_ble = BLE::Instance();
#if MBED_CONF_APP_FILESYSTEM_SUPPORT
/* if filesystem creation fails or there is no filesystem the security manager
* will fallback to storing the security database in memory */
@@ -242,14 +234,15 @@
peripheral->run();
btle_thread.start(callback(&eventQueue_ble, &EventQueue::dispatch_forever));
- //btle_thread.start(callback(peripheral, &SMDevicePeripheral::run));
- printWaitAbortKeyPress(120, "Wait after BLE dispatch\r\n");
- int start = Kernel::get_ms_count();
- network = WiFiInterface::get_default_instance();
- if (!network) {
- dbg_printf(LOG, "ERROR: No WiFiInterface found.\n");
- }
- printWaitAbortKeyPress(120, "Wait after WiFi instantiation\r\n");
+}
+
+void stop_BLE()
+{
+ delete peripheral;
+}
+
+void start_WiFi()
+{
wiFiManager = new WiFiManager(wifi_config, network,
eventQueue_wifi,
&aT2WiFimPool, &aT2WiFiCmdQueue,
@@ -266,6 +259,60 @@
initialise_debug(NONE);
// dispatch wifi event queue on event thread
wifi_evt_thread.start(callback(&eventQueue_wifi, &EventQueue::dispatch_forever));
+}
+
+void stop_WiFi()
+{
+ delete network;
+}
+
+
+void trigger_start_BLE()
+{
+ mainLoop = START_BLE;
+}
+
+
+void trigger_stop_BLE()
+{
+ mainLoop = STOP_BLE;
+}
+
+
+void trigger_start_WiFi()
+{
+ mainLoop = START_WIFI;
+}
+
+
+void trigger_stop_WiFi()
+{
+ mainLoop = STOP_WIFI;
+}
+
+
+
+
+#define PAUSE_SECONDS 0
+#define PAUSE_SECONDS_BLE 0
+int main() {
+ device = new RawSerial(USBTX, USBRX, 2*DEFAULT_BAUD_RATE);
+ uint8_t debug_level = (LOG | ERR | TXT | DBG);
+ initialise_debug(debug_level);
+#ifdef MBED_MAJOR_VERSION
+ dbg_printf(LOG, "Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
+#endif
+
+ reset_counter++;
+ dbg_printf(LOG, "\r\n ++++++ PROGRAM STARTING -- reset count = %d ++++++ \r\n", reset_counter);
+ setupDefaultWiFiConfig();
+ setupDefaultBleConfig();
+ //btle_thread.start(callback(peripheral, &SMDevicePeripheral::run));
+ start_BLE();
+ printWaitAbortKeyPress(120, "Wait after BLE dispatch\r\n");
+ int start = Kernel::get_ms_count();
+ start_WiFi();
+ printWaitAbortKeyPress(120, "Wait after WiFi instantiation\r\n");
// dispatch atcmd event queue on event thread
atcmd_evt_thread.start(callback(&eventQueue_atcmd, &EventQueue::dispatch_forever));
dbg_printf(LOG, "\r\n++++++ Starting ATCmdmanager ++++++ \r\n");
@@ -281,6 +328,30 @@
print_memory_info();
while(1)
{
+ switch(mainLoop)
+ {
+ case MAIN_IDLE:
+ break;
+ case START_BLE:
+ start_BLE();
+ mainLoop = MAIN_IDLE;
+ break;
+ case START_WIFI:
+ start_WiFi();
+ mainLoop = MAIN_IDLE;
+ break;
+ case STOP_BLE:
+ stop_BLE();
+ mainLoop = MAIN_IDLE;
+ break;
+ case STOP_WIFI:
+ stop_WiFi();
+ mainLoop = MAIN_IDLE;
+ break;
+ default:
+ mainLoop = MAIN_IDLE;
+ break;
+ }
wait(0.1);
}
}