Example #1
0
int system_sleep_impl(Spark_Sleep_TypeDef sleepMode, long seconds, uint32_t param, void* reserved)
{
    SYSTEM_THREAD_CONTEXT_SYNC(system_sleep_impl(sleepMode, seconds, param, reserved));
    // TODO - determine if these are valuable:
    // - Currently publishes will get through with or without #1.
    // - More data is consumed with #1.
    // - Session is not resuming after waking from DEEP sleep,
    //   so a full handshake currently outweighs leaving the
    //   modem on for #2.
    //
    //---- #1
    // If we're connected to the cloud, make sure all
    // confirmable UDP messages are sent before sleeping
    // if (spark_cloud_flag_connected()) {
    //     Spark_Sleep();
    // }
    //---- #2
    // SLEEP_NETWORK_STANDBY can keep the modem on during DEEP sleep
    // System.sleep(10) always powers down the network, even if SLEEP_NETWORK_STANDBY flag is used.
    if (network_sleep_flag(param) || SLEEP_MODE_WLAN == sleepMode) {
        network_suspend();
    }

    switch (sleepMode)
    {
        case SLEEP_MODE_WLAN:
            if (seconds)
            {
                HAL_RTC_Set_UnixAlarm((time_t) seconds);
            }
            break;

        case SLEEP_MODE_DEEP:
            if (network_sleep_flag(param))
            {
                network_disconnect(0, NETWORK_DISCONNECT_REASON_SLEEP, NULL);
                network_off(0, 0, 0, NULL);
            }

            system_power_management_sleep();
            return HAL_Core_Enter_Standby_Mode(seconds,
                    (param & SLEEP_DISABLE_WKP_PIN.value()) ? HAL_STANDBY_MODE_FLAG_DISABLE_WKP_PIN : 0);
            break;

#if Wiring_SetupButtonUX
        case SLEEP_MODE_SOFTPOWEROFF:
            network_disconnect(0, NETWORK_DISCONNECT_REASON_SLEEP, NULL);
            network_off(0, 0, 0, NULL);
            sleep_fuel_gauge();
            system_power_management_sleep();
            return HAL_Core_Enter_Standby_Mode(seconds,
                    (param & SLEEP_DISABLE_WKP_PIN.value()) ? HAL_STANDBY_MODE_FLAG_DISABLE_WKP_PIN : 0);
            break;
#endif
    }
    return 0;
}
Example #2
0
void system_sleep(Spark_Sleep_TypeDef sleepMode, long seconds, uint32_t param, void* reserved)
{
    // TODO - determine if these are valuable:
    // - Currently publishes will get through with or without #1.
    // - More data is consumed with #1.
    // - Session is not resuming after waking from DEEP sleep,
    //   so a full handshake currently outweighs leaving the
    //   modem on for #2.
    //
    //---- #1
    // If we're connected to the cloud, make sure all
    // confirmable UDP messages are sent before sleeping
    // if (spark_cloud_flag_connected()) {
    //     Spark_Sleep();
    // }
    //---- #2
    // SLEEP_NETWORK_STANDBY can keep the modem on during DEEP sleep
    // System.sleep(10) always powers down the network, even if SLEEP_NETWORK_STANDBY flag is used.
    if (network_sleep_flag(param) || SLEEP_MODE_WLAN == sleepMode) {
        network_suspend();
    }

    switch (sleepMode)
    {
        case SLEEP_MODE_WLAN:
            break;

        case SLEEP_MODE_DEEP:
            if (network_sleep_flag(param))
            {
                network_disconnect(0, 0, NULL);
                network_off(0, 0, 0, NULL);
            }
            HAL_Core_Enter_Standby_Mode(seconds, nullptr);
            break;

#if Wiring_SetupButtonUX
        case SLEEP_MODE_SOFTPOWEROFF:
            network_disconnect(0,0,NULL);
            network_off(0, 0, 0, NULL);
            sleep_fuel_gauge();
            HAL_Core_Enter_Standby_Mode(seconds, nullptr);
            break;
#endif
    }
}