summaryrefslogtreecommitdiffstats
path: root/keyboards/handwired/promethium
diff options
context:
space:
mode:
authorPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-10 15:28:46 +0100
committerPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-10 15:28:46 +0100
commit5944ab246a981d6ceca94b0972345277a746c2d3 (patch)
tree01c240c2dd6a39cc44157e51287a7b194c6b4017 /keyboards/handwired/promethium
parent07879bf66b29535214a147b1797f96767b1faa58 (diff)
downloadqmk_firmware-5944ab246a981d6ceca94b0972345277a746c2d3.tar.gz
qmk_firmware-5944ab246a981d6ceca94b0972345277a746c2d3.tar.xz
Implement battery level indicator
Diffstat (limited to 'keyboards/handwired/promethium')
-rw-r--r--keyboards/handwired/promethium/keymaps/priyadi/keymap.c11
-rw-r--r--keyboards/handwired/promethium/promethium.c34
-rw-r--r--keyboards/handwired/promethium/promethium.h6
-rw-r--r--keyboards/handwired/promethium/rgbsps.c51
-rw-r--r--keyboards/handwired/promethium/rgbsps.h3
-rw-r--r--keyboards/handwired/promethium/rules.mk3
6 files changed, 97 insertions, 11 deletions
diff --git a/keyboards/handwired/promethium/keymaps/priyadi/keymap.c b/keyboards/handwired/promethium/keymaps/priyadi/keymap.c
index 65fa14dd3..469d7a5d8 100644
--- a/keyboards/handwired/promethium/keymaps/priyadi/keymap.c
+++ b/keyboards/handwired/promethium/keymaps/priyadi/keymap.c
@@ -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;
diff --git a/keyboards/handwired/promethium/promethium.c b/keyboards/handwired/promethium/promethium.c
index a0035cce1..7f876c756 100644
--- a/keyboards/handwired/promethium/promethium.c
+++ b/keyboards/handwired/promethium/promethium.c
@@ -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 battery_poll(float percentage) {
+}
+void matrix_init_kb(void) {
matrix_init_user();
-} \ No newline at end of file
+}
+
+void matrix_scan_kb(void) {
+ static uint16_t counter = BATTERY_POLL;
+ counter++;
+
+ if (counter > BATTERY_POLL) {
+ counter = 0;
+ battery_poll(battery_percentage());
+ }
+}
+
+
diff --git a/keyboards/handwired/promethium/promethium.h b/keyboards/handwired/promethium/promethium.h
index a2572db2a..6d51f81ca 100644
--- a/keyboards/handwired/promethium/promethium.h
+++ b/keyboards/handwired/promethium/promethium.h
@@ -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); \ No newline at end of file
diff --git a/keyboards/handwired/promethium/rgbsps.c b/keyboards/handwired/promethium/rgbsps.c
index ea922ec3f..f30badd35 100644
--- a/keyboards/handwired/promethium/rgbsps.c
+++ b/keyboards/handwired/promethium/rgbsps.c
@@ -21,4 +21,53 @@ void rgbsps_turnoff(void) {
void rgbsps_send(void) {
ws2812_setleds(led, RGBSPS_NUM);
-} \ No newline at end of file
+}
+
+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);
+}
+
diff --git a/keyboards/handwired/promethium/rgbsps.h b/keyboards/handwired/promethium/rgbsps.h
index 6da197f75..72612a7a8 100644
--- a/keyboards/handwired/promethium/rgbsps.h
+++ b/keyboards/handwired/promethium/rgbsps.h
@@ -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); \ No newline at end of file
+void rgbsps_send(void);
+void rgbsps_sethsv(uint8_t index, uint16_t hue, uint8_t sat, uint8_t val); \ No newline at end of file
diff --git a/keyboards/handwired/promethium/rules.mk b/keyboards/handwired/promethium/rules.mk
index 465ef3359..e75cf4dde 100644
--- a/keyboards/handwired/promethium/rules.mk
+++ b/keyboards/handwired/promethium/rules.mk
@@ -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 \ No newline at end of file
+SRC += rgbsps.c
+SRC += $(QUANTUM_DIR)/analog.c \ No newline at end of file