Add a number of properties to the user config that are related to mou… (#501)

* Add a number of properties to the user config that are related to mouse movement, LED brightness, data model versioning, and double tap switch layer timeout. Update firmware related version numbers.

* use default config if parse loaded config from device failed

* add asserts to the new user config fields

* separate user and hardware config parser

* fix indent

* fix user-config size read
This commit is contained in:
László Monda
2017-12-02 23:55:43 +01:00
committed by GitHub
parent 58b1b9b1dc
commit 7537e5b823
7 changed files with 200 additions and 46 deletions

View File

@@ -82,7 +82,9 @@ export class KeymapEditComponent {
site: 'https://ultimatehackingkeyboard.com',
description: 'Ultimate Hacking Keyboard keymap',
keyboardModel: 'UHK60',
dataModelVersion: userConfiguration.dataModelVersion,
dataModelMajorVersion: userConfiguration.dataModelMajorVersion,
dataModelMinorVersion: userConfiguration.dataModelMinorVersion,
dataModelPatchVersion: userConfiguration.dataModelPatchVersion,
objectType: 'keymap',
objectValue: keymap.toJsonObject()
};

View File

@@ -1,6 +1,20 @@
{
"dataModelVersion": 4,
"dataModelMajorVersion": 3,
"dataModelMinorVersion": 0,
"dataModelPatchVersion": 0,
"deviceName": "My UHK",
"doubleTapSwitchLayerTimeout": 300,
"keyBacklightBrightness": 255,
"mouseMoveInitialSpeed": 5,
"mouseMoveAcceleration": 35,
"mouseMoveDeceleratedSpeed": 10,
"mouseMoveBaseSpeed": 40,
"mouseMoveAcceleratedSpeed": 80,
"mouseScrollInitialSpeed": 20,
"mouseScrollAcceleration": 20,
"mouseScrollDeceleratedSpeed": 20,
"mouseScrollBaseSpeed": 20,
"mouseScrollAcceleratedSpeed": 50,
"moduleConfigurations": [
{
"id": 1,
@@ -7134,4 +7148,4 @@
]
}
]
}
}

View File

@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Actions, Effect, toPayload } from '@ngrx/effects';
import { Actions, Effect } from '@ngrx/effects';
import { Observable } from 'rxjs/Observable';
import { defer } from 'rxjs/observable/defer';
import { Action, Store } from '@ngrx/store';
@@ -24,6 +24,7 @@ import {
import {
ActionTypes,
LoadConfigFromDeviceReplyAction,
LoadUserConfigSuccessAction,
RenameUserConfigurationAction,
SaveUserConfigSuccessAction
@@ -33,7 +34,12 @@ import { DataStorageRepositoryService } from '../../services/datastorage-reposit
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
import { AppState, getPrevUserConfiguration, getUserConfiguration } from '../index';
import { KeymapAction, KeymapActions, MacroAction, MacroActions } from '../actions';
import { ShowNotificationAction, DismissUndoNotificationAction, LoadHardwareConfigurationSuccessAction } from '../actions/app';
import {
DismissUndoNotificationAction,
LoadHardwareConfigurationSuccessAction,
ShowNotificationAction,
UndoLastAction
} from '../actions/app';
import { ShowSaveToKeyboardButtonAction } from '../actions/device';
import { DeviceRendererService } from '../../services/device-renderer.service';
import { UndoUserConfigData } from '../../models/undo-user-config-data';
@@ -46,7 +52,7 @@ export class UserConfigEffects {
const userConfig = new UserConfiguration();
userConfig.fromBinary(UhkBuffer.fromArray(data));
if (userConfig.dataModelVersion > 0) {
if (userConfig.dataModelMajorVersion > 0) {
return userConfig;
}
@@ -111,8 +117,8 @@ export class UserConfigEffects {
});
@Effect() undoUserConfig$: Observable<Action> = this.actions$
.ofType(KeymapActions.UNDO_LAST_ACTION)
.map(toPayload)
.ofType<UndoLastAction>(KeymapActions.UNDO_LAST_ACTION)
.map(action => action.payload)
.mergeMap((payload: UndoUserConfigData) => {
const config = new UserConfiguration().fromJsonObject(payload.config);
this.dataStorageRepository.saveConfig(config);
@@ -125,8 +131,8 @@ export class UserConfigEffects {
.do(() => this.deviceRendererService.loadConfigurationFromKeyboard());
@Effect() loadConfigFromDeviceReply$ = this.actions$
.ofType(ActionTypes.LOAD_CONFIG_FROM_DEVICE_REPLY)
.map(toPayload)
.ofType<LoadConfigFromDeviceReplyAction>(ActionTypes.LOAD_CONFIG_FROM_DEVICE_REPLY)
.map(action => action.payload)
.mergeMap((data: ConfigurationReply): any => {
if (!data.success) {
return [new ShowNotificationAction({
@@ -135,22 +141,37 @@ export class UserConfigEffects {
})];
}
const result = [];
try {
const userConfig = UserConfigEffects.getUserConfigFromDeviceResponse(data.userConfiguration);
const hardwareConfig = UserConfigEffects.getHardwareConfigFromDeviceResponse(data.hardwareConfiguration);
this.router.navigate(['/']);
result.push(new LoadUserConfigSuccessAction(userConfig));
return [
new LoadUserConfigSuccessAction(userConfig),
new LoadHardwareConfigurationSuccessAction(hardwareConfig)
];
} catch (err) {
this.logService.error('Eeprom parse error:', err);
return [new ShowNotificationAction({
type: NotificationType.Error,
message: err
})];
this.logService.error('Eeprom user-config parse error:', err);
result.push(
new ShowNotificationAction({
type: NotificationType.Error,
message: err
}));
result.push(new LoadUserConfigSuccessAction(this.getUserConfiguration()));
}
try {
const hardwareConfig = UserConfigEffects.getHardwareConfigFromDeviceResponse(data.hardwareConfiguration);
result.push(new LoadHardwareConfigurationSuccessAction(hardwareConfig));
} catch (err) {
this.logService.error('Eeprom hardware-config parse error:', err);
result.push(
new ShowNotificationAction({
type: NotificationType.Error,
message: err
}));
}
this.router.navigate(['/']);
return result;
});
@Effect({dispatch: false}) saveUserConfigInJsonFile$ = this.actions$
@@ -186,7 +207,8 @@ export class UserConfigEffects {
let config: UserConfiguration;
if (configJsonObject) {
if (configJsonObject.dataModelVersion === this.defaultUserConfigurationService.getDefault().dataModelVersion) {
if (configJsonObject.dataModelMajorVersion ===
this.defaultUserConfigurationService.getDefault().dataModelMajorVersion) {
config = new UserConfiguration().fromJsonObject(configJsonObject);
}
}