@@ -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"
-void matrix_init_kb(void) {
+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 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);
@@ -21,4 +21,53 @@ 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;
+ base = ((255 - sat) * val) >> 8;
+ color = (val - base) * (hue % 60) / 60;
+ switch (hue / 60) {
+ case 0:
+ g = base + color;
+ b = base;
+ break;
+ case 1:
+ r = val - color;
+ case 2:
+ r = base;
+ b = base + color;
+ case 3:
+ g = val - color;
+ case 4:
+ r = base + color;
+ g = base;
+ case 5:
+ b = val - color;
+ rgbsps_set(index, r, g, b);
@@ -1,4 +1,5 @@
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_send(void);
+void rgbsps_sethsv(uint8_t index, uint16_t hue, uint8_t sat, uint8_t val);
@@ -72,4 +72,5 @@ API_SYSEX_ENABLE ?= no
SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
SRC += $(QUANTUM_DIR)/light_ws2812.c
-SRC += rgbsps.c
+SRC += rgbsps.c
+SRC += $(QUANTUM_DIR)/analog.c