Skip to content

Commit

Permalink
[Temporary] Add a icon for encoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
yoichiro committed Sep 20, 2023
1 parent 8d5fa9f commit 249fb78
Show file tree
Hide file tree
Showing 17 changed files with 585 additions and 142 deletions.
49 changes: 38 additions & 11 deletions src/actions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import { Key } from '../components/configure/keycodekey/KeyGen';
import KeyModel from '../models/KeyModel';
import { IEncoderKeymap, IKeymap } from '../services/hid/Hid';
import { KeyboardLabelLang } from '../services/labellang/KeyLabelLangs';
import { ISetupPhase, RootState, SetupPhase } from '../store/state';
import {
IKeySwitchOperation,
ISetupPhase,
RootState,
SetupPhase,
} from '../store/state';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
import { LayoutOption } from '../components/configure/keymap/Keymap';
import { hidActionsThunk } from './hid.action';

export const KEYMAP_ACTIONS = '@Keymap';
export const KEYMAP_CLEAR_SELECTED_POS = `${KEYMAP_ACTIONS}/ClearSelectedLayer`;
export const KEYMAP_CLEAR_SELECTED_KEY_POSITION = `${KEYMAP_ACTIONS}/ClearSelectedKeyPosition`;
export const KEYMAP_UPDATE_SELECTED_LAYER = `${KEYMAP_ACTIONS}/UpdateSelectedLayer`;
export const KEYMAP_UPDATE_SELECTED_POS = `${KEYMAP_ACTIONS}/UpdateSelectedPos`;
export const KEYMAP_UPDATE_SELECTED_KEY_POSITION = `${KEYMAP_ACTIONS}/UpdateSelectedKeyPosition`;
export const KeymapActions = {
clearSelectedPos: () => {
clearSelectedKeyPosition: () => {
return {
type: KEYMAP_UPDATE_SELECTED_POS,
type: KEYMAP_CLEAR_SELECTED_KEY_POSITION,
};
},
updateSelectedLayer: (layer: number) => {
Expand All @@ -24,10 +29,18 @@ export const KeymapActions = {
value: layer,
};
},
updateSelectedPos: (pos: string) => {
updateSelectedKeyPosition: (
pos: string,
encoderId: number | null,
keySwitchOperation: IKeySwitchOperation
) => {
return {
type: KEYMAP_UPDATE_SELECTED_POS,
value: pos,
type: KEYMAP_UPDATE_SELECTED_KEY_POSITION,
value: {
pos,
encoderId,
keySwitchOperation,
},
};
},
};
Expand Down Expand Up @@ -253,19 +266,28 @@ export const AppActions = {
encodersRemapsInit: (layerCount: number) => {
const encodersRemaps: { [id: number]: IEncoderKeymap }[] = new Array(
layerCount
).fill({});
).fill({
clockwise: null,
counterclockwise: null,
});
return {
type: APP_ENCODERS_REMAPS_INIT,
value: encodersRemaps,
};
},
encodersRemapsSetKey: (layer: number, id: number, keymap: IEncoderKeymap) => {
encodersRemapsSetKey: (
layer: number,
id: number,
keymap: IKeymap,
keySwitchOperation: IKeySwitchOperation
) => {
return {
type: APP_ENCODERS_REMAPS_SET_KEY,
value: {
layer,
id,
keymap,
keySwitchOperation,
},
};
},
Expand All @@ -275,12 +297,17 @@ export const AppActions = {
value: keymaps,
};
},
encodersRemapsRemoveKey: (layer: number, id: number) => {
encodersRemapsRemoveKey: (
layer: number,
id: number,
keySwitchOperation: IKeySwitchOperation
) => {
return {
type: APP_ENCODERS_REMAPS_REMOVE_KEY,
value: {
id,
layer,
keySwitchOperation,
},
};
},
Expand Down
72 changes: 38 additions & 34 deletions src/actions/hid.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ export const hidActionsThunk = {
dispatch(AppActions.remapsClear());
dispatch(KeydiffActions.clearKeydiff());
dispatch(KeycodeKeyActions.clear());
dispatch(KeymapActions.clearSelectedPos());
dispatch(KeymapActions.clearSelectedKeyPosition());
dispatch(StorageActions.updateKeyboardDefinition(null));
dispatch(HidActions.updateKeyboard(null));
},
Expand All @@ -453,7 +453,7 @@ export const hidActionsThunk = {
dispatch(AppActions.remapsClear());
dispatch(KeydiffActions.clearKeydiff());
dispatch(KeycodeKeyActions.clear());
dispatch(KeymapActions.clearSelectedPos());
dispatch(KeymapActions.clearSelectedKeyPosition());
dispatch(StorageActions.updateKeyboardDefinition(null));
dispatch(StorageActions.clearKeyboardDefinitionDocument());
dispatch(StorageActions.updateSavedKeymaps([]));
Expand Down Expand Up @@ -512,39 +512,43 @@ export const hidActionsThunk = {
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
)
if (encoderKeymap.clockwise) {
const result = await keyboard.updateEncoderKeymap(
layer,
encoderId,
true,
encoderKeymap.clockwise.code
);
dispatch(HeaderActions.updateFlashing(false));
return;
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
)
if (encoderKeymap.counterclockwise) {
const result = await keyboard.updateEncoderKeymap(
layer,
encoderId,
false,
encoderKeymap.counterclockwise.code
);
dispatch(HeaderActions.updateFlashing(false));
return;
if (!result.success) {
console.error(result.cause);
dispatch(
NotificationActions.addError(
`Flash error: [${encoderId}-counterclockwise] ${result.error!}`,
result.cause
)
);
dispatch(HeaderActions.updateFlashing(false));
return;
}
}
}
}
Expand Down Expand Up @@ -574,7 +578,7 @@ export const hidActionsThunk = {
dispatch(AppActions.encodersRemapsInit(entities.device.layerCount));
dispatch(KeydiffActions.clearKeydiff());
dispatch(KeycodeKeyActions.clear());
dispatch(KeymapActions.clearSelectedPos());
dispatch(KeymapActions.clearSelectedKeyPosition());
dispatch(HeaderActions.updateFlashing(false));
},

Expand Down Expand Up @@ -687,7 +691,7 @@ export const hidActionsThunk = {
dispatch(AppActions.encodersRemapsInit(entities.device.layerCount));
dispatch(KeydiffActions.clearKeydiff());
dispatch(KeycodeKeyActions.clear());
dispatch(KeymapActions.clearSelectedPos());
dispatch(KeymapActions.clearSelectedKeyPosition());
dispatch(NotificationActions.addInfo('Resetting keymap succeeded.'));
},

Expand Down
2 changes: 1 addition & 1 deletion src/actions/storage.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export const storageActionsThunk = {
dispatch(AppActions.encodersRemapsInit(entities.device.layerCount));
dispatch(KeydiffActions.clearKeydiff());
dispatch(KeycodeKeyActions.clear());
dispatch(KeymapActions.clearSelectedPos());
dispatch(KeymapActions.clearSelectedKeyPosition());
},

// eslint-disable-next-line no-undef
Expand Down
31 changes: 29 additions & 2 deletions src/components/configure/keycap/Keycap.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AppActions,
} from '../../../actions/actions';
import { Key } from '../keycodekey/KeyGen';
import { RootState } from '../../../store/state';
import { IKeySwitchOperation, RootState } from '../../../store/state';

const mapStateToProps = (state: RootState) => {
return {
Expand All @@ -23,6 +23,8 @@ const mapDispatchToProps = (_dispatch: any) => {
return {
onClickKeycap: (
pos: string,
encoderId: number | null,
keySwitchOperation: IKeySwitchOperation,
isSelectedKey: boolean,
orgKey: Key,
dstKey: Key | null
Expand All @@ -35,7 +37,13 @@ const mapDispatchToProps = (_dispatch: any) => {
_dispatch(KeydiffActions.clearKeydiff());
}
// set new selected Position and
_dispatch(KeymapActions.updateSelectedPos(pos));
_dispatch(
KeymapActions.updateSelectedKeyPosition(
pos,
encoderId,
keySwitchOperation
)
);
},
onDropKeycode: (
draggingKey: Key,
Expand All @@ -50,6 +58,25 @@ const mapDispatchToProps = (_dispatch: any) => {
AppActions.remapsSetKey(selectedLayer, pos, draggingKey.keymap)
);
},
onDropKeycodeToEncoder: (
draggingKey: Key,
selectedLayer: number,
encoderId: number,
keySwitchOperation: IKeySwitchOperation,
orgKey: Key
) => {
if (draggingKey.keymap.code === orgKey.keymap.code) {
return;
}
_dispatch(
AppActions.encodersRemapsSetKey(
selectedLayer,
encoderId,
draggingKey.keymap,
keySwitchOperation
)
);
},
};
};

Expand Down
7 changes: 7 additions & 0 deletions src/components/configure/keycap/Keycap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@

border-radius: 5px;
font-size: 12px;
position: relative;

.encoder-toggle-icon {
position: absolute;
bottom: -16px;
left: -8px;
}
}

.keycap:hover,
Expand Down
Loading

0 comments on commit 249fb78

Please sign in to comment.