promethium.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "promethium.h"
  2. #include "analog.h"
  3. #include "timer.h"
  4. #include "matrix.h"
  5. #include "musical_notes.h"
  6. #include "adafruit_ble.h"
  7. float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_A4, 0.0625);
  8. float fauxclicky_released_note[2] = MUSICAL_NOTE(_A4, 0.0625);
  9. float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C6, 0.25);
  10. // 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}
  11. uint8_t battery_level(void) {
  12. float voltage = adafruit_ble_read_battery_voltage() * 2 * 3.3 / 1024;
  13. if (voltage < MIN_VOLTAGE) return 0;
  14. if (voltage > MAX_VOLTAGE) return 255;
  15. return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
  16. }
  17. __attribute__ ((weak))
  18. void battery_poll(uint8_t level) {
  19. }
  20. void matrix_init_kb(void) {
  21. matrix_init_user();
  22. }
  23. void matrix_scan_kb(void) {
  24. static uint16_t counter = BATTERY_POLL;
  25. counter++;
  26. if (counter > BATTERY_POLL) {
  27. counter = 0;
  28. battery_poll(battery_level());
  29. }
  30. matrix_scan_user();
  31. }
  32. void led_set_kb(uint8_t usb_led) {
  33. led_set_user(usb_led);
  34. }
  35. __attribute__ ((weak))
  36. void led_set_user(uint8_t usb_led) {
  37. }