You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ModulinoKnob::get() method currently has a bug where it properly returns 0 when the I2C read operation fails, but it fails to update the internal _pressed state variable. This means that subsequent calls to isPressed() will return whatever the last successfully read button state was, rather than indicating that the state is unknown/invalid.
✅ Expected behavior
When I2C communication fails, both the position value and the button state should be invalidated.
❌ Current behavior
If I2C communication fails, the position is reset to 0, but the button state remains at its last known valid value.
🎮 Reproduction
Successfully read a knob with button pressed (_pressed = true)
Disconnect the I2C bus or cause another communication failure
Call get() - returns 0 as expected
Call isPressed() - incorrectly returns true when it should acknowledge the failure
✅ Proposed solution
Update the get() method to reset _pressed to false when read fails:
int16_tget() {
uint8_t buf[3];
auto res = read(buf, 3);
if (res == false) {
_pressed = false; // Reset pressed state on read failurereturn0;
}
_pressed = (buf[2] != 0);
int16_t ret = buf[0] | (buf[1] << 8);
return ret;
}
Modulino/src/Modulino.h
Lines 273 to 275 in cf5e2b2
The text was updated successfully, but these errors were encountered: