ramapcsx2 / gbs-control

GNU General Public License v3.0
784 stars 110 forks source link

Setting toggle buttons not updated when no preset is selected #323

Open karas84 opened 2 years ago

karas84 commented 2 years ago

While no preset is selected, as can happen after performing a default reset through the "Reset Defaults" button in the system tab, toggle buttons in the preference tab are not updated.

Looking at the source code it seems that the problem is caused by the server sending the preset slot number as char "as is" in gbs-control.ino:

toSend[2] = (char)uopt->presetSlot;.

In fact, upon reset, the slot number is always set to 0, which is interpreted as string termination character by the WebSocket client. This results in the ping message being converted to "#0" and thus the subsequent bytes used for encoding the various settings are effectively always ignored, resulting in all toggle buttons being set to off.

This can be observed on the client side in the onmessage callback. While parsing the received message:

const [messageDataAt0, messageDataAt1, messageDataAt2, messageDataAt3, messageDataAt4, messageDataAt5,] = message.data;

the various bytes result as follows:

messageDataAt0 is "#", messageDataAt1 is "0", but messageDataAt2, messageDataAt3, messageDataAt4, messageDataAt5 are all set to undefined.