void set_system_mode(System_Mode_TypeDef mode) { // the SystemClass is constructed twice, // once for the `System` instance used by the system (to provide the System.xxx api) // and again for the SYSTEM_MODE() macro. The order of module initialization is // undefined in C++ so they may be initialized in any arbitrary order. // Meaning, the instance from SYSTEM_MODE() macro might be constructed first, // followed by the `System` instance, which sets the mode back to `AUTOMATIC`. // The DEFAULT mode prevents this. if (mode==DEFAULT) { // the default system instance if (current_mode==DEFAULT) // no mode set yet mode = AUTOMATIC; // set to automatic mode else return; // don't change the current mode when constructing the system instance and it's already set } current_mode = mode; switch (mode) { case DEFAULT: // DEFAULT can't happen in practice since it's cleared above. just keeps gcc happy. case SAFE_MODE: case AUTOMATIC: //spark_cloud_flag_connect(); //break; case MANUAL: case SEMI_AUTOMATIC: spark_cloud_flag_disconnect(); SPARK_WLAN_SLEEP = 1; break; } }
static void network_suspend() { // save the current state so it can be restored on wakeup wakeupState.wifi = !SPARK_WLAN_SLEEP; wakeupState.wifiConnected = wakeupState.cloud | network_ready(0, 0, NULL) | network_connecting(0, 0, NULL); #ifndef SPARK_NO_CLOUD wakeupState.cloud = spark_cloud_flag_auto_connect(); // disconnect the cloud now, and clear the auto connect status spark_cloud_socket_disconnect(); spark_cloud_flag_disconnect(); #endif network_off(0, 0, 0, NULL); }
static void network_suspend() { // save the current state so it can be restored on wakeup #ifndef SPARK_NO_CLOUD wakeupState.cloud = spark_cloud_flag_auto_connect(); #endif wakeupState.wifi = !SPARK_WLAN_SLEEP; wakeupState.wifiConnected = wakeupState.cloud || network_ready(0, 0, NULL) || network_connecting(0, 0, NULL); // Disconnect the cloud and the network network_disconnect(0, NETWORK_DISCONNECT_REASON_SLEEP, NULL); #ifndef SPARK_NO_CLOUD // Clear the auto connect status spark_cloud_flag_disconnect(); #endif network_off(0, 0, 0, NULL); }