From 923b1db9db2b78ced1e86d365b892e9f040412f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Tu=C4=8Dek?= Date: Wed, 11 Dec 2024 12:56:08 +0100 Subject: [PATCH 1/3] Turn off all led slots again when the light all mode is exited --- right/src/ledmap.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/right/src/ledmap.c b/right/src/ledmap.c index 451a36101..ccac4f47f 100644 --- a/right/src/ledmap.c +++ b/right/src/ledmap.c @@ -576,6 +576,22 @@ static void updateLedsByPerKeyKeyStragegy() { } } +static void setEntireMatrix(uint8_t v) { +#ifdef __ZEPHYR__ +#if DEVICE_IS_UHK80_LEFT || DEVICE_IS_UHK80_RIGHT + for (uint8_t i = 0; i < UHK80_LED_DRIVER_LED_COUNT_MAX; i++) { + Uhk80LedDriverValues[i] = 255; + } +#endif +#else + for (uint8_t slotId=0; slotId Date: Wed, 11 Dec 2024 16:49:00 +0100 Subject: [PATCH 2/3] Fix a typo. --- right/src/ledmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/right/src/ledmap.c b/right/src/ledmap.c index ccac4f47f..c16b1cafc 100644 --- a/right/src/ledmap.c +++ b/right/src/ledmap.c @@ -580,13 +580,13 @@ static void setEntireMatrix(uint8_t v) { #ifdef __ZEPHYR__ #if DEVICE_IS_UHK80_LEFT || DEVICE_IS_UHK80_RIGHT for (uint8_t i = 0; i < UHK80_LED_DRIVER_LED_COUNT_MAX; i++) { - Uhk80LedDriverValues[i] = 255; + Uhk80LedDriverValues[i] = v; } #endif #else for (uint8_t slotId=0; slotId Date: Wed, 11 Dec 2024 17:11:17 +0100 Subject: [PATCH 3/3] Refactor always on backlight modes. --- doc-dev/reference-manual.md | 1 + right/src/config_manager.c | 1 + right/src/config_manager.h | 1 + right/src/config_parser/parse_config.c | 1 - right/src/led_manager.c | 12 ++++++++---- right/src/ledmap.c | 9 +++++++++ right/src/ledmap.h | 1 + right/src/macros/set_command.c | 5 ++++- right/src/usb_commands/usb_command_apply_config.c | 3 --- 9 files changed, 25 insertions(+), 9 deletions(-) diff --git a/doc-dev/reference-manual.md b/doc-dev/reference-manual.md index 5c79c0b7e..79ba37f25 100644 --- a/doc-dev/reference-manual.md +++ b/doc-dev/reference-manual.md @@ -276,6 +276,7 @@ COMMAND = clearStatus COMMAND = set setEmergencyKey KEYID COMMAND = validateUserConfig COMMAND = resetConfiguration +COMMAND = set leds.alwaysOn BOOL ############## # DEPRECATED # ############## diff --git a/right/src/config_manager.c b/right/src/config_manager.c index b57243b08..4c7fa7856 100644 --- a/right/src/config_manager.c +++ b/right/src/config_manager.c @@ -235,6 +235,7 @@ const config_t DefaultCfg = (config_t){ .KeyBacklightFadeOutTimeout = 0, .KeyBacklightFadeOutBatteryTimeout = 60000, .LedsEnabled = true, + .LedsAlwaysOn = false, .LedBrightnessMultiplier = 1.0f, .LayerConfig = { { .layerIsDefined = true, .exactModifierMatch = false, .modifierLayerMask = 0}, diff --git a/right/src/config_manager.h b/right/src/config_manager.h index 9e11ebbff..de63a339a 100644 --- a/right/src/config_manager.h +++ b/right/src/config_manager.h @@ -65,6 +65,7 @@ uint32_t KeyBacklightFadeOutBatteryTimeout; bool LedsEnabled; + bool LedsAlwaysOn; // layers layer_config_t LayerConfig[LayerId_Count]; diff --git a/right/src/config_parser/parse_config.c b/right/src/config_parser/parse_config.c index 692fa768f..6fa61df7e 100644 --- a/right/src/config_parser/parse_config.c +++ b/right/src/config_parser/parse_config.c @@ -327,7 +327,6 @@ parser_error_t parseConfig(config_buffer_t *buffer) Cfg.KeyBacklightFadeOutTimeout = keyBacklightFadeOutTimeout; Cfg.KeyBacklightFadeOutBatteryTimeout = keyBacklightFadeOutBatteryTimeout; - AlwaysOnMode = false; LedManager_RecalculateLedBrightness(); LedManager_UpdateSleepModes(); BtPair_ClearUnknownBonds(); diff --git a/right/src/led_manager.c b/right/src/led_manager.c index cfd5016cc..0f286c089 100644 --- a/right/src/led_manager.c +++ b/right/src/led_manager.c @@ -1,5 +1,6 @@ #include "led_manager.h" #include "event_scheduler.h" +#include "ledmap.h" #include "usb_composite_device.h" #include "config_manager.h" #include "stubs.h" @@ -23,25 +24,28 @@ bool DisplaySleepModeActive = false; uint8_t DisplayBrightness = 0xff; uint8_t KeyBacklightBrightness = 0xff; -bool AlwaysOnMode = false; - static void recalculateLedBrightness() { bool globalSleepMode = !Cfg.LedsEnabled || CurrentPowerMode > PowerMode_Awake || Cfg.LedBrightnessMultiplier == 0.0f; + bool globalAlwaysOn = Cfg.LedsAlwaysOn || Ledmap_AlwaysOn; - if (!AlwaysOnMode && (globalSleepMode || KeyBacklightSleepModeActive)) { + if (!globalAlwaysOn && (globalSleepMode || KeyBacklightSleepModeActive)) { KeyBacklightBrightness = 0; } else { uint8_t keyBacklightBrightnessBase = RunningOnBattery ? Cfg.KeyBacklightBrightnessBatteryDefault : Cfg.KeyBacklightBrightnessDefault; KeyBacklightBrightness = MIN(255, keyBacklightBrightnessBase * Cfg.LedBrightnessMultiplier); } - if (!AlwaysOnMode && (globalSleepMode || DisplaySleepModeActive)) { + if (!globalAlwaysOn && (globalSleepMode || DisplaySleepModeActive)) { DisplayBrightness = 0; } else { uint8_t displayBrightnessBase = RunningOnBattery ? Cfg.DisplayBrightnessBatteryDefault : Cfg.DisplayBrightnessDefault; DisplayBrightness = MIN(255, displayBrightnessBase * Cfg.LedBrightnessMultiplier); } + + if (Ledmap_AlwaysOn) { + KeyBacklightBrightness = 255; + } } void LedManager_FullUpdate() diff --git a/right/src/ledmap.c b/right/src/ledmap.c index c16b1cafc..deb1eac74 100644 --- a/right/src/ledmap.c +++ b/right/src/ledmap.c @@ -3,6 +3,7 @@ #include "layer.h" #include "layer_switcher.h" #include "ledmap.h" +#include "led_manager.h" #include "slave_drivers/is31fl3xxx_driver.h" #include "config_parser/config_globals.h" #include "debug.h" @@ -25,6 +26,7 @@ static const rgb_t black = RGB(0x00, 0x00, 0x00); static const rgb_t white = RGB(0xff, 0xff, 0xff); +bool Ledmap_AlwaysOn = false; backlighting_mode_t TemporaryBacklightingMode = BacklightingMode_Unspecified; typedef enum { @@ -743,8 +745,14 @@ void Ledmap_InitLedLayout(void) { #endif } +static void updateAlwaysOn() { + backlighting_mode_t mode = Ledmap_GetEffectiveBacklightMode(); + Ledmap_AlwaysOn = mode == BacklightingMode_LightAll || mode == BacklightingMode_LedTest; +} + void Ledmap_SetTemporaryLedBacklightingMode(backlighting_mode_t newMode) { TemporaryBacklightingMode = newMode; + updateAlwaysOn(); #ifdef __ZEPHYR__ StateSync_UpdateProperty(StateSyncPropertyId_Backlight, NULL); #endif @@ -760,6 +768,7 @@ void Ledmap_ResetTemporaryLedBacklightingMode() { void Ledmap_SetLedBacklightingMode(backlighting_mode_t newMode) { Cfg.BacklightingMode = newMode; + updateAlwaysOn(); #ifdef __ZEPHYR__ StateSync_UpdateProperty(StateSyncPropertyId_Backlight, NULL); #endif diff --git a/right/src/ledmap.h b/right/src/ledmap.h index 046f23ae4..3797096a0 100644 --- a/right/src/ledmap.h +++ b/right/src/ledmap.h @@ -43,6 +43,7 @@ // Variables: extern bool Ledmap_LedTestActive; + extern bool Ledmap_AlwaysOn; // Functions: diff --git a/right/src/macros/set_command.c b/right/src/macros/set_command.c index aaac9803b..2b790bf4d 100644 --- a/right/src/macros/set_command.c +++ b/right/src/macros/set_command.c @@ -568,7 +568,10 @@ static macro_variable_t leds(parser_context_t* ctx, set_command_action_t action) ASSIGN_FLOAT(Cfg.LedBrightnessMultiplier); } else if (ConsumeToken(ctx, "enabled")) { ASSIGN_BOOL(Cfg.LedsEnabled); - } else { + } else if (ConsumeToken(ctx, "alwaysOn")) { + ASSIGN_BOOL(Cfg.LedsAlwaysOn); + } + else { Macros_ReportError("Parameter not recognized:", ctx->at, ctx->end); } diff --git a/right/src/usb_commands/usb_command_apply_config.c b/right/src/usb_commands/usb_command_apply_config.c index a60b97b94..457f91508 100644 --- a/right/src/usb_commands/usb_command_apply_config.c +++ b/right/src/usb_commands/usb_command_apply_config.c @@ -49,9 +49,6 @@ void UsbCommand_ApplyConfigAsync(void) { static void setLedsWhite() { // Set the led test backlight mode, but don't activate the switch test mode. Ledmap_SetLedBacklightingMode(BacklightingMode_LightAll); - AlwaysOnMode = true; - Cfg.KeyBacklightBrightnessDefault = 255; - Cfg.KeyBacklightBrightnessBatteryDefault = 255; EventVector_Set(EventVector_LedMapUpdateNeeded); }