From b5ce02e944f5bbe3289f6c94aecfbe5741b91bc4 Mon Sep 17 00:00:00 2001 From: Luke Arntson Date: Thu, 2 Jan 2025 15:55:07 -0500 Subject: [PATCH] Modified gamepad options so vendorID and productID are strings instead of integers when passing data to the web config. Saving is still an integer so we don't have to parse the string on the webconfig.cpp side. --- src/configs/webconfig.cpp | 11 ++++++++--- www/server/app.js | 4 ++-- www/src/Pages/SettingsPage.jsx | 6 ++++-- www/src/Services/WebApi.js | 4 ---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/configs/webconfig.cpp b/src/configs/webconfig.cpp index 790e56567..d5d9c7011 100644 --- a/src/configs/webconfig.cpp +++ b/src/configs/webconfig.cpp @@ -737,9 +737,14 @@ std::string getGamepadOptions() writeDoc(doc, "usbDescProduct", gamepadOptions.usbDescProduct); writeDoc(doc, "usbDescVersion", gamepadOptions.usbDescVersion); writeDoc(doc, "usbOverrideID", gamepadOptions.usbOverrideID); - writeDoc(doc, "usbVendorID", gamepadOptions.usbVendorID); - writeDoc(doc, "usbProductID", gamepadOptions.usbProductID); - + // Write USB Vendor ID and Product ID as 4 character hex strings with 0 padding + char idBuffer[5]; + snprintf(idBuffer, 4, "%04X", gamepadOptions.usbVendorID); + idBuffer[4] = '\0'; + writeDoc(doc, "usbVendorID", idBuffer); + snprintf(idBuffer, 4, "%04X", gamepadOptions.usbProductID); + idBuffer[4] = '\0'; + writeDoc(doc, "usbProductID", idBuffer); writeDoc(doc, "fnButtonPin", -1); GpioMappingInfo* gpioMappings = Storage::getInstance().getGpioMappings().pins; for (unsigned int pin = 0; pin < NUM_BANK0_GPIOS; pin++) { diff --git a/www/server/app.js b/www/server/app.js index 88fe99aae..8734f7f7d 100644 --- a/www/server/app.js +++ b/www/server/app.js @@ -120,8 +120,8 @@ app.get('/api/getGamepadOptions', (req, res) => { usbDescManufacturer: 'Open Stick Community', usbDescVersion: '1.0', usbOverrideID: 0, - usbVendorID: 4292, - usbProductID: 33472, + usbVendorID: '10C4', + usbProductID: '82C0', hotkey01: { auxMask: 32768, buttonsMask: 66304, diff --git a/www/src/Pages/SettingsPage.jsx b/www/src/Pages/SettingsPage.jsx index 97fdf17fd..214299443 100644 --- a/www/src/Pages/SettingsPage.jsx +++ b/www/src/Pages/SettingsPage.jsx @@ -1062,10 +1062,11 @@ export default function SettingsPage() { size="sm" type="text" name="usbVendorID" - value={values.usbVendorID.toString(16).toUpperCase()} + value={values.usbVendorID} error={errors.usbVendorID} isInvalid={errors?.usbVendorID} onChange={handleChange} + onBlur={(e)=>{e.target.value = e.target.value.padStart(4,'0'); return handleChange(e)}} minLength={4} maxLength={4} /> @@ -1076,10 +1077,11 @@ export default function SettingsPage() { size="sm" type="text" name="usbProductID" - value={values.usbProductID.toString(16).toUpperCase()} + value={values.usbProductID} error={errors?.usbProductID} isInvalid={errors?.usbProductID} onChange={handleChange} + onBlur={(e)=>{e.target.value = e.target.value.padStart(4,'0'); return handleChange(e)}} minLength={4} maxLength={4} /> diff --git a/www/src/Services/WebApi.js b/www/src/Services/WebApi.js index af845b167..e6f024405 100644 --- a/www/src/Services/WebApi.js +++ b/www/src/Services/WebApi.js @@ -276,10 +276,6 @@ async function getGamepadOptions(setLoading) { try { const response = await Http.get(`${baseUrl}/api/getGamepadOptions`); setLoading(false); - - response.data.usbVendorID = response.data.usbVendorID.toString(16).toUpperCase() || '0000'; - response.data.usbProductID = response.data.usbProductID.toString(16).toUpperCase() || '0000'; - return response.data; } catch (error) { setLoading(false);