Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update key mappings data in EEPROM for encoders at flashing key mappings #743

Merged
merged 1 commit into from
Sep 29, 2022
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
46 changes: 45 additions & 1 deletion src/actions/hid.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export const hidActionsThunk = {
console.error(result.cause);
dispatch(
NotificationActions.addError(
`Flush error: [${pos}] ${result.error!}`,
`Flash error: [${pos}] ${result.error!}`,
result.cause
)
);
Expand All @@ -490,6 +490,50 @@ export const hidActionsThunk = {
return;
}
}
if (0x0a <= entities.device.viaProtocolVersion) {
const encodersRemaps = app.encodersRemaps;
for (let layer = 0; layer < encodersRemaps.length; layer++) {
const encodersRemap = encodersRemaps[layer];
for (const encoderIdString of Object.keys(encodersRemap)) {
const encoderId = Number(encoderIdString);
const encoderKeymap = encodersRemap[encoderId];
let result = await keyboard.updateEncoderKeymap(
layer,
encoderId,
true,
encoderKeymap.clockwise.code
);
if (!result.success) {
console.error(result.cause);
dispatch(
NotificationActions.addError(
`Flash error: [${encoderId}-clockwise] ${result.error!}`,
result.cause
)
);
dispatch(HeaderActions.updateFlashing(false));
return;
}
result = await keyboard.updateEncoderKeymap(
layer,
encoderId,
false,
encoderKeymap.counterclockwise.code
);
if (!result.success) {
console.error(result.cause);
dispatch(
NotificationActions.addError(
`Flash error: [${encoderId}-counterclockwise] ${result.error!}`,
result.cause
)
);
dispatch(HeaderActions.updateFlashing(false));
return;
}
}
}
}
const keymaps: IKeymaps[] = await loadKeymap(
dispatch,
keyboard,
Expand Down
10 changes: 10 additions & 0 deletions src/services/hid/Hid.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ export const mockIKeyboad: IKeyboard = {
resolve({ success: true });
});
},
updateEncoderKeymap(
layer: number,
encoderId: number,
clockwise: boolean,
code: number
): Promise<IResult> {
return new Promise((resolve) => {
resolve({ success: true });
});
},
fetchBacklightBrightness: () => {
return new Promise((resolve) => {
resolve({ success: true, brightness: 100 });
Expand Down
6 changes: 6 additions & 0 deletions src/services/hid/Hid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ export interface IKeyboard {
column: number,
code: number
): Promise<IResult>;
updateEncoderKeymap(
layer: number,
encoderId: number,
clockwise: boolean,
code: number
): Promise<IResult>;
fetchBacklightBrightness(): Promise<IFetchBrightnessResult>;
fetchBacklightEffect(): Promise<IFetchBacklightEffectResult>;
fetchRGBLightBrightness(): Promise<IFetchBrightnessResult>;
Expand Down
33 changes: 33 additions & 0 deletions src/services/hid/WebHid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
DynamicKeymapMacroSetBufferCommand,
DynamicKeymapReadBufferCommand,
DynamicKeymapResetCommand,
DynamicKeymapSetEncoderCommand,
DynamicKeymapSetKeycodeCommand,
GetLayoutOptionsCommand,
GetProtocolVersionCommand,
Expand Down Expand Up @@ -398,6 +399,38 @@ export class Keyboard implements IKeyboard {
});
}

updateEncoderKeymap(
layer: number,
encoderId: number,
clockwise: boolean,
code: number
): Promise<IResult> {
return new Promise<IResult>((resolve) => {
const command = new DynamicKeymapSetEncoderCommand(
{
layer,
encoderId,
clockwise,
code,
},
async (result) => {
if (result.success) {
resolve({
success: true,
});
} else {
resolve({
success: false,
error: result.error,
cause: result.cause,
});
}
}
);
return this.enqueue(command);
});
}

fetchBacklightBrightness(): Promise<IFetchBrightnessResult> {
return new Promise<IFetchBrightnessResult>((resolve) => {
const command = new LightingGetValueCommand(
Expand Down