-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Hi,
I'm building my own custom firmware to support OLED displays, however I have common buttons and LEDs as well. The problem is that, the LED is not working with custom firmware, just with the official firmware.
I dug myself into the code and I found that the MF Connector sends SetPin command with the configured pin number. However in the MF_Output the OnSet gets this argument and use as an index of pin array, not as pin number.
01/24/2026 10:47:08(901): MobiFlightOutput.Set(): Command: SetPin <2,18,0;>.
01/24/2026 10:47:08(901): MobiFlightOutput.Set(): Command: SetPin <2,20,0;>.
In my case, there are 2 LEDs as pins 18 and 20. So in the array, there are 2 items only. So when "SetPin" command received it doesn't find the output as index 18 and 20.
For a workaround, I changed the OnSet function to find the correct index based on the pin number:
Original:
void OnSet()
{
// Read led state argument, interpret string as boolean
int output = cmdMessenger.readInt16Arg();
int state = cmdMessenger.readInt16Arg();
outputs[output].set(state);
}Working code:
void OnSet()
{
// Read led state argument, interpret string as boolean
const int output = cmdMessenger.readInt16Arg();
const int state = cmdMessenger.readInt16Arg();
// Connector/firmware compatibility:
// Some connector versions send the *pin number* here, while the classic core firmware expects an *output index*.
// Prefer mapping by pin, fall back to index for backwards compatibility.
int mappedIndex = -1;
if (output >= 0 && output <= 255) {
for (uint8_t i = 0; i < outputsRegistered; ++i) {
if (outputs[i].pin() == (uint8_t)output) {
mappedIndex = (int)i;
break;
}
}
}
if (mappedIndex < 0) {
if (output >= 0 && output < (int)outputsRegistered) {
mappedIndex = output;
}
}
if (mappedIndex < 0) {
return;
}
outputs[mappedIndex].set((uint8_t)state);
}Is it a bug or there is something wrong in my configuration which cause wrong operation?
Thanks, in advance!