summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authordi0ib <git@porkhash.net>2016-08-07 20:20:16 -1000
committerdi0ib <git@porkhash.net>2016-08-07 20:20:16 -1000
commita36b2a0756761513a9853af78d61e8b666b34aa7 (patch)
treea783cea131f5afe22788809a069b1a365a9c3fba /quantum
parent8610481c372e9de02fe1ec7b77a9f3598a72a372 (diff)
parent213cb2c24306e198e717fc162806201567666f36 (diff)
Merge remote-tracking branch 'refs/remotes/jackhumbert/master'
Diffstat (limited to 'quantum')
-rw-r--r--quantum/audio/song_list.h8
-rw-r--r--quantum/keymap_common.c2
-rw-r--r--quantum/keymap_extras/keymap_bepo.h4
-rw-r--r--quantum/keymap_extras/keymap_cyrillic.h161
-rw-r--r--quantum/keymap_extras/keymap_dvorak.h15
-rw-r--r--quantum/keymap_extras/keymap_fr_ch.h2
-rw-r--r--quantum/keymap_extras/keymap_french.h4
-rw-r--r--quantum/keymap_extras/keymap_german.h2
-rw-r--r--quantum/keymap_extras/keymap_german_ch.h2
-rw-r--r--quantum/keymap_extras/keymap_nordic.h4
-rw-r--r--quantum/keymap_extras/keymap_norwegian.h2
-rw-r--r--quantum/keymap_extras/keymap_spanish.h2
-rw-r--r--quantum/keymap_extras/keymap_uk.h4
-rw-r--r--quantum/process_keycode/process_midi.c24
-rw-r--r--quantum/process_keycode/process_music.c7
-rw-r--r--quantum/process_keycode/process_tap_dance.c108
-rw-r--r--quantum/process_keycode/process_tap_dance.h47
-rw-r--r--quantum/quantum.c36
-rw-r--r--quantum/quantum.h3
-rw-r--r--quantum/rgblight.c735
20 files changed, 721 insertions, 451 deletions
diff --git a/quantum/audio/song_list.h b/quantum/audio/song_list.h
index fc6fcdeef1..8022ca6729 100644
--- a/quantum/audio/song_list.h
+++ b/quantum/audio/song_list.h
@@ -28,6 +28,14 @@
Q__NOTE(_E4), Q__NOTE(_C4), \
Q__NOTE(_E4),
+/* Requires: PLAY_NOTE_ARRAY(..., ..., STACCATO); */
+#define IN_LIKE_FLINT \
+ E__NOTE(_AS4), E__NOTE(_AS4), QD_NOTE(_B4), \
+ E__NOTE(_AS4), E__NOTE(_B4), QD_NOTE(_CS4), \
+ E__NOTE(_B4), E__NOTE(_CS4), QD_NOTE(_DS4), \
+ E__NOTE(_CS4), E__NOTE(_B4), QD_NOTE(_AS4), \
+ E__NOTE(_AS4), E__NOTE(_AS4), QD_NOTE(_B4),
+
#define GOODBYE_SOUND \
E__NOTE(_E7), \
E__NOTE(_A6), \
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index d0a8312c1e..833e5a8f8d 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "quantum.h"
#ifdef MIDI_ENABLE
- #include "keymap_midi.h"
+ #include "process_midi.h"
#endif
extern keymap_config_t keymap_config;
diff --git a/quantum/keymap_extras/keymap_bepo.h b/quantum/keymap_extras/keymap_bepo.h
index 4c30960547..e5ef39552a 100644
--- a/quantum/keymap_extras/keymap_bepo.h
+++ b/quantum/keymap_extras/keymap_bepo.h
@@ -118,7 +118,7 @@
// Fourth row
#define BP_COLON LSFT(BP_DOT) // :
#define BP_COLN BP_COLON
-#define BP_QUESTION LSFT(BP_QUOTE) // ?
+#define BP_QUESTION LSFT(BP_APOS) // ?
#define BP_QEST BP_QUESTION
// Space bar
@@ -183,7 +183,7 @@
// Third row
#define BP_AE_LIGATURE ALTGR(BP_A) // æ
#define BP_AE BP_AE_LIGATURE
-#define BP_U_GRAVE AGR(BP_U) // ù
+#define BP_U_GRAVE ALTGR(BP_U) // ù
#define BP_UGRV BP_U_GRAVE
#define BP_DEAD_TREMA ALTGR(BP_I) // dead ¨ (trema/umlaut/diaresis)
#define BP_DTRM BP_DEAD_TREMA
diff --git a/quantum/keymap_extras/keymap_cyrillic.h b/quantum/keymap_extras/keymap_cyrillic.h
new file mode 100644
index 0000000000..d5390afff5
--- /dev/null
+++ b/quantum/keymap_extras/keymap_cyrillic.h
@@ -0,0 +1,161 @@
+#ifndef KEYMAP_CYRILLIC_H
+#define KEYMAP_CYRILLIC_H
+
+#include "keymap.h"
+
+/*
+ * This is based off of
+ * https://en.wikipedia.org/wiki/Cyrillic_script
+ */
+
+// Capital Char russian/ukrainian/bulgarian
+#define CY_A UC(0x0410) // А rus ukr bul
+#define CY_BE UC(0x0411) // Б rus ukr bul
+#define CY_VE UC(0x0412) // В rus ukr bul
+#define CY_GHE UC(0x0413) // Г rus ukr bul
+#define CY_GHEUP UC(0x0490) // Ґ ukr
+#define CY_DE UC(0x0414) // Д rus ukr bul
+#define CY_DJE UC(0x0402) // Ђ
+#define CY_GJE UC(0x0403) // Ѓ
+#define CY_IE UC(0x0415) // Е rus ukr bul
+#define CY_IO UC(0x0401) // Ё rus
+#define CY_UIE UC(0x0404) // Є ukr
+#define CY_ZHE UC(0x0416) // Ж rus ukr bul
+#define CY_ZE UC(0x0417) // З rus ukr bul
+#define CY_DZE UC(0x0405) // Ѕ
+#define CY_I UC(0x0418) // И rus ukr bul
+#define CY_B_U_I UC(0x0406) // І ukr
+#define CY_YI UC(0x0407) // Ї ukr
+#define CY_SRT_I UC(0x0419) // Й rus ukr bul
+#define CY_JE UC(0x0408) // Ј
+#define CY_KA UC(0x041a) // К rus ukr bul
+#define CY_EL UC(0x041b) // Л rus ukr bul
+#define CY_LJE UC(0x0409) // Љ
+#define CY_EM UC(0x041c) // М rus ukr bul
+#define CY_EN UC(0x041d) // Н rus ukr bul
+#define CY_NJE UC(0x040a) // Њ
+#define CY_O UC(0x041e) // О rus ukr bul
+#define CY_PE UC(0x041f) // П rus ukr bul
+#define CY_ER UC(0x0420) // Р rus ukr bul
+#define CY_ES UC(0x0421) // С rus ukr bul
+#define CY_TE UC(0x0422) // Т rus ukr bul
+#define CY_TSHE UC(0x040b) // Ћ
+#define CY_KJE UC(0x040c) // Ќ
+#define CY_U UC(0x0423) // У rus ukr bul
+#define CY_SRT_U UC(0x040e) // Ў
+#define CY_EF UC(0x0424) // Ф rus ukr bul
+#define CY_HA UC(0x0425) // Х rus bul
+#define CY_TSE UC(0x0426) // Ц rus ukr bul
+#define CY_CHE UC(0x0427) // Ч rus ukr bul
+#define CY_DZHE UC(0x040f) // Џ
+#define CY_SHA UC(0x0428) // Ш rus ukr bul
+#define CY_SHCHA UC(0x0429) // Щ rus ukr bul
+#define CY_HSIGN UC(0x042a) // Ъ rus bul
+#define CY_YERU UC(0x042b) // Ы rus
+#define CY_SSIGN UC(0x042c) // Ь rus ukr bul
+#define CY_E UC(0x042d) // Э rus
+#define CY_YU UC(0x042e) // Ю rus ukr bul
+#define CY_YA UC(0x042f) // Я rus ukr bul
+// Important Cyrillic non-Slavic letters
+#define CY_PALOCHKA UC(0x04c0) // Ӏ
+#define CY_SCHWA UC(0x04d8) // Ә
+#define CY_GHE_S UC(0x0492) // Ғ
+#define CY_ZE_D UC(0x0498) // Ҙ
+#define CY_ES_D UC(0x04aa) // Ҫ
+#define CY_BR_KA UC(0x04a0) // Ҡ
+#define CY_ZHE_D UC(0x0496) // Җ
+#define CY_KA_D UC(0x049a) // Қ
+#define CY_EN_D UC(0x04a2) // Ң
+#define CY_ENGHE UC(0x04a4) // Ҥ
+#define CY_BRD_O UC(0x04e8) // Ө
+#define CY_STR_U UC(0x04ae) // Ү
+#define CY_S_U_S UC(0x04b0) // Ұ
+#define CY_SHHA UC(0x04ba) // Һ
+#define CY_HA_D UC(0x04b2) // Ҳ
+
+
+// Small
+#define CY_a UC(0x0430) // a rus ukr bul
+#define CY_be UC(0x0431) // б rus ukr bul
+#define CY_ve UC(0x0432) // в rus ukr bul
+#define CY_ghe UC(0x0433) // г rus ukr bul
+#define CY_gheup UC(0x0491) // ґ ukr
+#define CY_de UC(0x0434) // д rus ukr bul
+#define CY_dje UC(0x0452) // ђ
+#define CY_gje UC(0x0453) // ѓ
+#define CY_ie UC(0x0435) // е rus ukr bul
+#define CY_io UC(0x0451) // ё rus
+#define CY_uie UC(0x0454) // є ukr
+#define CY_zhe UC(0x0436) // ж rus ukr bul
+#define CY_ze UC(0x0437) // з rus ukr bul
+#define CY_dze UC(0x0455) // ѕ
+#define CY_i UC(0x0438) // и rus ukr bul
+#define CY_b_u_i UC(0x0456) // і ukr
+#define CY_yi UC(0x0457) // ї ukr
+#define CY_srt_i UC(0x0439) // й rus ukr bul
+#define CY_je UC(0x0458) // ј
+#define CY_ka UC(0x043a) // к rus ukr bul
+#define CY_el UC(0x043b) // л rus ukr bul
+#define CY_lje UC(0x0459) // љ
+#define CY_em UC(0x043c) // м rus ukr bul
+#define CY_en UC(0x043d) // н rus ukr bul
+#define CY_nje UC(0x045a) // њ
+#define CY_o UC(0x043e) // о rus ukr bul
+#define CY_pe UC(0x043f) // п rus ukr bul
+#define CY_er UC(0x0440) // р rus ukr bul
+#define CY_es UC(0x0441) // с rus ukr bul
+#define CY_te UC(0x0442) // т rus ukr bul
+#define CY_tshe UC(0x045b) // ћ
+#define CY_kje UC(0x045c) // ќ
+#define CY_u UC(0x0443) // у rus ukr bul
+#define CY_srt_u UC(0x045e) // ў
+#define CY_ef UC(0x0444) // ф rus ukr bul
+#define CY_ha UC(0x0445) // х rus ukr bul
+#define CY_tse UC(0x0446) // ц rus ukr bul
+#define CY_che UC(0x0447) // ч rus ukr bul
+#define CY_dzhe UC(0x045f) // џ
+#define CY_sha UC(0x0448) // ш rus ukr bul
+#define CY_shcha UC(0x0449) // щ rus ukr bul
+#define CY_hsign UC(0x044a) // ъ rus bul
+#define CY_yeru UC(0x044b) // ы rus
+#define CY_ssign UC(0x044c) // ь rus ukr bul
+#define CY_e UC(0x044d) // э rus
+#define CY_yu UC(0x044e) // ю rus ukr bul
+#define CY_ya UC(0x044f) // я rus ukr bul
+// Important Cyrillic non-Slavic letters
+#define CY_palochka UC(0x04cf) // ӏ
+#define CY_schwa UC(0x04d9) // ә
+#define CY_ghe_s UC(0x0493) // ғ
+#define CY_ze_d UC(0x0499) // ҙ
+#define CY_es_d UC(0x04ab) // ҫ
+#define CY_br_ka UC(0x04a1) // ҡ
+#define CY_zhe_d UC(0x0497) // җ
+#define CY_ka_d UC(0x049b) // қ
+#define CY_en_d UC(0x04a3) // ң
+#define CY_enghe UC(0x04a5) // ҥ
+#define CY_brd_o UC(0x04e9) // ө
+#define CY_str_u UC(0x04af) // ү
+#define CY_s_u_s UC(0x04b1) // ұ
+#define CY_shha UC(0x04bb) // һ
+#define CY_ha_d UC(0x04b3) // ҳ
+
+
+// Extra
+#define CY_slr_ve UC(0x1c80) // ᲀ CYRILLIC SMALL LETTER ROUNDED VE
+#define CY_ll_de UC(0x1c81) // ᲁ CYRILLIC SMALL LETTER LONG-LEGGED DE
+#define CY_ZEMLYA UC(0xa640) // Ꙁ CYRILLIC CAPITAL LETTER ZEMLYA
+#define CY_zemlya UC(0xa641) // ꙁ CYRILLIC SMALL LETTER ZEMLYA
+#define CY_RV_DZE UC(0xa644) // Ꙅ CYRILLIC CAPITAL LETTER REVERSED DZE
+#define CY_rv_DZE UC(0xa645) // ꙅ CYRILLIC SMALL LETTER REVERSED DZE
+#define CY_slw_es UC(0x1c83) // ᲃ CYRILLIC SMALL LETTER WIDE ES
+#define CY_st_te UC(0x1c84) // ᲄ CYRILLIC SMALL LETTER TALL TE
+#define CY_3l_te UC(0x1c85) // ᲅ CYRILLIC SMALL LETTER THREE-LEGGED TE
+#define CY_thsign UC(0x1c86) // ᲆ CYRILLIC SMALL LETTER TALL HARD SIGN
+#define CY_YERUBY UC(0xa650) // Ꙑ CYRILLIC CAPITAL LETTER YERU WITH BACK YER
+#define CY_yeruby UC(0xa651) // ꙑ CYRILLIC SMALL LETTER YERU WITH BACK YER
+#define CY_RUBLE UC(0x20bd) // ₽
+#define CY_NUMERO UC(0x2116) // №
+
+// The letters Zje and Sje are made for other letters and accent marks
+
+#endif
diff --git a/quantum/keymap_extras/keymap_dvorak.h b/quantum/keymap_extras/keymap_dvorak.h
index e855056e83..17f2059774 100644
--- a/quantum/keymap_extras/keymap_dvorak.h
+++ b/quantum/keymap_extras/keymap_dvorak.h
@@ -18,18 +18,19 @@
#define DV_LBRC KC_MINS
#define DV_RBRC KC_EQL
-#define DV_QUOT KC_Q
+#define DV_QUOT KC_Q
#define DV_COMM KC_W
#define DV_DOT KC_E
#define DV_P KC_R
#define DV_Y KC_T
#define DV_F KC_Y
#define DV_G KC_U
-#define DV_C KC_I
+#define DV_C KC_I
#define DV_R KC_O
#define DV_L KC_P
#define DV_SLSH KC_LBRC
#define DV_EQL KC_RBRC
+#define DV_BSLS KC_BSLS
#define DV_A KC_A
#define DV_O KC_S
@@ -68,7 +69,13 @@
#define DV_RPRN LSFT(DV_0)
#define DV_LCBR LSFT(DV_LBRC)
#define DV_RCBR LSFT(DV_RBRC)
-#define DV_UNDS LSFT(DV_MINS)
-#define DV_PLUS LSFT(DV_EQL)
+
+#define DV_QUES LSFT(DV_SLSH)
+#define DV_PLUS LSFT(DV_EQL)
+#define DV_PIPE LSFT(DV_BSLS)
+
+#define DV_UNDS LSFT(DV_MINS)
+
+#define DV_COLN LSFT(DV_SCLN)
#endif
diff --git a/quantum/keymap_extras/keymap_fr_ch.h b/quantum/keymap_extras/keymap_fr_ch.h
index 3fd9713575..87d4bb24cf 100644
--- a/quantum/keymap_extras/keymap_fr_ch.h
+++ b/quantum/keymap_extras/keymap_fr_ch.h
@@ -4,7 +4,7 @@
#include "keymap.h"
// Alt gr
-#define ALGR(kc) kc | 0x1400
+#define ALGR(kc) RALT(kc)
#define FR_CH_ALGR KC_RALT
// normal characters
diff --git a/quantum/keymap_extras/keymap_french.h b/quantum/keymap_extras/keymap_french.h
index 2a44c80b14..834c69650e 100644
--- a/quantum/keymap_extras/keymap_french.h
+++ b/quantum/keymap_extras/keymap_french.h
@@ -4,7 +4,7 @@
#include "keymap.h"
// Alt gr
-#define ALGR(kc) kc | 0x1400
+#define ALGR(kc) RALT(kc)
#define NO_ALGR KC_RALT
// Normal characters
@@ -80,4 +80,4 @@
#define FR_EURO ALGR(KC_E)
#define FR_BULT ALGR(FR_DLR)
-#endif \ No newline at end of file
+#endif
diff --git a/quantum/keymap_extras/keymap_german.h b/quantum/keymap_extras/keymap_german.h
index 3f9ae8bade..7e2e0ed44e 100644
--- a/quantum/keymap_extras/keymap_german.h
+++ b/quantum/keymap_extras/keymap_german.h
@@ -4,7 +4,7 @@
#include "keymap.h"
// Alt gr
-#define ALGR(kc) kc | 0x1400
+#define ALGR(kc) RALT(kc)
#define DE_ALGR KC_RALT
// normal characters
diff --git a/quantum/keymap_extras/keymap_german_ch.h b/quantum/keymap_extras/keymap_german_ch.h
index 6a782bcd7b..b66d582a44 100644
--- a/quantum/keymap_extras/keymap_german_ch.h
+++ b/quantum/keymap_extras/keymap_german_ch.h
@@ -4,7 +4,7 @@
#include "keymap.h"
// Alt gr
-#define ALGR(kc) kc | 0x1400
+#define ALGR(kc) RALT(kc)
#define CH_ALGR KC_RALT
// normal characters
diff --git a/quantum/keymap_extras/keymap_nordic.h b/quantum/keymap_extras/keymap_nordic.h
index 3acb8b6983..da5c829757 100644
--- a/quantum/keymap_extras/keymap_nordic.h
+++ b/quantum/keymap_extras/keymap_nordic.h
@@ -4,7 +4,7 @@
#include "keymap.h"
// Alt gr
-#define ALGR(kc) kc | 0x1400
+#define ALGR(kc) RALT(kc)
#define NO_ALGR KC_RALT
// Normal characters
@@ -25,7 +25,7 @@
#define NO_SECT LSFT(NO_HALF)
#define NO_QUO2 LSFT(KC_2)
#define NO_BULT LSFT(KC_4)
-#define NO_AMP LSFT(KC_6)
+#define NO_AMPR LSFT(KC_6)
#define NO_SLSH LSFT(KC_7)
#define NO_LPRN LSFT(KC_8)
#define NO_RPRN LSFT(KC_9)
diff --git a/quantum/keymap_extras/keymap_norwegian.h b/quantum/keymap_extras/keymap_norwegian.h
index 018bfeae59..5c4e8c4955 100644
--- a/quantum/keymap_extras/keymap_norwegian.h
+++ b/quantum/keymap_extras/keymap_norwegian.h
@@ -13,7 +13,7 @@
#undef NO_BSLS
#define NO_BSLS KC_EQL // '\'
#undef NO_CIRC
-#define NO_CIRC LSFT(C_RBRC) // ^
+#define NO_CIRC LSFT(KC_RBRC) // ^
#undef NO_GRV
#define NO_GRV LSFT(NO_BSLS) //
#undef NO_OSLH
diff --git a/quantum/keymap_extras/keymap_spanish.h b/quantum/keymap_extras/keymap_spanish.h
index af76e39fcb..4ba568af23 100644
--- a/quantum/keymap_extras/keymap_spanish.h
+++ b/quantum/keymap_extras/keymap_spanish.h
@@ -4,7 +4,7 @@
#include "keymap.h"
// Alt gr
-#define ALGR(kc) kc | 0x1400
+#define ALGR(kc) RALT(kc)
#define NO_ALGR KC_RALT
// Normal characters
diff --git a/quantum/keymap_extras/keymap_uk.h b/quantum/keymap_extras/keymap_uk.h
index 5c5d951791..00c87afc3e 100644
--- a/quantum/keymap_extras/keymap_uk.h
+++ b/quantum/keymap_extras/keymap_uk.h
@@ -4,7 +4,7 @@
#include "keymap.h"
// Alt gr
-#define ALGR(kc) kc | 0x1400
+#define ALGR(kc) RALT(kc)
#define NO_ALGR KC_RALT
// Normal characters
@@ -33,4 +33,4 @@
#define UK_AACT ALGR(KC_A)
-#endif \ No newline at end of file
+#endif
diff --git a/quantum/process_keycode/process_midi.c b/quantum/process_keycode/process_midi.c
index d6ab9c6264..8784e64f36 100644
--- a/quantum/process_keycode/process_midi.c
+++ b/quantum/process_keycode/process_midi.c
@@ -1,8 +1,8 @@
#include "process_midi.h"
bool midi_activated = false;
-uint8_t starting_note = 0x0C;
-int offset = 7;
+uint8_t midi_starting_note = 0x0C;
+int midi_offset = 7;
bool process_midi(uint16_t keycode, keyrecord_t *record) {
if (keycode == MI_ON && record->event.pressed) {
@@ -20,42 +20,42 @@ bool process_midi(uint16_t keycode, keyrecord_t *record) {
if (midi_activated) {
if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
if (record->event.pressed) {
- starting_note++; // Change key
+ midi_starting_note++; // Change key
midi_send_cc(&midi_device, 0, 0x7B, 0);
}
return false;
}
if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
if (record->event.pressed) {
- starting_note--; // Change key
+ midi_starting_note--; // Change key
midi_send_cc(&midi_device, 0, 0x7B, 0);
}
return false;
}
if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
- offset++; // Change scale
+ midi_offset++; // Change scale
midi_send_cc(&midi_device, 0, 0x7B, 0);
return false;
}
if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
- offset--; // Change scale
+ midi_offset--; // Change scale
midi_send_cc(&midi_device, 0, 0x7B, 0);
return false;
}
// basic
- // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
+ // uint8_t note = (midi_starting_note + SCALE[record->event.key.col + midi_offset])+12*(MATRIX_ROWS - record->event.key.row);
// advanced
- // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
+ // uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+12*(MATRIX_ROWS - record->event.key.row);
// guitar
- uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
+ uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+5*(MATRIX_ROWS - record->event.key.row);
// violin
- // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
+ // uint8_t note = (midi_starting_note + record->event.key.col + midi_offset)+7*(MATRIX_ROWS - record->event.key.row);
if (record->event.pressed) {
- // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
+ // midi_send_noteon(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127);
midi_send_noteon(&midi_device, 0, note, 127);
} else {
- // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
+ // midi_send_noteoff(&midi_device, record->event.key.row, midi_starting_note + SCALE[record->event.key.col], 127);
midi_send_noteoff(&midi_device, 0, note, 127);
}
diff --git a/quantum/process_keycode/process_music.c b/quantum/process_keycode/process_music.c
index c8f3ddb900..2d52e47a72 100644
--- a/quantum/process_keycode/process_music.c
+++ b/quantum/process_keycode/process_music.c
@@ -6,6 +6,7 @@ int offset = 7;
// music sequencer
static bool music_sequence_recording = false;
+static bool music_sequence_recorded = false;
static bool music_sequence_playing = false;
static float music_sequence[16] = {0};
static uint8_t music_sequence_count = 0;
@@ -77,6 +78,7 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
if (keycode == KC_LCTL && record->event.pressed) { // Start recording
stop_all_notes();
music_sequence_recording = true;
+ music_sequence_recorded = false;
music_sequence_playing = false;
music_sequence_count = 0;
return false;
@@ -84,12 +86,15 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
stop_all_notes();
+ if (music_sequence_recording) { // was recording
+ music_sequence_recorded = true;
+ }
music_sequence_recording = false;
music_sequence_playing = false;
return false;
}
- if (keycode == KC_LGUI && record->event.pressed) { // Start playing
+ if (keycode == KC_LGUI && record->event.pressed && music_sequence_recorded) { // Start playing
stop_all_notes();
music_sequence_recording = false;
music_sequence_playing = true;
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index 9b172e1b6c..5429e34383 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -1,62 +1,86 @@
#include "quantum.h"
static qk_tap_dance_state_t qk_tap_dance_state;
+bool td_debug_enable = false;
+
+#if CONSOLE_ENABLE
+#define td_debug(s) if (td_debug_enable) \
+ { \
+ xprintf ("D:tap_dance:%s:%s = { keycode = %d, count = %d, active = %d, pressed = %d }\n", __FUNCTION__, s, \
+ qk_tap_dance_state.keycode, qk_tap_dance_state.count, \
+ qk_tap_dance_state.active, qk_tap_dance_state.pressed); \
+ }
+#else
+#define td_debug(s)
+#endif
-static void _process_tap_dance_action_pair (qk_tap_dance_state_t *state,
- uint16_t kc1, uint16_t kc2) {
- uint16_t kc;
-
- if (state->count == 0)
- return;
+void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data) {
+ qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
- kc = (state->count == 1) ? kc1 : kc2;
+ if (state->count == 1) {
+ register_code (pair->kc1);
+ } else if (state->count == 2) {
+ register_code (pair->kc2);
+ }
+}
- register_code (kc);
- unregister_code (kc);
+void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data) {
+ qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
- if (state->count >= 2) {
- reset_tap_dance (state);
+ if (state->count == 1) {
+ unregister_code (pair->kc1);
+ } else if (state->count == 2) {
+ unregister_code (pair->kc2);
}
}
-static void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
+static inline void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
+ void *user_data,
qk_tap_dance_user_fn_t fn)
{
- fn(state);
+ if (fn) {
+ fn(state, user_data);
+ }
}
-void process_tap_dance_action (uint16_t keycode)
+static inline void process_tap_dance_action_on_each_tap (qk_tap_dance_action_t action)
{
- uint16_t idx = keycode - QK_TAP_DANCE;
- qk_tap_dance_action_t action;
-
- action = tap_dance_actions[idx];
+ td_debug("trigger");
+ _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_each_tap);
+}
- switch (action.type) {
- case QK_TAP_DANCE_TYPE_PAIR:
- _process_tap_dance_action_pair (&qk_tap_dance_state,
- action.pair.kc1, action.pair.kc2);
- break;
- case QK_TAP_DANCE_TYPE_FN:
- _process_tap_dance_action_fn (&qk_tap_dance_state, action.fn);
- break;
+static inline void process_tap_dance_action_on_dance_finished (qk_tap_dance_action_t action)
+{
+ td_debug("trigger");
+ _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_dance_finished);
+}
- default:
- break;
- }
+static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t action)
+{
+ td_debug("trigger")
+ _process_tap_dance_action_fn (&qk_tap_dance_state, action.user_data, action.fn.on_reset);
}
bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
bool r = true;
+ uint16_t idx = keycode - QK_TAP_DANCE;
+ qk_tap_dance_action_t action;
switch(keycode) {
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
+ action = tap_dance_actions[idx];
+
+ process_tap_dance_action_on_each_tap (action);
if (qk_tap_dance_state.keycode && qk_tap_dance_state.keycode != keycode) {
- process_tap_dance_action (qk_tap_dance_state.keycode);
+ process_tap_dance_action_on_dance_finished (action);
+ } else if (qk_tap_dance_state.active && qk_tap_dance_state.pressed) {
+ reset_tap_dance (&qk_tap_dance_state);
} else {
r = false;
}
+ qk_tap_dance_state.active = true;
+ qk_tap_dance_state.pressed = record->event.pressed;
if (record->event.pressed) {
qk_tap_dance_state.keycode = keycode;
qk_tap_dance_state.timer = timer_read ();
@@ -66,9 +90,14 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
default:
if (qk_tap_dance_state.keycode) {
- process_tap_dance_action (qk_tap_dance_state.keycode);
+ // if we are here, the tap dance was interrupted by a different key
+ idx = qk_tap_dance_state.keycode - QK_TAP_DANCE;
+ action = tap_dance_actions[idx];
+ process_tap_dance_action_on_each_tap (action);
+ process_tap_dance_action_on_dance_finished (action);
reset_tap_dance (&qk_tap_dance_state);
+ qk_tap_dance_state.active = false;
}
break;
}
@@ -77,14 +106,27 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
}
void matrix_scan_tap_dance () {
- if (qk_tap_dance_state.keycode && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
- process_tap_dance_action (qk_tap_dance_state.keycode);
+ if (qk_tap_dance_state.active && timer_elapsed (qk_tap_dance_state.timer) > TAPPING_TERM) {
+ // if we are here, the tap dance was timed out
+ uint16_t idx = qk_tap_dance_state.keycode - QK_TAP_DANCE;
+ qk_tap_dance_action_t action = tap_dance_actions[idx];
+ process_tap_dance_action_on_dance_finished (action);
reset_tap_dance (&qk_tap_dance_state);
}
}
void reset_tap_dance (qk_tap_dance_state_t *state) {
+ uint16_t idx = state->keycode - QK_TAP_DANCE;
+ qk_tap_dance_action_t action;
+
+ if (state->pressed)
+ return;
+
+ action = tap_dance_actions[idx];
+ process_tap_dance_action_on_reset (action);
+
state->keycode = 0;
state->count = 0;
+ state->active = false;
}
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h
index b9d7c7fcf4..6a1258067e 100644
--- a/quantum/process_keycode/process_tap_dance.h
+++ b/quantum/process_keycode/process_tap_dance.h
@@ -11,41 +11,45 @@ typedef struct
uint8_t count;
uint16_t keycode;
uint16_t timer;
+ bool active:1;
+ bool pressed:1;
} qk_tap_dance_state_t;
#define TD(n) (QK_TAP_DANCE + n)
-typedef enum
-{
- QK_TAP_DANCE_TYPE_PAIR,
- QK_TAP_DANCE_TYPE_FN,
-} qk_tap_dance_type_t;
-
-typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state);
+typedef void (*qk_tap_dance_user_fn_t) (qk_tap_dance_state_t *state, void *user_data);
typedef struct
{
- qk_tap_dance_type_t type;
- union {
- struct {
- uint16_t kc1;
- uint16_t kc2;
- } pair;
- qk_tap_dance_user_fn_t fn;
- };
+ struct {
+ qk_tap_dance_user_fn_t on_each_tap;
+ qk_tap_dance_user_fn_t on_dance_finished;
+ qk_tap_dance_user_fn_t on_reset;
+ } fn;
+ void *user_data;
} qk_tap_dance_action_t;
+typedef struct
+{
+ uint16_t kc1;
+ uint16_t kc2;
+} qk_tap_dance_pair_t;
+
#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
- .type = QK_TAP_DANCE_TYPE_PAIR, \
- .pair = { kc1, kc2 } \
+ .fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
+ .user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }) \
+ }
+
+#define ACTION_TAP_DANCE_FN(user_fn) { \
+ .fn = { NULL, user_fn, NULL } \
}
-#define ACTION_TAP_DANCE_FN(user_fn) { \
- .type = QK_TAP_DANCE_TYPE_FN, \
- .fn = user_fn \
+#define ACTION_TAP_DANCE_FN_ADVANCED(user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset) { \
+ .fn = { user_fn_on_each_tap, user_fn_on_dance_finished, user_fn_on_reset } \
}
extern const qk_tap_dance_action_t tap_dance_actions[];
+extern bool td_debug_enable;
/* To be used internally */
@@ -53,6 +57,9 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
void matrix_scan_tap_dance (void);
void reset_tap_dance (qk_tap_dance_state_t *state);
+void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data);
+
#else
#define TD(n) KC_NO
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 09daa47127..bc2da510f2 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -15,6 +15,19 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
+void reset_keyboard(void) {
+ clear_keyboard();
+#ifdef AUDIO_ENABLE
+ stop_all_notes();
+ shutdown_user();
+#endif
+ wait_ms(250);
+#ifdef CATERINA_BOOTLOADER
+ *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
+#endif
+ bootloader_jump();
+}
+
// Shift / paren setup
#ifndef LSPO_KEY
@@ -83,16 +96,7 @@ bool process_record_quantum(keyrecord_t *record) {
switch(keycode) {
case RESET:
if (record->event.pressed) {
- clear_keyboard();
- #ifdef AUDIO_ENABLE
- stop_all_notes();
- shutdown_user();
- #endif
- wait_ms(250);
- #ifdef CATERINA_BOOTLOADER
- *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
- #endif
- bootloader_jump();
+ reset_keyboard();
}
return false;
break;
@@ -212,6 +216,12 @@ bool process_record_quantum(keyrecord_t *record) {
register_mods(MOD_BIT(KC_LSFT));
}
else {
+ #ifdef DISABLE_SPACE_CADET_ROLLOVER
+ if (get_mods() & MOD_BIT(KC_RSFT)) {
+ shift_interrupted[0] = true;
+ shift_interrupted[1] = true;
+ }
+ #endif
if (!shift_interrupted[0]) {
register_code(LSPO_KEY);
unregister_code(LSPO_KEY);
@@ -228,6 +238,12 @@ bool process_record_quantum(keyrecord_t *record) {
register_mods(MOD_BIT(KC_RSFT));
}
else {
+ #ifdef DISABLE_SPACE_CADET_ROLLOVER
+ if (get_mods() & MOD_BIT(KC_LSFT)) {
+ shift_interrupted[0] = true;
+ shift_interrupted[1] = true;
+ }
+ #endif
if (!shift_interrupted[1]) {
register_code(RSPC_KEY);
unregister_code(RSPC_KEY);
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 3a0b742028..6e3fbcc792 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -25,6 +25,7 @@
#include "led.h"
#include "action_util.h"
#include <stdlib.h>
+#include "print.h"
extern uint32_t default_layer_state;
@@ -77,6 +78,8 @@ bool process_action_kb(keyrecord_t *record);
bool process_record_kb(uint16_t keycode, keyrecord_t *record);
bool process_record_user(uint16_t keycode, keyrecord_t *record);
+void reset_keyboard(void);
+
void startup_user(void);
void shutdown_user(void);
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index b1b0f035d5..f82e3ec558 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -7,24 +7,41 @@
#include "debug.h"
const uint8_t DIM_CURVE[] PROGMEM = {
- 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
- 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
- 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6,
- 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
- 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11,
- 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15,
- 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20,
- 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26,
- 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35,
- 36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47,
- 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
- 63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82,
- 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109,
- 110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144,
- 146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190,
- 193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255,
+ 0, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6,
+ 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
+ 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 11,
+ 11, 11, 12, 12, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 14, 15,
+ 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 20,
+ 20, 20, 21, 21, 22, 22, 22, 23, 23, 24, 24, 25, 25, 25, 26, 26,
+ 27, 27, 28, 28, 29, 29, 30, 30, 31, 32, 32, 33, 33, 34, 35, 35,
+ 36, 36, 37, 38, 38, 39, 40, 40, 41, 42, 43, 43, 44, 45, 46, 47,
+ 48, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, 65, 66, 68, 69, 70, 71, 73, 74, 75, 76, 78, 79, 81, 82,
+ 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 103, 105, 107, 109,
+ 110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144,
+ 146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190,
+ 193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255
+};
+const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = {
+ 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 5, 5, 6, 7, 9,
+ 10, 11, 12, 14, 15, 17, 18, 20, 21, 23, 25, 27, 29, 31, 33, 35,
+ 37, 40, 42, 44, 47, 49, 52, 54, 57, 59, 62, 65, 67, 70, 73, 76,
+ 79, 82, 85, 88, 90, 93, 97, 100, 103, 106, 109, 112, 115, 118, 121, 124,
+ 127, 131, 134, 137, 140, 143, 146, 149, 152, 155, 158, 162, 165, 167, 170, 173,
+ 176, 179, 182, 185, 188, 190, 193, 196, 198, 201, 203, 206, 208, 211, 213, 215,
+ 218, 220, 222, 224, 226, 228, 230, 232, 234, 235, 237, 238, 240, 241, 243, 244,
+ 245, 246, 248, 249, 250, 250, 251, 252, 253, 253, 254, 254, 254, 255, 255, 255,
+ 255, 255, 255, 255, 254, 254, 254, 253, 253, 252, 251, 250, 250, 249, 248, 246,
+ 245, 244, 243, 241, 240, 238, 237, 235, 234, 232, 230, 228, 226, 224, 222, 220,
+ 218, 215, 213, 211, 208, 206, 203, 201, 198, 196, 193, 190, 188, 185, 182, 179,
+ 176, 173, 170, 167, 165, 162, 158, 155, 152, 149, 146, 143, 140, 137, 134, 131,
+ 128, 124, 121, 118, 115, 112, 109, 106, 103, 100, 97, 93, 90, 88, 85, 82,
+ 79, 76, 73, 70, 67, 65, 62, 59, 57, 54, 52, 49, 47, 44, 42, 40,
+ 37, 35, 33, 31, 29, 27, 25, 23, 21, 20, 18, 17, 15, 14, 12, 11,
+ 10, 9, 7, 6, 5, 5, 4, 3, 2, 2, 1, 1, 1, 0, 0, 0
};
-const uint8_t RGBLED_BREATHING_TABLE[] PROGMEM = {0,0,0,0,1,1,1,2,2,3,4,5,5,6,7,9,10,11,12,14,15,17,18,20,21,23,25,27,29,31,33,35,37,40,42,44,47,49,52,54,57,59,62,65,67,70,73,76,79,82,85,88,90,93,97,100,103,106,109,112,115,118,121,124,127,131,134,137,140,143,146,149,152,155,158,162,165,167,170,173,176,179,182,185,188,190,193,196,198,201,203,206,208,211,213,215,218,220,222,224,226,228,230,232,234,235,237,238,240,241,243,244,245,246,248,249,250,250,251,252,253,253,254,254,254,255,255,255,255,255,255,255,254,254,254,253,253,252,251,250,250,249,248,246,245,244,243,241,240,238,237,235,234,232,230,228,226,224,222,220,218,215,213,211,208,206,203,201,198,196,193,190,188,185,182,179,176,173,170,167,165,162,158,155,152,149,146,143,140,137,134,131,128,124,121,118,115,112,109,106,103,100,97,93,90,88,85,82,79,76,73,70,67,65,62,59,57,54,52,49,47,44,42,40,37,35,33,31,29,27,25,23,21,20,18,17,15,14,12,11,10,9,7,6,5,5,4,3,2,2,1,1,1,0,0,0};
const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30};
const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20};
@@ -38,63 +55,56 @@ uint8_t rgblight_inited = 0;
void sethsv(uint16_t hue, uint8_t sat, uint8_t val, struct cRGB *led1) {
- /* convert hue, saturation and brightness ( HSB/HSV ) to RGB
- The DIM_CURVE is used only on brightness/value and on saturation (inverted).
- This looks the most natural.
- */
- uint8_t r = 0, g = 0, b = 0;
+ // Convert hue, saturation, and value (HSV/HSB) to RGB. DIM_CURVE is used only
+ // on value and saturation (inverted). This looks the most natural.
+ uint8_t r = 0, g = 0, b = 0, base, color;
val = pgm_read_byte(&DIM_CURVE[val]);
- sat = 255 - pgm_read_byte(&DIM_CURVE[255 - sat]);
-
- uint8_t base;
-
- if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
- r = val;
- g = val;
- b = val;
- } else {
- base = ((255 - sat) * val) >> 8;
-
- switch (hue / 60) {
- case 0:
- r = val;
- g = (((val - base)*hue) / 60) + base;
- b = base;
- break;
-
- case 1:
- r = (((val - base)*(60 - (hue % 60))) / 60) + base;
- g = val;
- b = base;
- break;
-
- case 2:
- r = base;
- g = val;
- b = (((val - base)*(hue % 60)) / 60) + base;
- break;
-
- case 3:
- r = base;
- g = (((val - base)*(60 - (hue % 60))) / 60) + base;
- b = val;
- break;
-
- case 4:
- r = (((val - base)*(hue % 60)) / 60) + base;
- g = base;
- b = val;
- break;
-
- case 5:
- r = val;
- g = base;
- b = (((val - base)*(60 - (hue % 60))) / 60) + base;
- break;
- }
- }
- setrgb(r,g,b, led1);
+ sat = 255 - pgm_read_byte(&DIM_CURVE[255 - sat]);
+
+ 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;
+ }
+ }
+
+ setrgb(r, g, b, led1);
}
void setrgb(uint8_t r, uint8_t g, uint8_t b, struct cRGB *led1) {
@@ -111,44 +121,44 @@ void eeconfig_update_rgblight(uint32_t val) {
eeprom_update_dword(EECONFIG_RGBLIGHT, val);
}
void eeconfig_update_rgblight_default(void) {
- dprintf("eeconfig_update_rgblight_default\n");
- rgblight_config.enable = 1;
- rgblight_config.mode = 1;
- rgblight_config.hue = 200;
- rgblight_config.sat = 204;
- rgblight_config.val = 204;
- eeconfig_update_rgblight(rgblight_config.raw);
+ dprintf("eeconfig_update_rgblight_default\n");
+ rgblight_config.enable = 1;
+ rgblight_config.mode = 1;
+ rgblight_config.hue = 200;
+ rgblight_config.sat = 204;
+ rgblight_config.val = 204;
+ eeconfig_update_rgblight(rgblight_config.raw);
}
void eeconfig_debug_rgblight(void) {
- dprintf("rgblight_config eprom\n");
- dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
- dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
- dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
- dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
- dprintf("rgblight_config.val = %d\n", rgblight_config.val);
+ dprintf("rgblight_config eprom\n");
+ dprintf("rgblight_config.enable = %d\n", rgblight_config.enable);
+ dprintf("rghlight_config.mode = %d\n", rgblight_config.mode);
+ dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
+ dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
+ dprintf("rgblight_config.val = %d\n", rgblight_config.val);
}
void rgblight_init(void) {
debug_enable = 1; // Debug ON!
- dprintf("rgblight_init called.\n");
+ dprintf("rgblight_init called.\n");
rgblight_inited = 1;
- dprintf("rgblight_init start!\n");
+ dprintf("rgblight_init start!\n");
if (!eeconfig_is_enabled()) {
- dprintf("rgblight_init eeconfig is not enabled.\n");
+ dprintf("rgblight_init eeconfig is not enabled.\n");
eeconfig_init();
- eeconfig_update_rgblight_default();
+ eeconfig_update_rgblight_default();
}
rgblight_config.raw = eeconfig_read_rgblight();
- if (!rgblight_config.mode) {
- dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
- eeconfig_update_rgblight_default();
- rgblight_config.raw = eeconfig_read_rgblight();
- }
- eeconfig_debug_rgblight(); // display current eeprom values
+ if (!rgblight_config.mode) {
+ dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
+ eeconfig_update_rgblight_default();
+ rgblight_config.raw = eeconfig_read_rgblight();
+ }
+ eeconfig_debug_rgblight(); // display current eeprom values
- #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
- rgblight_timer_init(); // setup the timer
- #endif
+ #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
+ rgblight_timer_init(); // setup the timer
+ #endif
if (rgblight_config.enable) {
rgblight_mode(rgblight_config.mode);
@@ -156,58 +166,57 @@ void rgblight_init(void) {
}
void rgblight_increase(void) {
- uint8_t mode = 0;
+ uint8_t mode = 0;
if (rgblight_config.mode < RGBLIGHT_MODES) {
mode = rgblight_config.mode + 1;
}
- rgblight_mode(mode);
+ rgblight_mode(mode);
}
-
void rgblight_decrease(void) {
- uint8_t mode = 0;
- if (rgblight_config.mode > 1) { //mode will never < 1, if mode is less than 1, eeprom need to be initialized.
- mode = rgblight_config.mode-1;
+ uint8_t mode = 0;
+ // Mode will never be < 1. If it ever is, eeprom needs to be initialized.
+ if (rgblight_config.mode > 1) {
+ mode = rgblight_config.mode - 1;
}
- rgblight_mode(mode);
+ rgblight_mode(mode);
}
-
void rgblight_step(void) {
- uint8_t mode = 0;
+ uint8_t mode = 0;
mode = rgblight_config.mode + 1;
if (mode > RGBLIGHT_MODES) {
mode = 1;
}
- rgblight_mode(mode);
+ rgblight_mode(mode);
}
void rgblight_mode(uint8_t mode) {
- if (!rgblight_config.enable) {
- return;
- }
- if (mode<1) {
- rgblight_config.mode = 1;
- } else if (mode > RGBLIGHT_MODES) {
- rgblight_config.mode = RGBLIGHT_MODES;
- } else {
- rgblight_config.mode = mode;
- }
+ if (!rgblight_config.enable) {
+ return;
+ }
+ if (mode < 1) {
+ rgblight_config.mode = 1;
+ } else if (mode > RGBLIGHT_MODES) {
+ rgblight_config.mode = RGBLIGHT_MODES;
+ } else {
+ rgblight_config.mode = mode;
+ }
eeconfig_update_rgblight(rgblight_config.raw);
xprintf("rgblight mode: %u\n", rgblight_config.mode);
- if (rgblight_config.mode == 1) {
- #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
- rgblight_timer_disable();
- #endif
- } else if (rgblight_config.mode >=2 && rgblight_config.mode <=23) {
- // MODE 2-5, breathing
- // MODE 6-8, rainbow mood
- // MODE 9-14, rainbow swirl
- // MODE 15-20, snake
- // MODE 21-23, knight
-
- #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
- rgblight_timer_enable();
- #endif
- }
+ if (rgblight_config.mode == 1) {
+ #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
+ rgblight_timer_disable();
+ #endif
+ } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 23) {
+ // MODE 2-5, breathing
+ // MODE 6-8, rainbow mood
+ // MODE 9-14, rainbow swirl
+ // MODE 15-20, snake
+ // MODE 21-23, knight
+
+ #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
+ rgblight_timer_enable();
+ #endif
+ }
rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
}
@@ -215,306 +224,318 @@ void rgblight_toggle(void) {
rgblight_config.enable ^= 1;
eeconfig_update_rgblight(rgblight_config.raw);
xprintf("rgblight toggle: rgblight_config.enable = %u\n", rgblight_config.enable);
- if (rgblight_config.enable) {
- rgblight_mode(rgblight_config.mode);
- } else {
-
- #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
- rgblight_timer_disable();
- #endif
- _delay_ms(50);
- rgblight_set();
- }
+ if (rgblight_config.enable) {
+ rgblight_mode(rgblight_config.mode);
+ } else {
+ #if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
+ rgblight_timer_disable();
+ #endif
+ _delay_ms(50);
+ rgblight_set();
+ }
}
-void rgblight_increase_hue(void){
- uint16_t hue;
+void rgblight_increase_hue(void) {
+ uint16_t hue;
hue = (rgblight_config.hue+RGBLIGHT_HUE_STEP) % 360;
rgblight_sethsv(hue, rgblight_config.sat, rgblight_config.val);
}
-void rgblight_decrease_hue(void){
- uint16_t hue;
- if (rgblight_config.hue-RGBLIGHT_HUE_STEP <0 ) {
- hue = (rgblight_config.hue+360-RGBLIGHT_HUE_STEP) % 360;
- } else {
- hue = (rgblight_config.hue-RGBLIGHT_HUE_STEP) % 360;
- }
+void rgblight_decrease_hue(void) {
+ uint16_t hue;
+ if (rgblight_config.hue-RGBLIGHT_HUE_STEP < 0) {
+ hue = (rgblight_config.hue + 360 - RGBLIGHT_HUE_STEP) % 360;
+ } else {
+ hue = (rgblight_config.hue - RGBLIGHT_HUE_STEP) % 360;
+ }
rgblight_sethsv(hue, rgblight_config.sat, rgblight_config.val);
}
void rgblight_increase_sat(void) {
- uint8_t sat;
+ uint8_t sat;
if (rgblight_config.sat + RGBLIGHT_SAT_STEP > 255) {
sat = 255;
} else {
- sat = rgblight_config.sat+RGBLIGHT_SAT_STEP;
+ sat = rgblight_config.sat + RGBLIGHT_SAT_STEP;
}
rgblight_sethsv(rgblight_config.hue, sat, rgblight_config.val);
}
-void rgblight_decrease_sat(void){
- uint8_t sat;
+void rgblight_decrease_sat(void) {
+ uint8_t sat;
if (rgblight_config.sat - RGBLIGHT_SAT_STEP < 0) {
sat = 0;
} else {
- sat = rgblight_config.sat-RGBLIGHT_SAT_STEP;
+ sat = rgblight_config.sat - RGBLIGHT_SAT_STEP;
}
rgblight_sethsv(rgblight_config.hue, sat, rgblight_config.val);
}
-void rgblight_increase_val(void){
- uint8_t val;
+void rgblight_increase_val(void) {
+ uint8_t val;
if (rgblight_config.val + RGBLIGHT_VAL_STEP > 255) {
val = 255;
} else {
- val = rgblight_config.val+RGBLIGHT_VAL_STEP;
+ val = rgblight_config.val + RGBLIGHT_VAL_STEP;
}
rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, val);
}
void rgblight_decrease_val(void) {
- uint8_t val;
+ uint8_t val;
if (rgblight_config.val - RGBLIGHT_VAL_STEP < 0) {
val = 0;
} else {
- val = rgblight_config.val-RGBLIGHT_VAL_STEP;
+ val = rgblight_config.val - RGBLIGHT_VAL_STEP;
}
rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, val);
}
-void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val){
- inmem_config.raw = rgblight_config.raw;
+void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
+ inmem_config.raw = rgblight_config.raw;
if (rgblight_config.enable) {
struct cRGB tmp_led;
sethsv(hue, sat, val, &tmp_led);
- inmem_config.hue = hue;
- inmem_config.sat = sat;
- inmem_config.val = val;
+ inmem_config.hue = hue;
+ inmem_config.sat = sat;
+ inmem_config.val = val;
// dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val);
rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
}
}
-void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val){
+void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
if (rgblight_config.enable) {
- if (rgblight_config.mode == 1) {
- // same static color
- rgblight_sethsv_noeeprom(hue, sat, val);
- } else {
- // all LEDs in same color
- if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) {
- // breathing mode, ignore the change of val, use in memory value instead
- val = rgblight_config.val;
- } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 14) {
- // rainbow mood and rainbow swirl, ignore the change of hue
- hue = rgblight_config.hue;
- }
- }
- rgblight_config.hue = hue;
- rgblight_config.sat = sat;
- rgblight_config.val = val;
- eeconfig_update_rgblight(rgblight_config.raw);
- xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
- }
-}
-
-void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b){
+ if (rgblight_config.mode == 1) {
+ // same static color
+ rgblight_sethsv_noeeprom(hue, sat, val);
+ } else {
+ // all LEDs in same color
+ if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) {
+ // breathing mode, ignore the change of val, use in memory value instead
+ val = rgblight_config.val;
+ } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 14) {
+ // rainbow mood and rainbow swirl, ignore the change of hue
+ hue = rgblight_config.hue;
+ }
+ }
+ rgblight_config.hue = hue;
+ rgblight_config.sat = sat;
+ rgblight_config.val = val;
+ eeconfig_update_rgblight(rgblight_config.raw);
+ xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+ }
+}
+
+void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
// dprintf("rgblight set rgb: %u,%u,%u\n", r,g,b);
- for (uint8_t i=0;i<RGBLED_NUM;i++) {
+ for (uint8_t i = 0; i < RGBLED_NUM; i++) {
led[i].r = r;
led[i].g = g;
led[i].b = b;
}
rgblight_set();
-
}
void rgblight_set(void) {
- if (rgblight_config.enable) {
- ws2812_setleds(led, RGBLED_NUM);
- } else {
- for (uint8_t i=0;i<RGBLED_NUM;i++) {
- led[i].r = 0;
- led[i].g = 0;
- led[i].b = 0;
- }
- ws2812_setleds(led, RGBLED_NUM);
- }
+ if (rgblight_config.enable) {
+ ws2812_setleds(led, RGBLED_NUM);
+ } else {
+ for (uint8_t i = 0; i < RGBLED_NUM; i++) {
+ led[i].r = 0;
+ led[i].g = 0;
+ led[i].b = 0;
+ }
+ ws2812_setleds(led, RGBLED_NUM);
+ }
}
-
#if !defined(AUDIO_ENABLE) && defined(RGBLIGHT_TIMER)
// Animation timer -- AVR Timer3
void rgblight_timer_init(void) {
- static uint8_t rgblight_timer_is_init = 0;
- if (rgblight_timer_is_init) {
- return;
- }
- rgblight_timer_is_init = 1;
- /* Timer 3 setup */
- TCCR3B = _BV(WGM32) //CTC mode OCR3A as TOP
- | _BV(CS30); //Clock selelct: clk/1
- /* Set TOP value */
- uint8_t sreg = SREG;
- cli();
- OCR3AH = (RGBLED_TIMER_TOP>>8)&0xff;
- OCR3AL = RGBLED_TIMER_TOP&0xff;
- SREG = sreg;
+ static uint8_t rgblight_timer_is_init = 0;
+ if (rgblight_timer_is_init) {
+ return;
+ }
+ rgblight_timer_is_init = 1;
+ /* Timer 3 setup */
+ TCCR3B = _BV(WGM32) //CTC mode OCR3A as TOP
+ | _BV(CS30); //Clock selelct: clk/1
+ /* Set TOP value */
+ uint8_t sreg = SREG;
+ cli();
+ OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff;
+ OCR3AL = RGBLED_TIMER_TOP & 0xff;
+ SREG = sreg;
}
void rgblight_timer_enable(void) {
- TIMSK3 |= _BV(OCIE3A);
- dprintf("TIMER3 enabled.\n");
+ TIMSK3 |= _BV(OCIE3A);
+ dprintf("TIMER3 enabled.\n");
}
void rgblight_timer_disable(void) {
- TIMSK3 &= ~_BV(OCIE3A);
- dprintf("TIMER3 disabled.\n");
+ TIMSK3 &= ~_BV(OCIE3A);
+ dprintf("TIMER3 disabled.\n");
}
void rgblight_timer_toggle(void) {
- TIMSK3 ^= _BV(OCIE3A);
- dprintf("TIMER3 toggled.\n");
+ TIMSK3 ^= _BV(OCIE3A);
+ dprintf("TIMER3 toggled.\n");
}
ISR(TIMER3_COMPA_vect) {
- // Mode = 1, static light, do nothing here
- if (rgblight_config.mode>=2 && rgblight_config.mode<=5) {
- // mode = 2 to 5, breathing mode
- rgblight_effect_breathing(rgblight_config.mode-2);
-
- } else if (rgblight_config.mode>=6 && rgblight_config.mode<=8) {
- rgblight_effect_rainbow_mood(rgblight_config.mode-6);
- } else if (rgblight_config.mode>=9 && rgblight_config.mode<=14) {
- rgblight_effect_rainbow_swirl(rgblight_config.mode-9);
- } else if (rgblight_config.mode>=15 && rgblight_config.mode<=20) {
- rgblight_effect_snake(rgblight_config.mode-15);
- } else if (rgblight_config.mode>=21 && rgblight_config.mode<=23) {
- rgblight_effect_knight(rgblight_config.mode-21);
- }
-}
-
-// effects
+ // mode = 1, static light, do nothing here
+ if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) {
+ // mode = 2 to 5, breathing mode
+ rgblight_effect_breathing(rgblight_config.mode - 2);
+ } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) {
+ // mode = 6 to 8, rainbow mood mod
+ rgblight_effect_rainbow_mood(rgblight_config.mode - 6);
+ } else if (rgblight_config.mode >= 9 && rgblight_config.mode <= 14) {
+ // mode = 9 to 14, rainbow swirl mode
+ rgblight_effect_rainbow_swirl(rgblight_config.mode - 9);
+ } else if (rgblight_config.mode >= 15 && rgblight_config.mode <= 20) {
+ // mode = 15 to 20, snake mode
+ rgblight_effect_snake(rgblight_config.mode - 15);
+ } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) {
+ // mode = 21 to 23, knight mode
+ rgblight_effect_knight(rgblight_config.mode - 21);
+ }
+}
+
+// Effects
void rgblight_effect_breathing(uint8_t interval) {
- static uint8_t pos = 0;
- static uint16_t last_timer = 0;
+ static uint8_t pos = 0;
+ static uint16_t last_timer = 0;
- if (timer_elapsed(last_timer)<pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) return;
- last_timer = timer_read();
+ if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) {
+ return;
+ }
+ last_timer = timer_read();
- rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, pgm_read_byte(&RGBLED_BREATHING_TABLE[pos]));
- pos = (pos+1) % 256;
+ rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, pgm_read_byte(&RGBLED_BREATHING_TABLE[pos]));
+ pos = (pos + 1) % 256;
}
-
void rgblight_effect_rainbow_mood(uint8_t interval) {
- static uint16_t current_hue=0;
- static uint16_t last_timer = 0;
+ static uint16_t current_hue = 0;
+ static uint16_t last_timer = 0;
- if (timer_elapsed(last_timer)<pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) return;
- last_timer = timer_read();
- rgblight_sethsv_noeeprom(current_hue, rgblight_config.sat, rgblight_config.val);
- current_hue = (current_hue+1) % 360;
+ if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) {
+ return;
+ }
+ last_timer = timer_read();
+ rgblight_sethsv_noeeprom(current_hue, rgblight_config.sat, rgblight_config.val);
+ current_hue = (current_hue + 1) % 360;
}
-
void rgblight_effect_rainbow_swirl(uint8_t interval) {
- static uint16_t current_hue=0;
- static uint16_t last_timer = 0;
- uint16_t hue;
- uint8_t i;
- if (timer_elapsed(last_timer)<pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval/2])) return;
- last_timer = timer_read();
- for (i=0; i<RGBLED_NUM; i++) {
- hue = (360/RGBLED_NUM*i+current_hue)%360;
- sethsv(hue, rgblight_config.sat, rgblight_config.val, &led[i]);
- }
- rgblight_set();
-
- if (interval % 2) {
- current_hue = (current_hue+1) % 360;
- } else {
- if (current_hue -1 < 0) {
- current_hue = 359;
- } else {
- current_hue = current_hue - 1;
- }
-
- }
+ static uint16_t current_hue = 0;
+ static uint16_t last_timer = 0;
+ uint16_t hue;
+ uint8_t i;
+ if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval / 2])) {
+ return;
+ }
+ last_timer = timer_read();
+ for (i = 0; i < RGBLED_NUM; i++) {
+ hue = (360 / RGBLED_NUM * i + current_hue) % 360;
+ sethsv(hue, rgblight_config.sat, rgblight_config.val, &led[i]);
+ }
+ rgblight_set();
+
+ if (interval % 2) {
+ current_hue = (current_hue + 1) % 360;
+ } else {
+ if (current_hue - 1 < 0) {
+ current_hue = 359;
+ } else {
+ current_hue = current_hue - 1;
+ }
+ }
}
void rgblight_effect_snake(uint8_t interval) {
- static uint8_t pos=0;
- static uint16_t last_timer = 0;
- uint8_t i,j;
- int8_t k;
- int8_t increament = 1;
- if (interval%2) increament = -1;
- if (timer_elapsed(last_timer)<pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval/2])) return;
- last_timer = timer_read();
- for (i=0;i<RGBLED_NUM;i++) {
- led[i].r=0;
- led[i].g=0;
- led[i].b=0;
- for (j=0;j<RGBLIGHT_EFFECT_SNAKE_LENGTH;j++) {
- k = pos+j*increament;
- if (k<0) k = k+RGBLED_NUM;
- if (i==k) {
- sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), &led[i]);
- }
- }
- }
- rgblight_set();
- if (increament == 1) {
- if (pos - 1 < 0) {
- pos = RGBLED_NUM-1;
- } else {
- pos -= 1;
- }
- } else {
- pos = (pos+1)%RGBLED_NUM;
- }
-
+ static uint8_t pos = 0;
+ static uint16_t last_timer = 0;
+ uint8_t i, j;
+ int8_t k;
+ int8_t increment = 1;
+ if (interval % 2) {
+ increment = -1;
+ }
+ if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_SNAKE_INTERVALS[interval / 2])) {
+ return;
+ }
+ last_timer = timer_read();
+ for (i = 0; i < RGBLED_NUM; i++) {
+ led[i].r = 0;
+ led[i].g = 0;
+ led[i].b = 0;
+ for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) {
+ k = pos + j * increment;
+ if (k < 0) {
+ k = k + RGBLED_NUM;
+ }
+ if (i == k) {
+ sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), &led[i]);
+ }
+ }
+ }
+ rgblight_set();
+ if (increment == 1) {
+ if (pos - 1 < 0) {
+ pos = RGBLED_NUM - 1;
+ } else {
+ pos -= 1;
+ }
+ } else {
+ pos = (pos + 1) % RGBLED_NUM;
+ }
}
-
void rgblight_effect_knight(uint8_t interval) {
- static int8_t pos=0;
- static uint16_t last_timer = 0;
- uint8_t i,j,cur;
- int8_t k;
- struct cRGB preled[RGBLED_NUM];
- static int8_t increament = -1;
- if (timer_elapsed(last_timer)<pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) return;
- last_timer = timer_read();
- for (i=0;i<RGBLED_NUM;i++) {
- preled[i].r=0;
- preled[i].g=0;
- preled[i].b=0;
- for (j=0;j<RGBLIGHT_EFFECT_KNIGHT_LENGTH;j++) {
- k = pos+j*increament;
- if (k<0) k = 0;
- if (k>=RGBLED_NUM) k=RGBLED_NUM-1;
- if (i==k) {
- sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, &preled[i]);
- }
- }
- }
- if (RGBLIGHT_EFFECT_KNIGHT_OFFSET) {
- for (i=0;i<RGBLED_NUM;i++) {
- cur = (i+RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM;
- led[i].r = preled[cur].r;
- led[i].g = preled[cur].g;
- led[i].b = preled[cur].b;
- }
- }
- rgblight_set();
- if (increament == 1) {
- if (pos - 1 < 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH) {
- pos = 0- RGBLIGHT_EFFECT_KNIGHT_LENGTH;
- increament = -1;
- } else {
- pos -= 1;
- }
- } else {
- if (pos+1>RGBLED_NUM+RGBLIGHT_EFFECT_KNIGHT_LENGTH) {
- pos = RGBLED_NUM+RGBLIGHT_EFFECT_KNIGHT_LENGTH-1;
- increament = 1;
- } else {
- pos += 1;
- }
- }
-
-}
-
-#endif \ No newline at end of file
+ static int8_t pos = 0;
+ static uint16_t last_timer = 0;
+ uint8_t i, j, cur;
+ int8_t k;
+ struct cRGB preled[RGBLED_NUM];
+ static int8_t increment = -1;
+ if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_KNIGHT_INTERVALS[interval])) {
+ return;
+ }
+ last_timer = timer_read();
+ for (i = 0; i < RGBLED_NUM; i++) {
+ preled[i].r = 0;
+ preled[i].g = 0;
+ preled[i].b = 0;
+ for (j = 0; j < RGBLIGHT_EFFECT_KNIGHT_LENGTH; j++) {
+ k = pos + j * increment;
+ if (k < 0) {
+ k = 0;
+ }
+ if (k >= RGBLED_NUM) {
+ k = RGBLED_NUM - 1;
+ }
+ if (i == k) {
+ sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, &preled[i]);
+ }
+ }
+ }
+ if (RGBLIGHT_EFFECT_KNIGHT_OFFSET) {
+ for (i = 0; i < RGBLED_NUM; i++) {
+ cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % RGBLED_NUM;
+ led[i].r = preled[cur].r;
+ led[i].g = preled[cur].g;
+ led[i].b = preled[cur].b;
+ }
+ }
+ rgblight_set();
+ if (increment == 1) {
+ if (pos - 1 < 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH) {
+ pos = 0 - RGBLIGHT_EFFECT_KNIGHT_LENGTH;
+ increment = -1;
+ } else {
+ pos -= 1;
+ }
+ } else {
+ if (pos + 1 > RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH) {
+ pos = RGBLED_NUM + RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1;
+ increment = 1;
+ } else {
+ pos += 1;
+ }
+ }
+}
+
+#endif