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.

Debug.cpp 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "Debug.h"
  2. void Debug::printMicrosecondsPerScan()
  3. {
  4. static unsigned long nextTime = 0;
  5. static unsigned int scanCount = 0;
  6. if (millis() >= nextTime)
  7. {
  8. Keyboard.print(1000000/scanCount); //print microseconds per scan
  9. Keyboard.write(',');
  10. scanCount = 0;
  11. nextTime = millis() + 1000; //print every second
  12. }
  13. scanCount++;
  14. }
  15. void Debug::printScansPerSecond()
  16. {
  17. static unsigned long nextTime = 0;
  18. static unsigned int scanCount = 0;
  19. if (millis() >= nextTime)
  20. {
  21. Keyboard.print(scanCount); //print scans per second
  22. Keyboard.write(',');
  23. scanCount = 0;
  24. nextTime = millis() + 1000; //print every second
  25. }
  26. scanCount++;
  27. }
  28. //Sometimes OS takes 6 seconds to recongnize keyboard.
  29. //wait_for_OS() will blink LED and count up once per second for specified number of seconds.
  30. void Debug::wait_for_OS(LEDInterface& led, const uint8_t seconds)
  31. {
  32. for (uint8_t elapsed = 0; elapsed < seconds; elapsed++)
  33. {
  34. //print seconds elapsed
  35. Keyboard.print(elapsed);
  36. Keyboard.print(F(" "));
  37. //blink LED
  38. led.on();
  39. delay(500);
  40. led.off();
  41. delay(500);
  42. }
  43. }