Skip to content

Commit

Permalink
feat: enable deep sleep in wired mode.
Browse files Browse the repository at this point in the history
Signed-off-by: gonza2206 <[email protected]>
  • Loading branch information
gonza2206 committed Nov 7, 2024
1 parent 19b4608 commit a97da15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/kaleidoscope/plugin/IdleLEDsDefy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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_t_ms_default; // Default value for wired mode 10 minutes.

return EventHandlerResult::OK;
}

Expand Down
4 changes: 3 additions & 1 deletion src/kaleidoscope/plugin/IdleLEDsDefy.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ 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 void save_power_save_settings(const IdleTime& data);
static uint32_t ms_to_seconds(uint32_t time_in_ms);

Expand All @@ -57,6 +58,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_;
};

Expand Down

0 comments on commit a97da15

Please sign in to comment.