feat(config): Read / write hardware configuration area (#423)

* add write-hca.js

* refactor: Move config serializer into the uhk-common package

* refactor: Move getTransferBuffers into the uhk-usb package

* refactor: delete obsoleted classes

* build: add uhk-usb build command

* refactor: move eeprom transfer to uhk-usb package

* fix: Fix write-hca.js

* feat: load hardware config from the device and

* style: fix ts lint errors

* build: fix rxjs dependency resolve

* test: Add jasmine unit test framework to the tet serializer

* fix(user-config): A "type": "basic", properties to the "keystroke" action types

* feat(usb): set chmod+x on write-hca.js

* feat(usb): Create USB logger

* style: Fix type

* build: Add chalk to dependencies.

Chalk will colorize the output
This commit is contained in:
Róbert Kiss
2017-09-26 18:57:27 +02:00
committed by László Monda
parent 1122784bdb
commit 9294bede50
130 changed files with 9108 additions and 1991 deletions

View File

@@ -0,0 +1,108 @@
import { assertEnum, assertUInt8 } from '../assert';
import { UhkBuffer } from '../uhk-buffer';
import { KeyActionHelper, KeyAction, NoneAction, PlayMacroAction, SwitchKeymapAction } from './key-action';
import { Macro } from './macro';
import { UserConfiguration } from './user-configuration';
enum PointerRole {
none,
move,
scroll
}
export class Module {
@assertUInt8
id: number;
keyActions: KeyAction[];
@assertEnum(PointerRole)
pointerRole: PointerRole;
constructor(other?: Module) {
if (!other) {
return;
}
this.id = other.id;
this.keyActions = other.keyActions.map(keyAction => KeyActionHelper.createKeyAction(keyAction));
this.pointerRole = other.pointerRole;
}
fromJsonObject(jsonObject: any, macros?: Macro[]): Module {
this.id = jsonObject.id;
this.pointerRole = PointerRole[<string>jsonObject.pointerRole];
this.keyActions = jsonObject.keyActions.map((keyAction: any) => {
return KeyActionHelper.createKeyAction(keyAction, macros);
});
return this;
}
fromBinary(buffer: UhkBuffer, macros?: Macro[]): Module {
this.id = buffer.readUInt8();
this.pointerRole = buffer.readUInt8();
const keyActionsLength: number = buffer.readCompactLength();
this.keyActions = [];
for (let i = 0; i < keyActionsLength; ++i) {
this.keyActions.push(KeyActionHelper.createKeyAction(buffer, macros));
}
return this;
}
toJsonObject(macros?: Macro[]): any {
return {
id: this.id,
pointerRole: PointerRole[this.pointerRole],
keyActions: this.keyActions.map(keyAction => {
if (keyAction && (macros || !(keyAction instanceof PlayMacroAction || keyAction instanceof SwitchKeymapAction))) {
return keyAction.toJsonObject(macros);
}
})
};
}
toBinary(buffer: UhkBuffer, userConfiguration: UserConfiguration): void {
buffer.writeUInt8(this.id);
buffer.writeUInt8(this.pointerRole);
const noneAction = new NoneAction();
const keyActions: KeyAction[] = this.keyActions.map(keyAction => {
if (keyAction) {
return keyAction;
}
return noneAction;
});
buffer.writeArray(keyActions, (uhkBuffer: UhkBuffer, keyAction: KeyAction) => {
keyAction.toBinary(uhkBuffer, userConfiguration);
});
}
toString(): string {
return `<Module id="${this.id}" pointerRole="${this.pointerRole}">`;
}
renameKeymap(oldAbbr: string, newAbbr: string): Module {
let keyActions: KeyAction[];
let keyActionModified = false;
this.keyActions.forEach((keyAction, index) => {
if (!keyAction) { return; }
const newKeyAction = keyAction.renameKeymap(oldAbbr, newAbbr);
if (newKeyAction !== keyAction) {
if (!keyActionModified) {
keyActions = this.keyActions.slice();
keyActionModified = true;
}
keyActions[index] = newKeyAction;
}
});
if (keyActionModified) {
const newModule = Object.assign(new Module(), this);
newModule.keyActions = keyActions;
return newModule;
}
return this;
}
}