Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle debounce in I2CKeypad_interrupts_1 example #24

Merged
merged 1 commit into from
Aug 19, 2024

Conversation

rafork
Copy link
Contributor

@rafork rafork commented Aug 13, 2024

Hi, The example code in I2CKeypad_interrupts_1.ino has a potential bug. The loop() function doesn't handle the case where getKey() returns I2C_KEYPAD_THRESHOLD (255). Instead, it uses the number 255 as an index into an array of 19 bytes. That's an invalid memory access. To fix it, the following should be added after the call to getKey().

if (index == I2C_KEYPAD_THRESHOLD)
    return;

Perhaps it's not really a bug since it doesn't call the new setDebounceThreshold() method, but this pull request does that as well. It might not strictly be necessary for this example, but I think it makes it a better example.

@RobTillaart RobTillaart self-assigned this Aug 13, 2024
@RobTillaart RobTillaart added the enhancement New feature or request label Aug 13, 2024
@RobTillaart
Copy link
Owner

RobTillaart commented Aug 13, 2024

good catch,
The object keypad should be KeyPad, as the example doesn't compile anymore.

@rafork rafork force-pushed the interrupt_handle_debounce branch from d77df2b to 3142859 Compare August 15, 2024 21:49
@rafork
Copy link
Contributor Author

rafork commented Aug 15, 2024

Oops. I've fixed that (keyPad, not KeyPad).

@RobTillaart
Copy link
Owner

RobTillaart commented Aug 16, 2024

@rafork

There is another one to fix

Compilation failure details... 
    compiler_err... 
        /home/runner/work/I2CKeyPad/I2CKeyPad/examples/I2CKeypad_interrupts_1/I2CKeypad_interrupts_1.ino: In function 'void setup()':
        /home/runner/work/I2CKeyPad/I2CKeyPad/examples/I2CKeypad_interrupts_1/I2CKeypad_interrupts_1.ino:83:3: error: 'keypad' was not declared in this scope; did you mean 'keyPad'?
           83 |   keypad.setDebounceThreshold(50);
              |   ^~~~~~
              |   keyPad
    ...compiler_err         

did you push the fix to the rafork:interrupt_handle_debounce branch

@rafork rafork force-pushed the interrupt_handle_debounce branch from 3142859 to 812dd39 Compare August 18, 2024 11:37
@rafork
Copy link
Contributor Author

rafork commented Aug 18, 2024

Oops. It's there now.

@RobTillaart RobTillaart merged commit 8eb9f43 into RobTillaart:master Aug 19, 2024
3 checks passed
@RobTillaart
Copy link
Owner

@rafork
Merged into master,
Thanks again for the fix, appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants