keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

Row.cpp 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "Row.h"
  2. /*
  3. send() calls key's press() or release() function if key was pressed or released.
  4. Both parameters are bitwise.
  5. */
  6. void Row::send(const uint8_t readPinCount, const read_pins_t debouncedChanged)
  7. {
  8. read_pins_t isFallingEdge; //bitwise, 1 means falling edge
  9. read_pins_t isRisingEdge; //bitwise, 1 means rising edge
  10. read_pins_t readMask; //bitwise, active bit is 1
  11. uint8_t i; //index for ptrsKeys[i] array
  12. //bit=1 if last debounced changed from 1 to 0, else bit=0
  13. isFallingEdge = debouncedChanged & ~debounced;
  14. //bit=1 if last debounced changed from 0 to 1, else bit=0
  15. isRisingEdge = debouncedChanged & debounced;
  16. for (readMask=1, i=0; i < readPinCount; readMask<<=1, i++) //for each key in row
  17. {
  18. //release before press avoids impossible key sequence
  19. if (readMask & isFallingEdge) //if key was released
  20. {
  21. ptrsKeys[i]->release();
  22. }
  23. if (readMask & isRisingEdge) //if key was pressed
  24. {
  25. ptrsKeys[i]->press();
  26. keyWasPressed();
  27. }
  28. }
  29. }
  30. void Row::keyWasPressed()
  31. {
  32. //empty in Row class. To unstick sticky keys, override keyWasPressed() in derived Row class.
  33. }