aboutsummaryrefslogtreecommitdiff
path: root/quantum/visualizer/lcd_backlight.c
diff options
context:
space:
mode:
authorskullY <skullydazed@gmail.com>2019-08-30 11:19:03 -0700
committerskullydazed <skullydazed@users.noreply.github.com>2019-08-30 15:01:52 -0700
commitb624f32f944acdc59dcb130674c09090c5c404cb (patch)
treebc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/visualizer/lcd_backlight.c
parent61af76a10d00aba185b8338604171de490a13e3b (diff)
downloadqmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz
qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip
clang-format changes
Diffstat (limited to 'quantum/visualizer/lcd_backlight.c')
-rw-r--r--quantum/visualizer/lcd_backlight.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/quantum/visualizer/lcd_backlight.c b/quantum/visualizer/lcd_backlight.c
index 6cd996f75..23978974e 100644
--- a/quantum/visualizer/lcd_backlight.c
+++ b/quantum/visualizer/lcd_backlight.c
@@ -25,9 +25,9 @@ SOFTWARE.
25#include "lcd_backlight.h" 25#include "lcd_backlight.h"
26#include <math.h> 26#include <math.h>
27 27
28static uint8_t current_hue = 0; 28static uint8_t current_hue = 0;
29static uint8_t current_saturation = 0; 29static uint8_t current_saturation = 0;
30static uint8_t current_intensity = 0; 30static uint8_t current_intensity = 0;
31static uint8_t current_brightness = 0; 31static uint8_t current_brightness = 0;
32 32
33void lcd_backlight_init(void) { 33void lcd_backlight_init(void) {
@@ -40,26 +40,26 @@ void lcd_backlight_init(void) {
40// http://blog.saikoled.com/post/43693602826/why-every-led-light-should-be-using-hsi 40// http://blog.saikoled.com/post/43693602826/why-every-led-light-should-be-using-hsi
41static void hsi_to_rgb(float h, float s, float i, uint16_t* r_out, uint16_t* g_out, uint16_t* b_out) { 41static void hsi_to_rgb(float h, float s, float i, uint16_t* r_out, uint16_t* g_out, uint16_t* b_out) {
42 unsigned int r, g, b; 42 unsigned int r, g, b;
43 h = fmodf(h, 360.0f); // cycle h around to 0-360 degrees 43 h = fmodf(h, 360.0f); // cycle h around to 0-360 degrees
44 h = 3.14159f * h / 180.0f; // Convert to radians. 44 h = 3.14159f * h / 180.0f; // Convert to radians.
45 s = s > 0.0f ? (s < 1.0f ? s : 1.0f) : 0.0f; // clamp s and i to interval [0,1] 45 s = s > 0.0f ? (s < 1.0f ? s : 1.0f) : 0.0f; // clamp s and i to interval [0,1]
46 i = i > 0.0f ? (i < 1.0f ? i : 1.0f) : 0.0f; 46 i = i > 0.0f ? (i < 1.0f ? i : 1.0f) : 0.0f;
47 47
48 // Math! Thanks in part to Kyle Miller. 48 // Math! Thanks in part to Kyle Miller.
49 if(h < 2.09439f) { 49 if (h < 2.09439f) {
50 r = 65535.0f * i/3.0f *(1.0f + s * cos(h) / cosf(1.047196667f - h)); 50 r = 65535.0f * i / 3.0f * (1.0f + s * cos(h) / cosf(1.047196667f - h));
51 g = 65535.0f * i/3.0f *(1.0f + s *(1.0f - cosf(h) / cos(1.047196667f - h))); 51 g = 65535.0f * i / 3.0f * (1.0f + s * (1.0f - cosf(h) / cos(1.047196667f - h)));
52 b = 65535.0f * i/3.0f *(1.0f - s); 52 b = 65535.0f * i / 3.0f * (1.0f - s);
53 } else if(h < 4.188787) { 53 } else if (h < 4.188787) {
54 h = h - 2.09439; 54 h = h - 2.09439;
55 g = 65535.0f * i/3.0f *(1.0f + s * cosf(h) / cosf(1.047196667f - h)); 55 g = 65535.0f * i / 3.0f * (1.0f + s * cosf(h) / cosf(1.047196667f - h));
56 b = 65535.0f * i/3.0f *(1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h))); 56 b = 65535.0f * i / 3.0f * (1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h)));
57 r = 65535.0f * i/3.0f *(1.0f - s); 57 r = 65535.0f * i / 3.0f * (1.0f - s);
58 } else { 58 } else {
59 h = h - 4.188787; 59 h = h - 4.188787;
60 b = 65535.0f*i/3.0f * (1.0f + s * cosf(h) / cosf(1.047196667f - h)); 60 b = 65535.0f * i / 3.0f * (1.0f + s * cosf(h) / cosf(1.047196667f - h));
61 r = 65535.0f*i/3.0f * (1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h))); 61 r = 65535.0f * i / 3.0f * (1.0f + s * (1.0f - cosf(h) / cosf(1.047196667f - h)));
62 g = 65535.0f*i/3.0f * (1.0f - s); 62 g = 65535.0f * i / 3.0f * (1.0f - s);
63 } 63 }
64 *r_out = r > 65535 ? 65535 : r; 64 *r_out = r > 65535 ? 65535 : r;
65 *g_out = g > 65535 ? 65535 : g; 65 *g_out = g > 65535 ? 65535 : g;
@@ -68,15 +68,15 @@ static void hsi_to_rgb(float h, float s, float i, uint16_t* r_out, uint16_t* g_o
68 68
69void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity) { 69void lcd_backlight_color(uint8_t hue, uint8_t saturation, uint8_t intensity) {
70 uint16_t r, g, b; 70 uint16_t r, g, b;
71 float hue_f = 360.0f * (float)hue / 255.0f; 71 float hue_f = 360.0f * (float)hue / 255.0f;
72 float saturation_f = (float)saturation / 255.0f; 72 float saturation_f = (float)saturation / 255.0f;
73 float intensity_f = (float)intensity / 255.0f; 73 float intensity_f = (float)intensity / 255.0f;
74 intensity_f *= (float)current_brightness / 255.0f; 74 intensity_f *= (float)current_brightness / 255.0f;
75 hsi_to_rgb(hue_f, saturation_f, intensity_f, &r, &g, &b); 75 hsi_to_rgb(hue_f, saturation_f, intensity_f, &r, &g, &b);
76 current_hue = hue; 76 current_hue = hue;
77 current_saturation = saturation; 77 current_saturation = saturation;
78 current_intensity = intensity; 78 current_intensity = intensity;
79 lcd_backlight_hal_color(r, g, b); 79 lcd_backlight_hal_color(r, g, b);
80} 80}
81 81
82void lcd_backlight_brightness(uint8_t b) { 82void lcd_backlight_brightness(uint8_t b) {
@@ -84,6 +84,4 @@ void lcd_backlight_brightness(uint8_t b) {
84 lcd_backlight_color(current_hue, current_saturation, current_intensity); 84 lcd_backlight_color(current_hue, current_saturation, current_intensity);
85} 85}
86 86
87uint8_t lcd_get_backlight_brightness(void) { 87uint8_t lcd_get_backlight_brightness(void) { return current_brightness; }
88 return current_brightness;
89}