diff --git a/src/assets/cog.svg b/src/assets/cog.svg new file mode 100644 index 0000000..f778b64 --- /dev/null +++ b/src/assets/cog.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/assets/profile_template.png b/src/assets/profile_template.png index e8772b4..3bfba1b 100644 Binary files a/src/assets/profile_template.png and b/src/assets/profile_template.png differ diff --git a/src/components/profile/action_preview.ts b/src/components/profile/action_preview.ts index 5ec52e5..9d75d63 100644 --- a/src/components/profile/action_preview.ts +++ b/src/components/profile/action_preview.ts @@ -4,7 +4,6 @@ import { Component, Input } from '@angular/core' import { CommonModule } from '@angular/common' import { WebusbService } from 'services/webusb' -import { Profiles } from 'lib/profiles' import { HID, isAxis } from 'lib/hid' import { ActionGroup } from 'lib/actions' import { CtrlButton, CtrlGyroAxis, CtrlRotary, CtrlHome, sectionIsAnalog } from 'lib/ctrl' @@ -29,6 +28,7 @@ interface Icon { }) export class ButtonComponent { @Input() section: CtrlButton | CtrlRotary | CtrlGyroAxis + @Input() analog: boolean = false constructor( public webusb: WebusbService, @@ -223,7 +223,7 @@ export class ButtonComponent { if (index==1 && this.section.hold) cls += ' hold' if (index==2 && this.section.double) cls += ' double' } - if (sectionIsAnalog(this.section.sectionIndex) && isAxis(action)) { + if (this.analog && sectionIsAnalog(this.section.sectionIndex) && isAxis(action)) { cls += ' analog' } return cls diff --git a/src/components/profile/profile.html b/src/components/profile/profile.html index f772e42..c172998 100644 --- a/src/components/profile/profile.html +++ b/src/components/profile/profile.html @@ -25,6 +25,7 @@ @@ -38,21 +39,32 @@ - +
+   +
+ + +
 
  @@ -66,6 +78,7 @@
diff --git a/src/components/profile/profile.sass b/src/components/profile/profile.sass index 25d2e33..3903537 100644 --- a/src/components/profile/profile.sass +++ b/src/components/profile/profile.sass @@ -19,6 +19,8 @@ background-color: hsla(0deg, 0%, 100%, 0.1) &.pale background-color: hsla(0deg, 0%, 100%, 0.05) !important + &.settings + background-color: hsla(0deg, 0%, 100%, 0.8) !important .wide padding-left: 15% !important .thin @@ -37,7 +39,7 @@ background-size: contain display: grid grid-template-rows: 4fr 4fr 2fr 4fr 2fr 2fr 2fr 2fr 4fr 7fr 4fr 3fr 4fr 4fr 4fr 1fr 2fr 2fr 2fr 2fr 2fr 2fr - grid-template-columns: 12fr 12fr 3fr 3fr 3fr 3fr 1.5fr 1.5fr 1fr 1.5fr 1.5fr 3fr 3fr 3fr 3fr 12fr 12fr + grid-template-columns: 12fr 12fr 3fr 3fr 3fr 3fr 1.5fr 1.5fr 1fr 1.5fr 1.5fr 3fr 3fr 3fr 3fr 12fr 9fr 3fr &>div padding-left: 30% @@ -55,7 +57,13 @@ &.overflow overflow: initial ::ng-deep - min-width: 190% + min-width: 140% + &.settings + aspect-ratio: 1/1 + background-color: hsl(0deg, 0%, 50%) + border-top: 1px solid hsl(0deg, 0%, 80%) + border-right: 1px solid hsl(0deg, 0%, 80%) + background-image: url('/assets/cog.svg') .center flex-grow: 1 diff --git a/src/components/profile/profile.ts b/src/components/profile/profile.ts index 4464da8..24f47cc 100644 --- a/src/components/profile/profile.ts +++ b/src/components/profile/profile.ts @@ -13,8 +13,6 @@ import { ThumbstickMode, GyroMode } from 'lib/ctrl' import { sectionIsGyroAxis, sectionIsHome } from 'lib/ctrl' import { SectionIndex } from 'lib/ctrl' import { Device } from 'lib/device' -import { Profiles } from 'lib/profiles' -import { delay } from 'lib/delay' const MAX_FETCH_ATTEMPTS = 3 @@ -101,10 +99,12 @@ export class ProfileComponent { const log = `tryFetchProfile ${this.profileIndex}` console.log(log) let attempts = 0 + let success = false while(true) { try { const profiles = this.webusb.selectedDevice!.profiles await profiles.fetchProfile(this.profileIndex, false) + success = true break } catch(error) { attempts += 1 @@ -115,7 +115,8 @@ export class ProfileComponent { } } } - console.log(log, 'OK') + if (success) console.log(log, 'OK') + else console.log(log, 'FAILED') } getProfile() { @@ -130,12 +131,8 @@ export class ProfileComponent { this.selected = this.getProfile().meta } - setSelectedThumbstick() { - this.selected = this.getProfile().thumbstick - } - setSelectedGyro() { - this.selected = this.getProfile().gyro + this.selected = this.getProfile().settingsGyro } getSelected() { @@ -149,23 +146,49 @@ export class ProfileComponent { return cls } - getMapping( section: CtrlButton | CtrlRotary | CtrlGyroAxis) { + sectionCouldBeAnalog(section: CtrlSection) { + const dirLStick= [ + SectionIndex.LSTICK_LEFT, + SectionIndex.LSTICK_RIGHT, + SectionIndex.LSTICK_UP, + SectionIndex.LSTICK_DOWN + ] + const dirRStick= [ + SectionIndex.RSTICK_LEFT, + SectionIndex.RSTICK_RIGHT, + SectionIndex.RSTICK_UP, + SectionIndex.RSTICK_DOWN + ] + if (this.getProfile().settingsLStick.mode == ThumbstickMode.DIR4) { + if (dirLStick.includes(section.sectionIndex)) return true + } + if (this.getProfile().settingsRStick.mode == ThumbstickMode.DIR4) { + if (dirRStick.includes(section.sectionIndex)) return true + } + if (sectionIsGyroAxis(section.sectionIndex)) return true + return false + } + + getMapping(section: CtrlButton | CtrlRotary | CtrlGyroAxis) { const pos = position.filter((x) => x.section==section.sectionIndex)[0] let style = {'grid-column': pos.column, 'grid-row': pos.row} let cls = 'cls' in pos ? pos.cls : '' + let analog = false + if (this.sectionCouldBeAnalog(section)) analog = true if (section.sectionIndex == this.selected?.sectionIndex) cls += ' selected' return { section, cls, style, + analog, click: () => this.setSelected(section), } } getMappings() { const profile = this.getProfile() - const thumbstick = profile.thumbstick - const gyro = profile.gyro + const settingsLStick = profile.settingsLStick + const gyro = profile.settingsGyro const rotaryUp = this.getMapping(profile.rotaryUp) const rotaryDown = this.getMapping(profile.rotaryDown) const home = this.getMapping(profile.home) @@ -188,27 +211,34 @@ export class ProfileComponent { this.getMapping(profile.buttonR1), this.getMapping(profile.buttonR2), this.getMapping(profile.buttonR4), - this.getMapping(profile.buttonDhatLeft), - this.getMapping(profile.buttonDhatRight), - this.getMapping(profile.buttonDhatUp), - this.getMapping(profile.buttonDhatDown), - this.getMapping(profile.buttonDhatUL), - this.getMapping(profile.buttonDhatUR), - this.getMapping(profile.buttonDhatDL), - this.getMapping(profile.buttonDhatDR), - this.getMapping(profile.buttonDhatPush), + this.getMapping(profile.buttonRStickLeft), + this.getMapping(profile.buttonRStickRight), + this.getMapping(profile.buttonRStickUp), + this.getMapping(profile.buttonRStickDown), + this.getMapping(profile.buttonRStickUL), + this.getMapping(profile.buttonRStickUR), + this.getMapping(profile.buttonRStickDL), + this.getMapping(profile.buttonRStickDR), + this.getMapping(profile.buttonRStickPush), ] - let buttonsThumbstick: any = [] - if (thumbstick.mode == ThumbstickMode.DIR4) { - buttonsThumbstick = [ - this.getMapping(profile.buttonThumbstickLeft), - this.getMapping(profile.buttonThumbstickRight), - this.getMapping(profile.buttonThumbstickUp), - this.getMapping(profile.buttonThumbstickDown), - this.getMapping(profile.buttonThumbstickPush), - this.getMapping(profile.buttonThumbstickInner), - this.getMapping(profile.buttonThumbstickOuter), - ] + if (settingsLStick.mode==ThumbstickMode.DIR4 || settingsLStick.mode==ThumbstickMode.DIR8) { + buttons.push(...[ + this.getMapping(profile.buttonLStickLeft), + this.getMapping(profile.buttonLStickRight), + this.getMapping(profile.buttonLStickUp), + this.getMapping(profile.buttonLStickDown), + this.getMapping(profile.buttonLStickPush), + this.getMapping(profile.buttonLStickInner), + this.getMapping(profile.buttonLStickOuter), + ]) + } + if (settingsLStick.mode==ThumbstickMode.DIR8) { + buttons.push(...[ + this.getMapping(profile.buttonLStickUL), + this.getMapping(profile.buttonLStickUR), + this.getMapping(profile.buttonLStickDL), + this.getMapping(profile.buttonLStickDR), + ]) } let gyroAxis: any = [] if (gyro.mode != GyroMode.OFF) { @@ -218,7 +248,7 @@ export class ProfileComponent { this.getMapping(profile.gyroZ), ] } - return [...buttons, ...buttonsThumbstick, ...gyroAxis, rotaryUp, rotaryDown, home] + return [...buttons, ...gyroAxis, rotaryUp, rotaryDown, home] } // Required so change detection is working better is scenarios where the @@ -230,42 +260,49 @@ export class ProfileComponent { const position = [ {section: 0, column: 0, row: 0 }, - {section: SectionIndex.L2, column: 1, row: 1 }, - {section: SectionIndex.L1, column: 1, row: 2 }, + {section: SectionIndex.L2, column: 1, row: 1, cls:'overflow' }, + {section: SectionIndex.L1, column: 1, row: 2, cls:'overflow' }, {section: SectionIndex.DPAD_UP, column: 1, row: 4, cls:'overflow' }, {section: SectionIndex.DPAD_RIGHT, column: 1, row: '5/7', cls:'overflow' }, {section: SectionIndex.DPAD_LEFT, column: 1, row: '7/9', cls:'overflow' }, {section: SectionIndex.DPAD_DOWN, column: 1, row: 9, cls:'overflow' }, - {section: SectionIndex.L4, column: 1, row: 11 }, + {section: SectionIndex.L4, column: 1, row: 11, cls:'overflow' }, {section: SectionIndex.SELECT_1, column: '4/9', row: 1 }, {section: SectionIndex.SELECT_2, column: '4/9', row: 2 }, {section: SectionIndex.START_1, column: '10/15', row: 1 }, {section: SectionIndex.START_2, column: '10/15', row: 2 }, - {section: SectionIndex.R2, column: 17, row: 1 }, - {section: SectionIndex.R1, column: 17, row: 2 }, - {section: SectionIndex.Y, column: 17, row: 4 }, - {section: SectionIndex.X, column: 17, row: '5/7' }, - {section: SectionIndex.B, column: 17, row: '7/9' }, - {section: SectionIndex.A, column: 17, row: 9 }, - {section: SectionIndex.R4, column: 17, row: 11 }, - {section: SectionIndex.DHAT_LEFT, column: '12/16', row: 14 }, - {section: SectionIndex.DHAT_RIGHT, column: 17, row: 14 }, - {section: SectionIndex.DHAT_UP, column: 16, row: 13 }, - {section: SectionIndex.DHAT_DOWN, column: 16, row: 15 }, - {section: SectionIndex.DHAT_UL, column: '12/16', row: 13 }, - {section: SectionIndex.DHAT_UR, column: 17, row: 13 }, - {section: SectionIndex.DHAT_DL, column: '12/16', row: 15 }, - {section: SectionIndex.DHAT_DR, column: 17, row: 15 }, - {section: SectionIndex.DHAT_PUSH, column: 16, row: 14 }, + {section: SectionIndex.R2, column: '17/19', row: 1 }, + {section: SectionIndex.R1, column: '17/19', row: 2 }, + {section: SectionIndex.Y, column: '17/19', row: 4 }, + {section: SectionIndex.X, column: '17/19', row: '5/7' }, + {section: SectionIndex.B, column: '17/19', row: '7/9' }, + {section: SectionIndex.A, column: '17/19', row: 9 }, + {section: SectionIndex.R4, column: '17/19', row: 11 }, + + {section: SectionIndex.LSTICK_UL, column: 1, row: 13 }, + {section: SectionIndex.LSTICK_LEFT, column: 1, row: 14 }, + {section: SectionIndex.LSTICK_DL, column: 1, row: 15 }, + {section: SectionIndex.LSTICK_UP, column: 2, row: 13 }, + {section: SectionIndex.LSTICK_PUSH, column: 2, row: 14 }, + {section: SectionIndex.LSTICK_DOWN, column: 2, row: 15 }, + {section: SectionIndex.LSTICK_UR, column: '3/7', row: 13 }, + {section: SectionIndex.LSTICK_RIGHT, column: '3/7', row: 14 }, + {section: SectionIndex.LSTICK_DR, column: '3/7', row: 15 }, + {section: SectionIndex.LSTICK_INNER, column: 2, row: '18/20' }, + {section: SectionIndex.LSTICK_OUTER, column: 2, row: '20/22' }, + + {section: SectionIndex.RSTICK_LEFT, column: '12/16', row: 14 }, + {section: SectionIndex.RSTICK_RIGHT, column: '17/19', row: 14 }, + {section: SectionIndex.RSTICK_UP, column: 16, row: 13 }, + {section: SectionIndex.RSTICK_DOWN, column: 16, row: 15 }, + {section: SectionIndex.RSTICK_UL, column: '12/16', row: 13 }, + {section: SectionIndex.RSTICK_UR, column: '17/19', row: 13 }, + {section: SectionIndex.RSTICK_DL, column: '12/16', row: 15 }, + {section: SectionIndex.RSTICK_DR, column: '17/19', row: 15 }, + {section: SectionIndex.RSTICK_PUSH, column: 16, row: 14 }, + {section: SectionIndex.ROTARY_UP, column: '16/18', row: '18/20', cls:'wide'}, {section: SectionIndex.ROTARY_DOWN, column: '16/18', row: '20/22', cls:'wide'}, - {section: SectionIndex.THUMBSTICK_LEFT, column: 1, row: 14 }, - {section: SectionIndex.THUMBSTICK_RIGHT, column: '3/7', row: 14 }, - {section: SectionIndex.THUMBSTICK_UP, column: 2, row: 13 }, - {section: SectionIndex.THUMBSTICK_DOWN, column: 2, row: 15 }, - {section: SectionIndex.THUMBSTICK_PUSH, column: 2, row: 14 }, - {section: SectionIndex.THUMBSTICK_INNER, column: 2, row: '18/20' }, - {section: SectionIndex.THUMBSTICK_OUTER, column: 2, row: '20/22' }, {section: SectionIndex.GYRO_X, column: '6/13', row: '17/19', cls:'thin'}, {section: SectionIndex.GYRO_Y, column: '6/13', row: '19/21', cls:'thin'}, {section: SectionIndex.GYRO_Z, column: '6/13', row: '21/23', cls:'thin'}, diff --git a/src/components/profile/section.html b/src/components/profile/section.html index 5b7d7c3..c34728a 100644 --- a/src/components/profile/section.html +++ b/src/components/profile/section.html @@ -172,11 +172,12 @@

{{getSectionTitle()}}

> +
-
Distance calculation:
+
Analog distance calculation:
+
+
Saturation:
+
+ +
+
Axis overlap:
@@ -198,7 +212,7 @@

{{getSectionTitle()}}

/>
-
+
Deadzone:
@@ -221,7 +235,7 @@

{{getSectionTitle()}}

/>
-
+
Anti-deadzone:
{{getSectionTitle()}}
menu
-
keyboard_arrow_up
+
keyboard_arrow_up
Y
@@ -549,11 +563,11 @@

{{getSectionTitle()}}

B
-
keyboard_arrow_down
+
keyboard_arrow_down
arrow_upward
-
keyboard_arrow_up
+
keyboard_arrow_up
A
@@ -569,7 +583,7 @@

{{getSectionTitle()}}

arrow_downward
-
keyboard_arrow_down
+
keyboard_arrow_down
diff --git a/src/components/profile/section.ts b/src/components/profile/section.ts index dd7690f..9ac2f5f 100644 --- a/src/components/profile/section.ts +++ b/src/components/profile/section.ts @@ -32,6 +32,7 @@ import { delay } from 'lib/delay' export class SectionComponent { @Input() profileIndex: number = 0 @Input() section: CtrlSection = new CtrlSectionMeta(0, SectionIndex.META, '', 0, 0, 0, 0) + @Input() analog: boolean = false dialogKeyPicker: any pickerGroup = 0 pickerProfile = 1 @@ -115,7 +116,7 @@ export class SectionComponent { getGyroMode() { const profile = this.profiles.getProfile(this.profileIndex) as Profile - return profile.gyro.mode + return profile.settingsGyro.mode } async profileOverwrite() { @@ -275,7 +276,7 @@ export class SectionComponent { if (this.pickerGroup==1 && this.section.hold) cls += ' holdBG' if (this.pickerGroup==2 && this.section.double) cls += ' doubleBG' } - if (sectionIsAnalog(this.section.sectionIndex) && isAxis(action)) { + if (this.analog && sectionIsAnalog(this.section.sectionIndex) && isAxis(action)) { cls += ' analogBG' } if (actions.has(action)) return cls @@ -289,7 +290,7 @@ export class SectionComponent { if (index==1 && this.section.hold) cls += ' hold' if (index==2 && this.section.double) cls += ' double' } - if (sectionIsAnalog(this.section.sectionIndex) && isAxis(action)) { + if (this.analog && sectionIsAnalog(this.section.sectionIndex) && isAxis(action)) { cls += ' analog' } return cls @@ -322,26 +323,31 @@ const sectionTitles: SectionTitles = { [SectionIndex.R1]: 'Trigger R1', [SectionIndex.R2]: 'Trigger R2', [SectionIndex.R4]: 'Trigger R4', - [SectionIndex.DHAT_LEFT]: 'DHat Left', - [SectionIndex.DHAT_RIGHT]: 'DHat Right', - [SectionIndex.DHAT_UP]: 'DHat Up', - [SectionIndex.DHAT_DOWN]: 'DHat Down', - [SectionIndex.DHAT_UL]: 'DHat Up-Left', - [SectionIndex.DHAT_UR]: 'DHat Up-Right', - [SectionIndex.DHAT_DL]: 'DHat Down-Left', - [SectionIndex.DHAT_DR]: 'DHat Down-Right', - [SectionIndex.DHAT_PUSH]: 'DHat Push', + [SectionIndex.LSTICK_SETTINGS]: 'LStick Settings', + [SectionIndex.LSTICK_LEFT]: 'LStick Left', + [SectionIndex.LSTICK_RIGHT]: 'LStick Right', + [SectionIndex.LSTICK_UP]: 'LStick Up', + [SectionIndex.LSTICK_DOWN]: 'LStick Down', + [SectionIndex.LSTICK_UL]: 'LStick Up-Left', + [SectionIndex.LSTICK_UR]: 'LStick Up-Right', + [SectionIndex.LSTICK_DL]: 'LStick Down-Left', + [SectionIndex.LSTICK_DR]: 'LStick Down-Right', + [SectionIndex.LSTICK_PUSH]: 'LStick Push', + [SectionIndex.LSTICK_INNER]: 'LStick Inner', + [SectionIndex.LSTICK_OUTER]: 'LStick Outer', + [SectionIndex.RSTICK_SETTINGS]: 'RStick Settings', + [SectionIndex.RSTICK_LEFT]: 'RStick Left', + [SectionIndex.RSTICK_RIGHT]: 'RStick Right', + [SectionIndex.RSTICK_UP]: 'RStick Up', + [SectionIndex.RSTICK_DOWN]: 'RStick Down', + [SectionIndex.RSTICK_UL]: 'RStick Up-Left', + [SectionIndex.RSTICK_UR]: 'RStick Up-Right', + [SectionIndex.RSTICK_DL]: 'RStick Down-Left', + [SectionIndex.RSTICK_DR]: 'RStick Down-Right', + [SectionIndex.RSTICK_PUSH]: 'RStick Push', [SectionIndex.ROTARY_UP]: 'Rotary up', [SectionIndex.ROTARY_DOWN]: 'Rotary down', - [SectionIndex.THUMBSTICK]: 'Thumbstick settings', - [SectionIndex.THUMBSTICK_LEFT]: 'Thumbstick Left', - [SectionIndex.THUMBSTICK_RIGHT]: 'Thumbstick Right', - [SectionIndex.THUMBSTICK_UP]: 'Thumbstick Up', - [SectionIndex.THUMBSTICK_DOWN]: 'Thumbstick Down', - [SectionIndex.THUMBSTICK_PUSH]: 'Thumbstick Push', - [SectionIndex.THUMBSTICK_INNER]: 'Thumbstick Inner', - [SectionIndex.THUMBSTICK_OUTER]: 'Thumbstick Outer', - [SectionIndex.GYRO]: 'Gyro settings', + [SectionIndex.GYRO_SETTINGS]: 'Gyro settings', [SectionIndex.GYRO_X]: 'Gyro Axis X', [SectionIndex.GYRO_Y]: 'Gyro Axis Y', [SectionIndex.GYRO_Z]: 'Gyro Axis Z', diff --git a/src/lib/ctrl.ts b/src/lib/ctrl.ts index 79f50f1..85e58e7 100644 --- a/src/lib/ctrl.ts +++ b/src/lib/ctrl.ts @@ -40,8 +40,8 @@ export enum ConfigIndex { export enum SectionIndex { NONE, - META, - A = 2, + META = 1, + A, B, X, Y, @@ -59,26 +59,33 @@ export enum SectionIndex { R2, L4, R4, - DHAT_LEFT, - DHAT_RIGHT, - DHAT_UP, - DHAT_DOWN, - DHAT_UL, - DHAT_UR, - DHAT_DL, - DHAT_DR, - DHAT_PUSH, - ROTARY_UP, + ROTARY_UP = 29, ROTARY_DOWN, - THUMBSTICK, - THUMBSTICK_LEFT, - THUMBSTICK_RIGHT, - THUMBSTICK_UP, - THUMBSTICK_DOWN, - THUMBSTICK_PUSH, - THUMBSTICK_INNER, - THUMBSTICK_OUTER, - GLYPHS_0, + LSTICK_SETTINGS = 31, + LSTICK_LEFT, + LSTICK_RIGHT, + LSTICK_UP, + LSTICK_DOWN, + LSTICK_UL = 55, + LSTICK_UR, + LSTICK_DL, + LSTICK_DR, + LSTICK_PUSH = 36, + LSTICK_INNER, + LSTICK_OUTER, + RSTICK_SETTINGS = 59, + RSTICK_LEFT = 20, + RSTICK_RIGHT, + RSTICK_UP, + RSTICK_DOWN, + RSTICK_UL, + RSTICK_UR, + RSTICK_DL, + RSTICK_DR, + RSTICK_PUSH, + RSTICK_INNER = 60, + RSTICK_OUTER, + GLYPHS_0 = 39, GLYPHS_1, GLYPHS_2, GLYPHS_3, @@ -86,7 +93,7 @@ export enum SectionIndex { DAISY_1, DAISY_2, DAISY_3, - GYRO, + GYRO_SETTINGS, GYRO_X, GYRO_Y, GYRO_Z, @@ -117,6 +124,7 @@ export enum ThumbstickMode { OFF, DIR4, ALPHANUMERIC, + DIR8, } export enum ThumbstickDistanceMode { @@ -136,31 +144,30 @@ export function sectionIsMeta(section: SectionIndex) { return section == SectionIndex.META } -export function sectionIsButton(section: SectionIndex) { - return ( - (section >= SectionIndex.A && section <= SectionIndex.DHAT_PUSH) || - (section >= SectionIndex.THUMBSTICK_LEFT && section <= SectionIndex.THUMBSTICK_OUTER) - ) -} - export function sectionIsRotary(section: SectionIndex) { return section == SectionIndex.ROTARY_UP || section == SectionIndex.ROTARY_DOWN } export function sectionIsThumbtick(section: SectionIndex) { - return section == SectionIndex.THUMBSTICK + return ( + section==SectionIndex.LSTICK_SETTINGS || + section==SectionIndex.RSTICK_SETTINGS + ) } export function sectionIsThumbtickDirection(section: SectionIndex) { - return section >= SectionIndex.THUMBSTICK_LEFT && section <= SectionIndex.THUMBSTICK_DOWN + return ( + (section >= SectionIndex.LSTICK_LEFT && section <= SectionIndex.LSTICK_DOWN) || + (section >= SectionIndex.RSTICK_LEFT && section <= SectionIndex.RSTICK_DOWN) + ) } export function sectionIsThumbtickButton(section: SectionIndex) { - return sectionIsThumbtickDirection(section) || section == SectionIndex.THUMBSTICK_PUSH + return sectionIsThumbtickDirection(section) || section == SectionIndex.LSTICK_PUSH } export function sectionIsGyro(section: SectionIndex) { - return section == SectionIndex.GYRO + return section == SectionIndex.GYRO_SETTINGS } export function sectionIsGyroAxis(section: SectionIndex) { @@ -213,17 +220,17 @@ export class Ctrl { // See: https://github.com/inputlabs/alpakka_firmware/blob/main/docs/ctrl_protocol.md const data = Array.from(buffer) const msgType = data[2] - if (msgType== MessageType.LOG) return CtrlLog.decode(buffer) - if (msgType== MessageType.STATUS_SHARE) return CtrlStatusShare.decode(buffer) + if (msgType == MessageType.LOG) return CtrlLog.decode(buffer) + if (msgType == MessageType.STATUS_SHARE) return CtrlStatusShare.decode(buffer) if (msgType == MessageType.CONFIG_SHARE) return CtrlConfigShare.decode(buffer) if (msgType == MessageType.SECTION_SHARE) { const section = data[5] if (sectionIsMeta(section)) return CtrlSectionMeta.decode(buffer) - if (sectionIsButton(section)) return CtrlButton.decode(buffer) - if (sectionIsRotary(section)) return CtrlRotary.decode(buffer) - if (sectionIsThumbtick(section)) return CtrlThumbstick.decode(buffer) - if (sectionIsGyro(section)) return CtrlGyro.decode(buffer) - if (sectionIsGyroAxis(section)) return CtrlGyroAxis.decode(buffer) + else if (sectionIsRotary(section)) return CtrlRotary.decode(buffer) + else if (sectionIsThumbtick(section)) return CtrlThumbstick.decode(buffer) + else if (sectionIsGyro(section)) return CtrlGyro.decode(buffer) + else if (sectionIsGyroAxis(section)) return CtrlGyroAxis.decode(buffer) + else return CtrlButton.decode(buffer) } return false } @@ -552,6 +559,7 @@ export class CtrlThumbstick extends CtrlSection { public overlap : number, public deadzone_override: boolean, public antideadzone: number, + public saturation: number, ) { super(1, DeviceId.ALPAKKA, MessageType.SECTION_SHARE) } @@ -568,7 +576,8 @@ export class CtrlThumbstick extends CtrlSection { data[8], // Deadzone. data[9] <= 128 ? data[9] : data[9]-256, // Axis overlap (unsigned to signed). Boolean(data[10]), // Deadzone override. - data[11], // Antideadzone. + data[11], // Antideadzone. + data[12], // Saturation. ) } @@ -582,6 +591,7 @@ export class CtrlThumbstick extends CtrlSection { this.overlap, Number(this.deadzone_override), this.antideadzone, + this.saturation, ] } } diff --git a/src/lib/device.ts b/src/lib/device.ts index e09288c..4aa70b5 100644 --- a/src/lib/device.ts +++ b/src/lib/device.ts @@ -85,12 +85,11 @@ export class Device { async listen() { this.isListening = true try { - // console.log('Listening...') const response = await this.usbDevice.transferIn(ADDR_IN, PACKAGE_SIZE) let data = response.data as any const array = new Uint8Array(data.buffer) const ctrl = Ctrl.decode(array) - // console.log('received', ctrl) + // console.log('Received', ctrl) if (ctrl instanceof CtrlLog) this.handleCtrlLog(ctrl) if (ctrl instanceof CtrlStatusShare) this.handleCtrlStatusShare(ctrl) if (ctrl instanceof CtrlConfigShare) { @@ -137,6 +136,18 @@ export class Device { return false } + isDongle() { + return !this.isController() + } + + isAlpakkaV0() { + return this.usbDevice.serialNumber == 'v0' + } + + isAlpakkaV1() { + return this.usbDevice.serialNumber == 'v1' + } + handleCtrlLog(ctrl: CtrlLog) { if (!this.logs[0] || this.logs[0]?.endsWith('\n')) { this.logs.unshift(ctrl.logMessage) diff --git a/src/lib/hid.ts b/src/lib/hid.ts index 53d7f63..150b4b3 100644 --- a/src/lib/hid.ts +++ b/src/lib/hid.ts @@ -201,16 +201,16 @@ export enum HID { GAMEPAD_Y, GAMEPAD_AXIS_LX = GAMEPAD_AXIS_INDEX, - GAMEPAD_AXIS_LY, + GAMEPAD_AXIS_LY_NEG, // Inverted display of the vertical axis. GAMEPAD_AXIS_LZ, GAMEPAD_AXIS_RX, - GAMEPAD_AXIS_RY, + GAMEPAD_AXIS_RY_NEG, // Inverted. GAMEPAD_AXIS_RZ, GAMEPAD_AXIS_LX_NEG, - GAMEPAD_AXIS_LY_NEG, + GAMEPAD_AXIS_LY, // Inverted. GAMEPAD_AXIS_LZ_NEG, GAMEPAD_AXIS_RX_NEG, - GAMEPAD_AXIS_RY_NEG, + GAMEPAD_AXIS_RY, // Inverted. GAMEPAD_AXIS_RZ_NEG, PROC_PROFILE_0 = PROC_INDEX, diff --git a/src/lib/profile.ts b/src/lib/profile.ts index 52ea31f..e92b652 100644 --- a/src/lib/profile.ts +++ b/src/lib/profile.ts @@ -29,26 +29,35 @@ export class Profile { public buttonR1: CtrlButton = new CtrlButton(0, 0, 0), public buttonR2: CtrlButton = new CtrlButton(0, 0, 0), public buttonR4: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatLeft: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatRight: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatUp: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatDown: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatUL: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatUR: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatDL: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatDR: CtrlButton = new CtrlButton(0, 0, 0), - public buttonDhatPush: CtrlButton = new CtrlButton(0, 0, 0), - public buttonThumbstickLeft: CtrlButton = new CtrlButton(0, 0, 0), - public buttonThumbstickRight: CtrlButton = new CtrlButton(0, 0, 0), - public buttonThumbstickUp: CtrlButton = new CtrlButton(0, 0, 0), - public buttonThumbstickDown: CtrlButton = new CtrlButton(0, 0, 0), - public buttonThumbstickPush: CtrlButton = new CtrlButton(0, 0, 0), - public buttonThumbstickInner: CtrlButton = new CtrlButton(0, 0, 0), - public buttonThumbstickOuter: CtrlButton = new CtrlButton(0, 0, 0), + // Left stick. + public settingsLStick: CtrlThumbstick = new CtrlThumbstick(0, 0, 0, 0, 0, 0, false, 0, 0), + public buttonLStickLeft: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickRight: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickUp: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickDown: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickUL: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickUR: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickDL: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickDR: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickPush: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickInner: CtrlButton = new CtrlButton(0, 0, 0), + public buttonLStickOuter: CtrlButton = new CtrlButton(0, 0, 0), + // Right stick (stick or dhat). + public settingsRStick: CtrlThumbstick = new CtrlThumbstick(0, 0, 0, 0, 0, 0, false, 0, 0), + public buttonRStickLeft: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickRight: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickUp: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickDown: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickUL: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickUR: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickDL: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickDR: CtrlButton = new CtrlButton(0, 0, 0), + public buttonRStickPush: CtrlButton = new CtrlButton(0, 0, 0), + // Rotary. public rotaryUp: CtrlRotary = new CtrlRotary(0, 0), public rotaryDown: CtrlRotary = new CtrlRotary(0, 0), - public thumbstick: CtrlThumbstick = new CtrlThumbstick(0, 0, 0, 0, 0, 0, false, 0), - public gyro: CtrlGyro = new CtrlGyro(0, 0, 0, 0), + // Gyro. + public settingsGyro: CtrlGyro = new CtrlGyro(0, 0, 0, 0), public gyroX: CtrlGyroAxis = CtrlGyroAxis.default(), public gyroY: CtrlGyroAxis = CtrlGyroAxis.default(), public gyroZ: CtrlGyroAxis = CtrlGyroAxis.default(), diff --git a/src/lib/profiles.ts b/src/lib/profiles.ts index a43705d..e63a041 100644 --- a/src/lib/profiles.ts +++ b/src/lib/profiles.ts @@ -71,33 +71,41 @@ export class Profiles { profile.buttonR1 = await getButton(SectionIndex.R1) profile.buttonR2 = await getButton(SectionIndex.R2) profile.buttonR4 = await getButton(SectionIndex.R4) - profile.buttonDhatLeft = await getButton(SectionIndex.DHAT_LEFT) - profile.buttonDhatRight = await getButton(SectionIndex.DHAT_RIGHT) - profile.buttonDhatUp = await getButton(SectionIndex.DHAT_UP) - profile.buttonDhatDown = await getButton(SectionIndex.DHAT_DOWN) - profile.buttonDhatUL = await getButton(SectionIndex.DHAT_UL) - profile.buttonDhatUR = await getButton(SectionIndex.DHAT_UR) - profile.buttonDhatDL = await getButton(SectionIndex.DHAT_DL) - profile.buttonDhatDR = await getButton(SectionIndex.DHAT_DR) - profile.buttonDhatPush = await getButton(SectionIndex.DHAT_PUSH) - profile.buttonThumbstickLeft = await getButton(SectionIndex.THUMBSTICK_LEFT) - profile.buttonThumbstickRight = await getButton(SectionIndex.THUMBSTICK_RIGHT) - profile.buttonThumbstickUp = await getButton(SectionIndex.THUMBSTICK_UP) - profile.buttonThumbstickDown = await getButton(SectionIndex.THUMBSTICK_DOWN) - profile.buttonThumbstickPush = await getButton(SectionIndex.THUMBSTICK_PUSH) - profile.buttonThumbstickInner = await getButton(SectionIndex.THUMBSTICK_INNER) - profile.buttonThumbstickOuter = await getButton(SectionIndex.THUMBSTICK_OUTER) + // Left stick. + profile.buttonLStickLeft = await getButton(SectionIndex.LSTICK_LEFT) + profile.buttonLStickRight = await getButton(SectionIndex.LSTICK_RIGHT) + profile.buttonLStickUp = await getButton(SectionIndex.LSTICK_UP) + profile.buttonLStickDown = await getButton(SectionIndex.LSTICK_DOWN) + profile.buttonLStickUL = await getButton(SectionIndex.LSTICK_UL) + profile.buttonLStickUR = await getButton(SectionIndex.LSTICK_UR) + profile.buttonLStickDL = await getButton(SectionIndex.LSTICK_DL) + profile.buttonLStickDR = await getButton(SectionIndex.LSTICK_DR) + profile.buttonLStickPush = await getButton(SectionIndex.LSTICK_PUSH) + profile.buttonLStickInner = await getButton(SectionIndex.LSTICK_INNER) + profile.buttonLStickOuter = await getButton(SectionIndex.LSTICK_OUTER) + // Right stick (thumbstick or dhat). + profile.buttonRStickLeft = await getButton(SectionIndex.RSTICK_LEFT) + profile.buttonRStickRight = await getButton(SectionIndex.RSTICK_RIGHT) + profile.buttonRStickUp = await getButton(SectionIndex.RSTICK_UP) + profile.buttonRStickDown = await getButton(SectionIndex.RSTICK_DOWN) + profile.buttonRStickUL = await getButton(SectionIndex.RSTICK_UL) + profile.buttonRStickUR = await getButton(SectionIndex.RSTICK_UR) + profile.buttonRStickDL = await getButton(SectionIndex.RSTICK_DL) + profile.buttonRStickDR = await getButton(SectionIndex.RSTICK_DR) + profile.buttonRStickPush = await getButton(SectionIndex.RSTICK_PUSH) // Rotary. const rotaryUp = await this.device.getSection(profileIndex, SectionIndex.ROTARY_UP) as CtrlRotary const rotaryDown = await this.device.getSection(profileIndex, SectionIndex.ROTARY_DOWN) as CtrlRotary profile.rotaryUp = rotaryUp profile.rotaryDown = rotaryDown // Thumbstick mode. - const ts = await this.device.getSection(profileIndex, SectionIndex.THUMBSTICK) as CtrlThumbstick - profile.thumbstick = ts + const lStick = await this.device.getSection(profileIndex, SectionIndex.LSTICK_SETTINGS) as CtrlThumbstick + const rStick = await this.device.getSection(profileIndex, SectionIndex.RSTICK_SETTINGS) as CtrlThumbstick + profile.settingsLStick = lStick + profile.settingsRStick = rStick // Gyro mode. - const gyro = await this.device.getSection(profileIndex, SectionIndex.GYRO) as CtrlGyro - profile.gyro = gyro + const gyro = await this.device.getSection(profileIndex, SectionIndex.GYRO_SETTINGS) as CtrlGyro + profile.settingsGyro = gyro // Gyro Axes. profile.gyroX = await this.device.getSection(profileIndex, SectionIndex.GYRO_X) as CtrlGyroAxis profile.gyroY = await this.device.getSection(profileIndex, SectionIndex.GYRO_Y) as CtrlGyroAxis