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.

RowBase.h 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef ROWBASE_H
  2. #define ROWBASE_H
  3. #include <Arduino.h>
  4. #include <inttypes.h>
  5. #include <Key.h>
  6. #include <RowPort.h>
  7. #include <ColPort.h>
  8. /* RowBase is an abstract base class.
  9. */
  10. class RowBase
  11. {
  12. private:
  13. static const unsigned int DELAY_MICROSECONDS; //delay between each Row scan for debouncing
  14. Key *const *const ptrsKeys; //array of Key pointers
  15. RowPort &refRowPort; //this row's IC port
  16. const uint8_t rowPin; //bitwise, 1 indicates IC pin connected to this row
  17. ColPort *const *const ptrsColPorts; //array of column ports
  18. const uint8_t colPortCount;
  19. virtual void keyWasPressed();
  20. protected:
  21. uint8_t debounced; //bitwise, 1 means pressed, 0 means released
  22. void wait();
  23. void scan(const bool activeHigh);
  24. uint8_t getRowState(uint16_t& rowEnd, const bool activeHigh);
  25. void pressRelease(const uint16_t rowEnd, const uint8_t debouncedChanged);
  26. public:
  27. RowBase( RowPort &refRowPort, const uint8_t rowPin,
  28. ColPort *const ptrsColPorts[], const uint8_t colPortCount,
  29. Key *const ptrsKeys[])
  30. : ptrsKeys(ptrsKeys), refRowPort(refRowPort), rowPin(rowPin),
  31. ptrsColPorts(ptrsColPorts), colPortCount(colPortCount),
  32. debounced(0) { }
  33. virtual void process(const bool activeHigh)=0;
  34. };
  35. #endif