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.

47 lines
1.1 KiB

7 years ago
  1. #include "promethium.h"
  2. #include "analog.h"
  3. #include "timer.h"
  4. #include "matrix.h"
  5. #include "musical_notes.h"
  6. float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_A4, 0.0625);
  7. float fauxclicky_released_note[2] = MUSICAL_NOTE(_A4, 0.0625);
  8. float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C6, 0.25);
  9. // cubic fit {3.3, 0}, {3.5, 2.9}, {3.6, 5}, {3.7, 8.6}, {3.8, 36}, {3.9, 62}, {4.0, 73}, {4.05, 83}, {4.1, 89}, {4.15, 94}, {4.2, 100}
  10. uint8_t battery_level(void) {
  11. float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024;
  12. if (voltage < MIN_VOLTAGE) return 0;
  13. if (voltage > MAX_VOLTAGE) return 255;
  14. return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
  15. }
  16. __attribute__ ((weak))
  17. void battery_poll(uint8_t level) {
  18. }
  19. void matrix_init_kb(void) {
  20. matrix_init_user();
  21. }
  22. void matrix_scan_kb(void) {
  23. static uint16_t counter = BATTERY_POLL;
  24. counter++;
  25. if (counter > BATTERY_POLL) {
  26. counter = 0;
  27. battery_poll(battery_level());
  28. }
  29. matrix_scan_user();
  30. }
  31. void led_set_kb(uint8_t usb_led) {
  32. led_set_user(usb_led);
  33. }
  34. __attribute__ ((weak))
  35. void led_set_user(uint8_t usb_led) {
  36. }