keybrd library is an open source library for creating custom-keyboard firmware.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "Row.h"
  2. /* constructor
  3. */
  4. Row::Row(ScannerInterface& refScanner, const uint8_t strobePin,
  5. Key* const ptrsKeys[], const uint8_t readPinCount)
  6. : refScanner(refScanner), strobePin(strobePin),
  7. ptrsKeys(ptrsKeys), readPinCount(readPinCount), debounced(0)
  8. {
  9. refScanner.begin(strobePin);
  10. }
  11. /* process() scans the row and calls any newly pressed or released keys.
  12. Bitwise variables are 1 bit per key.
  13. */
  14. void Row::process()
  15. {
  16. read_pins_t readState; //bitwise, 1 means key is pressed, 0 means released
  17. read_pins_t debouncedChanged; //bitwise, 1 means debounced changed
  18. readState = refScanner.scan(strobePin);
  19. debouncedChanged = debouncer.debounce(readState, debounced);
  20. send(readPinCount, debouncedChanged);
  21. }
  22. /*
  23. send() calls key's press() or release() function if key was pressed or released.
  24. Both parameters are bitwise.
  25. */
  26. void Row::send(const uint8_t readPinCount, const read_pins_t debouncedChanged)
  27. {
  28. read_pins_t isFallingEdge; //bitwise, 1 means falling edge
  29. read_pins_t isRisingEdge; //bitwise, 1 means rising edge
  30. read_pins_t readMask; //bitwise, active bit is 1
  31. uint8_t i; //index for ptrsKeys[i] array
  32. //bit=1 if last debounced changed from 1 to 0, else bit=0
  33. isFallingEdge = debouncedChanged & ~debounced;
  34. //bit=1 if last debounced changed from 0 to 1, else bit=0
  35. isRisingEdge = debouncedChanged & debounced;
  36. for (readMask=1, i=0; i < readPinCount; readMask<<=1, i++) //for each key in row
  37. {
  38. //release before press avoids impossible key sequence
  39. if (readMask & isFallingEdge) //if key was released
  40. {
  41. ptrsKeys[i]->release();
  42. }
  43. if (readMask & isRisingEdge) //if key was pressed
  44. {
  45. ptrsKeys[i]->press();
  46. keyWasPressed();
  47. }
  48. }
  49. }
  50. void Row::keyWasPressed()
  51. {
  52. //empty in Row class. To unstick sticky keys, override keyWasPressed() in derived Row class.
  53. }