1
0
Fork 0

splits process_action up to handle records separately (#329)

* implements leader key for planck experimental

* allows override of leader timeout

* adds ability to use the leader key in seq

* fixes leader keycode

* adds chording prototype

* fixes keycode detection

* moves music mode to quantum.c

* disables chording by default

* adds music sequencer functionality

* implements audio/music functions in quantum.c

* splits up process_action to allow independent processing of actions

* merging?
This commit is contained in:
Jack Humbert 2016-05-15 00:47:25 -04:00
parent 15719f3574
commit bf5c2ccee5
5 changed files with 58 additions and 40 deletions

View file

@ -191,6 +191,9 @@ extern const uint16_t fn_actions[];
#define RESET 0x5000 #define RESET 0x5000
#define DEBUG 0x5001 #define DEBUG 0x5001
#define KC_LEAD 0x5014
// MAGIC keycodes // MAGIC keycodes
#define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002 #define MAGIC_SWAP_CONTROL_CAPSLOCK 0x5002

View file

@ -70,7 +70,7 @@ 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; static uint16_t music_sequence_interval = 100;
bool process_action_quantum(keyrecord_t *record) { bool process_record_quantum(keyrecord_t *record) {
/* This gets the keycode from the key pressed */ /* This gets the keycode from the key pressed */
keypos_t key = record->event.key; keypos_t key = record->event.key;
@ -90,6 +90,14 @@ bool process_action_quantum(keyrecord_t *record) {
keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key); keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
#endif #endif
// This is how you use actions here
// if (keycode == KC_LEAD) {
// action_t action;
// action.code = ACTION_DEFAULT_LAYER_SET(0);
// process_action(record, action);
// return false;
// }
#ifdef AUDIO_ENABLE #ifdef AUDIO_ENABLE
if (keycode == AU_ON && record->event.pressed) { if (keycode == AU_ON && record->event.pressed) {
audio_on(); audio_on();
@ -259,5 +267,6 @@ void matrix_scan_quantum() {
} }
#endif #endif
matrix_scan_kb(); matrix_scan_kb();
} }

View file

@ -46,7 +46,7 @@ void action_exec(keyevent_t event)
#ifndef NO_ACTION_TAPPING #ifndef NO_ACTION_TAPPING
action_tapping_process(record); action_tapping_process(record);
#else #else
process_action(&record); process_record(&record);
if (!IS_NOEVENT(record.event)) { if (!IS_NOEVENT(record.event)) {
dprint("processed: "); debug_record(record); dprintln(); dprint("processed: "); debug_record(record); dprintln();
} }
@ -56,25 +56,43 @@ void action_exec(keyevent_t event)
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
bool disable_action_cache = false; bool disable_action_cache = false;
void process_action_nocache(keyrecord_t *record) void process_record_nocache(keyrecord_t *record)
{ {
disable_action_cache = true; disable_action_cache = true;
process_action(record); process_record(record);
disable_action_cache = false; disable_action_cache = false;
} }
#else #else
void process_action_nocache(keyrecord_t *record) void process_record_nocache(keyrecord_t *record)
{ {
process_action(record); process_record(record);
} }
#endif #endif
__attribute__ ((weak)) __attribute__ ((weak))
bool process_action_quantum(keyrecord_t *record) { bool process_record_quantum(keyrecord_t *record) {
return true; return true;
} }
void process_action(keyrecord_t *record) void process_record(keyrecord_t *record)
{
if (IS_NOEVENT(record->event)) { return; }
if(!process_record_quantum(record))
return;
action_t action = store_or_get_action(record->event.pressed, record->event.key);
dprint("ACTION: "); debug_action(action);
#ifndef NO_ACTION_LAYER
dprint(" layer_state: "); layer_debug();
dprint(" default_layer_state: "); default_layer_debug();
#endif
dprintln();
process_action(record, action);
}
void process_action(keyrecord_t *record, action_t action)
{ {
bool do_release_oneshot = false; bool do_release_oneshot = false;
keyevent_t event = record->event; keyevent_t event = record->event;
@ -82,8 +100,6 @@ void process_action(keyrecord_t *record)
uint8_t tap_count = record->tap.count; uint8_t tap_count = record->tap.count;
#endif #endif
if (IS_NOEVENT(event)) { return; }
#if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0)) #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
if (has_oneshot_layer_timed_out()) { if (has_oneshot_layer_timed_out()) {
dprintf("Oneshot layer: timeout\n"); dprintf("Oneshot layer: timeout\n");
@ -91,17 +107,6 @@ void process_action(keyrecord_t *record)
} }
#endif #endif
if (!process_action_quantum(record))
return;
action_t action = store_or_get_action(event.pressed, event.key);
dprint("ACTION: "); debug_action(action);
#ifndef NO_ACTION_LAYER
dprint(" layer_state: "); layer_debug();
dprint(" default_layer_state: "); default_layer_debug();
#endif
dprintln();
if (event.pressed) { if (event.pressed) {
// clear the potential weak mods left by previously pressed keys // clear the potential weak mods left by previously pressed keys
clear_weak_mods(); clear_weak_mods();
@ -451,7 +456,7 @@ void process_action(keyrecord_t *record)
if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) { if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) {
record->event.pressed = false; record->event.pressed = false;
layer_on(get_oneshot_layer()); layer_on(get_oneshot_layer());
process_action(record); process_record(record);
layer_off(get_oneshot_layer()); layer_off(get_oneshot_layer());
} }
#endif #endif

View file

@ -59,14 +59,15 @@ const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt);
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt); void action_function(keyrecord_t *record, uint8_t id, uint8_t opt);
/* keyboard-specific key event (pre)processing */ /* keyboard-specific key event (pre)processing */
bool process_action_quantum(keyrecord_t *record); bool process_record_quantum(keyrecord_t *record);
/* Utilities for actions. */ /* Utilities for actions. */
#if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS) #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
extern bool disable_action_cache; extern bool disable_action_cache;
#endif #endif
void process_action_nocache(keyrecord_t *record); void process_record_nocache(keyrecord_t *record);
void process_action(keyrecord_t *record); void process_record(keyrecord_t *record);
void process_action(keyrecord_t *record, action_t action);
void register_code(uint8_t code); void register_code(uint8_t code);
void unregister_code(uint8_t code); void unregister_code(uint8_t code);
void register_mods(uint8_t mods); void register_mods(uint8_t mods);

View file

@ -89,7 +89,7 @@ bool process_tapping(keyrecord_t *keyp)
debug("Tapping: First tap(0->1).\n"); debug("Tapping: First tap(0->1).\n");
tapping_key.tap.count = 1; tapping_key.tap.count = 1;
debug_tapping_key(); debug_tapping_key();
process_action(&tapping_key); process_record(&tapping_key);
// copy tapping state // copy tapping state
keyp->tap = tapping_key.tap; keyp->tap = tapping_key.tap;
@ -103,7 +103,7 @@ bool process_tapping(keyrecord_t *keyp)
*/ */
else if (IS_RELEASED(event) && waiting_buffer_typed(event)) { else if (IS_RELEASED(event) && waiting_buffer_typed(event)) {
debug("Tapping: End. No tap. Interfered by typing key\n"); debug("Tapping: End. No tap. Interfered by typing key\n");
process_action(&tapping_key); process_record(&tapping_key);
tapping_key = (keyrecord_t){}; tapping_key = (keyrecord_t){};
debug_tapping_key(); debug_tapping_key();
// enqueue // enqueue
@ -131,7 +131,7 @@ bool process_tapping(keyrecord_t *keyp)
} }
// Release of key should be process immediately. // Release of key should be process immediately.
debug("Tapping: release event of a key pressed before tapping\n"); debug("Tapping: release event of a key pressed before tapping\n");
process_action(keyp); process_record(keyp);
return true; return true;
} }
else { else {
@ -148,7 +148,7 @@ bool process_tapping(keyrecord_t *keyp)
if (IS_TAPPING_KEY(event.key) && !event.pressed) { if (IS_TAPPING_KEY(event.key) && !event.pressed) {
debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n"); debug("Tapping: Tap release("); debug_dec(tapping_key.tap.count); debug(")\n");
keyp->tap = tapping_key.tap; keyp->tap = tapping_key.tap;
process_action(keyp); process_record(keyp);
tapping_key = *keyp; tapping_key = *keyp;
debug_tapping_key(); debug_tapping_key();
return true; return true;
@ -157,7 +157,7 @@ bool process_tapping(keyrecord_t *keyp)
if (tapping_key.tap.count > 1) { if (tapping_key.tap.count > 1) {
debug("Tapping: Start new tap with releasing last tap(>1).\n"); debug("Tapping: Start new tap with releasing last tap(>1).\n");
// unregister key // unregister key
process_action(&(keyrecord_t){ process_record(&(keyrecord_t){
.tap = tapping_key.tap, .tap = tapping_key.tap,
.event.key = tapping_key.event.key, .event.key = tapping_key.event.key,
.event.time = event.time, .event.time = event.time,
@ -175,7 +175,7 @@ bool process_tapping(keyrecord_t *keyp)
if (!IS_NOEVENT(event)) { if (!IS_NOEVENT(event)) {
debug("Tapping: key event while last tap(>0).\n"); debug("Tapping: key event while last tap(>0).\n");
} }
process_action(keyp); process_record(keyp);
return true; return true;
} }
} }
@ -185,7 +185,7 @@ bool process_tapping(keyrecord_t *keyp)
if (tapping_key.tap.count == 0) { if (tapping_key.tap.count == 0) {
debug("Tapping: End. Timeout. Not tap(0): "); debug("Tapping: End. Timeout. Not tap(0): ");
debug_event(event); debug("\n"); debug_event(event); debug("\n");
process_action(&tapping_key); process_record(&tapping_key);
tapping_key = (keyrecord_t){}; tapping_key = (keyrecord_t){};
debug_tapping_key(); debug_tapping_key();
return false; return false;
@ -193,7 +193,7 @@ bool process_tapping(keyrecord_t *keyp)
if (IS_TAPPING_KEY(event.key) && !event.pressed) { if (IS_TAPPING_KEY(event.key) && !event.pressed) {
debug("Tapping: End. last timeout tap release(>0)."); debug("Tapping: End. last timeout tap release(>0).");
keyp->tap = tapping_key.tap; keyp->tap = tapping_key.tap;
process_action(keyp); process_record(keyp);
tapping_key = (keyrecord_t){}; tapping_key = (keyrecord_t){};
return true; return true;
} }
@ -201,7 +201,7 @@ bool process_tapping(keyrecord_t *keyp)
if (tapping_key.tap.count > 1) { if (tapping_key.tap.count > 1) {
debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); debug("Tapping: Start new tap with releasing last timeout tap(>1).\n");
// unregister key // unregister key
process_action(&(keyrecord_t){ process_record(&(keyrecord_t){
.tap = tapping_key.tap, .tap = tapping_key.tap,
.event.key = tapping_key.event.key, .event.key = tapping_key.event.key,
.event.time = event.time, .event.time = event.time,
@ -219,7 +219,7 @@ bool process_tapping(keyrecord_t *keyp)
if (!IS_NOEVENT(event)) { if (!IS_NOEVENT(event)) {
debug("Tapping: key event while last timeout tap(>0).\n"); debug("Tapping: key event while last timeout tap(>0).\n");
} }
process_action(keyp); process_record(keyp);
return true; return true;
} }
} }
@ -233,7 +233,7 @@ bool process_tapping(keyrecord_t *keyp)
keyp->tap = tapping_key.tap; keyp->tap = tapping_key.tap;
if (keyp->tap.count < 15) keyp->tap.count += 1; if (keyp->tap.count < 15) keyp->tap.count += 1;
debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n"); debug("Tapping: Tap press("); debug_dec(keyp->tap.count); debug(")\n");
process_action(keyp); process_record(keyp);
tapping_key = *keyp; tapping_key = *keyp;
debug_tapping_key(); debug_tapping_key();
return true; return true;
@ -253,12 +253,12 @@ bool process_tapping(keyrecord_t *keyp)
// should none in buffer // should none in buffer
// FIX: interrupted when other key is pressed // FIX: interrupted when other key is pressed
tapping_key.tap.interrupted = true; tapping_key.tap.interrupted = true;
process_action(keyp); process_record(keyp);
return true; return true;
} }
} else { } else {
if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n"); if (!IS_NOEVENT(event)) debug("Tapping: other key just after tap.\n");
process_action(keyp); process_record(keyp);
return true; return true;
} }
} else { } else {
@ -280,7 +280,7 @@ bool process_tapping(keyrecord_t *keyp)
debug_tapping_key(); debug_tapping_key();
return true; return true;
} else { } else {
process_action(keyp); process_record(keyp);
return true; return true;
} }
} }
@ -347,7 +347,7 @@ void waiting_buffer_scan_tap(void)
WITHIN_TAPPING_TERM(waiting_buffer[i].event)) { WITHIN_TAPPING_TERM(waiting_buffer[i].event)) {
tapping_key.tap.count = 1; tapping_key.tap.count = 1;
waiting_buffer[i].tap.count = 1; waiting_buffer[i].tap.count = 1;
process_action(&tapping_key); process_record(&tapping_key);
debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n"); debug("waiting_buffer_scan_tap: found at ["); debug_dec(i); debug("]\n");
debug_waiting_buffer(); debug_waiting_buffer();