Skip to content

Commit

Permalink
Yup.boolean() should be Yup.number()
Browse files Browse the repository at this point in the history
Updated app to propery convert hex and int
  • Loading branch information
arntsonl committed Dec 23, 2024
1 parent e8c04ba commit f07b701
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ app.get('/api/getAddonsOptions', (req, res) => {
pinShmupDial: -1,
turboLedType: 1,
turboLedIndex: 16,
turboLedColor: '#065280',
turboLedColor: 16711680,
sliderSOCDModeDefault: 1,
snesPadClockPin: -1,
snesPadLatchPin: -1,
Expand Down
8 changes: 4 additions & 4 deletions www/src/Addons/Rotary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const rotaryScheme = {
.number()
.required()
.label('Rotary Encoder Add-On Enabled'),
encoderOneEnabled: yup.boolean().required().label('Encoder One Enabled'),
encoderOneEnabled: yup.number().required().label('Encoder One Enabled'),
encoderOnePinA: yup
.number()
.label('Encoder One Pin A')
Expand All @@ -61,11 +61,11 @@ export const rotaryScheme = {
.label('Encoder One Reset After')
.required(),
encoderOneAllowWrapAround: yup
.boolean()
.number()
.required()
.label('Encoder One Allow Wrap Around'),
encoderOneMultiplier: yup.number().label('Encoder One Multiplier').required(),
encoderTwoEnabled: yup.boolean().required().label('Encoder Two Enabled'),
encoderTwoEnabled: yup.number().required().label('Encoder Two Enabled'),
encoderTwoPinA: yup
.number()
.label('Encoder Two Pin A')
Expand All @@ -83,7 +83,7 @@ export const rotaryScheme = {
.label('Encoder Two Reset After')
.required(),
encoderTwoAllowWrapAround: yup
.boolean()
.number()
.required()
.label('Encoder Two Allow Wrap Around'),
encoderTwoMultiplier: yup.number().label('Encoder Two Multiplier').required(),
Expand Down
6 changes: 6 additions & 0 deletions www/src/Pages/AddonsConfigPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import set from 'lodash/set';

import { AppContext } from '../Contexts/AppContext';

import { hexToInt } from '../Services/Utilities';

import WebApi from '../Services/WebApi';
import Analog, { analogScheme, analogState } from '../Addons/Analog';
import Analog1256, {
Expand Down Expand Up @@ -59,6 +61,7 @@ import ReactiveLED, {
reactiveLEDScheme,
reactiveLEDState,
} from '../Addons/ReactiveLED';
import { rgbIntToHex } from '../Services/Utilities';

const schema = yup.object().shape({
...analogScheme,
Expand Down Expand Up @@ -198,6 +201,9 @@ export default function AddonsConfigPage() {
const flattened = flattenObject(storedData);
const valuesCopy = schema.cast(values); // Strip invalid values

// Convert turbo LED color if available
values.turboLedColor = hexToInt(values.turboLedColor || '#000000');

// Compare what's changed and set it to resultObject
let resultObject = {};
Object.entries(flattened)?.map((entry) => {
Expand Down
2 changes: 2 additions & 0 deletions www/src/Services/WebApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ async function getAddonsOptions(setLoading) {
const data = response.data;
setLoading(false);

response.data.turboLedColor = rgbIntToHex(response.data.turboLedColor) || '#ffffff';

// Merge saved keyMappings with defaults
const keyboardHostMap = Object.entries(data.keyboardHostMap).reduce(
(acc, [key, value]) => ({ ...acc, [key]: { ...acc[key], key: value } }),
Expand Down

0 comments on commit f07b701

Please sign in to comment.