Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Migrate to new keyid mappings. #259

Merged
merged 6 commits into from
Oct 18, 2024
Merged
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
11 changes: 9 additions & 2 deletions device/src/keyboard/key_scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "oled/oled_buffer.h"
#include "logger.h"
#include "key_states.h"
#include "keyboard/key_layout.h"
#include "bool_array_converter.h"
#include "legacy/module.h"
#include "logger.h"
Expand All @@ -21,6 +20,8 @@
#include "legacy/config_manager.h"
#include "legacy/macros/keyid_parser.h"
#include "attributes.h"
#include "legacy/layouts/key_layout.h"
#include "legacy/layouts/key_layout_80_to_universal.h"

// Thread definitions

Expand Down Expand Up @@ -113,7 +114,13 @@ static void scanKeys() {
for (uint8_t rowId=0; rowId<KEY_MATRIX_ROWS; rowId++) {
for (uint8_t colId=0; colId<KEY_MATRIX_COLS; colId++) {
uint8_t sourceIndex = rowId*KEY_MATRIX_COLS + colId;
uint8_t targetKeyId = KeyLayout_Uhk80_to_Uhk60[slotId][sourceIndex];
uint8_t targetKeyId;

if (DataModelVersion.major >= 8) {
targetKeyId = KeyLayout_Uhk80_to_Universal[slotId][sourceIndex];
} else {
targetKeyId = KeyLayout_Uhk80_to_Uhk60[slotId][sourceIndex];
}

if (targetKeyId < MAX_KEY_COUNT_PER_MODULE) {
if (currentBacklightingMode == BacklightingMode_LedTest) {
Expand Down
1 change: 1 addition & 0 deletions device/src/legacy/layouts/key_layout.c
1 change: 1 addition & 0 deletions device/src/legacy/layouts/key_layout.h
1 change: 1 addition & 0 deletions device/src/legacy/layouts/key_layout_60_to_universal.c
1 change: 1 addition & 0 deletions device/src/legacy/layouts/key_layout_60_to_universal.h
1 change: 1 addition & 0 deletions device/src/legacy/layouts/key_layout_80_to_universal.c
1 change: 1 addition & 0 deletions device/src/legacy/layouts/key_layout_80_to_universal.h
15 changes: 15 additions & 0 deletions device/src/state_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ static state_sync_prop_t stateSyncProps[StateSyncPropertyId_Count] = {
SIMPLE(MergeSensor, SyncDirection_LeftToRight, DirtyState_Clean, &MergeSensor_HalvesAreMerged),
SIMPLE(FunctionalColors, SyncDirection_RightToLeft, DirtyState_Clean, &Cfg.KeyActionColors),
SIMPLE(PowerMode, SyncDirection_RightToLeft, DirtyState_Clean, &CurrentPowerMode),
CUSTOM(Config, SyncDirection_RightToLeft, DirtyState_Clean),
};

static void invalidateProperty(state_sync_prop_id_t propId) {
Expand Down Expand Up @@ -332,6 +333,12 @@ static void receiveProperty(device_id_t src, state_sync_prop_id_t propId, const
EventVector_Set(EventVector_LedMapUpdateNeeded);
}
break;
case StateSyncPropertyId_Config:
if (!isLocalUpdate) {
sync_command_config_t* buffer = (sync_command_config_t*)data;
DataModelVersion = buffer->dataModelVersion;
}
break;
case StateSyncPropertyId_MergeSensor:
break;
default:
Expand Down Expand Up @@ -469,6 +476,12 @@ static void prepareData(device_id_t dst, const uint8_t *propDataPtr, state_sync_
submitPreparedData(dst, propId, (const uint8_t *)&buffer, sizeof(buffer));
return;
} break;
case StateSyncPropertyId_Config: {
sync_command_config_t buffer;
buffer.dataModelVersion = DataModelVersion;
submitPreparedData(dst, propId, (const uint8_t *)&buffer, sizeof(buffer));
return;
} break;
default:
break;
}
Expand Down Expand Up @@ -511,6 +524,7 @@ static void updateProperty(state_sync_prop_id_t propId) {

static bool handlePropertyUpdateRightToLeft() {
UPDATE_AND_RETURN_IF_DIRTY(StateSyncPropertyId_ResetRightLeftLink);
UPDATE_AND_RETURN_IF_DIRTY(StateSyncPropertyId_Config);

if (KeyBacklightBrightness != 0 && Cfg.BacklightingMode != BacklightingMode_ConstantRGB) {
// Update relevant data
Expand Down Expand Up @@ -642,6 +656,7 @@ void StateSync_ResetRightLeftLink(bool bidirectional) {
invalidateProperty(StateSyncPropertyId_ResetRightLeftLink);
}
if (DEVICE_ID == DeviceId_Uhk80_Right) {
invalidateProperty(StateSyncPropertyId_Config);
state_sync_prop_id_t first = StateSyncPropertyId_LayerActionFirst;
state_sync_prop_id_t last = StateSyncPropertyId_LayerActionLast;
for (state_sync_prop_id_t propId = first; propId <= last; propId++) {
Expand Down
5 changes: 5 additions & 0 deletions device/src/state_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
char firmwareChecksum[MD5_CHECKSUM_LENGTH];
} ATTR_PACKED sync_command_module_state_t;

typedef struct {
version_t dataModelVersion;
} sync_command_config_t;

// Draft for generic properties
typedef enum {
StateSyncPropertyId_LayerActionsLayer1 = 1,
Expand Down Expand Up @@ -89,6 +93,7 @@
StateSyncPropertyId_MergeSensor,
StateSyncPropertyId_FunctionalColors,
StateSyncPropertyId_PowerMode,
StateSyncPropertyId_Config,
StateSyncPropertyId_Count,
} state_sync_prop_id_t;

Expand Down
Loading