feat: Display/hide left keyboard half and merged/unmerged state (#987)

* feat: Display/hide left keyboard half and merged/unmerged state

* feat: improve the animation

* feat: decrease left fade animation time
This commit is contained in:
Róbert Kiss
2019-07-25 23:41:20 +02:00
committed by László Monda
parent a409c219d8
commit cbccaba1c5
18 changed files with 149 additions and 80 deletions

View File

@@ -2,7 +2,7 @@ import { Device, devices, HID } from 'node-hid';
import { pathExists } from 'fs-extra';
import * as path from 'path';
import { platform } from 'os';
import { CommandLineArgs, DeviceConnectionState, isEqualArray, LogService, UdevRulesInfo } from 'uhk-common';
import { CommandLineArgs, DeviceConnectionState, HalvesInfo, isEqualArray, LogService, UdevRulesInfo } from 'uhk-common';
import {
ConfigBufferId,
@@ -89,7 +89,8 @@ export class UhkHidDevice {
connected: false,
zeroInterfaceAvailable: false,
hasPermission: this.hasPermission(),
udevRulesInfo: await this.getUdevInfoAsync()
udevRulesInfo: await this.getUdevInfoAsync(),
halvesInfo: { areHalvesMerged: true, isLeftHalfConnected: true }
};
for (const dev of devs) {
@@ -105,6 +106,12 @@ export class UhkHidDevice {
}
}
if (result.connected && result.hasPermission && result.zeroInterfaceAvailable) {
result.halvesInfo = await this.getHalvesStates();
} else if (!result.connected) {
this._device = undefined;
}
return result;
}
@@ -253,6 +260,15 @@ export class UhkHidDevice {
await this.write(transfer);
}
async getHalvesStates(): Promise<HalvesInfo> {
const buffer = await this.write(Buffer.from([UsbCommand.GetDeviceState]));
return {
areHalvesMerged: buffer[2] !== 0,
isLeftHalfConnected: buffer[3] !== 0
};
}
/**
* Return the stored version of HID device. If not exist try to initialize.
* @returns {HID}