Un-extern
RGBLight led[]
array (#23322)
This commit is contained in:
parent
c038292c1e
commit
583cde398a
|
@ -356,27 +356,12 @@ Usually lighting layers apply their configured brightness once activated. If you
|
|||
|
||||
If you need to change your RGB lighting in code, for example in a macro to change the color whenever you switch layers, QMK provides a set of functions to assist you. See [`rgblight.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight/rgblight.h) for the full list, but the most commonly used functions include:
|
||||
|
||||
### Utility Functions
|
||||
|Function |Description |
|
||||
|--------------------------------------------|-------------------------------------------------------------------|
|
||||
|`sethsv(hue, sat, val, ledbuf)` |Set ledbuf to the given HSV value |
|
||||
|`sethsv_raw(hue, sat, val, ledbuf)` |Set ledbuf to the given HSV value without RGBLIGHT_LIMIT_VAL check |
|
||||
|`setrgb(r, g, b, ledbuf)` |Set ledbuf to the given RGB value where `r`/`g`/`b` |
|
||||
|
||||
### Low level Functions
|
||||
|Function |Description |
|
||||
|--------------------------------------------|-------------------------------------------|
|
||||
|`rgblight_set()` |Flush out led buffers to LEDs |
|
||||
|`rgblight_set_clipping_range(pos, num)` |Set clipping Range. see [Clipping Range](#clipping-range) |
|
||||
|
||||
Example:
|
||||
```c
|
||||
sethsv(HSV_WHITE, (rgb_led_t *)&led[0]); // led 0
|
||||
sethsv(HSV_RED, (rgb_led_t *)&led[1]); // led 1
|
||||
sethsv(HSV_GREEN, (rgb_led_t *)&led[2]); // led 2
|
||||
rgblight_set(); // Utility functions do not call rgblight_set() automatically, so they need to be called explicitly.
|
||||
```
|
||||
|
||||
### Effects and Animations Functions
|
||||
#### effect range setting
|
||||
|Function |Description |
|
||||
|
|
|
@ -82,12 +82,9 @@ void keyboard_post_init_user(void) {
|
|||
|
||||
__attribute__ ((weak))
|
||||
void hbcp_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
|
||||
rgb_led_t tmp_led;
|
||||
sethsv_raw(hue, sat, val, &tmp_led);
|
||||
for (uint8_t i = start; i < end; i++) {
|
||||
led[i] = tmp_led;
|
||||
rgblight_sethsv_at(hue, sat, val, i);
|
||||
}
|
||||
rgblight_set();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,13 +15,6 @@
|
|||
*/
|
||||
#include QMK_KEYBOARD_H
|
||||
|
||||
// Defines the keycodes used by our macros in process_record_user
|
||||
enum custom_keycodes {
|
||||
QMKBEST = SAFE_RANGE,
|
||||
ALTCUT,
|
||||
QMKURL
|
||||
};
|
||||
|
||||
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||
|
||||
[0] = LAYOUT_wkl( /* Base */
|
||||
|
@ -45,55 +38,24 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
|||
),
|
||||
};
|
||||
|
||||
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
case ALTCUT:
|
||||
if (record->event.pressed) {
|
||||
// when keycode QMKBEST is pressed
|
||||
send_string_with_delay_P(PSTR(SS_TAP(X_TAB)SS_TAP(X_T)SS_TAP(X_V)SS_TAP(X_B)), 20); // altium macro
|
||||
} else {
|
||||
// when keycode QMKBEST is released
|
||||
}
|
||||
break;
|
||||
case QMKURL:
|
||||
if (record->event.pressed) {
|
||||
// when keycode QMKURL is pressed
|
||||
SEND_STRING("https://qmk.fm/" SS_TAP(X_ENTER));
|
||||
} else {
|
||||
// when keycode QMKURL is released
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void matrix_init_user(void) {
|
||||
|
||||
}
|
||||
|
||||
void matrix_scan_user(void) {
|
||||
|
||||
}
|
||||
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
// The first three LEDs are used as indicators for CAPS_LOCK, NUM_LOCK and SCROLL_LOCK.
|
||||
bool led_update_user(led_t led_state) {
|
||||
if (led_state.caps_lock) {
|
||||
sethsv_raw(HSV_SOFT_RED, (rgb_led_t *)&led[0]);
|
||||
rgblight_sethsv_at(HSV_SOFT_RED, 0);
|
||||
} else {
|
||||
sethsv(HSV_BLACK, (rgb_led_t *)&led[0]);
|
||||
rgblight_sethsv_at(HSV_BLACK, 0);
|
||||
}
|
||||
if (led_state.num_lock) {
|
||||
sethsv_raw(HSV_WARM_WHITE, (rgb_led_t *)&led[1]);
|
||||
rgblight_sethsv_at(HSV_WARM_WHITE, 1);
|
||||
} else {
|
||||
sethsv(HSV_BLACK, (rgb_led_t *)&led[1]);
|
||||
rgblight_sethsv_at(HSV_BLACK, 1);
|
||||
}
|
||||
if (led_state.scroll_lock) {
|
||||
sethsv_raw(HSV_SOFT_BLUE, (rgb_led_t *)&led[2]);
|
||||
rgblight_sethsv_at(HSV_SOFT_BLUE, 2);
|
||||
} else {
|
||||
sethsv(HSV_BLACK, (rgb_led_t *)&led[2]);
|
||||
rgblight_sethsv_at(HSV_BLACK, 2);
|
||||
}
|
||||
rgblight_set();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,8 +25,7 @@
|
|||
"pin": "B0"
|
||||
},
|
||||
"rgblight": {
|
||||
"led_count": 5,
|
||||
"driver": "custom"
|
||||
"led_count": 5
|
||||
},
|
||||
"url": "",
|
||||
"usb": {
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
/**
|
||||
* @file nico.c
|
||||
*
|
||||
Copyright 2023 astro
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "quantum.h"
|
||||
#include "ws2812.h"
|
||||
#ifdef RGBLIGHT_ENABLE
|
||||
|
||||
static bool alert = false;
|
||||
static bool backup = false;
|
||||
static rgb_led_t caps_led;
|
||||
static uint16_t last_ticks = 0;
|
||||
|
||||
#define ALERT_INTERVAL 500
|
||||
#define ALERM_LED_R 0xFF
|
||||
#define ALERM_LED_G 0xA5
|
||||
#define ALERM_LED_B 0x00
|
||||
//golden 0xFF, 0xD9, 0x00
|
||||
|
||||
void housekeeping_task_kb(void)
|
||||
{
|
||||
if (host_keyboard_led_state().caps_lock) {
|
||||
if (!backup) {
|
||||
caps_led.r = led[4].r;
|
||||
caps_led.g = led[4].g;
|
||||
caps_led.b = led[4].b;
|
||||
backup = true;
|
||||
}
|
||||
if(alert) {
|
||||
led[4].r = ALERM_LED_G;
|
||||
led[4].g = ALERM_LED_R;
|
||||
led[4].b = ALERM_LED_B;
|
||||
} else {
|
||||
led[4].r = 0;
|
||||
led[4].g = 0;
|
||||
led[4].b = 0;
|
||||
}
|
||||
if (timer_elapsed(last_ticks) > ALERT_INTERVAL) {
|
||||
alert = !alert;
|
||||
last_ticks = timer_read();
|
||||
}
|
||||
ws2812_setleds(led, RGBLIGHT_LED_COUNT);
|
||||
} else {
|
||||
if (backup) {
|
||||
led[4].r = caps_led.r;
|
||||
led[4].g = caps_led.g;
|
||||
led[4].b = caps_led.b;
|
||||
backup = false;
|
||||
ws2812_setleds(led, RGBLIGHT_LED_COUNT);
|
||||
}
|
||||
}
|
||||
housekeeping_task_user();
|
||||
}
|
||||
|
||||
void setleds_custom(rgb_led_t *start_led, uint16_t num_leds)
|
||||
{
|
||||
start_led[2].r = start_led[0].r;
|
||||
start_led[2].g = start_led[0].g;
|
||||
start_led[2].b = start_led[0].b;
|
||||
|
||||
start_led[3].r = start_led[1].r;
|
||||
start_led[3].g = start_led[1].g;
|
||||
start_led[3].b = start_led[1].b;
|
||||
|
||||
uint8_t tmp = start_led[4].g;
|
||||
start_led[4].g = start_led[4].r;
|
||||
start_led[4].r = tmp;
|
||||
ws2812_setleds(start_led, RGBLIGHT_LED_COUNT);
|
||||
}
|
||||
|
||||
const rgblight_driver_t rgblight_driver = {
|
||||
.init = ws2812_init,
|
||||
.setleds = setleds_custom,
|
||||
};
|
||||
#endif
|
|
@ -1 +0,0 @@
|
|||
WS2812_DRIVER_REQUIRED = yes
|
|
@ -86,22 +86,6 @@ static void setupForFlashing(void) {
|
|||
|
||||
// Force data to be rendered
|
||||
oled_render_dirty(true);
|
||||
|
||||
// Set alternating backlight colors
|
||||
const uint8_t max = 20;
|
||||
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
|
||||
for (size_t i = 0; i < RGBLIGHT_LED_COUNT; ++i) {
|
||||
rgb_led_t *led_ = (rgb_led_t *)&led[i];
|
||||
switch (i % 2) {
|
||||
case 0:
|
||||
setrgb(max, 0, max, led_);
|
||||
break;
|
||||
case 1:
|
||||
setrgb(0, max, max, led_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
rgblight_set();
|
||||
}
|
||||
|
||||
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||
|
|
|
@ -145,6 +145,15 @@ __attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) {
|
|||
return hsv_to_rgb(hsv);
|
||||
}
|
||||
|
||||
void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1) {
|
||||
led1->r = r;
|
||||
led1->g = g;
|
||||
led1->b = b;
|
||||
#ifdef RGBW
|
||||
led1->w = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) {
|
||||
HSV hsv = {hue, sat, val};
|
||||
RGB rgb = rgblight_hsv_to_rgb(hsv);
|
||||
|
@ -155,15 +164,6 @@ void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) {
|
|||
sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1);
|
||||
}
|
||||
|
||||
void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1) {
|
||||
led1->r = r;
|
||||
led1->g = g;
|
||||
led1->b = b;
|
||||
#ifdef RGBW
|
||||
led1->w = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void rgblight_check_config(void) {
|
||||
/* Add some out of bound checks for RGB light config */
|
||||
|
||||
|
|
|
@ -240,8 +240,6 @@ void rgblight_unblink_all_but_layer(uint8_t layer);
|
|||
|
||||
#endif
|
||||
|
||||
extern rgb_led_t led[RGBLIGHT_LED_COUNT];
|
||||
|
||||
extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM;
|
||||
extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM;
|
||||
extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM;
|
||||
|
@ -290,11 +288,6 @@ typedef struct _rgblight_ranges_t {
|
|||
|
||||
extern rgblight_ranges_t rgblight_ranges;
|
||||
|
||||
/* === Utility Functions ===*/
|
||||
void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1);
|
||||
void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1); // without RGBLIGHT_LIMIT_VAL check
|
||||
void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1);
|
||||
|
||||
/* === Low level Functions === */
|
||||
void rgblight_set(void);
|
||||
void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds);
|
||||
|
|
Loading…
Reference in a new issue