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

@@ -12,7 +12,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/withLatestFrom';
import { NotificationType, IpcResponse } from 'uhk-common';
import { NotificationType, IpcResponse, UhkBuffer, UserConfiguration } from 'uhk-common';
import {
ActionTypes,
ConnectionStateChangedAction,
@@ -24,9 +24,7 @@ import {
import { DeviceRendererService } from '../../services/device-renderer.service';
import { ShowNotificationAction } from '../actions/app';
import { AppState } from '../index';
import { UserConfiguration } from '../../config-serializer/config-items/user-configuration';
import { UhkBuffer } from '../../config-serializer/uhk-buffer';
import { LoadUserConfigFromDeviceAction } from '../actions/user-config';
import { LoadConfigFromDeviceAction } from '../actions/user-config';
@Injectable()
export class DeviceEffects {
@@ -44,7 +42,7 @@ export class DeviceEffects {
})
.switchMap((connected: boolean) => {
if (connected) {
return Observable.of(new LoadUserConfigFromDeviceAction());
return Observable.of(new LoadConfigFromDeviceAction());
}
return Observable.empty();

View File

@@ -12,11 +12,10 @@ import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/observable/of';
import { Keymap } from 'uhk-common';
import { KeymapActions } from '../actions';
import { AppState } from '../index';
import { Keymap } from '../../config-serializer/config-items/keymap';
@Injectable()
export class KeymapEffects {

View File

@@ -11,7 +11,14 @@ import 'rxjs/add/operator/withLatestFrom';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/observable/of';
import { LogService, NotificationType } from 'uhk-common';
import {
ConfigurationReply,
HardwareConfiguration,
LogService,
NotificationType,
UhkBuffer,
UserConfiguration
} from 'uhk-common';
import {
ActionTypes,
@@ -20,21 +27,42 @@ import {
SaveUserConfigSuccessAction
} from '../actions/user-config';
import { UserConfiguration } from '../../config-serializer/config-items/user-configuration';
import { DataStorageRepositoryService } from '../../services/datastorage-repository.service';
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
import { AppState, getPrevUserConfiguration, getUserConfiguration } from '../index';
import { KeymapActions } from '../actions/keymap';
import { MacroActions } from '../actions/macro';
import { UndoUserConfigData } from '../../models/undo-user-config-data';
import { ShowNotificationAction, DismissUndoNotificationAction } from '../actions/app';
import { ShowNotificationAction, DismissUndoNotificationAction, LoadHardwareConfigurationSuccessAction } from '../actions/app';
import { ShowSaveToKeyboardButtonAction } from '../actions/device';
import { DeviceRendererService } from '../../services/device-renderer.service';
import { UhkBuffer } from '../../config-serializer/uhk-buffer';
@Injectable()
export class UserConfigEffects {
private static getUserConfigFromDeviceResponse(json: string): UserConfiguration {
const data = JSON.parse(json);
const userConfig = new UserConfiguration();
userConfig.fromBinary(UhkBuffer.fromArray(data));
if (userConfig.dataModelVersion > 0) {
return userConfig;
}
return null;
}
private static getHardwareConfigFromDeviceResponse(json: string): HardwareConfiguration {
const data = JSON.parse(json);
const hardwareConfig = new HardwareConfiguration();
hardwareConfig.fromBinary(UhkBuffer.fromArray(data));
if (hardwareConfig.uuid > 0) {
return hardwareConfig;
}
return null;
}
@Effect() loadUserConfig$: Observable<Action> = this.actions$
.ofType(ActionTypes.LOAD_USER_CONFIG)
.startWith(new LoadUserConfigAction())
@@ -88,38 +116,36 @@ export class UserConfigEffects {
return [new LoadUserConfigSuccessAction(config), go(payload.path)];
});
@Effect({dispatch: false}) loadUserConfigFromDevice$ = this.actions$
.ofType(ActionTypes.LOAD_USER_CONFIG_FROM_DEVICE)
.do(() => this.deviceRendererService.loadUserConfiguration());
@Effect({dispatch: false}) loadConfigFromDevice$ = this.actions$
.ofType(ActionTypes.LOAD_CONFIG_FROM_DEVICE)
.do(() => this.deviceRendererService.loadConfigurationFromKeyboard());
@Effect() loadUserConfigFromDeviceReply$ = this.actions$
.ofType(ActionTypes.LOAD_USER_CONFIG_FROM_DEVICE_REPLY)
.map(action => action.payload)
.switchMap((data: Array<number>) => {
try {
let userConfig;
if (data.length > 0) {
const uhkBuffer = new UhkBuffer();
let hasNonZeroValue = false;
for (const num of data) {
if (num > 0) {
hasNonZeroValue = true;
}
uhkBuffer.writeUInt8(num);
}
uhkBuffer.offset = 0;
userConfig = new UserConfiguration();
userConfig.fromBinary(uhkBuffer);
if (hasNonZeroValue) {
return Observable.of(new LoadUserConfigSuccessAction(userConfig));
}
}
} catch (err) {
this.logService.error('Eeprom parse error:', err);
@Effect() loadConfigFromDeviceReply$ = this.actions$
.ofType(ActionTypes.LOAD_CONFIG_FROM_DEVICE_REPLY)
.map(toPayload)
.mergeMap((data: ConfigurationReply): any => {
if (!data.success) {
return [new ShowNotificationAction({
type: NotificationType.Error,
message: data.error
})];
}
return Observable.empty();
try {
const userConfig = UserConfigEffects.getUserConfigFromDeviceResponse(data.userConfiguration);
const hardwareConfig = UserConfigEffects.getHardwareConfigFromDeviceResponse(data.hardwareConfiguration);
return [
new LoadUserConfigSuccessAction(userConfig),
new LoadHardwareConfigurationSuccessAction(hardwareConfig)
];
} catch (err) {
this.logService.error('Eeprom parse error:', err);
return [new ShowNotificationAction({
type: NotificationType.Error,
message: err.message
})];
}
});
constructor(private actions$: Actions,
@@ -147,4 +173,5 @@ export class UserConfigEffects {
return config;
}
}