mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-18 05:32:05 +00:00
Correctly handle scrolling when adjusting effect speed
This commit is contained in:
parent
ffd8acf7cc
commit
a91035ef98
@ -14,50 +14,50 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "quantum.h"
|
#include "quantum.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <rgb_matrix.h>
|
#include <rgb_matrix.h>
|
||||||
|
|
||||||
#if defined(RGB_MATRIX_EFFECT)
|
#if defined(RGB_MATRIX_EFFECT)
|
||||||
# undef RGB_MATRIX_EFFECT
|
# undef RGB_MATRIX_EFFECT
|
||||||
#endif // defined(RGB_MATRIX_EFFECT)
|
#endif // defined(RGB_MATRIX_EFFECT)
|
||||||
|
|
||||||
#define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x,
|
#define RGB_MATRIX_EFFECT(x) RGB_MATRIX_EFFECT_##x,
|
||||||
enum {
|
enum {
|
||||||
RGB_MATRIX_EFFECT_NONE,
|
RGB_MATRIX_EFFECT_NONE,
|
||||||
#include "rgb_matrix_effects.inc"
|
#include "rgb_matrix_effects.inc"
|
||||||
#ifdef RGB_MATRIX_CUSTOM_KB
|
#ifdef RGB_MATRIX_CUSTOM_KB
|
||||||
# include "rgb_matrix_kb.inc"
|
# include "rgb_matrix_kb.inc"
|
||||||
#endif // RGB_MATRIX_CUSTOM_KB
|
#endif // RGB_MATRIX_CUSTOM_KB
|
||||||
#ifdef RGB_MATRIX_CUSTOM_USER
|
#ifdef RGB_MATRIX_CUSTOM_USER
|
||||||
# include "rgb_matrix_user.inc"
|
# include "rgb_matrix_user.inc"
|
||||||
#endif // RGB_MATRIX_CUSTOM_USER
|
#endif // RGB_MATRIX_CUSTOM_USER
|
||||||
#undef RGB_MATRIX_EFFECT
|
#undef RGB_MATRIX_EFFECT
|
||||||
};
|
};
|
||||||
|
|
||||||
#define RGB_MATRIX_EFFECT(x) \
|
#define RGB_MATRIX_EFFECT(x) \
|
||||||
case RGB_MATRIX_EFFECT_##x: \
|
case RGB_MATRIX_EFFECT_##x: \
|
||||||
return #x;
|
return #x;
|
||||||
const char *rgb_matrix_name(uint8_t effect) {
|
const char *rgb_matrix_name(uint8_t effect) {
|
||||||
switch (effect) {
|
switch (effect) {
|
||||||
case RGB_MATRIX_EFFECT_NONE:
|
case RGB_MATRIX_EFFECT_NONE:
|
||||||
return "NONE";
|
return "NONE";
|
||||||
#include "rgb_matrix_effects.inc"
|
#include "rgb_matrix_effects.inc"
|
||||||
#ifdef RGB_MATRIX_CUSTOM_KB
|
#ifdef RGB_MATRIX_CUSTOM_KB
|
||||||
# include "rgb_matrix_kb.inc"
|
# include "rgb_matrix_kb.inc"
|
||||||
#endif // RGB_MATRIX_CUSTOM_KB
|
#endif // RGB_MATRIX_CUSTOM_KB
|
||||||
#ifdef RGB_MATRIX_CUSTOM_USER
|
#ifdef RGB_MATRIX_CUSTOM_USER
|
||||||
# include "rgb_matrix_user.inc"
|
# include "rgb_matrix_user.inc"
|
||||||
#endif // RGB_MATRIX_CUSTOM_USER
|
#endif // RGB_MATRIX_CUSTOM_USER
|
||||||
#undef RGB_MATRIX_EFFECT
|
#undef RGB_MATRIX_EFFECT
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t effect_name_len = 0;
|
static uint8_t effect_name_len = 0;
|
||||||
|
|
||||||
const char *rgb_matrix_get_effect_name(void) {
|
const char *rgb_matrix_get_effect_name(void) {
|
||||||
static char buf[32] = {0};
|
static char buf[32] = {0};
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode()));
|
snprintf(buf, sizeof(buf), "%s", rgb_matrix_name(rgb_matrix_get_mode()));
|
||||||
@ -73,24 +73,29 @@ const char *rgb_matrix_get_effect_name(void) {
|
|||||||
buf[i] = tolower(buf[i]);
|
buf[i] = tolower(buf[i]);
|
||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool oled_task_user(void) {
|
bool oled_task_user(void) {
|
||||||
static uint8_t last_effect = 0;
|
static uint8_t last_effect = 0;
|
||||||
static uint8_t last_speed = 0;
|
static uint8_t last_speed = 0;
|
||||||
static uint16_t key_timer = 0;
|
static uint16_t key_timer = 0;
|
||||||
static uint8_t start_index = 0;
|
static uint8_t start_index = 0;
|
||||||
|
|
||||||
uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0);
|
uint8_t speedPercentage = (uint8_t)(((float)rgb_matrix_get_speed() / 255.0) * 100.0);
|
||||||
|
bool is_timer_elapsed = timer_elapsed(key_timer) > 200;
|
||||||
|
|
||||||
if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || timer_elapsed(key_timer) > 200) {
|
if (last_effect != rgb_matrix_get_mode() || last_speed != speedPercentage || is_timer_elapsed) {
|
||||||
last_effect = rgb_matrix_get_mode();
|
last_effect = rgb_matrix_get_mode();
|
||||||
last_speed = speedPercentage;
|
last_speed = speedPercentage;
|
||||||
key_timer = timer_read();
|
|
||||||
|
|
||||||
oled_write_ln_P(PSTR("Mode: "), false);
|
oled_write_ln_P(PSTR("Mode: "), false);
|
||||||
const char *name = rgb_matrix_get_effect_name();
|
const char *name = rgb_matrix_get_effect_name();
|
||||||
if (effect_name_len > 21) {
|
if (effect_name_len > 21) {
|
||||||
|
if (!is_timer_elapsed && start_index != 0) {
|
||||||
|
start_index -= 1;
|
||||||
|
} else {
|
||||||
|
key_timer = timer_read();
|
||||||
|
}
|
||||||
if (start_index > effect_name_len) {
|
if (start_index > effect_name_len) {
|
||||||
start_index = 0;
|
start_index = 0;
|
||||||
}
|
}
|
||||||
@ -116,4 +121,5 @@ bool oled_task_user(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user