Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion device/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ int main(void) {
}

if (DEVICE_IS_UHK80_LEFT || DEVICE_IS_UHK80_RIGHT) {
ConfigManager_ResetConfiguration(false);
Ledmap_InitLedLayout();
}

Expand All @@ -148,6 +147,10 @@ int main(void) {
Macros_Initialize();
}

if (DEVICE_IS_UHK80_LEFT) {
UsbCommand_ApplyFactory();
}

USB_EnableHid(); // has to be after USB_SetSerialNumber

bt_enable(NULL);
Expand Down
1 change: 1 addition & 0 deletions right/src/config_parser/parse_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ parser_error_t parseConfig(config_buffer_t *buffer)
Cfg.KeyBacklightFadeOutTimeout = keyBacklightFadeOutTimeout;
Cfg.KeyBacklightFadeOutBatteryTimeout = keyBacklightFadeOutBatteryTimeout;

AlwaysOnMode = false;
LedManager_RecalculateLedBrightness();
LedManager_UpdateSleepModes();
BtPair_ClearUnknownBonds();
Expand Down
6 changes: 4 additions & 2 deletions right/src/led_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,20 @@ 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;

if (globalSleepMode || KeyBacklightSleepModeActive) {
if (!AlwaysOnMode && (globalSleepMode || KeyBacklightSleepModeActive)) {
KeyBacklightBrightness = 0;
} else {
uint8_t keyBacklightBrightnessBase = RunningOnBattery ? Cfg.KeyBacklightBrightnessBatteryDefault : Cfg.KeyBacklightBrightnessDefault;
KeyBacklightBrightness = MIN(255, keyBacklightBrightnessBase * Cfg.LedBrightnessMultiplier);
}

if (globalSleepMode || DisplaySleepModeActive) {
if (!AlwaysOnMode && (globalSleepMode || DisplaySleepModeActive)) {
DisplayBrightness = 0;
} else {
uint8_t displayBrightnessBase = RunningOnBattery ? Cfg.DisplayBrightnessBatteryDefault : Cfg.DisplayBrightnessDefault;
Expand Down
2 changes: 2 additions & 0 deletions right/src/led_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
extern bool KeyBacklightSleepModeActive;
extern bool DisplaySleepModeActive;

extern bool AlwaysOnMode;

// Functions:

void LedManager_FullUpdate();
Expand Down
19 changes: 19 additions & 0 deletions right/src/ledmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,22 @@ static void updateLedsByLedTestStragegy() {
}
}

static void updateLedsByLightAllStragegy() {
#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<SLOT_COUNT; slotId++) {
for (uint8_t i=0; i<LED_DRIVER_LED_COUNT_MAX; i++) {
LedDriverValues[slotId][i] = 255;
}
}
#endif
}

void Ledmap_ActivateTestled(uint8_t slotId, uint8_t keyId) {
if (CurrentTime < backlightingLedTestStart + 1000) {
return;
Expand Down Expand Up @@ -661,6 +677,9 @@ void Ledmap_UpdateBacklightLeds(void) {
case BacklightingMode_LedTest:
updateLedsByLedTestStragegy();
break;
case BacklightingMode_LightAll:
updateLedsByLightAllStragegy();
break;
case BacklightingMode_Unspecified:
break;
}
Expand Down
1 change: 1 addition & 0 deletions right/src/ledmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
BacklightingMode_ConstantRGB,
BacklightingMode_Numpad,
BacklightingMode_LedTest,
BacklightingMode_LightAll,
BacklightingMode_Unspecified,
} backlighting_mode_t;

Expand Down
22 changes: 22 additions & 0 deletions right/src/usb_commands/usb_command_apply_config.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <string.h>
#include "ledmap.h"
#include "usb_commands/usb_command_apply_config.h"
#include "config_parser/config_globals.h"
#include "config_parser/parse_config.h"
Expand Down Expand Up @@ -45,6 +46,19 @@ 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);
}

static bool hwConfigEmpty() {
return HardwareConfig->majorVersion == 0 || HardwareConfig->majorVersion == 255;
}

void UsbCommand_ApplyFactory(void)
{
EventVector_Unset(EventVector_ApplyConfig);
Expand All @@ -55,6 +69,10 @@ void UsbCommand_ApplyFactory(void)

ConfigManager_ResetConfiguration(false);

if (hwConfigEmpty()) {
setLedsWhite();
}

#ifdef __ZEPHYR__
StateSync_ResetConfig();
StateSync_ResetRightLeftLink(true);
Expand Down Expand Up @@ -107,6 +125,10 @@ uint8_t UsbCommand_ApplyConfig(void)

MacroEvent_OnInit();

if (hwConfigEmpty()) {
setLedsWhite();
}

#ifdef __ZEPHYR__
StateSync_ResetConfig();
#endif
Expand Down
3 changes: 3 additions & 0 deletions shared/versioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
(((v).major > (MAJ)) || ((v).major == (MAJ) && (v).minor > (MIN)) || \
((v).major == (MAJ) && (v).minor == (MIN) && (v).patch >= (PATCH)))

#define VERSION_EQUAL(v, MAJ, MIN, PATCH) \
((v).major == (MAJ) && (v).minor == (MIN) && (v).patch == (PATCH))

// Typedefs:

typedef struct {
Expand Down