Beispiel #1
0
/**
 * Wraps the actual implementation, which has to return a value as part of the threaded implementation.
 */
int system_sleep_pin(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds, uint32_t param, void* reserved)
{
    // Cancel current connection attempt to unblock the system thread
    network_connect_cancel(0, 1, 0, 0);
    InterruptMode m = (InterruptMode)edgeTriggerMode;
    return system_sleep_pin_impl(&wakeUpPin, 1, &m, 1, seconds, param, reserved);
}
Beispiel #2
0
int system_sleep_pin_impl(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds, uint32_t param, void* reserved)
{
    SYSTEM_THREAD_CONTEXT_SYNC(system_sleep_pin_impl(wakeUpPin, edgeTriggerMode, seconds, param, reserved));
    // If we're connected to the cloud, make sure all
    // confirmable UDP messages are sent before sleeping
    if (spark_cloud_flag_connected()) {
        Spark_Sleep();
    }

    bool network_sleep = network_sleep_flag(param);
    if (network_sleep)
    {
        network_suspend();
    }
    LED_Off(LED_RGB);
    HAL_Core_Enter_Stop_Mode(wakeUpPin, edgeTriggerMode, seconds);
    if (network_sleep)
    {
        network_resume();   // asynchronously bring up the network/cloud
    }
    // if single-threaded, managed mode then reconnect to the cloud (for up to 60 seconds)
    auto mode = system_mode();
    if (system_thread_get_state(nullptr)==spark::feature::DISABLED && (mode==AUTOMATIC || mode==SEMI_AUTOMATIC) && spark_cloud_flag_auto_connect()) {
        waitFor(spark_cloud_flag_connected, 60000);
    }

    if (spark_cloud_flag_connected()) {
        Spark_Wake();
    }
    return 0;
}
Beispiel #3
0
int system_sleep_pins(const uint16_t* pins, size_t pins_count, const InterruptMode* modes, size_t modes_count, long seconds, uint32_t param, void* reserved)
{
    network_connect_cancel(0, 1, 0, 0);
    return system_sleep_pin_impl(pins, pins_count, modes, modes_count, seconds, param, reserved);
}
Beispiel #4
0
int system_sleep_pin_impl(const uint16_t* pins, size_t pins_count, const InterruptMode* modes, size_t modes_count, long seconds, uint32_t param, void* reserved)
{
    SYSTEM_THREAD_CONTEXT_SYNC(system_sleep_pin_impl(pins, pins_count, modes, modes_count, seconds, param, reserved));
    // If we're connected to the cloud, make sure all
    // confirmable UDP messages are sent before sleeping
    if (spark_cloud_flag_connected()) {
        Spark_Sleep();
    }

    bool network_sleep = network_sleep_flag(param);
    if (network_sleep)
    {
        network_suspend();
    }

#if HAL_PLATFORM_CELLULAR
    if (!network_sleep_flag(param)) {
        // Pause the modem Serial
        cellular_pause(nullptr);
    }
#endif // HAL_PLATFORM_CELLULAR

#if HAL_PLATFORM_MESH
    // FIXME: We are still going to turn off OpenThread with SLEEP_NETWORK_STANDBY, otherwise
    // there are various issues with sleep
    if (!network_sleep_flag(param)) {
        network_off(NETWORK_INTERFACE_MESH, 0, 0, nullptr);
    }
#endif // HAL_PLATFORM_MESH

    led_set_update_enabled(0, nullptr); // Disable background LED updates
    LED_Off(LED_RGB);
	system_power_management_sleep();
    int ret = HAL_Core_Enter_Stop_Mode_Ext(pins, pins_count, modes, modes_count, seconds, nullptr);
    led_set_update_enabled(1, nullptr); // Enable background LED updates

#if HAL_PLATFORM_CELLULAR
    if (!network_sleep_flag(param)) {
        // Pause the modem Serial
        cellular_resume(nullptr);
    }
#endif // HAL_PLATFORM_CELLULAR

#if HAL_PLATFORM_MESH
    // FIXME: we need to bring Mesh interface back up because we've turned it off
    // despite SLEEP_NETWORK_STANDBY
    if (!network_sleep_flag(param)) {
        network_on(NETWORK_INTERFACE_MESH, 0, 0, nullptr);
    }
#endif // HAL_PLATFORM_MESH

    if (network_sleep)
    {
        network_resume();   // asynchronously bring up the network/cloud
    }

    // if single-threaded, managed mode then reconnect to the cloud (for up to 60 seconds)
    auto mode = system_mode();
    if (system_thread_get_state(nullptr)==spark::feature::DISABLED && (mode==AUTOMATIC || mode==SEMI_AUTOMATIC) && spark_cloud_flag_auto_connect()) {
        waitFor(spark_cloud_flag_connected, 60000);
    }

    if (spark_cloud_flag_connected()) {
        Spark_Wake();
    }
    return ret;
}
Beispiel #5
0
/**
 * Wraps the actual implementation, which has to return a value as part of the threaded implementation.
 */
void system_sleep_pin(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds, uint32_t param, void* reserved)
{
    system_sleep_pin_impl(wakeUpPin, edgeTriggerMode, seconds, param, reserved);
}