aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-10 21:28:46 +0700
committerPriyadi Iman Nurcahyo <priyadi@priyadi.net>2017-02-10 21:28:46 +0700
commit5944ab246a981d6ceca94b0972345277a746c2d3 (patch)
tree01c240c2dd6a39cc44157e51287a7b194c6b4017
parent07879bf66b29535214a147b1797f96767b1faa58 (diff)
downloadqmk_firmware-5944ab246a981d6ceca94b0972345277a746c2d3.tar.gz
qmk_firmware-5944ab246a981d6ceca94b0972345277a746c2d3.zip
Implement battery level indicator
-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 {
25 GLOW_MIN, 25 GLOW_MIN,
26 GLOW_FULL 26 GLOW_FULL
27}; 27};
28
28uint8_t glow_mode = GLOW_MIN; 29uint8_t glow_mode = GLOW_MIN;
29 30
30extern keymap_config_t keymap_config; 31extern keymap_config_t keymap_config;
@@ -505,11 +506,6 @@ void led_init(void) {
505 rgbsps_set(LED_TRACKPOINT2, 0, 0, 15); 506 rgbsps_set(LED_TRACKPOINT2, 0, 0, 15);
506 rgbsps_set(LED_TRACKPOINT3, 15, 0, 0); 507 rgbsps_set(LED_TRACKPOINT3, 15, 0, 0);
507 508
508 // // hardcode indicator for now
509 rgbsps_set(LED_IND_BLUETOOTH, 0, 0, 15);
510 rgbsps_set(LED_IND_USB, 15, 15, 15);
511 rgbsps_set(LED_IND_BATTERY, 0, 15, 0);
512
513 led_layer_normal(); 509 led_layer_normal();
514} 510}
515 511
@@ -996,6 +992,11 @@ void matrix_init_user(void) {
996 } 992 }
997} 993}
998 994
995void battery_poll(float percentage) {
996 rgbsps_sethsv(LED_IND_BATTERY, percentage*120/100, 255, 15);
997 rgbsps_send();
998}
999
999void ps2_mouse_init_user() { 1000void ps2_mouse_init_user() {
1000 uint8_t rcv; 1001 uint8_t rcv;
1001 1002
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 @@
1#include "promethium.h" 1#include "promethium.h"
2#include "analog.h"
3#include "timer.h"
4#include "matrix.h"
2 5
3void matrix_init_kb(void) { 6float battery_percentage(void) {
7 float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024;
8 float percentage = (voltage - 3.5) * 143;
9 if (percentage > 100) {
10 return 100;
11 } else if (percentage < 0) {
12 return 0;
13 } else {
14 return percentage;
15 }
16}
17
18__attribute__ ((weak))
19void battery_poll(float percentage) {
20}
4 21
22void matrix_init_kb(void) {
5 matrix_init_user(); 23 matrix_init_user();
6} \ No newline at end of file 24}
25
26void matrix_scan_kb(void) {
27 static uint16_t counter = BATTERY_POLL;
28 counter++;
29
30 if (counter > BATTERY_POLL) {
31 counter = 0;
32 battery_poll(battery_percentage());
33 }
34}
35
36
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 @@
5 5
6#define PS2_INIT_DELAY 2000 6#define PS2_INIT_DELAY 2000
7#define UNICODE_TYPE_DELAY 0 7#define UNICODE_TYPE_DELAY 0
8#define BATTERY_PIN 9
9#define BATTERY_POLL 30000
8 10
9#define KEYMAP( \ 11#define KEYMAP( \
10 k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, \ 12 k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, \
@@ -23,6 +25,8 @@
23 {k47, k48, k49, k4a, k4b, k4c} \ 25 {k47, k48, k49, k4a, k4b, k4c} \
24} 26}
25 27
28
29
26enum led_sequence { 30enum led_sequence {
27 LED_IND_BLUETOOTH, 31 LED_IND_BLUETOOTH,
28 LED_IND_USB, 32 LED_IND_USB,
@@ -99,4 +103,4 @@ enum led_sequence {
99 103
100#endif 104#endif
101 105
102 106void 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) {
21 21
22void rgbsps_send(void) { 22void rgbsps_send(void) {
23 ws2812_setleds(led, RGBSPS_NUM); 23 ws2812_setleds(led, RGBSPS_NUM);
24} \ No newline at end of file 24}
25
26void rgbsps_sethsv(uint8_t index, uint16_t hue, uint8_t sat, uint8_t val) {
27 uint8_t r = 0, g = 0, b = 0, base, color;
28
29 if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
30 r = val;
31 g = val;
32 b = val;
33 } else {
34 base = ((255 - sat) * val) >> 8;
35 color = (val - base) * (hue % 60) / 60;
36
37 switch (hue / 60) {
38 case 0:
39 r = val;
40 g = base + color;
41 b = base;
42 break;
43 case 1:
44 r = val - color;
45 g = val;
46 b = base;
47 break;
48 case 2:
49 r = base;
50 g = val;
51 b = base + color;
52 break;
53 case 3:
54 r = base;
55 g = val - color;
56 b = val;
57 break;
58 case 4:
59 r = base + color;
60 g = base;
61 b = val;
62 break;
63 case 5:
64 r = val;
65 g = base;
66 b = val - color;
67 break;
68 }
69 }
70
71 rgbsps_set(index, r, g, b);
72}
73
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 @@
1void rgbsps_set(uint8_t index, uint8_t r, uint8_t g, uint8_t b); 1void rgbsps_set(uint8_t index, uint8_t r, uint8_t g, uint8_t b);
2void rgbsps_setall(uint8_t r, uint8_t g, uint8_t b); 2void rgbsps_setall(uint8_t r, uint8_t g, uint8_t b);
3void rgbsps_turnoff(void); 3void rgbsps_turnoff(void);
4void rgbsps_send(void); \ No newline at end of file 4void rgbsps_send(void);
5void 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
72SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend 72SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
73 73
74SRC += $(QUANTUM_DIR)/light_ws2812.c 74SRC += $(QUANTUM_DIR)/light_ws2812.c
75SRC += rgbsps.c \ No newline at end of file 75SRC += rgbsps.c
76SRC += $(QUANTUM_DIR)/analog.c \ No newline at end of file