2016-11-26 06:11:40 +00:00
|
|
|
#include "promethium.h"
|
2017-02-10 14:28:46 +00:00
|
|
|
#include "analog.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "matrix.h"
|
2022-01-30 17:29:42 +00:00
|
|
|
#include "bluefruit_le.h"
|
2017-04-18 18:38:08 +00:00
|
|
|
|
2017-02-11 07:50:43 +00:00
|
|
|
// 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}
|
|
|
|
|
|
|
|
uint8_t battery_level(void) {
|
2022-01-30 17:29:42 +00:00
|
|
|
float voltage = bluefruit_le_read_battery_voltage() * 2 * 3.3 / 1024;
|
2017-02-11 07:50:43 +00:00
|
|
|
if (voltage < MIN_VOLTAGE) return 0;
|
|
|
|
if (voltage > MAX_VOLTAGE) return 255;
|
|
|
|
return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
|
2017-02-10 14:28:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__ ((weak))
|
2017-02-11 07:50:43 +00:00
|
|
|
void battery_poll(uint8_t level) {
|
2017-02-10 14:28:46 +00:00
|
|
|
}
|
2016-11-26 06:11:40 +00:00
|
|
|
|
2024-07-27 05:02:51 +00:00
|
|
|
void housekeeping_task_kb(void) {
|
2017-02-10 14:28:46 +00:00
|
|
|
static uint16_t counter = BATTERY_POLL;
|
|
|
|
counter++;
|
|
|
|
|
|
|
|
if (counter > BATTERY_POLL) {
|
|
|
|
counter = 0;
|
2017-02-11 07:50:43 +00:00
|
|
|
battery_poll(battery_level());
|
2017-02-10 14:28:46 +00:00
|
|
|
}
|
|
|
|
}
|