clang-format changes
This commit is contained in:
parent
61af76a10d
commit
b624f32f94
30 changed files with 32694 additions and 39497 deletions
|
|
@ -2,30 +2,28 @@
|
|||
#include "process_audio.h"
|
||||
|
||||
#ifndef VOICE_CHANGE_SONG
|
||||
#define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
|
||||
# define VOICE_CHANGE_SONG SONG(VOICE_CHANGE_SOUND)
|
||||
#endif
|
||||
float voice_change_song[][2] = VOICE_CHANGE_SONG;
|
||||
|
||||
#ifndef PITCH_STANDARD_A
|
||||
#define PITCH_STANDARD_A 440.0f
|
||||
# define PITCH_STANDARD_A 440.0f
|
||||
#endif
|
||||
|
||||
float compute_freq_for_midi_note(uint8_t note)
|
||||
{
|
||||
float compute_freq_for_midi_note(uint8_t note) {
|
||||
// https://en.wikipedia.org/wiki/MIDI_tuning_standard
|
||||
return pow(2.0, (note - 69) / 12.0) * PITCH_STANDARD_A;
|
||||
}
|
||||
|
||||
bool process_audio(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
if (keycode == AU_ON && record->event.pressed) {
|
||||
audio_on();
|
||||
return false;
|
||||
audio_on();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == AU_OFF && record->event.pressed) {
|
||||
audio_off();
|
||||
return false;
|
||||
audio_off();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == AU_TOG && record->event.pressed) {
|
||||
|
|
@ -52,17 +50,10 @@ bool process_audio(uint16_t keycode, keyrecord_t *record) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void process_audio_noteon(uint8_t note) {
|
||||
play_note(compute_freq_for_midi_note(note), 0xF);
|
||||
}
|
||||
void process_audio_noteon(uint8_t note) { play_note(compute_freq_for_midi_note(note), 0xF); }
|
||||
|
||||
void process_audio_noteoff(uint8_t note) {
|
||||
stop_note(compute_freq_for_midi_note(note));
|
||||
}
|
||||
void process_audio_noteoff(uint8_t note) { stop_note(compute_freq_for_midi_note(note)); }
|
||||
|
||||
void process_audio_all_notes_off(void) {
|
||||
stop_all_notes();
|
||||
}
|
||||
void process_audio_all_notes_off(void) { stop_all_notes(); }
|
||||
|
||||
__attribute__ ((weak))
|
||||
void audio_on_user() {}
|
||||
__attribute__((weak)) void audio_on_user() {}
|
||||
|
|
|
|||
|
|
@ -16,195 +16,185 @@
|
|||
|
||||
#ifdef AUTO_SHIFT_ENABLE
|
||||
|
||||
#include <stdio.h>
|
||||
# include <stdio.h>
|
||||
|
||||
#include "process_auto_shift.h"
|
||||
# include "process_auto_shift.h"
|
||||
|
||||
#define TAP(key) \
|
||||
register_code(key); \
|
||||
unregister_code(key)
|
||||
# define TAP(key) \
|
||||
register_code(key); \
|
||||
unregister_code(key)
|
||||
|
||||
#define TAP_WITH_MOD(mod, key) \
|
||||
register_code(mod); \
|
||||
register_code(key); \
|
||||
unregister_code(key); \
|
||||
unregister_code(mod)
|
||||
# define TAP_WITH_MOD(mod, key) \
|
||||
register_code(mod); \
|
||||
register_code(key); \
|
||||
unregister_code(key); \
|
||||
unregister_code(mod)
|
||||
|
||||
uint16_t autoshift_time = 0;
|
||||
uint16_t autoshift_time = 0;
|
||||
uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
|
||||
uint16_t autoshift_lastkey = KC_NO;
|
||||
|
||||
void autoshift_timer_report(void) {
|
||||
char display[8];
|
||||
char display[8];
|
||||
|
||||
snprintf(display, 8, "\n%d\n", autoshift_timeout);
|
||||
snprintf(display, 8, "\n%d\n", autoshift_timeout);
|
||||
|
||||
send_string((const char *)display);
|
||||
send_string((const char *)display);
|
||||
}
|
||||
|
||||
void autoshift_on(uint16_t keycode) {
|
||||
autoshift_time = timer_read();
|
||||
autoshift_lastkey = keycode;
|
||||
autoshift_time = timer_read();
|
||||
autoshift_lastkey = keycode;
|
||||
}
|
||||
|
||||
void autoshift_flush(void) {
|
||||
if (autoshift_lastkey != KC_NO) {
|
||||
uint16_t elapsed = timer_elapsed(autoshift_time);
|
||||
if (autoshift_lastkey != KC_NO) {
|
||||
uint16_t elapsed = timer_elapsed(autoshift_time);
|
||||
|
||||
if (elapsed > autoshift_timeout) {
|
||||
register_code(KC_LSFT);
|
||||
if (elapsed > autoshift_timeout) {
|
||||
register_code(KC_LSFT);
|
||||
}
|
||||
|
||||
register_code(autoshift_lastkey);
|
||||
unregister_code(autoshift_lastkey);
|
||||
|
||||
if (elapsed > autoshift_timeout) {
|
||||
unregister_code(KC_LSFT);
|
||||
}
|
||||
|
||||
autoshift_time = 0;
|
||||
autoshift_lastkey = KC_NO;
|
||||
}
|
||||
|
||||
register_code(autoshift_lastkey);
|
||||
unregister_code(autoshift_lastkey);
|
||||
|
||||
if (elapsed > autoshift_timeout) {
|
||||
unregister_code(KC_LSFT);
|
||||
}
|
||||
|
||||
autoshift_time = 0;
|
||||
autoshift_lastkey = KC_NO;
|
||||
}
|
||||
}
|
||||
|
||||
bool autoshift_enabled = true;
|
||||
|
||||
void autoshift_enable(void) {
|
||||
autoshift_enabled = true;
|
||||
}
|
||||
void autoshift_enable(void) { autoshift_enabled = true; }
|
||||
void autoshift_disable(void) {
|
||||
autoshift_enabled = false;
|
||||
autoshift_flush();
|
||||
autoshift_enabled = false;
|
||||
autoshift_flush();
|
||||
}
|
||||
|
||||
void autoshift_toggle(void) {
|
||||
if (autoshift_enabled) {
|
||||
autoshift_enabled = false;
|
||||
autoshift_flush();
|
||||
}
|
||||
else {
|
||||
autoshift_enabled = true;
|
||||
}
|
||||
if (autoshift_enabled) {
|
||||
autoshift_enabled = false;
|
||||
autoshift_flush();
|
||||
} else {
|
||||
autoshift_enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool autoshift_state(void) {
|
||||
return autoshift_enabled;
|
||||
}
|
||||
bool autoshift_state(void) { return autoshift_enabled; }
|
||||
|
||||
bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
|
||||
#ifndef AUTO_SHIFT_MODIFIERS
|
||||
static uint8_t any_mod_pressed;
|
||||
#endif
|
||||
# ifndef AUTO_SHIFT_MODIFIERS
|
||||
static uint8_t any_mod_pressed;
|
||||
# endif
|
||||
|
||||
if (record->event.pressed) {
|
||||
switch (keycode) {
|
||||
case KC_ASUP:
|
||||
autoshift_timeout += 5;
|
||||
return false;
|
||||
if (record->event.pressed) {
|
||||
switch (keycode) {
|
||||
case KC_ASUP:
|
||||
autoshift_timeout += 5;
|
||||
return false;
|
||||
|
||||
case KC_ASDN:
|
||||
autoshift_timeout -= 5;
|
||||
return false;
|
||||
case KC_ASDN:
|
||||
autoshift_timeout -= 5;
|
||||
return false;
|
||||
|
||||
case KC_ASRP:
|
||||
autoshift_timer_report();
|
||||
return false;
|
||||
case KC_ASRP:
|
||||
autoshift_timer_report();
|
||||
return false;
|
||||
|
||||
case KC_ASTG:
|
||||
autoshift_toggle();
|
||||
return false;
|
||||
case KC_ASON:
|
||||
autoshift_enable();
|
||||
return false;
|
||||
case KC_ASOFF:
|
||||
autoshift_disable();
|
||||
return false;
|
||||
case KC_ASTG:
|
||||
autoshift_toggle();
|
||||
return false;
|
||||
case KC_ASON:
|
||||
autoshift_enable();
|
||||
return false;
|
||||
case KC_ASOFF:
|
||||
autoshift_disable();
|
||||
return false;
|
||||
|
||||
#ifndef NO_AUTO_SHIFT_ALPHA
|
||||
case KC_A:
|
||||
case KC_B:
|
||||
case KC_C:
|
||||
case KC_D:
|
||||
case KC_E:
|
||||
case KC_F:
|
||||
case KC_G:
|
||||
case KC_H:
|
||||
case KC_I:
|
||||
case KC_J:
|
||||
case KC_K:
|
||||
case KC_L:
|
||||
case KC_M:
|
||||
case KC_N:
|
||||
case KC_O:
|
||||
case KC_P:
|
||||
case KC_Q:
|
||||
case KC_R:
|
||||
case KC_S:
|
||||
case KC_T:
|
||||
case KC_U:
|
||||
case KC_V:
|
||||
case KC_W:
|
||||
case KC_X:
|
||||
case KC_Y:
|
||||
case KC_Z:
|
||||
#endif
|
||||
#ifndef NO_AUTO_SHIFT_NUMERIC
|
||||
case KC_1:
|
||||
case KC_2:
|
||||
case KC_3:
|
||||
case KC_4:
|
||||
case KC_5:
|
||||
case KC_6:
|
||||
case KC_7:
|
||||
case KC_8:
|
||||
case KC_9:
|
||||
case KC_0:
|
||||
#endif
|
||||
#ifndef NO_AUTO_SHIFT_SPECIAL
|
||||
case KC_MINUS:
|
||||
case KC_EQL:
|
||||
case KC_TAB:
|
||||
case KC_LBRC:
|
||||
case KC_RBRC:
|
||||
case KC_BSLS:
|
||||
case KC_SCLN:
|
||||
case KC_QUOT:
|
||||
case KC_COMM:
|
||||
case KC_DOT:
|
||||
case KC_SLSH:
|
||||
case KC_GRAVE:
|
||||
case KC_NONUS_BSLASH:
|
||||
case KC_NONUS_HASH:
|
||||
#endif
|
||||
# ifndef NO_AUTO_SHIFT_ALPHA
|
||||
case KC_A:
|
||||
case KC_B:
|
||||
case KC_C:
|
||||
case KC_D:
|
||||
case KC_E:
|
||||
case KC_F:
|
||||
case KC_G:
|
||||
case KC_H:
|
||||
case KC_I:
|
||||
case KC_J:
|
||||
case KC_K:
|
||||
case KC_L:
|
||||
case KC_M:
|
||||
case KC_N:
|
||||
case KC_O:
|
||||
case KC_P:
|
||||
case KC_Q:
|
||||
case KC_R:
|
||||
case KC_S:
|
||||
case KC_T:
|
||||
case KC_U:
|
||||
case KC_V:
|
||||
case KC_W:
|
||||
case KC_X:
|
||||
case KC_Y:
|
||||
case KC_Z:
|
||||
# endif
|
||||
# ifndef NO_AUTO_SHIFT_NUMERIC
|
||||
case KC_1:
|
||||
case KC_2:
|
||||
case KC_3:
|
||||
case KC_4:
|
||||
case KC_5:
|
||||
case KC_6:
|
||||
case KC_7:
|
||||
case KC_8:
|
||||
case KC_9:
|
||||
case KC_0:
|
||||
# endif
|
||||
# ifndef NO_AUTO_SHIFT_SPECIAL
|
||||
case KC_MINUS:
|
||||
case KC_EQL:
|
||||
case KC_TAB:
|
||||
case KC_LBRC:
|
||||
case KC_RBRC:
|
||||
case KC_BSLS:
|
||||
case KC_SCLN:
|
||||
case KC_QUOT:
|
||||
case KC_COMM:
|
||||
case KC_DOT:
|
||||
case KC_SLSH:
|
||||
case KC_GRAVE:
|
||||
case KC_NONUS_BSLASH:
|
||||
case KC_NONUS_HASH:
|
||||
# endif
|
||||
|
||||
autoshift_flush();
|
||||
if (!autoshift_enabled) return true;
|
||||
autoshift_flush();
|
||||
if (!autoshift_enabled) return true;
|
||||
|
||||
#ifndef AUTO_SHIFT_MODIFIERS
|
||||
any_mod_pressed = get_mods() & (
|
||||
MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|
|
||||
MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)|
|
||||
MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)|
|
||||
MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)
|
||||
);
|
||||
# ifndef AUTO_SHIFT_MODIFIERS
|
||||
any_mod_pressed = get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI) | MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT) | MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL) | MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT));
|
||||
|
||||
if (any_mod_pressed) {
|
||||
return true;
|
||||
if (any_mod_pressed) {
|
||||
return true;
|
||||
}
|
||||
# endif
|
||||
|
||||
autoshift_on(keycode);
|
||||
return false;
|
||||
|
||||
default:
|
||||
autoshift_flush();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
autoshift_on(keycode);
|
||||
return false;
|
||||
|
||||
default:
|
||||
} else {
|
||||
autoshift_flush();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
autoshift_flush();
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
#include "quantum.h"
|
||||
|
||||
#ifndef AUTO_SHIFT_TIMEOUT
|
||||
#define AUTO_SHIFT_TIMEOUT 175
|
||||
# define AUTO_SHIFT_TIMEOUT 175
|
||||
#endif
|
||||
|
||||
bool process_auto_shift(uint16_t keycode, keyrecord_t *record);
|
||||
|
|
|
|||
|
|
@ -3,104 +3,111 @@
|
|||
|
||||
#ifdef AUDIO_CLICKY
|
||||
|
||||
#ifndef AUDIO_CLICKY_DELAY_DURATION
|
||||
#define AUDIO_CLICKY_DELAY_DURATION 1
|
||||
#endif // !AUDIO_CLICKY_DELAY_DURATION
|
||||
#ifndef AUDIO_CLICKY_FREQ_DEFAULT
|
||||
#define AUDIO_CLICKY_FREQ_DEFAULT 440.0f
|
||||
#endif // !AUDIO_CLICKY_FREQ_DEFAULT
|
||||
#ifndef AUDIO_CLICKY_FREQ_MIN
|
||||
#define AUDIO_CLICKY_FREQ_MIN 65.0f
|
||||
#endif // !AUDIO_CLICKY_FREQ_MIN
|
||||
#ifndef AUDIO_CLICKY_FREQ_MAX
|
||||
#define AUDIO_CLICKY_FREQ_MAX 1500.0f
|
||||
#endif // !AUDIO_CLICKY_FREQ_MAX
|
||||
#ifndef AUDIO_CLICKY_FREQ_FACTOR
|
||||
#define AUDIO_CLICKY_FREQ_FACTOR 1.18921f
|
||||
#endif // !AUDIO_CLICKY_FREQ_FACTOR
|
||||
#ifndef AUDIO_CLICKY_FREQ_RANDOMNESS
|
||||
#define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f
|
||||
#endif // !AUDIO_CLICKY_FREQ_RANDOMNESS
|
||||
# ifndef AUDIO_CLICKY_DELAY_DURATION
|
||||
# define AUDIO_CLICKY_DELAY_DURATION 1
|
||||
# endif // !AUDIO_CLICKY_DELAY_DURATION
|
||||
# ifndef AUDIO_CLICKY_FREQ_DEFAULT
|
||||
# define AUDIO_CLICKY_FREQ_DEFAULT 440.0f
|
||||
# endif // !AUDIO_CLICKY_FREQ_DEFAULT
|
||||
# ifndef AUDIO_CLICKY_FREQ_MIN
|
||||
# define AUDIO_CLICKY_FREQ_MIN 65.0f
|
||||
# endif // !AUDIO_CLICKY_FREQ_MIN
|
||||
# ifndef AUDIO_CLICKY_FREQ_MAX
|
||||
# define AUDIO_CLICKY_FREQ_MAX 1500.0f
|
||||
# endif // !AUDIO_CLICKY_FREQ_MAX
|
||||
# ifndef AUDIO_CLICKY_FREQ_FACTOR
|
||||
# define AUDIO_CLICKY_FREQ_FACTOR 1.18921f
|
||||
# endif // !AUDIO_CLICKY_FREQ_FACTOR
|
||||
# ifndef AUDIO_CLICKY_FREQ_RANDOMNESS
|
||||
# define AUDIO_CLICKY_FREQ_RANDOMNESS 0.05f
|
||||
# endif // !AUDIO_CLICKY_FREQ_RANDOMNESS
|
||||
|
||||
float clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
|
||||
float clicky_rand = AUDIO_CLICKY_FREQ_RANDOMNESS;
|
||||
|
||||
// the first "note" is an intentional delay; the 2nd and 3rd notes are the "clicky"
|
||||
float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations
|
||||
float clicky_song[][2] = {{AUDIO_CLICKY_FREQ_MIN, AUDIO_CLICKY_DELAY_DURATION}, {AUDIO_CLICKY_FREQ_DEFAULT, 3}, {AUDIO_CLICKY_FREQ_DEFAULT, 1}}; // 3 and 1 --> durations
|
||||
|
||||
extern audio_config_t audio_config;
|
||||
|
||||
#ifndef NO_MUSIC_MODE
|
||||
# ifndef NO_MUSIC_MODE
|
||||
extern bool music_activated;
|
||||
extern bool midi_activated;
|
||||
#endif // !NO_MUSIC_MODE
|
||||
# endif // !NO_MUSIC_MODE
|
||||
|
||||
void clicky_play(void) {
|
||||
#ifndef NO_MUSIC_MODE
|
||||
if (music_activated || midi_activated || !audio_config.enable) return;
|
||||
#endif // !NO_MUSIC_MODE
|
||||
clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
|
||||
clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * ( ((float)rand()) / ((float)(RAND_MAX)) ) );
|
||||
PLAY_SONG(clicky_song);
|
||||
# ifndef NO_MUSIC_MODE
|
||||
if (music_activated || midi_activated || !audio_config.enable) return;
|
||||
# endif // !NO_MUSIC_MODE
|
||||
clicky_song[1][0] = 2.0f * clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX))));
|
||||
clicky_song[2][0] = clicky_freq * (1.0f + clicky_rand * (((float)rand()) / ((float)(RAND_MAX))));
|
||||
PLAY_SONG(clicky_song);
|
||||
}
|
||||
|
||||
void clicky_freq_up(void) {
|
||||
float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
|
||||
if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
|
||||
clicky_freq = new_freq;
|
||||
}
|
||||
float new_freq = clicky_freq * AUDIO_CLICKY_FREQ_FACTOR;
|
||||
if (new_freq < AUDIO_CLICKY_FREQ_MAX) {
|
||||
clicky_freq = new_freq;
|
||||
}
|
||||
}
|
||||
|
||||
void clicky_freq_down(void) {
|
||||
float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
|
||||
if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
|
||||
clicky_freq = new_freq;
|
||||
}
|
||||
float new_freq = clicky_freq / AUDIO_CLICKY_FREQ_FACTOR;
|
||||
if (new_freq > AUDIO_CLICKY_FREQ_MIN) {
|
||||
clicky_freq = new_freq;
|
||||
}
|
||||
}
|
||||
|
||||
void clicky_freq_reset(void) {
|
||||
clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT;
|
||||
}
|
||||
void clicky_freq_reset(void) { clicky_freq = AUDIO_CLICKY_FREQ_DEFAULT; }
|
||||
|
||||
void clicky_toggle(void) {
|
||||
audio_config.clicky_enable ^= 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
audio_config.clicky_enable ^= 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
}
|
||||
|
||||
void clicky_on(void) {
|
||||
audio_config.clicky_enable = 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
audio_config.clicky_enable = 1;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
}
|
||||
|
||||
void clicky_off(void) {
|
||||
audio_config.clicky_enable = 0;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
audio_config.clicky_enable = 0;
|
||||
eeconfig_update_audio(audio_config.raw);
|
||||
}
|
||||
|
||||
bool is_clicky_on(void) {
|
||||
return (audio_config.clicky_enable != 0);
|
||||
}
|
||||
bool is_clicky_on(void) { return (audio_config.clicky_enable != 0); }
|
||||
|
||||
bool process_clicky(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode == CLICKY_TOGGLE && record->event.pressed) { clicky_toggle(); }
|
||||
|
||||
if (keycode == CLICKY_ENABLE && record->event.pressed) { clicky_on(); }
|
||||
if (keycode == CLICKY_DISABLE && record->event.pressed) { clicky_off(); }
|
||||
|
||||
if (keycode == CLICKY_RESET && record->event.pressed) { clicky_freq_reset(); }
|
||||
|
||||
if (keycode == CLICKY_UP && record->event.pressed) { clicky_freq_up(); }
|
||||
if (keycode == CLICKY_DOWN && record->event.pressed) { clicky_freq_down(); }
|
||||
|
||||
|
||||
if (audio_config.enable && audio_config.clicky_enable) {
|
||||
if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound
|
||||
if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
|
||||
clicky_play();
|
||||
}
|
||||
if (keycode == CLICKY_TOGGLE && record->event.pressed) {
|
||||
clicky_toggle();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
if (keycode == CLICKY_ENABLE && record->event.pressed) {
|
||||
clicky_on();
|
||||
}
|
||||
if (keycode == CLICKY_DISABLE && record->event.pressed) {
|
||||
clicky_off();
|
||||
}
|
||||
|
||||
if (keycode == CLICKY_RESET && record->event.pressed) {
|
||||
clicky_freq_reset();
|
||||
}
|
||||
|
||||
if (keycode == CLICKY_UP && record->event.pressed) {
|
||||
clicky_freq_up();
|
||||
}
|
||||
if (keycode == CLICKY_DOWN && record->event.pressed) {
|
||||
clicky_freq_down();
|
||||
}
|
||||
|
||||
if (audio_config.enable && audio_config.clicky_enable) {
|
||||
if (record->event.pressed) { // Leave this separate so it's easier to add upstroke sound
|
||||
if (keycode != AU_OFF && keycode != AU_TOG) { // DO NOT PLAY if audio will be disabled, and causes issuse on ARM
|
||||
clicky_play();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif //AUDIO_CLICKY
|
||||
#endif // AUDIO_CLICKY
|
||||
|
|
|
|||
|
|
@ -21,14 +21,13 @@ __attribute__((weak)) combo_t key_combos[COMBO_COUNT] = {
|
|||
|
||||
};
|
||||
|
||||
__attribute__((weak)) void process_combo_event(uint8_t combo_index,
|
||||
bool pressed) {}
|
||||
__attribute__((weak)) void process_combo_event(uint8_t combo_index, bool pressed) {}
|
||||
|
||||
static uint16_t timer = 0;
|
||||
static uint8_t current_combo_index = 0;
|
||||
static bool drop_buffer = false;
|
||||
static bool is_active = false;
|
||||
static bool b_combo_enable = true; // defaults to enabled
|
||||
static uint16_t timer = 0;
|
||||
static uint8_t current_combo_index = 0;
|
||||
static bool drop_buffer = false;
|
||||
static bool is_active = false;
|
||||
static bool b_combo_enable = true; // defaults to enabled
|
||||
|
||||
static uint8_t buffer_size = 0;
|
||||
#ifdef COMBO_ALLOW_ACTION_KEYS
|
||||
|
|
@ -38,171 +37,163 @@ static uint16_t key_buffer[MAX_COMBO_LENGTH];
|
|||
#endif
|
||||
|
||||
static inline void send_combo(uint16_t action, bool pressed) {
|
||||
if (action) {
|
||||
if (pressed) {
|
||||
register_code16(action);
|
||||
if (action) {
|
||||
if (pressed) {
|
||||
register_code16(action);
|
||||
} else {
|
||||
unregister_code16(action);
|
||||
}
|
||||
} else {
|
||||
unregister_code16(action);
|
||||
process_combo_event(current_combo_index, pressed);
|
||||
}
|
||||
} else {
|
||||
process_combo_event(current_combo_index, pressed);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void dump_key_buffer(bool emit) {
|
||||
if (buffer_size == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (emit) {
|
||||
for (uint8_t i = 0; i < buffer_size; i++) {
|
||||
#ifdef COMBO_ALLOW_ACTION_KEYS
|
||||
const action_t action = store_or_get_action(key_buffer[i].event.pressed,
|
||||
key_buffer[i].event.key);
|
||||
process_action(&(key_buffer[i]), action);
|
||||
#else
|
||||
register_code16(key_buffer[i]);
|
||||
send_keyboard_report();
|
||||
#endif
|
||||
if (buffer_size == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
buffer_size = 0;
|
||||
if (emit) {
|
||||
for (uint8_t i = 0; i < buffer_size; i++) {
|
||||
#ifdef COMBO_ALLOW_ACTION_KEYS
|
||||
const action_t action = store_or_get_action(key_buffer[i].event.pressed, key_buffer[i].event.key);
|
||||
process_action(&(key_buffer[i]), action);
|
||||
#else
|
||||
register_code16(key_buffer[i]);
|
||||
send_keyboard_report();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
buffer_size = 0;
|
||||
}
|
||||
|
||||
#define ALL_COMBO_KEYS_ARE_DOWN (((1 << count) - 1) == combo->state)
|
||||
#define KEY_STATE_DOWN(key) \
|
||||
do { \
|
||||
combo->state |= (1 << key); \
|
||||
} while (0)
|
||||
#define KEY_STATE_UP(key) \
|
||||
do { \
|
||||
combo->state &= ~(1 << key); \
|
||||
} while (0)
|
||||
#define KEY_STATE_DOWN(key) \
|
||||
do { \
|
||||
combo->state |= (1 << key); \
|
||||
} while (0)
|
||||
#define KEY_STATE_UP(key) \
|
||||
do { \
|
||||
combo->state &= ~(1 << key); \
|
||||
} while (0)
|
||||
|
||||
static bool process_single_combo(combo_t *combo, uint16_t keycode,
|
||||
keyrecord_t *record) {
|
||||
uint8_t count = 0;
|
||||
uint8_t index = -1;
|
||||
/* Find index of keycode and number of combo keys */
|
||||
for (const uint16_t *keys = combo->keys;; ++count) {
|
||||
uint16_t key = pgm_read_word(&keys[count]);
|
||||
if (keycode == key)
|
||||
index = count;
|
||||
if (COMBO_END == key)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Continue processing if not a combo key */
|
||||
if (-1 == (int8_t)index)
|
||||
return false;
|
||||
|
||||
bool is_combo_active = is_active;
|
||||
|
||||
if (record->event.pressed) {
|
||||
KEY_STATE_DOWN(index);
|
||||
|
||||
if (is_combo_active) {
|
||||
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */
|
||||
send_combo(combo->keycode, true);
|
||||
drop_buffer = true;
|
||||
}
|
||||
static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *record) {
|
||||
uint8_t count = 0;
|
||||
uint8_t index = -1;
|
||||
/* Find index of keycode and number of combo keys */
|
||||
for (const uint16_t *keys = combo->keys;; ++count) {
|
||||
uint16_t key = pgm_read_word(&keys[count]);
|
||||
if (keycode == key) index = count;
|
||||
if (COMBO_END == key) break;
|
||||
}
|
||||
} else {
|
||||
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */
|
||||
send_combo(combo->keycode, false);
|
||||
|
||||
/* Continue processing if not a combo key */
|
||||
if (-1 == (int8_t)index) return false;
|
||||
|
||||
bool is_combo_active = is_active;
|
||||
|
||||
if (record->event.pressed) {
|
||||
KEY_STATE_DOWN(index);
|
||||
|
||||
if (is_combo_active) {
|
||||
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was pressed */
|
||||
send_combo(combo->keycode, true);
|
||||
drop_buffer = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* continue processing without immediately returning */
|
||||
is_combo_active = false;
|
||||
if (ALL_COMBO_KEYS_ARE_DOWN) { /* Combo was released */
|
||||
send_combo(combo->keycode, false);
|
||||
} else {
|
||||
/* continue processing without immediately returning */
|
||||
is_combo_active = false;
|
||||
}
|
||||
|
||||
KEY_STATE_UP(index);
|
||||
}
|
||||
|
||||
KEY_STATE_UP(index);
|
||||
}
|
||||
|
||||
return is_combo_active;
|
||||
return is_combo_active;
|
||||
}
|
||||
|
||||
#define NO_COMBO_KEYS_ARE_DOWN (0 == combo->state)
|
||||
|
||||
bool process_combo(uint16_t keycode, keyrecord_t *record) {
|
||||
bool is_combo_key = false;
|
||||
drop_buffer = false;
|
||||
bool no_combo_keys_pressed = true;
|
||||
bool is_combo_key = false;
|
||||
drop_buffer = false;
|
||||
bool no_combo_keys_pressed = true;
|
||||
|
||||
if (keycode == CMB_ON && record->event.pressed) {
|
||||
combo_enable();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keycode == CMB_OFF && record->event.pressed) {
|
||||
combo_disable();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keycode == CMB_TOG && record->event.pressed) {
|
||||
combo_toggle();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_combo_enabled()) { return true; }
|
||||
|
||||
for (current_combo_index = 0; current_combo_index < COMBO_COUNT;
|
||||
++current_combo_index) {
|
||||
combo_t *combo = &key_combos[current_combo_index];
|
||||
is_combo_key |= process_single_combo(combo, keycode, record);
|
||||
no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN;
|
||||
}
|
||||
|
||||
if (drop_buffer) {
|
||||
/* buffer is only dropped when we complete a combo, so we refresh the timer
|
||||
* here */
|
||||
timer = timer_read();
|
||||
dump_key_buffer(false);
|
||||
} else if (!is_combo_key) {
|
||||
/* if no combos claim the key we need to emit the keybuffer */
|
||||
dump_key_buffer(true);
|
||||
|
||||
// reset state if there are no combo keys pressed at all
|
||||
if (no_combo_keys_pressed) {
|
||||
timer = 0;
|
||||
is_active = true;
|
||||
if (keycode == CMB_ON && record->event.pressed) {
|
||||
combo_enable();
|
||||
return true;
|
||||
}
|
||||
} else if (record->event.pressed && is_active) {
|
||||
/* otherwise the key is consumed and placed in the buffer */
|
||||
timer = timer_read();
|
||||
|
||||
if (buffer_size < MAX_COMBO_LENGTH) {
|
||||
if (keycode == CMB_OFF && record->event.pressed) {
|
||||
combo_disable();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (keycode == CMB_TOG && record->event.pressed) {
|
||||
combo_toggle();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_combo_enabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (current_combo_index = 0; current_combo_index < COMBO_COUNT; ++current_combo_index) {
|
||||
combo_t *combo = &key_combos[current_combo_index];
|
||||
is_combo_key |= process_single_combo(combo, keycode, record);
|
||||
no_combo_keys_pressed = no_combo_keys_pressed && NO_COMBO_KEYS_ARE_DOWN;
|
||||
}
|
||||
|
||||
if (drop_buffer) {
|
||||
/* buffer is only dropped when we complete a combo, so we refresh the timer
|
||||
* here */
|
||||
timer = timer_read();
|
||||
dump_key_buffer(false);
|
||||
} else if (!is_combo_key) {
|
||||
/* if no combos claim the key we need to emit the keybuffer */
|
||||
dump_key_buffer(true);
|
||||
|
||||
// reset state if there are no combo keys pressed at all
|
||||
if (no_combo_keys_pressed) {
|
||||
timer = 0;
|
||||
is_active = true;
|
||||
}
|
||||
} else if (record->event.pressed && is_active) {
|
||||
/* otherwise the key is consumed and placed in the buffer */
|
||||
timer = timer_read();
|
||||
|
||||
if (buffer_size < MAX_COMBO_LENGTH) {
|
||||
#ifdef COMBO_ALLOW_ACTION_KEYS
|
||||
key_buffer[buffer_size++] = *record;
|
||||
key_buffer[buffer_size++] = *record;
|
||||
#else
|
||||
key_buffer[buffer_size++] = keycode;
|
||||
key_buffer[buffer_size++] = keycode;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !is_combo_key;
|
||||
return !is_combo_key;
|
||||
}
|
||||
|
||||
void matrix_scan_combo(void) {
|
||||
if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) {
|
||||
|
||||
/* This disables the combo, meaning key events for this
|
||||
* combo will be handled by the next processors in the chain
|
||||
*/
|
||||
is_active = false;
|
||||
dump_key_buffer(true);
|
||||
}
|
||||
if (b_combo_enable && is_active && timer && timer_elapsed(timer) > COMBO_TERM) {
|
||||
/* This disables the combo, meaning key events for this
|
||||
* combo will be handled by the next processors in the chain
|
||||
*/
|
||||
is_active = false;
|
||||
dump_key_buffer(true);
|
||||
}
|
||||
}
|
||||
|
||||
void combo_enable(void) {
|
||||
b_combo_enable = true;
|
||||
}
|
||||
void combo_enable(void) { b_combo_enable = true; }
|
||||
|
||||
void combo_disable(void) {
|
||||
b_combo_enable = is_active = false;
|
||||
timer = 0;
|
||||
timer = 0;
|
||||
dump_key_buffer(true);
|
||||
|
||||
}
|
||||
|
||||
void combo_toggle(void) {
|
||||
|
|
@ -213,6 +204,4 @@ void combo_toggle(void) {
|
|||
}
|
||||
}
|
||||
|
||||
bool is_combo_enabled(void) {
|
||||
return b_combo_enable;
|
||||
}
|
||||
bool is_combo_enabled(void) { return b_combo_enable; }
|
||||
|
|
|
|||
|
|
@ -22,36 +22,36 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#ifdef EXTRA_EXTRA_LONG_COMBOS
|
||||
#define MAX_COMBO_LENGTH 32
|
||||
# define MAX_COMBO_LENGTH 32
|
||||
#elif EXTRA_LONG_COMBOS
|
||||
#define MAX_COMBO_LENGTH 16
|
||||
# define MAX_COMBO_LENGTH 16
|
||||
#else
|
||||
#define MAX_COMBO_LENGTH 8
|
||||
# define MAX_COMBO_LENGTH 8
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
const uint16_t *keys;
|
||||
uint16_t keycode;
|
||||
const uint16_t *keys;
|
||||
uint16_t keycode;
|
||||
#ifdef EXTRA_EXTRA_LONG_COMBOS
|
||||
uint32_t state;
|
||||
uint32_t state;
|
||||
#elif EXTRA_LONG_COMBOS
|
||||
uint16_t state;
|
||||
uint16_t state;
|
||||
#else
|
||||
uint8_t state;
|
||||
uint8_t state;
|
||||
#endif
|
||||
} combo_t;
|
||||
|
||||
#define COMBO(ck, ca) \
|
||||
{ .keys = &(ck)[0], .keycode = (ca) }
|
||||
#define COMBO_ACTION(ck) \
|
||||
{ .keys = &(ck)[0] }
|
||||
#define COMBO(ck, ca) \
|
||||
{ .keys = &(ck)[0], .keycode = (ca) }
|
||||
#define COMBO_ACTION(ck) \
|
||||
{ .keys = &(ck)[0] }
|
||||
|
||||
#define COMBO_END 0
|
||||
#ifndef COMBO_COUNT
|
||||
#define COMBO_COUNT 0
|
||||
# define COMBO_COUNT 0
|
||||
#endif
|
||||
#ifndef COMBO_TERM
|
||||
#define COMBO_TERM TAPPING_TERM
|
||||
# define COMBO_TERM TAPPING_TERM
|
||||
#endif
|
||||
|
||||
bool process_combo(uint16_t keycode, keyrecord_t *record);
|
||||
|
|
|
|||
|
|
@ -19,36 +19,33 @@
|
|||
#include "process_key_lock.h"
|
||||
|
||||
#define BV_64(shift) (((uint64_t)1) << (shift))
|
||||
#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : \
|
||||
((code) < 0x80) ? key_state[1] : \
|
||||
((code) < 0xC0) ? key_state[2] : key_state[3])
|
||||
#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : \
|
||||
((code) < 0x80) ? (code) - 0x40 : \
|
||||
((code) < 0xC0) ? (code) - 0x80 : (code) - 0xC0)
|
||||
#define KEY_STATE(code) (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code))
|
||||
#define SET_KEY_ARRAY_STATE(code, val) do { \
|
||||
switch (code) { \
|
||||
case 0x00 ... 0x3F: \
|
||||
key_state[0] = (val); \
|
||||
break; \
|
||||
case 0x40 ... 0x7F: \
|
||||
key_state[1] = (val); \
|
||||
break; \
|
||||
case 0x80 ... 0xBF: \
|
||||
key_state[2] = (val); \
|
||||
break; \
|
||||
case 0xC0 ... 0xFF: \
|
||||
key_state[3] = (val); \
|
||||
break; \
|
||||
} \
|
||||
} while(0)
|
||||
#define GET_KEY_ARRAY(code) (((code) < 0x40) ? key_state[0] : ((code) < 0x80) ? key_state[1] : ((code) < 0xC0) ? key_state[2] : key_state[3])
|
||||
#define GET_CODE_INDEX(code) (((code) < 0x40) ? (code) : ((code) < 0x80) ? (code)-0x40 : ((code) < 0xC0) ? (code)-0x80 : (code)-0xC0)
|
||||
#define KEY_STATE(code) (GET_KEY_ARRAY(code) & BV_64(GET_CODE_INDEX(code))) == BV_64(GET_CODE_INDEX(code))
|
||||
#define SET_KEY_ARRAY_STATE(code, val) \
|
||||
do { \
|
||||
switch (code) { \
|
||||
case 0x00 ... 0x3F: \
|
||||
key_state[0] = (val); \
|
||||
break; \
|
||||
case 0x40 ... 0x7F: \
|
||||
key_state[1] = (val); \
|
||||
break; \
|
||||
case 0x80 ... 0xBF: \
|
||||
key_state[2] = (val); \
|
||||
break; \
|
||||
case 0xC0 ... 0xFF: \
|
||||
key_state[3] = (val); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
#define SET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code) | BV_64(GET_CODE_INDEX(code))))
|
||||
#define UNSET_KEY_STATE(code) SET_KEY_ARRAY_STATE(code, (GET_KEY_ARRAY(code)) & ~(BV_64(GET_CODE_INDEX(code))))
|
||||
#define IS_STANDARD_KEYCODE(code) ((code) <= 0xFF)
|
||||
|
||||
// Locked key state. This is an array of 256 bits, one for each of the standard keys supported qmk.
|
||||
uint64_t key_state[4] = { 0x0, 0x0, 0x0, 0x0 };
|
||||
bool watching = false;
|
||||
uint64_t key_state[4] = {0x0, 0x0, 0x0, 0x0};
|
||||
bool watching = false;
|
||||
|
||||
// Translate any OSM keycodes back to their unmasked versions.
|
||||
static inline uint16_t translate_keycode(uint16_t keycode) {
|
||||
|
|
@ -135,4 +132,3 @@ bool process_key_lock(uint16_t *keycode, keyrecord_t *record) {
|
|||
return !(IS_STANDARD_KEYCODE(translated_keycode) && KEY_STATE(translated_keycode));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,4 +21,4 @@
|
|||
|
||||
bool process_key_lock(uint16_t *keycode, keyrecord_t *record);
|
||||
|
||||
#endif // PROCESS_KEY_LOCK_H
|
||||
#endif // PROCESS_KEY_LOCK_H
|
||||
|
|
|
|||
|
|
@ -16,64 +16,64 @@
|
|||
|
||||
#ifdef LEADER_ENABLE
|
||||
|
||||
#include "process_leader.h"
|
||||
#include <string.h>
|
||||
# include "process_leader.h"
|
||||
# include <string.h>
|
||||
|
||||
#ifndef LEADER_TIMEOUT
|
||||
#define LEADER_TIMEOUT 300
|
||||
#endif
|
||||
# ifndef LEADER_TIMEOUT
|
||||
# define LEADER_TIMEOUT 300
|
||||
# endif
|
||||
|
||||
__attribute__ ((weak))
|
||||
void leader_start(void) {}
|
||||
__attribute__((weak)) void leader_start(void) {}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void leader_end(void) {}
|
||||
__attribute__((weak)) void leader_end(void) {}
|
||||
|
||||
// Leader key stuff
|
||||
bool leading = false;
|
||||
bool leading = false;
|
||||
uint16_t leader_time = 0;
|
||||
|
||||
uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
|
||||
uint8_t leader_sequence_size = 0;
|
||||
uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
|
||||
uint8_t leader_sequence_size = 0;
|
||||
|
||||
void qk_leader_start(void) {
|
||||
if (leading) { return; }
|
||||
leader_start();
|
||||
leading = true;
|
||||
leader_time = timer_read();
|
||||
leader_sequence_size = 0;
|
||||
memset(leader_sequence, 0, sizeof(leader_sequence));
|
||||
if (leading) {
|
||||
return;
|
||||
}
|
||||
leader_start();
|
||||
leading = true;
|
||||
leader_time = timer_read();
|
||||
leader_sequence_size = 0;
|
||||
memset(leader_sequence, 0, sizeof(leader_sequence));
|
||||
}
|
||||
|
||||
bool process_leader(uint16_t keycode, keyrecord_t *record) {
|
||||
// Leader key set-up
|
||||
if (record->event.pressed) {
|
||||
if (leading) {
|
||||
if (timer_elapsed(leader_time) < LEADER_TIMEOUT) {
|
||||
#ifndef LEADER_KEY_STRICT_KEY_PROCESSING
|
||||
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
|
||||
keycode = keycode & 0xFF;
|
||||
}
|
||||
#endif // LEADER_KEY_STRICT_KEY_PROCESSING
|
||||
if ( leader_sequence_size < ( sizeof(leader_sequence) / sizeof(leader_sequence[0]) ) ) {
|
||||
leader_sequence[leader_sequence_size] = keycode;
|
||||
leader_sequence_size++;
|
||||
// Leader key set-up
|
||||
if (record->event.pressed) {
|
||||
if (leading) {
|
||||
if (timer_elapsed(leader_time) < LEADER_TIMEOUT) {
|
||||
# ifndef LEADER_KEY_STRICT_KEY_PROCESSING
|
||||
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
|
||||
keycode = keycode & 0xFF;
|
||||
}
|
||||
# endif // LEADER_KEY_STRICT_KEY_PROCESSING
|
||||
if (leader_sequence_size < (sizeof(leader_sequence) / sizeof(leader_sequence[0]))) {
|
||||
leader_sequence[leader_sequence_size] = keycode;
|
||||
leader_sequence_size++;
|
||||
} else {
|
||||
leading = false;
|
||||
leader_end();
|
||||
}
|
||||
# ifdef LEADER_PER_KEY_TIMING
|
||||
leader_time = timer_read();
|
||||
# endif
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
leading = false;
|
||||
leader_end();
|
||||
if (keycode == KC_LEAD) {
|
||||
qk_leader_start();
|
||||
}
|
||||
}
|
||||
#ifdef LEADER_PER_KEY_TIMING
|
||||
leader_time = timer_read();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (keycode == KC_LEAD) {
|
||||
qk_leader_start();
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include "quantum.h"
|
||||
|
||||
|
||||
bool process_leader(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
void leader_start(void);
|
||||
|
|
@ -32,7 +31,11 @@ void qk_leader_start(void);
|
|||
#define SEQ_FOUR_KEYS(key1, key2, key3, key4) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == 0)
|
||||
#define SEQ_FIVE_KEYS(key1, key2, key3, key4, key5) if (leader_sequence[0] == (key1) && leader_sequence[1] == (key2) && leader_sequence[2] == (key3) && leader_sequence[3] == (key4) && leader_sequence[4] == (key5))
|
||||
|
||||
#define LEADER_EXTERNS() extern bool leading; extern uint16_t leader_time; extern uint16_t leader_sequence[5]; extern uint8_t leader_sequence_size
|
||||
#define LEADER_EXTERNS() \
|
||||
extern bool leading; \
|
||||
extern uint16_t leader_time; \
|
||||
extern uint16_t leader_sequence[5]; \
|
||||
extern uint8_t leader_sequence_size
|
||||
#define LEADER_DICTIONARY() if (leading && timer_elapsed(leader_time) > LEADER_TIMEOUT)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,86 +16,65 @@
|
|||
#include "process_midi.h"
|
||||
|
||||
#ifdef MIDI_ENABLE
|
||||
#include <LUFA/Drivers/USB/USB.h>
|
||||
#include "midi.h"
|
||||
#include "qmk_midi.h"
|
||||
# include <LUFA/Drivers/USB/USB.h>
|
||||
# include "midi.h"
|
||||
# include "qmk_midi.h"
|
||||
|
||||
#ifdef MIDI_BASIC
|
||||
# ifdef MIDI_BASIC
|
||||
|
||||
void process_midi_basic_noteon(uint8_t note)
|
||||
{
|
||||
midi_send_noteon(&midi_device, 0, note, 127);
|
||||
}
|
||||
void process_midi_basic_noteon(uint8_t note) { midi_send_noteon(&midi_device, 0, note, 127); }
|
||||
|
||||
void process_midi_basic_noteoff(uint8_t note)
|
||||
{
|
||||
midi_send_noteoff(&midi_device, 0, note, 0);
|
||||
}
|
||||
void process_midi_basic_noteoff(uint8_t note) { midi_send_noteoff(&midi_device, 0, note, 0); }
|
||||
|
||||
void process_midi_all_notes_off(void)
|
||||
{
|
||||
midi_send_cc(&midi_device, 0, 0x7B, 0);
|
||||
}
|
||||
void process_midi_all_notes_off(void) { midi_send_cc(&midi_device, 0, 0x7B, 0); }
|
||||
|
||||
#endif // MIDI_BASIC
|
||||
# endif // MIDI_BASIC
|
||||
|
||||
#ifdef MIDI_ADVANCED
|
||||
# ifdef MIDI_ADVANCED
|
||||
|
||||
#include "timer.h"
|
||||
# include "timer.h"
|
||||
|
||||
static uint8_t tone_status[MIDI_TONE_COUNT];
|
||||
|
||||
static uint8_t midi_modulation;
|
||||
static int8_t midi_modulation_step;
|
||||
static uint8_t midi_modulation;
|
||||
static int8_t midi_modulation_step;
|
||||
static uint16_t midi_modulation_timer;
|
||||
midi_config_t midi_config;
|
||||
midi_config_t midi_config;
|
||||
|
||||
inline uint8_t compute_velocity(uint8_t setting)
|
||||
{
|
||||
return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1));
|
||||
}
|
||||
inline uint8_t compute_velocity(uint8_t setting) { return (setting + 1) * (128 / (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN + 1)); }
|
||||
|
||||
void midi_init(void)
|
||||
{
|
||||
midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN;
|
||||
midi_config.transpose = 0;
|
||||
midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN);
|
||||
midi_config.channel = 0;
|
||||
void midi_init(void) {
|
||||
midi_config.octave = MI_OCT_2 - MIDI_OCTAVE_MIN;
|
||||
midi_config.transpose = 0;
|
||||
midi_config.velocity = (MIDI_VELOCITY_MAX - MIDI_VELOCITY_MIN);
|
||||
midi_config.channel = 0;
|
||||
midi_config.modulation_interval = 8;
|
||||
|
||||
for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++)
|
||||
{
|
||||
for (uint8_t i = 0; i < MIDI_TONE_COUNT; i++) {
|
||||
tone_status[i] = MIDI_INVALID_NOTE;
|
||||
}
|
||||
|
||||
midi_modulation = 0;
|
||||
midi_modulation_step = 0;
|
||||
midi_modulation = 0;
|
||||
midi_modulation_step = 0;
|
||||
midi_modulation_timer = 0;
|
||||
}
|
||||
|
||||
uint8_t midi_compute_note(uint16_t keycode)
|
||||
{
|
||||
return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose;
|
||||
}
|
||||
uint8_t midi_compute_note(uint16_t keycode) { return 12 * midi_config.octave + (keycode - MIDI_TONE_MIN) + midi_config.transpose; }
|
||||
|
||||
bool process_midi(uint16_t keycode, keyrecord_t *record)
|
||||
{
|
||||
bool process_midi(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
case MIDI_TONE_MIN ... MIDI_TONE_MAX:
|
||||
{
|
||||
uint8_t channel = midi_config.channel;
|
||||
uint8_t tone = keycode - MIDI_TONE_MIN;
|
||||
case MIDI_TONE_MIN ... MIDI_TONE_MAX: {
|
||||
uint8_t channel = midi_config.channel;
|
||||
uint8_t tone = keycode - MIDI_TONE_MIN;
|
||||
uint8_t velocity = compute_velocity(midi_config.velocity);
|
||||
if (record->event.pressed) {
|
||||
uint8_t note = midi_compute_note(keycode);
|
||||
midi_send_noteon(&midi_device, channel, note, velocity);
|
||||
dprintf("midi noteon channel:%d note:%d velocity:%d\n", channel, note, velocity);
|
||||
tone_status[tone] = note;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
uint8_t note = tone_status[tone];
|
||||
if (note != MIDI_INVALID_NOTE)
|
||||
{
|
||||
if (note != MIDI_INVALID_NOTE) {
|
||||
midi_send_noteoff(&midi_device, channel, note, velocity);
|
||||
dprintf("midi noteoff channel:%d note:%d velocity:%d\n", channel, note, velocity);
|
||||
}
|
||||
|
|
@ -137,8 +116,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
|
|||
if (record->event.pressed && midi_config.transpose < (MIDI_TRANSPOSE_MAX - MI_TRNS_0)) {
|
||||
const bool positive = midi_config.transpose > 0;
|
||||
midi_config.transpose++;
|
||||
if (positive && midi_config.transpose < 0)
|
||||
midi_config.transpose--;
|
||||
if (positive && midi_config.transpose < 0) midi_config.transpose--;
|
||||
dprintf("midi transpose %d\n", midi_config.transpose);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -211,8 +189,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
|
|||
if (record->event.pressed) {
|
||||
midi_config.modulation_interval++;
|
||||
// prevent overflow
|
||||
if (midi_config.modulation_interval == 0)
|
||||
midi_config.modulation_interval--;
|
||||
if (midi_config.modulation_interval == 0) midi_config.modulation_interval--;
|
||||
dprintf("midi modulation interval %d\n", midi_config.modulation_interval);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -226,8 +203,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
|
|||
if (record->event.pressed) {
|
||||
midi_send_pitchbend(&midi_device, midi_config.channel, -0x2000);
|
||||
dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, -0x2000);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
midi_send_pitchbend(&midi_device, midi_config.channel, 0);
|
||||
dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0);
|
||||
}
|
||||
|
|
@ -236,8 +212,7 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
|
|||
if (record->event.pressed) {
|
||||
midi_send_pitchbend(&midi_device, midi_config.channel, 0x1fff);
|
||||
dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0x1fff);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
midi_send_pitchbend(&midi_device, midi_config.channel, 0);
|
||||
dprintf("midi pitchbend channel:%d amount:%d\n", midi_config.channel, 0);
|
||||
}
|
||||
|
|
@ -247,35 +222,29 @@ bool process_midi(uint16_t keycode, keyrecord_t *record)
|
|||
return true;
|
||||
}
|
||||
|
||||
#endif // MIDI_ADVANCED
|
||||
# endif // MIDI_ADVANCED
|
||||
|
||||
void midi_task(void)
|
||||
{
|
||||
void midi_task(void) {
|
||||
midi_device_process(&midi_device);
|
||||
#ifdef MIDI_ADVANCED
|
||||
if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval)
|
||||
return;
|
||||
# ifdef MIDI_ADVANCED
|
||||
if (timer_elapsed(midi_modulation_timer) < midi_config.modulation_interval) return;
|
||||
midi_modulation_timer = timer_read();
|
||||
|
||||
if (midi_modulation_step != 0)
|
||||
{
|
||||
if (midi_modulation_step != 0) {
|
||||
dprintf("midi modulation %d\n", midi_modulation);
|
||||
midi_send_cc(&midi_device, midi_config.channel, 0x1, midi_modulation);
|
||||
|
||||
if (midi_modulation_step < 0 && midi_modulation < -midi_modulation_step) {
|
||||
midi_modulation = 0;
|
||||
midi_modulation = 0;
|
||||
midi_modulation_step = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
midi_modulation += midi_modulation_step;
|
||||
|
||||
if (midi_modulation > 127)
|
||||
midi_modulation = 127;
|
||||
if (midi_modulation > 127) midi_modulation = 127;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // MIDI_ENABLE
|
||||
#endif // MIDI_ENABLE
|
||||
|
|
|
|||
|
|
@ -21,24 +21,24 @@
|
|||
|
||||
#ifdef MIDI_ENABLE
|
||||
|
||||
#ifdef MIDI_BASIC
|
||||
# ifdef MIDI_BASIC
|
||||
void process_midi_basic_noteon(uint8_t note);
|
||||
void process_midi_basic_noteoff(uint8_t note);
|
||||
void process_midi_all_notes_off(void);
|
||||
#endif
|
||||
# endif
|
||||
|
||||
void midi_task(void);
|
||||
|
||||
#ifdef MIDI_ADVANCED
|
||||
# ifdef MIDI_ADVANCED
|
||||
typedef union {
|
||||
uint32_t raw;
|
||||
struct {
|
||||
uint8_t octave :4;
|
||||
int8_t transpose :4;
|
||||
uint8_t velocity :4;
|
||||
uint8_t channel :4;
|
||||
uint8_t modulation_interval :4;
|
||||
};
|
||||
uint32_t raw;
|
||||
struct {
|
||||
uint8_t octave : 4;
|
||||
int8_t transpose : 4;
|
||||
uint8_t velocity : 4;
|
||||
uint8_t channel : 4;
|
||||
uint8_t modulation_interval : 4;
|
||||
};
|
||||
} midi_config_t;
|
||||
|
||||
extern midi_config_t midi_config;
|
||||
|
|
@ -46,12 +46,12 @@ extern midi_config_t midi_config;
|
|||
void midi_init(void);
|
||||
bool process_midi(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
#define MIDI_INVALID_NOTE 0xFF
|
||||
#define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
|
||||
# define MIDI_INVALID_NOTE 0xFF
|
||||
# define MIDI_TONE_COUNT (MIDI_TONE_MAX - MIDI_TONE_MIN + 1)
|
||||
|
||||
uint8_t midi_compute_note(uint16_t keycode);
|
||||
#endif // MIDI_ADVANCED
|
||||
# endif // MIDI_ADVANCED
|
||||
|
||||
#endif // MIDI_ENABLE
|
||||
#endif // MIDI_ENABLE
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -16,103 +16,91 @@
|
|||
#include "process_music.h"
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
#include "process_audio.h"
|
||||
# include "process_audio.h"
|
||||
#endif
|
||||
#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
#include "process_midi.h"
|
||||
# include "process_midi.h"
|
||||
#endif
|
||||
|
||||
#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
|
||||
|
||||
bool music_activated = false;
|
||||
bool midi_activated = false;
|
||||
bool music_activated = false;
|
||||
bool midi_activated = false;
|
||||
uint8_t music_starting_note = 0x0C;
|
||||
int music_offset = 7;
|
||||
uint8_t music_mode = MUSIC_MODE_MAJOR;
|
||||
int music_offset = 7;
|
||||
uint8_t music_mode = MUSIC_MODE_MAJOR;
|
||||
|
||||
// music sequencer
|
||||
static bool music_sequence_recording = false;
|
||||
static bool music_sequence_recorded = false;
|
||||
static bool music_sequence_playing = false;
|
||||
static uint8_t music_sequence[16] = {0};
|
||||
static uint8_t music_sequence_count = 0;
|
||||
static uint8_t music_sequence_position = 0;
|
||||
static bool music_sequence_recording = false;
|
||||
static bool music_sequence_recorded = false;
|
||||
static bool music_sequence_playing = false;
|
||||
static uint8_t music_sequence[16] = {0};
|
||||
static uint8_t music_sequence_count = 0;
|
||||
static uint8_t music_sequence_position = 0;
|
||||
|
||||
static uint16_t music_sequence_timer = 0;
|
||||
static uint16_t music_sequence_timer = 0;
|
||||
static uint16_t music_sequence_interval = 100;
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
#ifndef MUSIC_ON_SONG
|
||||
#define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND)
|
||||
#endif
|
||||
#ifndef MUSIC_OFF_SONG
|
||||
#define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
|
||||
#endif
|
||||
#ifndef MIDI_ON_SONG
|
||||
#define MIDI_ON_SONG SONG(MUSIC_ON_SOUND)
|
||||
#endif
|
||||
#ifndef MIDI_OFF_SONG
|
||||
#define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND)
|
||||
#endif
|
||||
#ifndef CHROMATIC_SONG
|
||||
#define CHROMATIC_SONG SONG(CHROMATIC_SOUND)
|
||||
#endif
|
||||
#ifndef GUITAR_SONG
|
||||
#define GUITAR_SONG SONG(GUITAR_SOUND)
|
||||
#endif
|
||||
#ifndef VIOLIN_SONG
|
||||
#define VIOLIN_SONG SONG(VIOLIN_SOUND)
|
||||
#endif
|
||||
#ifndef MAJOR_SONG
|
||||
#define MAJOR_SONG SONG(MAJOR_SOUND)
|
||||
#endif
|
||||
float music_mode_songs[NUMBER_OF_MODES][5][2] = {
|
||||
CHROMATIC_SONG,
|
||||
GUITAR_SONG,
|
||||
VIOLIN_SONG,
|
||||
MAJOR_SONG
|
||||
};
|
||||
float music_on_song[][2] = MUSIC_ON_SONG;
|
||||
float music_off_song[][2] = MUSIC_OFF_SONG;
|
||||
float midi_on_song[][2] = MIDI_ON_SONG;
|
||||
float midi_off_song[][2] = MIDI_OFF_SONG;
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
# ifndef MUSIC_ON_SONG
|
||||
# define MUSIC_ON_SONG SONG(MUSIC_ON_SOUND)
|
||||
# endif
|
||||
# ifndef MUSIC_OFF_SONG
|
||||
# define MUSIC_OFF_SONG SONG(MUSIC_OFF_SOUND)
|
||||
# endif
|
||||
# ifndef MIDI_ON_SONG
|
||||
# define MIDI_ON_SONG SONG(MUSIC_ON_SOUND)
|
||||
# endif
|
||||
# ifndef MIDI_OFF_SONG
|
||||
# define MIDI_OFF_SONG SONG(MUSIC_OFF_SOUND)
|
||||
# endif
|
||||
# ifndef CHROMATIC_SONG
|
||||
# define CHROMATIC_SONG SONG(CHROMATIC_SOUND)
|
||||
# endif
|
||||
# ifndef GUITAR_SONG
|
||||
# define GUITAR_SONG SONG(GUITAR_SOUND)
|
||||
# endif
|
||||
# ifndef VIOLIN_SONG
|
||||
# define VIOLIN_SONG SONG(VIOLIN_SOUND)
|
||||
# endif
|
||||
# ifndef MAJOR_SONG
|
||||
# define MAJOR_SONG SONG(MAJOR_SOUND)
|
||||
# endif
|
||||
float music_mode_songs[NUMBER_OF_MODES][5][2] = {CHROMATIC_SONG, GUITAR_SONG, VIOLIN_SONG, MAJOR_SONG};
|
||||
float music_on_song[][2] = MUSIC_ON_SONG;
|
||||
float music_off_song[][2] = MUSIC_OFF_SONG;
|
||||
float midi_on_song[][2] = MIDI_ON_SONG;
|
||||
float midi_off_song[][2] = MIDI_OFF_SONG;
|
||||
# endif
|
||||
|
||||
static void music_noteon(uint8_t note) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
if (music_activated)
|
||||
process_audio_noteon(note);
|
||||
#endif
|
||||
#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
if (midi_activated)
|
||||
process_midi_basic_noteon(note);
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
if (music_activated) process_audio_noteon(note);
|
||||
# endif
|
||||
# if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
if (midi_activated) process_midi_basic_noteon(note);
|
||||
# endif
|
||||
}
|
||||
|
||||
static void music_noteoff(uint8_t note) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
if (music_activated)
|
||||
process_audio_noteoff(note);
|
||||
#endif
|
||||
#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
if (midi_activated)
|
||||
process_midi_basic_noteoff(note);
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
if (music_activated) process_audio_noteoff(note);
|
||||
# endif
|
||||
# if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
if (midi_activated) process_midi_basic_noteoff(note);
|
||||
# endif
|
||||
}
|
||||
|
||||
void music_all_notes_off(void) {
|
||||
#ifdef AUDIO_ENABLE
|
||||
if (music_activated)
|
||||
process_audio_all_notes_off();
|
||||
#endif
|
||||
#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
if (midi_activated)
|
||||
process_midi_all_notes_off();
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
if (music_activated) process_audio_all_notes_off();
|
||||
# endif
|
||||
# if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
if (midi_activated) process_midi_all_notes_off();
|
||||
# endif
|
||||
}
|
||||
|
||||
bool process_music(uint16_t keycode, keyrecord_t *record) {
|
||||
|
||||
if (keycode == MU_ON && record->event.pressed) {
|
||||
music_on();
|
||||
return false;
|
||||
|
|
@ -152,110 +140,101 @@ bool process_music(uint16_t keycode, keyrecord_t *record) {
|
|||
}
|
||||
|
||||
if (keycode == MU_MOD && record->event.pressed) {
|
||||
music_mode_cycle();
|
||||
return false;
|
||||
music_mode_cycle();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (music_activated || midi_activated) {
|
||||
if (record->event.pressed) {
|
||||
if (keycode == KC_LCTL) { // Start recording
|
||||
music_all_notes_off();
|
||||
music_sequence_recording = true;
|
||||
music_sequence_recorded = false;
|
||||
music_sequence_playing = false;
|
||||
music_sequence_count = 0;
|
||||
return false;
|
||||
if (record->event.pressed) {
|
||||
if (keycode == KC_LCTL) { // Start recording
|
||||
music_all_notes_off();
|
||||
music_sequence_recording = true;
|
||||
music_sequence_recorded = false;
|
||||
music_sequence_playing = false;
|
||||
music_sequence_count = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == KC_LALT) { // Stop recording/playing
|
||||
music_all_notes_off();
|
||||
if (music_sequence_recording) { // was recording
|
||||
music_sequence_recorded = true;
|
||||
}
|
||||
music_sequence_recording = false;
|
||||
music_sequence_playing = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing
|
||||
music_all_notes_off();
|
||||
music_sequence_recording = false;
|
||||
music_sequence_playing = true;
|
||||
music_sequence_position = 0;
|
||||
music_sequence_timer = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == KC_UP) {
|
||||
music_sequence_interval -= 10;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == KC_DOWN) {
|
||||
music_sequence_interval += 10;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (keycode == KC_LALT) { // Stop recording/playing
|
||||
music_all_notes_off();
|
||||
if (music_sequence_recording) { // was recording
|
||||
music_sequence_recorded = true;
|
||||
}
|
||||
music_sequence_recording = false;
|
||||
music_sequence_playing = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == KC_LGUI && music_sequence_recorded) { // Start playing
|
||||
music_all_notes_off();
|
||||
music_sequence_recording = false;
|
||||
music_sequence_playing = true;
|
||||
music_sequence_position = 0;
|
||||
music_sequence_timer = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == KC_UP) {
|
||||
music_sequence_interval-=10;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (keycode == KC_DOWN) {
|
||||
music_sequence_interval+=10;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t note = 36;
|
||||
#ifdef MUSIC_MAP
|
||||
uint8_t note = 36;
|
||||
# ifdef MUSIC_MAP
|
||||
if (music_mode == MUSIC_MODE_CHROMATIC) {
|
||||
note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col];
|
||||
note = music_starting_note + music_offset + 36 + music_map[record->event.key.row][record->event.key.col];
|
||||
} else {
|
||||
uint8_t position = music_map[record->event.key.row][record->event.key.col];
|
||||
note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12)*12;
|
||||
uint8_t position = music_map[record->event.key.row][record->event.key.col];
|
||||
note = music_starting_note + music_offset + 36 + SCALE[position % 12] + (position / 12) * 12;
|
||||
}
|
||||
#else
|
||||
# else
|
||||
if (music_mode == MUSIC_MODE_CHROMATIC)
|
||||
note = (music_starting_note + record->event.key.col + music_offset - 3)+12*(MATRIX_ROWS - record->event.key.row);
|
||||
note = (music_starting_note + record->event.key.col + music_offset - 3) + 12 * (MATRIX_ROWS - record->event.key.row);
|
||||
else if (music_mode == MUSIC_MODE_GUITAR)
|
||||
note = (music_starting_note + record->event.key.col + music_offset + 32)+5*(MATRIX_ROWS - record->event.key.row);
|
||||
note = (music_starting_note + record->event.key.col + music_offset + 32) + 5 * (MATRIX_ROWS - record->event.key.row);
|
||||
else if (music_mode == MUSIC_MODE_VIOLIN)
|
||||
note = (music_starting_note + record->event.key.col + music_offset + 32)+7*(MATRIX_ROWS - record->event.key.row);
|
||||
note = (music_starting_note + record->event.key.col + music_offset + 32) + 7 * (MATRIX_ROWS - record->event.key.row);
|
||||
else if (music_mode == MUSIC_MODE_MAJOR)
|
||||
note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3)+12*(MATRIX_ROWS - record->event.key.row);
|
||||
note = (music_starting_note + SCALE[record->event.key.col + music_offset] - 3) + 12 * (MATRIX_ROWS - record->event.key.row);
|
||||
else
|
||||
note = music_starting_note;
|
||||
#endif
|
||||
note = music_starting_note;
|
||||
# endif
|
||||
|
||||
if (record->event.pressed) {
|
||||
music_noteon(note);
|
||||
if (music_sequence_recording) {
|
||||
music_sequence[music_sequence_count] = note;
|
||||
music_sequence_count++;
|
||||
if (record->event.pressed) {
|
||||
music_noteon(note);
|
||||
if (music_sequence_recording) {
|
||||
music_sequence[music_sequence_count] = note;
|
||||
music_sequence_count++;
|
||||
}
|
||||
} else {
|
||||
music_noteoff(note);
|
||||
}
|
||||
} else {
|
||||
music_noteoff(note);
|
||||
}
|
||||
|
||||
if (music_mask(keycode))
|
||||
return false;
|
||||
if (music_mask(keycode)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool music_mask(uint16_t keycode) {
|
||||
#ifdef MUSIC_MASK
|
||||
# ifdef MUSIC_MASK
|
||||
return MUSIC_MASK;
|
||||
#else
|
||||
# else
|
||||
return music_mask_kb(keycode);
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
__attribute__((weak))
|
||||
bool music_mask_kb(uint16_t keycode) {
|
||||
return music_mask_user(keycode);
|
||||
}
|
||||
__attribute__((weak)) bool music_mask_kb(uint16_t keycode) { return music_mask_user(keycode); }
|
||||
|
||||
__attribute__((weak))
|
||||
bool music_mask_user(uint16_t keycode) {
|
||||
return keycode < 0xFF;
|
||||
}
|
||||
__attribute__((weak)) bool music_mask_user(uint16_t keycode) { return keycode < 0xFF; }
|
||||
|
||||
bool is_music_on(void) {
|
||||
return (music_activated != 0);
|
||||
}
|
||||
bool is_music_on(void) { return (music_activated != 0); }
|
||||
|
||||
void music_toggle(void) {
|
||||
if (!music_activated) {
|
||||
|
|
@ -267,23 +246,21 @@ void music_toggle(void) {
|
|||
|
||||
void music_on(void) {
|
||||
music_activated = 1;
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(music_on_song);
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(music_on_song);
|
||||
# endif
|
||||
music_on_user();
|
||||
}
|
||||
|
||||
void music_off(void) {
|
||||
music_all_notes_off();
|
||||
music_activated = 0;
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(music_off_song);
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(music_off_song);
|
||||
# endif
|
||||
}
|
||||
|
||||
bool is_midi_on(void) {
|
||||
return (midi_activated != 0);
|
||||
}
|
||||
bool is_midi_on(void) { return (midi_activated != 0); }
|
||||
|
||||
void midi_toggle(void) {
|
||||
if (!midi_activated) {
|
||||
|
|
@ -295,50 +272,47 @@ void midi_toggle(void) {
|
|||
|
||||
void midi_on(void) {
|
||||
midi_activated = 1;
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(midi_on_song);
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(midi_on_song);
|
||||
# endif
|
||||
midi_on_user();
|
||||
}
|
||||
|
||||
void midi_off(void) {
|
||||
#if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
process_midi_all_notes_off();
|
||||
#endif
|
||||
# if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
|
||||
process_midi_all_notes_off();
|
||||
# endif
|
||||
midi_activated = 0;
|
||||
#ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(midi_off_song);
|
||||
#endif
|
||||
# ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(midi_off_song);
|
||||
# endif
|
||||
}
|
||||
|
||||
void music_mode_cycle(void) {
|
||||
music_all_notes_off();
|
||||
music_mode = (music_mode + 1) % NUMBER_OF_MODES;
|
||||
#ifdef AUDIO_ENABLE
|
||||
music_all_notes_off();
|
||||
music_mode = (music_mode + 1) % NUMBER_OF_MODES;
|
||||
# ifdef AUDIO_ENABLE
|
||||
PLAY_SONG(music_mode_songs[music_mode]);
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
void matrix_scan_music(void) {
|
||||
if (music_sequence_playing) {
|
||||
if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
|
||||
music_sequence_timer = timer_read();
|
||||
uint8_t prev_note = music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)];
|
||||
uint8_t next_note = music_sequence[music_sequence_position];
|
||||
music_noteoff(prev_note);
|
||||
music_noteon(next_note);
|
||||
music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
|
||||
if (music_sequence_playing) {
|
||||
if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
|
||||
music_sequence_timer = timer_read();
|
||||
uint8_t prev_note = music_sequence[(music_sequence_position - 1 < 0) ? (music_sequence_position - 1 + music_sequence_count) : (music_sequence_position - 1)];
|
||||
uint8_t next_note = music_sequence[music_sequence_position];
|
||||
music_noteoff(prev_note);
|
||||
music_noteon(next_note);
|
||||
music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void music_on_user() {}
|
||||
__attribute__((weak)) void music_on_user() {}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void midi_on_user() {}
|
||||
__attribute__((weak)) void midi_on_user() {}
|
||||
|
||||
__attribute__ ((weak))
|
||||
void music_scale_user() {}
|
||||
__attribute__((weak)) void music_scale_user() {}
|
||||
|
||||
#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
|
||||
#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
|
||||
|
|
|
|||
|
|
@ -21,18 +21,11 @@
|
|||
|
||||
#if defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
|
||||
|
||||
enum music_modes {
|
||||
MUSIC_MODE_CHROMATIC,
|
||||
MUSIC_MODE_GUITAR,
|
||||
MUSIC_MODE_VIOLIN,
|
||||
MUSIC_MODE_MAJOR,
|
||||
NUMBER_OF_MODES
|
||||
};
|
||||
enum music_modes { MUSIC_MODE_CHROMATIC, MUSIC_MODE_GUITAR, MUSIC_MODE_VIOLIN, MUSIC_MODE_MAJOR, NUMBER_OF_MODES };
|
||||
|
||||
|
||||
#ifdef MUSIC_MAP
|
||||
extern const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS];
|
||||
#endif
|
||||
# ifdef MUSIC_MAP
|
||||
extern const uint8_t music_map[MATRIX_ROWS][MATRIX_COLS];
|
||||
# endif
|
||||
|
||||
bool process_music(uint16_t keycode, keyrecord_t *record);
|
||||
|
||||
|
|
@ -58,14 +51,11 @@ bool music_mask(uint16_t keycode);
|
|||
bool music_mask_kb(uint16_t keycode);
|
||||
bool music_mask_user(uint16_t keycode);
|
||||
|
||||
#ifndef SCALE
|
||||
#define SCALE (int8_t []){ 0 + (12*0), 2 + (12*0), 4 + (12*0), 5 + (12*0), 7 + (12*0), 9 + (12*0), 11 + (12*0), \
|
||||
0 + (12*1), 2 + (12*1), 4 + (12*1), 5 + (12*1), 7 + (12*1), 9 + (12*1), 11 + (12*1), \
|
||||
0 + (12*2), 2 + (12*2), 4 + (12*2), 5 + (12*2), 7 + (12*2), 9 + (12*2), 11 + (12*2), \
|
||||
0 + (12*3), 2 + (12*3), 4 + (12*3), 5 + (12*3), 7 + (12*3), 9 + (12*3), 11 + (12*3), \
|
||||
0 + (12*4), 2 + (12*4), 4 + (12*4), 5 + (12*4), 7 + (12*4), 9 + (12*4), 11 + (12*4), }
|
||||
#endif
|
||||
# ifndef SCALE
|
||||
# define SCALE \
|
||||
(int8_t[]) { 0 + (12 * 0), 2 + (12 * 0), 4 + (12 * 0), 5 + (12 * 0), 7 + (12 * 0), 9 + (12 * 0), 11 + (12 * 0), 0 + (12 * 1), 2 + (12 * 1), 4 + (12 * 1), 5 + (12 * 1), 7 + (12 * 1), 9 + (12 * 1), 11 + (12 * 1), 0 + (12 * 2), 2 + (12 * 2), 4 + (12 * 2), 5 + (12 * 2), 7 + (12 * 2), 9 + (12 * 2), 11 + (12 * 2), 0 + (12 * 3), 2 + (12 * 3), 4 + (12 * 3), 5 + (12 * 3), 7 + (12 * 3), 9 + (12 * 3), 11 + (12 * 3), 0 + (12 * 4), 2 + (12 * 4), 4 + (12 * 4), 5 + (12 * 4), 7 + (12 * 4), 9 + (12 * 4), 11 + (12 * 4), }
|
||||
# endif
|
||||
|
||||
#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
|
||||
#endif // defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -17,17 +17,15 @@
|
|||
#include "process_printer.h"
|
||||
#include "action_util.h"
|
||||
|
||||
bool printing_enabled = false;
|
||||
uint8_t character_shift = 0;
|
||||
bool printing_enabled = false;
|
||||
uint8_t character_shift = 0;
|
||||
|
||||
void enable_printing(void) {
|
||||
printing_enabled = true;
|
||||
serial_init();
|
||||
printing_enabled = true;
|
||||
serial_init();
|
||||
}
|
||||
|
||||
void disable_printing(void) {
|
||||
printing_enabled = false;
|
||||
}
|
||||
void disable_printing(void) { printing_enabled = false; }
|
||||
|
||||
uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
|
||||
|
||||
|
|
@ -36,235 +34,232 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0
|
|||
// keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
|
||||
|
||||
void print_char(char c) {
|
||||
USB_Disable();
|
||||
serial_send(c);
|
||||
USB_Init();
|
||||
USB_Disable();
|
||||
serial_send(c);
|
||||
USB_Init();
|
||||
}
|
||||
|
||||
void print_string(char c[]) {
|
||||
for(uint8_t i = 0; i < strlen(c); i++)
|
||||
print_char(c[i]);
|
||||
for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]);
|
||||
}
|
||||
|
||||
void print_box_string(const char text[]) {
|
||||
size_t len = strlen(text);
|
||||
char out[len * 3 + 8];
|
||||
out[0] = 0xDA;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
out[i+1] = 0xC4;
|
||||
}
|
||||
out[len + 1] = 0xBF;
|
||||
out[len + 2] = '\n';
|
||||
size_t len = strlen(text);
|
||||
char out[len * 3 + 8];
|
||||
out[0] = 0xDA;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
out[i + 1] = 0xC4;
|
||||
}
|
||||
out[len + 1] = 0xBF;
|
||||
out[len + 2] = '\n';
|
||||
|
||||
out[len + 3] = 0xB3;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
out[len + 4 + i] = text[i];
|
||||
}
|
||||
out[len * 2 + 4] = 0xB3;
|
||||
out[len * 2 + 5] = '\n';
|
||||
out[len + 3] = 0xB3;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
out[len + 4 + i] = text[i];
|
||||
}
|
||||
out[len * 2 + 4] = 0xB3;
|
||||
out[len * 2 + 5] = '\n';
|
||||
|
||||
out[len * 2 + 6] = 0xC0;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
out[len * 2 + 7 + i] = 0xC4;
|
||||
}
|
||||
out[len * 3 + 7] = 0xD9;
|
||||
out[len * 3 + 8] = '\n';
|
||||
|
||||
out[len * 2 + 6] = 0xC0;
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
out[len * 2 + 7 + i] = 0xC4;
|
||||
}
|
||||
out[len * 3 + 7] = 0xD9;
|
||||
out[len * 3 + 8] = '\n';
|
||||
|
||||
print_string(out);
|
||||
print_string(out);
|
||||
}
|
||||
|
||||
bool process_printer(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode == PRINT_ON) {
|
||||
enable_printing();
|
||||
return false;
|
||||
}
|
||||
if (keycode == PRINT_OFF) {
|
||||
disable_printing();
|
||||
return false;
|
||||
}
|
||||
if (keycode == PRINT_ON) {
|
||||
enable_printing();
|
||||
return false;
|
||||
}
|
||||
if (keycode == PRINT_OFF) {
|
||||
disable_printing();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (printing_enabled) {
|
||||
switch(keycode) {
|
||||
case KC_EXLM ... KC_RPRN:
|
||||
case KC_UNDS:
|
||||
case KC_PLUS:
|
||||
case KC_LCBR:
|
||||
case KC_RCBR:
|
||||
case KC_PIPE:
|
||||
case KC_TILD:
|
||||
keycode &= 0xFF;
|
||||
case KC_LSFT:
|
||||
case KC_RSFT:
|
||||
if (record->event.pressed) {
|
||||
character_shift++;
|
||||
} else {
|
||||
character_shift--;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(keycode) {
|
||||
case KC_F1:
|
||||
if (record->event.pressed) {
|
||||
print_box_string("This is a line of text!");
|
||||
}
|
||||
return false;
|
||||
case KC_ESC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x1B);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SPC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x20);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_A ... KC_Z:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x41 + (keycode - KC_A));
|
||||
} else {
|
||||
print_char(0x61 + (keycode - KC_A));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_1 ... KC_0:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(shifted_numbers[keycode - KC_1]);
|
||||
} else {
|
||||
print_char(0x30 + ((keycode - KC_1 + 1) % 10));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_ENT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x0C);
|
||||
} else {
|
||||
print_char(0x0A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSPC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x18);
|
||||
} else {
|
||||
print_char(0x1A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_DOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3E);
|
||||
} else {
|
||||
print_char(0x2E);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_COMM:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3C);
|
||||
} else {
|
||||
print_char(0x2C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SLSH:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3F);
|
||||
} else {
|
||||
print_char(0x2F);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_QUOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x22);
|
||||
} else {
|
||||
print_char(0x27);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_GRV:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7E);
|
||||
} else {
|
||||
print_char(0x60);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_MINS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x5F);
|
||||
} else {
|
||||
print_char(0x2D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_EQL:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x2B);
|
||||
} else {
|
||||
print_char(0x3D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_LBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7B);
|
||||
} else {
|
||||
print_char(0x5B);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_RBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7D);
|
||||
} else {
|
||||
print_char(0x5D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSLS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7C);
|
||||
} else {
|
||||
print_char(0x5C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (printing_enabled) {
|
||||
switch (keycode) {
|
||||
case KC_EXLM ... KC_RPRN:
|
||||
case KC_UNDS:
|
||||
case KC_PLUS:
|
||||
case KC_LCBR:
|
||||
case KC_RCBR:
|
||||
case KC_PIPE:
|
||||
case KC_TILD:
|
||||
keycode &= 0xFF;
|
||||
case KC_LSFT:
|
||||
case KC_RSFT:
|
||||
if (record->event.pressed) {
|
||||
character_shift++;
|
||||
} else {
|
||||
character_shift--;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (keycode) {
|
||||
case KC_F1:
|
||||
if (record->event.pressed) {
|
||||
print_box_string("This is a line of text!");
|
||||
}
|
||||
return false;
|
||||
case KC_ESC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x1B);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SPC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x20);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_A ... KC_Z:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x41 + (keycode - KC_A));
|
||||
} else {
|
||||
print_char(0x61 + (keycode - KC_A));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_1 ... KC_0:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(shifted_numbers[keycode - KC_1]);
|
||||
} else {
|
||||
print_char(0x30 + ((keycode - KC_1 + 1) % 10));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_ENT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x0C);
|
||||
} else {
|
||||
print_char(0x0A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSPC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x18);
|
||||
} else {
|
||||
print_char(0x1A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_DOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3E);
|
||||
} else {
|
||||
print_char(0x2E);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_COMM:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3C);
|
||||
} else {
|
||||
print_char(0x2C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SLSH:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3F);
|
||||
} else {
|
||||
print_char(0x2F);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_QUOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x22);
|
||||
} else {
|
||||
print_char(0x27);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_GRV:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7E);
|
||||
} else {
|
||||
print_char(0x60);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_MINS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x5F);
|
||||
} else {
|
||||
print_char(0x2D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_EQL:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x2B);
|
||||
} else {
|
||||
print_char(0x3D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_LBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7B);
|
||||
} else {
|
||||
print_char(0x5B);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_RBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7D);
|
||||
} else {
|
||||
print_char(0x5D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSLS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7C);
|
||||
} else {
|
||||
print_char(0x5C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,44 +17,29 @@
|
|||
#include "process_printer.h"
|
||||
#include "action_util.h"
|
||||
|
||||
bool printing_enabled = false;
|
||||
uint8_t character_shift = 0;
|
||||
bool printing_enabled = false;
|
||||
uint8_t character_shift = 0;
|
||||
|
||||
#define SERIAL_PIN_DDR DDRD
|
||||
#define SERIAL_PIN_PORT PORTD
|
||||
#define SERIAL_PIN_MASK _BV(PD3)
|
||||
#define SERIAL_DELAY 52
|
||||
|
||||
inline static
|
||||
void serial_delay(void) {
|
||||
_delay_us(SERIAL_DELAY);
|
||||
}
|
||||
inline static void serial_delay(void) { _delay_us(SERIAL_DELAY); }
|
||||
|
||||
inline static
|
||||
void serial_high(void) {
|
||||
SERIAL_PIN_PORT |= SERIAL_PIN_MASK;
|
||||
}
|
||||
inline static void serial_high(void) { SERIAL_PIN_PORT |= SERIAL_PIN_MASK; }
|
||||
|
||||
inline static
|
||||
void serial_low(void) {
|
||||
SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK;
|
||||
}
|
||||
|
||||
inline static
|
||||
void serial_output(void) {
|
||||
SERIAL_PIN_DDR |= SERIAL_PIN_MASK;
|
||||
}
|
||||
inline static void serial_low(void) { SERIAL_PIN_PORT &= ~SERIAL_PIN_MASK; }
|
||||
|
||||
inline static void serial_output(void) { SERIAL_PIN_DDR |= SERIAL_PIN_MASK; }
|
||||
|
||||
void enable_printing() {
|
||||
printing_enabled = true;
|
||||
serial_output();
|
||||
serial_high();
|
||||
printing_enabled = true;
|
||||
serial_output();
|
||||
serial_high();
|
||||
}
|
||||
|
||||
void disable_printing() {
|
||||
printing_enabled = false;
|
||||
}
|
||||
void disable_printing() { printing_enabled = false; }
|
||||
|
||||
uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29};
|
||||
|
||||
|
|
@ -63,214 +48,212 @@ uint8_t shifted_numbers[10] = {0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0
|
|||
// keycode_to_ascii[KC_MINS] = {0x2D, 0x5F};
|
||||
|
||||
void print_char(char c) {
|
||||
uint8_t b = 8;
|
||||
serial_output();
|
||||
while( b-- ) {
|
||||
if(c & (1 << b)) {
|
||||
serial_high();
|
||||
} else {
|
||||
serial_low();
|
||||
uint8_t b = 8;
|
||||
serial_output();
|
||||
while (b--) {
|
||||
if (c & (1 << b)) {
|
||||
serial_high();
|
||||
} else {
|
||||
serial_low();
|
||||
}
|
||||
serial_delay();
|
||||
}
|
||||
serial_delay();
|
||||
}
|
||||
}
|
||||
|
||||
void print_string(char c[]) {
|
||||
for(uint8_t i = 0; i < strlen(c); i++)
|
||||
print_char(c[i]);
|
||||
for (uint8_t i = 0; i < strlen(c); i++) print_char(c[i]);
|
||||
}
|
||||
|
||||
bool process_printer(uint16_t keycode, keyrecord_t *record) {
|
||||
if (keycode == PRINT_ON) {
|
||||
enable_printing();
|
||||
return false;
|
||||
}
|
||||
if (keycode == PRINT_OFF) {
|
||||
disable_printing();
|
||||
return false;
|
||||
}
|
||||
if (keycode == PRINT_ON) {
|
||||
enable_printing();
|
||||
return false;
|
||||
}
|
||||
if (keycode == PRINT_OFF) {
|
||||
disable_printing();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (printing_enabled) {
|
||||
switch(keycode) {
|
||||
case KC_EXLM ... KC_RPRN:
|
||||
case KC_UNDS:
|
||||
case KC_PLUS:
|
||||
case KC_LCBR:
|
||||
case KC_RCBR:
|
||||
case KC_PIPE:
|
||||
case KC_TILD:
|
||||
keycode &= 0xFF;
|
||||
case KC_LSFT:
|
||||
case KC_RSFT:
|
||||
if (record->event.pressed) {
|
||||
character_shift++;
|
||||
} else {
|
||||
character_shift--;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch(keycode) {
|
||||
case KC_F1:
|
||||
if (record->event.pressed) {
|
||||
print_string("This is a line of text!\n\n\n");
|
||||
}
|
||||
return false;
|
||||
case KC_ESC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x1B);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SPC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x20);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_A ... KC_Z:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x41 + (keycode - KC_A));
|
||||
} else {
|
||||
print_char(0x61 + (keycode - KC_A));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_1 ... KC_0:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(shifted_numbers[keycode - KC_1]);
|
||||
} else {
|
||||
print_char(0x30 + ((keycode - KC_1 + 1) % 10));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_ENT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x0C);
|
||||
} else {
|
||||
print_char(0x0A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSPC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x18);
|
||||
} else {
|
||||
print_char(0x1A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_DOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3E);
|
||||
} else {
|
||||
print_char(0x2E);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_COMM:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3C);
|
||||
} else {
|
||||
print_char(0x2C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SLSH:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3F);
|
||||
} else {
|
||||
print_char(0x2F);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_QUOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x22);
|
||||
} else {
|
||||
print_char(0x27);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_GRV:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7E);
|
||||
} else {
|
||||
print_char(0x60);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_MINS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x5F);
|
||||
} else {
|
||||
print_char(0x2D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_EQL:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x2B);
|
||||
} else {
|
||||
print_char(0x3D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_LBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7B);
|
||||
} else {
|
||||
print_char(0x5B);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_RBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7D);
|
||||
} else {
|
||||
print_char(0x5D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSLS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7C);
|
||||
} else {
|
||||
print_char(0x5C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (printing_enabled) {
|
||||
switch (keycode) {
|
||||
case KC_EXLM ... KC_RPRN:
|
||||
case KC_UNDS:
|
||||
case KC_PLUS:
|
||||
case KC_LCBR:
|
||||
case KC_RCBR:
|
||||
case KC_PIPE:
|
||||
case KC_TILD:
|
||||
keycode &= 0xFF;
|
||||
case KC_LSFT:
|
||||
case KC_RSFT:
|
||||
if (record->event.pressed) {
|
||||
character_shift++;
|
||||
} else {
|
||||
character_shift--;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (keycode) {
|
||||
case KC_F1:
|
||||
if (record->event.pressed) {
|
||||
print_string("This is a line of text!\n\n\n");
|
||||
}
|
||||
return false;
|
||||
case KC_ESC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x1B);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SPC:
|
||||
if (record->event.pressed) {
|
||||
print_char(0x20);
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_A ... KC_Z:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x41 + (keycode - KC_A));
|
||||
} else {
|
||||
print_char(0x61 + (keycode - KC_A));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_1 ... KC_0:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(shifted_numbers[keycode - KC_1]);
|
||||
} else {
|
||||
print_char(0x30 + ((keycode - KC_1 + 1) % 10));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_ENT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x0C);
|
||||
} else {
|
||||
print_char(0x0A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSPC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x18);
|
||||
} else {
|
||||
print_char(0x1A);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_DOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3E);
|
||||
} else {
|
||||
print_char(0x2E);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_COMM:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3C);
|
||||
} else {
|
||||
print_char(0x2C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_SLSH:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x3F);
|
||||
} else {
|
||||
print_char(0x2F);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_QUOT:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x22);
|
||||
} else {
|
||||
print_char(0x27);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_GRV:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7E);
|
||||
} else {
|
||||
print_char(0x60);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_MINS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x5F);
|
||||
} else {
|
||||
print_char(0x2D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_EQL:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x2B);
|
||||
} else {
|
||||
print_char(0x3D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_LBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7B);
|
||||
} else {
|
||||
print_char(0x5B);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_RBRC:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7D);
|
||||
} else {
|
||||
print_char(0x5D);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
case KC_BSLS:
|
||||
if (record->event.pressed) {
|
||||
if (character_shift) {
|
||||
print_char(0x7C);
|
||||
} else {
|
||||
print_char(0x5C);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,150 +16,149 @@
|
|||
#include "process_space_cadet.h"
|
||||
|
||||
#ifndef TAPPING_TERM
|
||||
#define TAPPING_TERM 200
|
||||
# define TAPPING_TERM 200
|
||||
#endif
|
||||
|
||||
// ********** OBSOLETE DEFINES, STOP USING! (pls?) **********
|
||||
// Shift / paren setup
|
||||
#ifndef LSPO_KEY
|
||||
#define LSPO_KEY KC_9
|
||||
# define LSPO_KEY KC_9
|
||||
#endif
|
||||
#ifndef RSPC_KEY
|
||||
#define RSPC_KEY KC_0
|
||||
# define RSPC_KEY KC_0
|
||||
#endif
|
||||
|
||||
// Shift / Enter setup
|
||||
#ifndef SFTENT_KEY
|
||||
#define SFTENT_KEY KC_ENT
|
||||
# define SFTENT_KEY KC_ENT
|
||||
#endif
|
||||
|
||||
#ifdef DISABLE_SPACE_CADET_MODIFIER
|
||||
#ifndef LSPO_MOD
|
||||
#define LSPO_MOD KC_TRNS
|
||||
#endif
|
||||
#ifndef RSPC_MOD
|
||||
#define RSPC_MOD KC_TRNS
|
||||
#endif
|
||||
# ifndef LSPO_MOD
|
||||
# define LSPO_MOD KC_TRNS
|
||||
# endif
|
||||
# ifndef RSPC_MOD
|
||||
# define RSPC_MOD KC_TRNS
|
||||
# endif
|
||||
#else
|
||||
#ifndef LSPO_MOD
|
||||
#define LSPO_MOD KC_LSFT
|
||||
#endif
|
||||
#ifndef RSPC_MOD
|
||||
#define RSPC_MOD KC_RSFT
|
||||
#endif
|
||||
# ifndef LSPO_MOD
|
||||
# define LSPO_MOD KC_LSFT
|
||||
# endif
|
||||
# ifndef RSPC_MOD
|
||||
# define RSPC_MOD KC_RSFT
|
||||
# endif
|
||||
#endif
|
||||
// **********************************************************
|
||||
|
||||
// Shift / paren setup
|
||||
#ifndef LSPO_KEYS
|
||||
#define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY
|
||||
# define LSPO_KEYS KC_LSFT, LSPO_MOD, LSPO_KEY
|
||||
#endif
|
||||
#ifndef RSPC_KEYS
|
||||
#define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY
|
||||
# define RSPC_KEYS KC_RSFT, RSPC_MOD, RSPC_KEY
|
||||
#endif
|
||||
|
||||
// Control / paren setup
|
||||
#ifndef LCPO_KEYS
|
||||
#define LCPO_KEYS KC_LCTL, KC_LSFT, KC_9
|
||||
# define LCPO_KEYS KC_LCTL, KC_LSFT, KC_9
|
||||
#endif
|
||||
#ifndef RCPC_KEYS
|
||||
#define RCPC_KEYS KC_RCTL, KC_RSFT, KC_0
|
||||
# define RCPC_KEYS KC_RCTL, KC_RSFT, KC_0
|
||||
#endif
|
||||
|
||||
// Alt / paren setup
|
||||
#ifndef LAPO_KEYS
|
||||
#define LAPO_KEYS KC_LALT, KC_LSFT, KC_9
|
||||
# define LAPO_KEYS KC_LALT, KC_LSFT, KC_9
|
||||
#endif
|
||||
#ifndef RAPC_KEYS
|
||||
#define RAPC_KEYS KC_RALT, KC_RSFT, KC_0
|
||||
# define RAPC_KEYS KC_RALT, KC_RSFT, KC_0
|
||||
#endif
|
||||
|
||||
// Shift / Enter setup
|
||||
#ifndef SFTENT_KEYS
|
||||
#define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY
|
||||
# define SFTENT_KEYS KC_RSFT, KC_TRNS, SFTENT_KEY
|
||||
#endif
|
||||
|
||||
static uint8_t sc_last = 0;
|
||||
static uint8_t sc_last = 0;
|
||||
static uint16_t sc_timer = 0;
|
||||
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
|
||||
static uint8_t sc_mods = 0;
|
||||
#endif
|
||||
|
||||
void perform_space_cadet(keyrecord_t *record, uint8_t holdMod, uint8_t tapMod, uint8_t keycode) {
|
||||
if (record->event.pressed) {
|
||||
sc_last = holdMod;
|
||||
sc_timer = timer_read ();
|
||||
if (record->event.pressed) {
|
||||
sc_last = holdMod;
|
||||
sc_timer = timer_read();
|
||||
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
|
||||
sc_mods = get_mods();
|
||||
sc_mods = get_mods();
|
||||
#endif
|
||||
if (IS_MOD(holdMod)) {
|
||||
register_mods(MOD_BIT(holdMod));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) {
|
||||
if (holdMod != tapMod) {
|
||||
if (IS_MOD(holdMod)) {
|
||||
unregister_mods(MOD_BIT(holdMod));
|
||||
register_mods(MOD_BIT(holdMod));
|
||||
}
|
||||
if (IS_MOD(tapMod)) {
|
||||
register_mods(MOD_BIT(tapMod));
|
||||
}
|
||||
}
|
||||
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
|
||||
set_weak_mods(sc_mods);
|
||||
#endif
|
||||
tap_code(keycode);
|
||||
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
|
||||
clear_weak_mods();
|
||||
#endif
|
||||
if (IS_MOD(tapMod)) {
|
||||
unregister_mods(MOD_BIT(tapMod));
|
||||
}
|
||||
} else {
|
||||
if (IS_MOD(holdMod)) {
|
||||
unregister_mods(MOD_BIT(holdMod));
|
||||
}
|
||||
if (sc_last == holdMod && timer_elapsed(sc_timer) < TAPPING_TERM) {
|
||||
if (holdMod != tapMod) {
|
||||
if (IS_MOD(holdMod)) {
|
||||
unregister_mods(MOD_BIT(holdMod));
|
||||
}
|
||||
if (IS_MOD(tapMod)) {
|
||||
register_mods(MOD_BIT(tapMod));
|
||||
}
|
||||
}
|
||||
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
|
||||
set_weak_mods(sc_mods);
|
||||
#endif
|
||||
tap_code(keycode);
|
||||
#ifdef SPACE_CADET_MODIFIER_CARRYOVER
|
||||
clear_weak_mods();
|
||||
#endif
|
||||
if (IS_MOD(tapMod)) {
|
||||
unregister_mods(MOD_BIT(tapMod));
|
||||
}
|
||||
} else {
|
||||
if (IS_MOD(holdMod)) {
|
||||
unregister_mods(MOD_BIT(holdMod));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool process_space_cadet(uint16_t keycode, keyrecord_t *record) {
|
||||
switch(keycode) {
|
||||
case KC_LSPO: {
|
||||
perform_space_cadet(record, LSPO_KEYS);
|
||||
return false;
|
||||
switch (keycode) {
|
||||
case KC_LSPO: {
|
||||
perform_space_cadet(record, LSPO_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_RSPC: {
|
||||
perform_space_cadet(record, RSPC_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_LCPO: {
|
||||
perform_space_cadet(record, LCPO_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_RCPC: {
|
||||
perform_space_cadet(record, RCPC_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_LAPO: {
|
||||
perform_space_cadet(record, LAPO_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_RAPC: {
|
||||
perform_space_cadet(record, RAPC_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_SFTENT: {
|
||||
perform_space_cadet(record, SFTENT_KEYS);
|
||||
return false;
|
||||
}
|
||||
default: {
|
||||
if (record->event.pressed) {
|
||||
sc_last = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
case KC_RSPC: {
|
||||
perform_space_cadet(record, RSPC_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_LCPO: {
|
||||
perform_space_cadet(record, LCPO_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_RCPC: {
|
||||
perform_space_cadet(record, RCPC_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_LAPO: {
|
||||
perform_space_cadet(record, LAPO_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_RAPC: {
|
||||
perform_space_cadet(record, RAPC_KEYS);
|
||||
return false;
|
||||
}
|
||||
case KC_SFTENT: {
|
||||
perform_space_cadet(record, SFTENT_KEYS);
|
||||
return false;
|
||||
}
|
||||
default: {
|
||||
if (record->event.pressed) {
|
||||
sc_last = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,150 +58,136 @@
|
|||
#define GEMINI_STATE_SIZE 6
|
||||
#define MAX_STATE_SIZE GEMINI_STATE_SIZE
|
||||
|
||||
static uint8_t state[MAX_STATE_SIZE] = {0};
|
||||
static uint8_t chord[MAX_STATE_SIZE] = {0};
|
||||
static int8_t pressed = 0;
|
||||
static uint8_t state[MAX_STATE_SIZE] = {0};
|
||||
static uint8_t chord[MAX_STATE_SIZE] = {0};
|
||||
static int8_t pressed = 0;
|
||||
static steno_mode_t mode;
|
||||
|
||||
static const uint8_t boltmap[64] PROGMEM = {
|
||||
TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM,
|
||||
TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L,
|
||||
TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL,
|
||||
TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R,
|
||||
TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R,
|
||||
TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R
|
||||
};
|
||||
static const uint8_t boltmap[64] PROGMEM = {TXB_NUL, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_S_L, TXB_S_L, TXB_T_L, TXB_K_L, TXB_P_L, TXB_W_L, TXB_H_L, TXB_R_L, TXB_A_L, TXB_O_L, TXB_STR, TXB_STR, TXB_NUL, TXB_NUL, TXB_NUL, TXB_STR, TXB_STR, TXB_E_R, TXB_U_R, TXB_F_R, TXB_R_R, TXB_P_R, TXB_B_R, TXB_L_R, TXB_G_R, TXB_T_R, TXB_S_R, TXB_D_R, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_NUM, TXB_Z_R};
|
||||
|
||||
static void steno_clear_state(void) {
|
||||
memset(state, 0, sizeof(state));
|
||||
memset(chord, 0, sizeof(chord));
|
||||
memset(state, 0, sizeof(state));
|
||||
memset(chord, 0, sizeof(chord));
|
||||
}
|
||||
|
||||
static void send_steno_state(uint8_t size, bool send_empty) {
|
||||
for (uint8_t i = 0; i < size; ++i) {
|
||||
if (chord[i] || send_empty) {
|
||||
virtser_send(chord[i]);
|
||||
for (uint8_t i = 0; i < size; ++i) {
|
||||
if (chord[i] || send_empty) {
|
||||
virtser_send(chord[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void steno_init() {
|
||||
if (!eeconfig_is_enabled()) {
|
||||
eeconfig_init();
|
||||
}
|
||||
mode = eeprom_read_byte(EECONFIG_STENOMODE);
|
||||
if (!eeconfig_is_enabled()) {
|
||||
eeconfig_init();
|
||||
}
|
||||
mode = eeprom_read_byte(EECONFIG_STENOMODE);
|
||||
}
|
||||
|
||||
void steno_set_mode(steno_mode_t new_mode) {
|
||||
steno_clear_state();
|
||||
mode = new_mode;
|
||||
eeprom_update_byte(EECONFIG_STENOMODE, mode);
|
||||
steno_clear_state();
|
||||
mode = new_mode;
|
||||
eeprom_update_byte(EECONFIG_STENOMODE, mode);
|
||||
}
|
||||
|
||||
/* override to intercept chords right before they get sent.
|
||||
* return zero to suppress normal sending behavior.
|
||||
*/
|
||||
__attribute__ ((weak))
|
||||
bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { return true; }
|
||||
__attribute__((weak)) bool send_steno_chord_user(steno_mode_t mode, uint8_t chord[6]) { return true; }
|
||||
|
||||
__attribute__ ((weak))
|
||||
bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { return true; }
|
||||
__attribute__((weak)) bool postprocess_steno_user(uint16_t keycode, keyrecord_t *record, steno_mode_t mode, uint8_t chord[6], int8_t pressed) { return true; }
|
||||
|
||||
__attribute__ ((weak))
|
||||
bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; }
|
||||
__attribute__((weak)) bool process_steno_user(uint16_t keycode, keyrecord_t *record) { return true; }
|
||||
|
||||
static void send_steno_chord(void) {
|
||||
if (send_steno_chord_user(mode, chord)) {
|
||||
switch(mode) {
|
||||
case STENO_MODE_BOLT:
|
||||
send_steno_state(BOLT_STATE_SIZE, false);
|
||||
virtser_send(0); // terminating byte
|
||||
break;
|
||||
case STENO_MODE_GEMINI:
|
||||
chord[0] |= 0x80; // Indicate start of packet
|
||||
send_steno_state(GEMINI_STATE_SIZE, true);
|
||||
break;
|
||||
if (send_steno_chord_user(mode, chord)) {
|
||||
switch (mode) {
|
||||
case STENO_MODE_BOLT:
|
||||
send_steno_state(BOLT_STATE_SIZE, false);
|
||||
virtser_send(0); // terminating byte
|
||||
break;
|
||||
case STENO_MODE_GEMINI:
|
||||
chord[0] |= 0x80; // Indicate start of packet
|
||||
send_steno_state(GEMINI_STATE_SIZE, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
steno_clear_state();
|
||||
steno_clear_state();
|
||||
}
|
||||
|
||||
uint8_t *steno_get_state(void) {
|
||||
return &state[0];
|
||||
}
|
||||
uint8_t *steno_get_state(void) { return &state[0]; }
|
||||
|
||||
uint8_t *steno_get_chord(void) {
|
||||
return &chord[0];
|
||||
}
|
||||
uint8_t *steno_get_chord(void) { return &chord[0]; }
|
||||
|
||||
static bool update_state_bolt(uint8_t key, bool press) {
|
||||
uint8_t boltcode = pgm_read_byte(boltmap + key);
|
||||
if (press) {
|
||||
state[TXB_GET_GROUP(boltcode)] |= boltcode;
|
||||
chord[TXB_GET_GROUP(boltcode)] |= boltcode;
|
||||
} else {
|
||||
state[TXB_GET_GROUP(boltcode)] &= ~boltcode;
|
||||
}
|
||||
return false;
|
||||
uint8_t boltcode = pgm_read_byte(boltmap + key);
|
||||
if (press) {
|
||||
state[TXB_GET_GROUP(boltcode)] |= boltcode;
|
||||
chord[TXB_GET_GROUP(boltcode)] |= boltcode;
|
||||
} else {
|
||||
state[TXB_GET_GROUP(boltcode)] &= ~boltcode;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool update_state_gemini(uint8_t key, bool press) {
|
||||
int idx = key / 7;
|
||||
uint8_t bit = 1 << (6 - (key % 7));
|
||||
if (press) {
|
||||
state[idx] |= bit;
|
||||
chord[idx] |= bit;
|
||||
} else {
|
||||
state[idx] &= ~bit;
|
||||
}
|
||||
return false;
|
||||
int idx = key / 7;
|
||||
uint8_t bit = 1 << (6 - (key % 7));
|
||||
if (press) {
|
||||
state[idx] |= bit;
|
||||
chord[idx] |= bit;
|
||||
} else {
|
||||
state[idx] &= ~bit;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool process_steno(uint16_t keycode, keyrecord_t *record) {
|
||||
switch (keycode) {
|
||||
case QK_STENO_BOLT:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
if (IS_PRESSED(record->event)) {
|
||||
steno_set_mode(STENO_MODE_BOLT);
|
||||
}
|
||||
return false;
|
||||
switch (keycode) {
|
||||
case QK_STENO_BOLT:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
if (IS_PRESSED(record->event)) {
|
||||
steno_set_mode(STENO_MODE_BOLT);
|
||||
}
|
||||
return false;
|
||||
|
||||
case QK_STENO_GEMINI:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
if (IS_PRESSED(record->event)) {
|
||||
steno_set_mode(STENO_MODE_GEMINI);
|
||||
}
|
||||
return false;
|
||||
case QK_STENO_GEMINI:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
if (IS_PRESSED(record->event)) {
|
||||
steno_set_mode(STENO_MODE_GEMINI);
|
||||
}
|
||||
return false;
|
||||
|
||||
case STN__MIN...STN__MAX:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
switch(mode) {
|
||||
case STENO_MODE_BOLT:
|
||||
update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
break;
|
||||
case STENO_MODE_GEMINI:
|
||||
update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
break;
|
||||
}
|
||||
// allow postprocessing hooks
|
||||
if (postprocess_steno_user(keycode, record, mode, chord, pressed)) {
|
||||
if (IS_PRESSED(record->event)) {
|
||||
++pressed;
|
||||
} else {
|
||||
--pressed;
|
||||
if (pressed <= 0) {
|
||||
pressed = 0;
|
||||
send_steno_chord();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
case STN__MIN ... STN__MAX:
|
||||
if (!process_steno_user(keycode, record)) {
|
||||
return false;
|
||||
}
|
||||
switch (mode) {
|
||||
case STENO_MODE_BOLT:
|
||||
update_state_bolt(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
break;
|
||||
case STENO_MODE_GEMINI:
|
||||
update_state_gemini(keycode - QK_STENO, IS_PRESSED(record->event));
|
||||
break;
|
||||
}
|
||||
// allow postprocessing hooks
|
||||
if (postprocess_steno_user(keycode, record, mode, chord, pressed)) {
|
||||
if (IS_PRESSED(record->event)) {
|
||||
++pressed;
|
||||
} else {
|
||||
--pressed;
|
||||
if (pressed <= 0) {
|
||||
pressed = 0;
|
||||
send_steno_chord();
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@
|
|||
#include "quantum.h"
|
||||
|
||||
#if defined(STENO_ENABLE) && !defined(VIRTSER_ENABLE)
|
||||
#error "must have virtser enabled to use steno"
|
||||
# error "must have virtser enabled to use steno"
|
||||
#endif
|
||||
|
||||
typedef enum { STENO_MODE_BOLT, STENO_MODE_GEMINI } steno_mode_t;
|
||||
|
||||
bool process_steno(uint16_t keycode, keyrecord_t *record);
|
||||
void steno_init(void);
|
||||
void steno_set_mode(steno_mode_t mode);
|
||||
bool process_steno(uint16_t keycode, keyrecord_t *record);
|
||||
void steno_init(void);
|
||||
void steno_set_mode(steno_mode_t mode);
|
||||
uint8_t *steno_get_state(void);
|
||||
uint8_t *steno_get_chord(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
#include "action_tapping.h"
|
||||
|
||||
#ifndef TAPPING_TERM
|
||||
#define TAPPING_TERM 200
|
||||
# define TAPPING_TERM 200
|
||||
#endif
|
||||
|
||||
#ifndef NO_ACTION_ONESHOT
|
||||
|
|
@ -25,191 +25,173 @@ uint8_t get_oneshot_mods(void);
|
|||
#endif
|
||||
|
||||
static uint16_t last_td;
|
||||
static int8_t highest_td = -1;
|
||||
static int8_t highest_td = -1;
|
||||
|
||||
void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data) {
|
||||
qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
|
||||
void qk_tap_dance_pair_on_each_tap(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) {
|
||||
register_code16 (pair->kc2);
|
||||
state->finished = true;
|
||||
}
|
||||
if (state->count == 2) {
|
||||
register_code16(pair->kc2);
|
||||
state->finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
if (state->count == 1) {
|
||||
register_code16 (pair->kc1);
|
||||
} else if (state->count == 2) {
|
||||
register_code16 (pair->kc2);
|
||||
}
|
||||
if (state->count == 1) {
|
||||
register_code16(pair->kc1);
|
||||
} else if (state->count == 2) {
|
||||
register_code16(pair->kc2);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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 == 1) {
|
||||
unregister_code16 (pair->kc1);
|
||||
} else if (state->count == 2) {
|
||||
unregister_code16 (pair->kc2);
|
||||
}
|
||||
if (state->count == 1) {
|
||||
unregister_code16(pair->kc1);
|
||||
} else if (state->count == 2) {
|
||||
unregister_code16(pair->kc2);
|
||||
}
|
||||
}
|
||||
|
||||
void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data) {
|
||||
qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
|
||||
void qk_tap_dance_dual_role_on_each_tap(qk_tap_dance_state_t *state, void *user_data) {
|
||||
qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
|
||||
|
||||
if (state->count == 2) {
|
||||
layer_move (pair->layer);
|
||||
state->finished = true;
|
||||
}
|
||||
if (state->count == 2) {
|
||||
layer_move(pair->layer);
|
||||
state->finished = true;
|
||||
}
|
||||
}
|
||||
|
||||
void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data) {
|
||||
qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
|
||||
void qk_tap_dance_dual_role_finished(qk_tap_dance_state_t *state, void *user_data) {
|
||||
qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
|
||||
|
||||
if (state->count == 1) {
|
||||
register_code16 (pair->kc);
|
||||
} else if (state->count == 2) {
|
||||
layer_move (pair->layer);
|
||||
}
|
||||
if (state->count == 1) {
|
||||
register_code16(pair->kc);
|
||||
} else if (state->count == 2) {
|
||||
layer_move(pair->layer);
|
||||
}
|
||||
}
|
||||
|
||||
void qk_tap_dance_dual_role_reset (qk_tap_dance_state_t *state, void *user_data) {
|
||||
qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
|
||||
void qk_tap_dance_dual_role_reset(qk_tap_dance_state_t *state, void *user_data) {
|
||||
qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
|
||||
|
||||
if (state->count == 1) {
|
||||
unregister_code16 (pair->kc);
|
||||
}
|
||||
if (state->count == 1) {
|
||||
unregister_code16(pair->kc);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _process_tap_dance_action_fn (qk_tap_dance_state_t *state,
|
||||
void *user_data,
|
||||
qk_tap_dance_user_fn_t fn)
|
||||
{
|
||||
if (fn) {
|
||||
fn(state, user_data);
|
||||
}
|
||||
static inline void _process_tap_dance_action_fn(qk_tap_dance_state_t *state, void *user_data, qk_tap_dance_user_fn_t fn) {
|
||||
if (fn) {
|
||||
fn(state, user_data);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void process_tap_dance_action_on_each_tap (qk_tap_dance_action_t *action)
|
||||
{
|
||||
_process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_each_tap);
|
||||
static inline void process_tap_dance_action_on_each_tap(qk_tap_dance_action_t *action) { _process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_each_tap); }
|
||||
|
||||
static inline void process_tap_dance_action_on_dance_finished(qk_tap_dance_action_t *action) {
|
||||
if (action->state.finished) return;
|
||||
action->state.finished = true;
|
||||
add_mods(action->state.oneshot_mods);
|
||||
add_weak_mods(action->state.weak_mods);
|
||||
send_keyboard_report();
|
||||
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_dance_finished);
|
||||
}
|
||||
|
||||
static inline void process_tap_dance_action_on_dance_finished (qk_tap_dance_action_t *action)
|
||||
{
|
||||
if (action->state.finished)
|
||||
return;
|
||||
action->state.finished = true;
|
||||
add_mods(action->state.oneshot_mods);
|
||||
add_weak_mods(action->state.weak_mods);
|
||||
send_keyboard_report();
|
||||
_process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_dance_finished);
|
||||
}
|
||||
|
||||
static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *action)
|
||||
{
|
||||
_process_tap_dance_action_fn (&action->state, action->user_data, action->fn.on_reset);
|
||||
del_mods(action->state.oneshot_mods);
|
||||
del_weak_mods(action->state.weak_mods);
|
||||
send_keyboard_report();
|
||||
static inline void process_tap_dance_action_on_reset(qk_tap_dance_action_t *action) {
|
||||
_process_tap_dance_action_fn(&action->state, action->user_data, action->fn.on_reset);
|
||||
del_mods(action->state.oneshot_mods);
|
||||
del_weak_mods(action->state.weak_mods);
|
||||
send_keyboard_report();
|
||||
}
|
||||
|
||||
void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
||||
qk_tap_dance_action_t *action;
|
||||
qk_tap_dance_action_t *action;
|
||||
|
||||
if (!record->event.pressed)
|
||||
return;
|
||||
if (!record->event.pressed) return;
|
||||
|
||||
if (highest_td == -1)
|
||||
return;
|
||||
if (highest_td == -1) return;
|
||||
|
||||
for (int i = 0; i <= highest_td; i++) {
|
||||
action = &tap_dance_actions[i];
|
||||
if (action->state.count) {
|
||||
if (keycode == action->state.keycode && keycode == last_td)
|
||||
continue;
|
||||
action->state.interrupted = true;
|
||||
action->state.interrupting_keycode = keycode;
|
||||
process_tap_dance_action_on_dance_finished (action);
|
||||
reset_tap_dance (&action->state);
|
||||
for (int i = 0; i <= highest_td; i++) {
|
||||
action = &tap_dance_actions[i];
|
||||
if (action->state.count) {
|
||||
if (keycode == action->state.keycode && keycode == last_td) continue;
|
||||
action->state.interrupted = true;
|
||||
action->state.interrupting_keycode = keycode;
|
||||
process_tap_dance_action_on_dance_finished(action);
|
||||
reset_tap_dance(&action->state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
|
||||
uint16_t idx = keycode - QK_TAP_DANCE;
|
||||
qk_tap_dance_action_t *action;
|
||||
uint16_t idx = keycode - QK_TAP_DANCE;
|
||||
qk_tap_dance_action_t *action;
|
||||
|
||||
switch(keycode) {
|
||||
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
|
||||
if ((int16_t)idx > highest_td)
|
||||
highest_td = idx;
|
||||
action = &tap_dance_actions[idx];
|
||||
switch (keycode) {
|
||||
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
|
||||
if ((int16_t)idx > highest_td) highest_td = idx;
|
||||
action = &tap_dance_actions[idx];
|
||||
|
||||
action->state.pressed = record->event.pressed;
|
||||
if (record->event.pressed) {
|
||||
action->state.keycode = keycode;
|
||||
action->state.count++;
|
||||
action->state.timer = timer_read();
|
||||
action->state.pressed = record->event.pressed;
|
||||
if (record->event.pressed) {
|
||||
action->state.keycode = keycode;
|
||||
action->state.count++;
|
||||
action->state.timer = timer_read();
|
||||
#ifndef NO_ACTION_ONESHOT
|
||||
action->state.oneshot_mods = get_oneshot_mods();
|
||||
action->state.oneshot_mods = get_oneshot_mods();
|
||||
#else
|
||||
action->state.oneshot_mods = 0;
|
||||
action->state.oneshot_mods = 0;
|
||||
#endif
|
||||
action->state.weak_mods = get_mods();
|
||||
action->state.weak_mods |= get_weak_mods();
|
||||
process_tap_dance_action_on_each_tap (action);
|
||||
action->state.weak_mods = get_mods();
|
||||
action->state.weak_mods |= get_weak_mods();
|
||||
process_tap_dance_action_on_each_tap(action);
|
||||
|
||||
last_td = keycode;
|
||||
} else {
|
||||
if (action->state.count && action->state.finished) {
|
||||
reset_tap_dance (&action->state);
|
||||
}
|
||||
last_td = keycode;
|
||||
} else {
|
||||
if (action->state.count && action->state.finished) {
|
||||
reset_tap_dance(&action->state);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void matrix_scan_tap_dance() {
|
||||
if (highest_td == -1) return;
|
||||
uint16_t tap_user_defined;
|
||||
|
||||
|
||||
void matrix_scan_tap_dance () {
|
||||
if (highest_td == -1)
|
||||
return;
|
||||
uint16_t tap_user_defined;
|
||||
|
||||
for (uint8_t i = 0; i <= highest_td; i++) {
|
||||
qk_tap_dance_action_t *action = &tap_dance_actions[i];
|
||||
if(action->custom_tapping_term > 0 ) {
|
||||
tap_user_defined = action->custom_tapping_term;
|
||||
for (uint8_t i = 0; i <= highest_td; i++) {
|
||||
qk_tap_dance_action_t *action = &tap_dance_actions[i];
|
||||
if (action->custom_tapping_term > 0) {
|
||||
tap_user_defined = action->custom_tapping_term;
|
||||
} else {
|
||||
tap_user_defined = TAPPING_TERM;
|
||||
}
|
||||
if (action->state.count && timer_elapsed(action->state.timer) > tap_user_defined) {
|
||||
process_tap_dance_action_on_dance_finished(action);
|
||||
reset_tap_dance(&action->state);
|
||||
}
|
||||
}
|
||||
else{
|
||||
tap_user_defined = TAPPING_TERM;
|
||||
}
|
||||
if (action->state.count && timer_elapsed (action->state.timer) > tap_user_defined) {
|
||||
process_tap_dance_action_on_dance_finished (action);
|
||||
reset_tap_dance (&action->state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void reset_tap_dance (qk_tap_dance_state_t *state) {
|
||||
qk_tap_dance_action_t *action;
|
||||
void reset_tap_dance(qk_tap_dance_state_t *state) {
|
||||
qk_tap_dance_action_t *action;
|
||||
|
||||
if (state->pressed)
|
||||
return;
|
||||
if (state->pressed) return;
|
||||
|
||||
action = &tap_dance_actions[state->keycode - QK_TAP_DANCE];
|
||||
action = &tap_dance_actions[state->keycode - QK_TAP_DANCE];
|
||||
|
||||
process_tap_dance_action_on_reset (action);
|
||||
process_tap_dance_action_on_reset(action);
|
||||
|
||||
state->count = 0;
|
||||
state->interrupted = false;
|
||||
state->finished = false;
|
||||
state->interrupting_keycode = 0;
|
||||
last_td = 0;
|
||||
state->count = 0;
|
||||
state->interrupted = false;
|
||||
state->finished = false;
|
||||
state->interrupting_keycode = 0;
|
||||
last_td = 0;
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue