From 446f9eb1007abcf5ccfd5980514d4817ab8cac3e Mon Sep 17 00:00:00 2001 From: Everton Correia <1169768+evertonstz@users.noreply.github.com> Date: Fri, 3 May 2024 14:59:29 -0300 Subject: [PATCH] Implement haptics message (#51) Fixes #50 --- src/components/MainContent/SelectedDevice.tsx | 22 ++++ src/pax/containers/api/get.ts | 3 + src/pax/core/messages/HapticsMessage.ts | 109 ++++++++++++++++++ src/pax/core/messages/index.ts | 1 + src/state/paxState/actions.ts | 10 ++ src/state/paxState/reducer.ts | 3 + src/state/paxState/types.ts | 1 + 7 files changed, 149 insertions(+) create mode 100644 src/pax/core/messages/HapticsMessage.ts diff --git a/src/components/MainContent/SelectedDevice.tsx b/src/components/MainContent/SelectedDevice.tsx index e8647c3..258403c 100644 --- a/src/components/MainContent/SelectedDevice.tsx +++ b/src/components/MainContent/SelectedDevice.tsx @@ -6,6 +6,7 @@ import { BatteryPercentageMessage, BrightnessMessage, ColorThemeMessage, + HapticsMessage, RequestStatusMessage, } from '@/pax/core/messages'; import { Messages } from '@/pax/shared/enums'; @@ -60,6 +61,9 @@ export const SelectedDevice = ({ currentDevice }: SelectedDeviceProps) => { if (message instanceof BrightnessMessage) { actions.setBrightness(message.brightness); } + if (message instanceof HapticsMessage) { + actions.setHaptics(message.percentage); + } }) .catch(e => { if (e instanceof BaseBluetoothException) { @@ -119,6 +123,23 @@ export const SelectedDevice = ({ currentDevice }: SelectedDeviceProps) => { void bluetoothState.writeToMainService(toPost.packet); }} /> + { + actions.setHaptics(value[0]); + }} + onValueCommit={value => { + const toPost = post( + HapticsMessage.createWithHaptics(value[0]), + currentDevice, + ); + void bluetoothState.writeToMainService(toPost.packet); + }} + /> +

Device: {!currentDevice ? '' : currentDevice.serial}