Implement battery level indicator
This commit is contained in:
parent
07879bf66b
commit
5944ab246a
6 changed files with 97 additions and 11 deletions
|
@ -25,6 +25,7 @@ enum glow_modes {
|
|||
GLOW_MIN,
|
||||
GLOW_FULL
|
||||
};
|
||||
|
||||
uint8_t glow_mode = GLOW_MIN;
|
||||
|
||||
extern keymap_config_t keymap_config;
|
||||
|
@ -505,11 +506,6 @@ void led_init(void) {
|
|||
rgbsps_set(LED_TRACKPOINT2, 0, 0, 15);
|
||||
rgbsps_set(LED_TRACKPOINT3, 15, 0, 0);
|
||||
|
||||
// // hardcode indicator for now
|
||||
rgbsps_set(LED_IND_BLUETOOTH, 0, 0, 15);
|
||||
rgbsps_set(LED_IND_USB, 15, 15, 15);
|
||||
rgbsps_set(LED_IND_BATTERY, 0, 15, 0);
|
||||
|
||||
led_layer_normal();
|
||||
}
|
||||
|
||||
|
@ -996,6 +992,11 @@ void matrix_init_user(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void battery_poll(float percentage) {
|
||||
rgbsps_sethsv(LED_IND_BATTERY, percentage*120/100, 255, 15);
|
||||
rgbsps_send();
|
||||
}
|
||||
|
||||
void ps2_mouse_init_user() {
|
||||
uint8_t rcv;
|
||||
|
||||
|
|
|
@ -1,6 +1,36 @@
|
|||
#include "promethium.h"
|
||||
#include "analog.h"
|
||||
#include "timer.h"
|
||||
#include "matrix.h"
|
||||
|
||||
float battery_percentage(void) {
|
||||
float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024;
|
||||
float percentage = (voltage - 3.5) * 143;
|
||||
if (percentage > 100) {
|
||||
return 100;
|
||||
} else if (percentage < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return percentage;
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void battery_poll(float percentage) {
|
||||
}
|
||||
|
||||
void matrix_init_kb(void) {
|
||||
|
||||
matrix_init_user();
|
||||
}
|
||||
|
||||
void matrix_scan_kb(void) {
|
||||
static uint16_t counter = BATTERY_POLL;
|
||||
counter++;
|
||||
|
||||
if (counter > BATTERY_POLL) {
|
||||
counter = 0;
|
||||
battery_poll(battery_percentage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#define PS2_INIT_DELAY 2000
|
||||
#define UNICODE_TYPE_DELAY 0
|
||||
#define BATTERY_PIN 9
|
||||
#define BATTERY_POLL 30000
|
||||
|
||||
#define KEYMAP( \
|
||||
k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, \
|
||||
|
@ -23,6 +25,8 @@
|
|||
{k47, k48, k49, k4a, k4b, k4c} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum led_sequence {
|
||||
LED_IND_BLUETOOTH,
|
||||
LED_IND_USB,
|
||||
|
@ -99,4 +103,4 @@ enum led_sequence {
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
void battery_poll(float percentage);
|
|
@ -22,3 +22,52 @@ void rgbsps_turnoff(void) {
|
|||
void rgbsps_send(void) {
|
||||
ws2812_setleds(led, RGBSPS_NUM);
|
||||
}
|
||||
|
||||
void rgbsps_sethsv(uint8_t index, uint16_t hue, uint8_t sat, uint8_t val) {
|
||||
uint8_t r = 0, g = 0, b = 0, base, color;
|
||||
|
||||
if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
|
||||
r = val;
|
||||
g = val;
|
||||
b = val;
|
||||
} else {
|
||||
base = ((255 - sat) * val) >> 8;
|
||||
color = (val - base) * (hue % 60) / 60;
|
||||
|
||||
switch (hue / 60) {
|
||||
case 0:
|
||||
r = val;
|
||||
g = base + color;
|
||||
b = base;
|
||||
break;
|
||||
case 1:
|
||||
r = val - color;
|
||||
g = val;
|
||||
b = base;
|
||||
break;
|
||||
case 2:
|
||||
r = base;
|
||||
g = val;
|
||||
b = base + color;
|
||||
break;
|
||||
case 3:
|
||||
r = base;
|
||||
g = val - color;
|
||||
b = val;
|
||||
break;
|
||||
case 4:
|
||||
r = base + color;
|
||||
g = base;
|
||||
b = val;
|
||||
break;
|
||||
case 5:
|
||||
r = val;
|
||||
g = base;
|
||||
b = val - color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rgbsps_set(index, r, g, b);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,3 +2,4 @@ void rgbsps_set(uint8_t index, uint8_t r, uint8_t g, uint8_t b);
|
|||
void rgbsps_setall(uint8_t r, uint8_t g, uint8_t b);
|
||||
void rgbsps_turnoff(void);
|
||||
void rgbsps_send(void);
|
||||
void rgbsps_sethsv(uint8_t index, uint16_t hue, uint8_t sat, uint8_t val);
|
|
@ -73,3 +73,4 @@ SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
|
|||
|
||||
SRC += $(QUANTUM_DIR)/light_ws2812.c
|
||||
SRC += rgbsps.c
|
||||
SRC += $(QUANTUM_DIR)/analog.c
|
Loading…
Reference in a new issue