Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/uhk-common/src/models/device-connection-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import { UhkDeviceProduct } from './uhk-products.js';

export interface DeviceConnectionState {
bleAddress?: string;
// UHK80 connected via bluetooth
bleDeviceConnected: boolean;
isPairedWithDongle?: boolean;
connectedDevice?: UhkDeviceProduct;
dongle: Dongle;
leftHalfBootloaderActive: boolean;
hasPermission: boolean;
bootloaderActive: boolean;
isMacroStatusDirty: boolean;
leftHalfDetected: boolean;
/**
* True if more than 1 UHK device connected.
*/
Expand Down
1 change: 1 addition & 0 deletions packages/uhk-common/src/models/uhk-products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { UHK_MODULE_IDS, UHK_MODULE_IDS_TYPE } from './uhk-module-ids.js';

export const UHK_VENDOR_ID_OLD = 0x1D50; // decimal 7504
export const UHK_VENDOR_ID = 0x37A8; // decimal 14248
export const UHK_BLE_MIN_PRODUCT_iD = 0x8000; // decimal 32768

export interface VidPidPair {
vid: number;
Expand Down
13 changes: 12 additions & 1 deletion packages/uhk-usb/src/uhk-hid-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import {
RightSlotModules,
UdevRulesInfo,
UhkBuffer,
UHK_BLE_MIN_PRODUCT_iD,
UHK_DONGLE,
UHK_80_DEVICE,
UHK_80_DEVICE_LEFT,
UHK_VENDOR_ID,
} from 'uhk-common';
import {
DevicePropertyIds,
Expand Down Expand Up @@ -316,6 +318,7 @@ export class UhkHidDevice {
const devs = await this.getUhkDevices();
const result: DeviceConnectionState = {
bootloaderActive: false,
bleDeviceConnected: false,
communicationInterfaceAvailable: false,
dongle: {
bootloaderActive: false,
Expand All @@ -332,6 +335,7 @@ export class UhkHidDevice {
},
hardwareModules: {},
isMacroStatusDirty: false,
leftHalfDetected: false,
multiDevice: await getNumberOfConnectedDevices(this.options) > 1,
udevRulesInfo: await this.getUdevInfoAsync(),
};
Expand Down Expand Up @@ -373,9 +377,16 @@ export class UhkHidDevice {

if (isUhkCommunicationInterface(dev)) {
result.communicationInterfaceAvailable = true;
} else if (isBootloader(dev)) {
}
else if (isBootloader(dev)) {
result.bootloaderActive = true;
}
else if (dev.vendorId === UHK_VENDOR_ID && dev.productId >= UHK_BLE_MIN_PRODUCT_iD) {
result.bleDeviceConnected = true;
}
else if (UHK_80_DEVICE_LEFT.keyboard.some(vidPid => dev.vendorId === vidPid.vid && dev.productId === vidPid.pid)) {
result.leftHalfDetected = true;
}
}

if (isDongleCommunicationDevice(dev)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<uhk-message [header]="state.header"
[subtitle]="state.subtitle"
[description]="state.description"
[showLogo]="true"></uhk-message>
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<h1> {{ header }} </h1>
<h2 *ngIf="!smallText"> {{ subtitle }} </h2>
<div *ngIf="smallText"> {{ subtitle }} </div>
<p *ngIf="description"> {{ description }} </p>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
changeDetection: ChangeDetectionStrategy.OnPush
})
export class UhkMessageComponent {
@Input() description: string;
@Input() header: string;
@Input() subtitle: string;
@Input() rotateLogo = false;
Expand Down
1 change: 1 addition & 0 deletions packages/uhk-web/src/app/models/missing-device-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface MissingDeviceState {
header: string;
subtitle: string;
description?: string;
}
32 changes: 31 additions & 1 deletion packages/uhk-web/src/app/store/reducers/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getSaveToKeyboardButtonState, initProgressButtonState, ProgressButtonSt

export interface State {
bleAddress?: string;
bleDeviceConnected: boolean;
dongle?: Dongle;
isKeyboardLayoutChanging: boolean;
isPairedWithDongle?: boolean;
Expand All @@ -36,6 +37,7 @@ export interface State {
deviceConnectionStateLoaded: boolean;
keyboardHalvesAlwaysJoined: boolean;
leftHalfBootloaderActive: boolean;
leftHalfDetected: boolean;
multiDevice: boolean;
communicationInterfaceAvailable: boolean;
saveToKeyboard: ProgressButtonState;
Expand All @@ -54,12 +56,14 @@ export interface State {
}

export const initialState: State = {
bleDeviceConnected: false,
isKeyboardLayoutChanging: false,
hasPermission: true,
bootloaderActive: false,
deviceConnectionStateLoaded: false,
keyboardHalvesAlwaysJoined: false,
leftHalfBootloaderActive: false,
leftHalfDetected: false,
multiDevice: false,
communicationInterfaceAvailable: true,
saveToKeyboard: initProgressButtonState,
Expand Down Expand Up @@ -124,15 +128,17 @@ export function reducer(state = initialState, action: Action): State {
return {
...state,
bleAddress: data.bleAddress,
bleDeviceConnected: data.bleDeviceConnected,
dongle: data.dongle,
isPairedWithDongle: data.isPairedWithDongle,
connectedDevice: data.connectedDevice,
deviceConnectionStateLoaded: true,
leftHalfBootloaderActive: data.leftHalfBootloaderActive,
hasPermission: data.hasPermission,
communicationInterfaceAvailable: data.communicationInterfaceAvailable,
bootloaderActive: data.bootloaderActive,
halvesInfo: data.halvesInfo,
leftHalfBootloaderActive: data.leftHalfBootloaderActive,
leftHalfDetected: data.leftHalfDetected,
modules: data.hardwareModules,
multiDevice: data.multiDevice,
udevRuleInfo: data.udevRulesInfo,
Expand Down Expand Up @@ -292,6 +298,29 @@ export const getMissingDeviceState = (state: State): MissingDeviceState => {
};
}

if (!state.connectedDevice) {
if (state.bleDeviceConnected) {
return {
header: 'UHK 80 connected via BLE',
subtitle: 'Disconnect BLE and connect your UHK via its right USB port!'
};
}

if (state.dongle?.serialNumber) {
return {
header: 'Dongle connected',
subtitle: 'Please connect the UHK right half via USB cable!'
};
}

if (state.leftHalfDetected) {
return {
header: 'UHK 80 left half connected',
subtitle: 'Please connect the right half instead!'
};
}
}

if (state.connectedDevice && !state.communicationInterfaceAvailable) {
return {
header: 'Cannot find your UHK',
Expand All @@ -300,6 +329,7 @@ export const getMissingDeviceState = (state: State): MissingDeviceState => {
}

return {
description: 'If you have a UHK 80, connect its right half via USB, and ensure it\'s not connected to a dongle or BLE host!',
header: 'Cannot find your UHK',
subtitle: 'Please plug it in!'
};
Expand Down