diff --git a/src/kaleidoscope/plugin/IdleLEDsDefy.cpp b/src/kaleidoscope/plugin/IdleLEDsDefy.cpp index 8cdeead..74afdf8 100644 --- a/src/kaleidoscope/plugin/IdleLEDsDefy.cpp +++ b/src/kaleidoscope/plugin/IdleLEDsDefy.cpp @@ -31,11 +31,13 @@ namespace kaleidoscope namespace plugin { +//Deep sleep flag bool IdleLEDsDefy::sleep_ = false; IdleLEDsDefy::IdleTime IdleLEDsDefy::Power_save; uint32_t IdleLEDsDefy::start_time_wired = 0; uint32_t IdleLEDsDefy::start_time_wireless = 0; uint32_t IdleLEDsDefy::start_time_true_sleep = 0; +uint32_t IdleLEDsDefy::start_time_true_sleep_wired = 0; bool IdleLEDsDefy::idle_ = false; // Initialize with false uint32_t IdleLEDsDefy::ms_to_seconds(uint32_t time_in_ms) @@ -62,8 +64,20 @@ EventHandlerResult IdleLEDsDefy::beforeEachCycle() Runtime.hasTimeExpired(start_time_wired, Power_save.leds_off_usb_idle_t_ms)) { ::LEDControl.disable(); + start_time_true_sleep_wired = Runtime.millisAtCycleStart(); + sleep_ = false; idle_ = true; } + + if (!::LEDControl.isEnabled() && + !sleep_ && + Runtime.hasTimeExpired(start_time_true_sleep_wired, Power_save.sides_sleep_idle_wired_t_ms)) + { + Communications_protocol::Packet p{}; + p.header.command = Communications_protocol::SLEEP; + Communications.sendPacket(p); + sleep_ = true; + } } else { @@ -105,6 +119,7 @@ EventHandlerResult IdleLEDsDefy::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a start_time_wired = Runtime.millisAtCycleStart(); start_time_wireless = Runtime.millisAtCycleStart(); start_time_true_sleep = Runtime.millisAtCycleStart(); + start_time_true_sleep_wired = Runtime.millisAtCycleStart(); sleep_ = false; return EventHandlerResult::OK; } @@ -136,6 +151,8 @@ EventHandlerResult PersistentIdleDefyLEDs::onSetup() save_power_save_settings(idle_time); Runtime.storage().get(settings_base_, Power_save); + Power_save.sides_sleep_idle_wired_t_ms = sides_sleep_idle_wired_t_ms_default; // Default value for wired mode 20 minutes. + return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/IdleLEDsDefy.h b/src/kaleidoscope/plugin/IdleLEDsDefy.h index 1f8453f..aeb09f2 100644 --- a/src/kaleidoscope/plugin/IdleLEDsDefy.h +++ b/src/kaleidoscope/plugin/IdleLEDsDefy.h @@ -37,13 +37,15 @@ class IdleLEDsDefy : public kaleidoscope::Plugin uint32_t sides_sleep_idle_t_ms; // Timeout to put to sleep the keyboard sides [ms]. uint32_t leds_off_usb_idle_t_ms; // Power off time for LEDs, when the n2 is in USB mode [ms]. uint32_t leds_off_ble_idle_t_ms; // Power off time for LEDs, when the n2 is in BLE mode [ms]. + uint32_t sides_sleep_idle_wired_t_ms; // Timeout to put to sleep the keyboard sides when wired [ms]. }; static IdleTime Power_save; static constexpr const uint32_t leds_off_usb_idle_t_ms_default = 600000; // 600.000 ms = 10 minutes static constexpr const uint32_t leds_off_ble_idle_t_ms_default = 300000; // 300.000 ms = 5 minutes static constexpr const uint32_t sides_sleep_idle_t_ms_default = 60000; // 60.000 ms = 1 minutes - + static constexpr const uint32_t sides_sleep_idle_wired_t_ms_default = 18000000; // 1.800.000 ms = 30 minutes + static void save_power_save_settings(const IdleTime& data); static uint32_t ms_to_seconds(uint32_t time_in_ms); @@ -57,6 +59,7 @@ class IdleLEDsDefy : public kaleidoscope::Plugin static uint32_t start_time_wired; static uint32_t start_time_wireless; static uint32_t start_time_true_sleep; + static uint32_t start_time_true_sleep_wired; static bool sleep_; };