mirror of
https://github.com/qmk/qmk_userspace.git
synced 2026-03-10 02:10:25 -04:00
Test repeat and one-shot callback functionality
This commit is contained in:
parent
0dd58e2d88
commit
dcadece8ed
4 changed files with 52 additions and 16 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -14,3 +14,5 @@
|
|||
compile_commands.json
|
||||
.clangd/
|
||||
.cache/
|
||||
|
||||
a.out
|
||||
|
|
|
|||
|
|
@ -135,11 +135,45 @@ bool search_trie2(const trie2_t *trie, int offset, trie2_visitor_t *v)
|
|||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
void print_cb2(trie2_visitor_t *v, int bspaces, int func, const char *completion)
|
||||
void print_traverse_cb2(trie2_visitor_t *v, int bspaces, int func, const char *completion)
|
||||
{
|
||||
printf(" depth %d: ", v->stack.size);
|
||||
printf(" -> %s (bspc: %d, func: %d)\n", completion, bspaces, func);
|
||||
|
||||
if (v->cb_data) {
|
||||
int entries = *(int*)v->cb_data;
|
||||
*(int*)v->cb_data = entries + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
void print_search_cb2(trie2_visitor_t *v, int bspaces, int func, const char *completion)
|
||||
{
|
||||
printf(" depth %d: ", v->stack.size);
|
||||
stack_print(&v->stack);
|
||||
printf(" -> %s (bspc: %d, func: %d)\n", completion, bspaces, func);
|
||||
search_buffer_t *search = (search_buffer_t*)v->cb_data;
|
||||
char last_char;
|
||||
int i;
|
||||
switch (func) {
|
||||
case 1: // repeat
|
||||
i = search->size - 1;
|
||||
last_char = search->data[i];
|
||||
while ((last_char == '*' || last_char == '@') && i >= 0) {
|
||||
last_char = search->data[--i];
|
||||
}
|
||||
search->data[search->size-1] = last_char;
|
||||
printf(" -> %s%c (bspc: %d, func: %d)\n", completion, last_char, bspaces, func);
|
||||
printf(" new buffer: %s", search->data);
|
||||
printf("\n");
|
||||
break;
|
||||
case 2: // one-shot-shift
|
||||
printf(" -> %s (bspc: %d, func: %d)\n", completion, bspaces, func);
|
||||
printf(" Activating One-Shot-Shift\n");
|
||||
break;
|
||||
default:
|
||||
printf(" -> %s (bspc: %d, func: %d)\n", completion, bspaces, func);
|
||||
}
|
||||
|
||||
if (v->cb_data) {
|
||||
int entries = *(int*)v->cb_data;
|
||||
*(int*)v->cb_data = entries + 1;
|
||||
|
|
@ -153,7 +187,7 @@ void test_traverse2(trie2_t *trie)
|
|||
trie2_visitor_t visitor;
|
||||
visitor.stack.size = 0;
|
||||
visitor.cb_data = (void*)&entries;
|
||||
visitor.cb_func = print_cb2;
|
||||
visitor.cb_func = print_traverse_cb2;
|
||||
traverse_trie2(trie, 0, &visitor);
|
||||
printf("Found %d entries.\n\n", entries);
|
||||
}
|
||||
|
|
@ -167,7 +201,7 @@ void test_search2(const trie2_t *trie, const char *buffer)
|
|||
trie2_visitor_t visitor;
|
||||
visitor.stack.size = 0;
|
||||
visitor.cb_data = (void*)&search;
|
||||
visitor.cb_func = print_cb2;
|
||||
visitor.cb_func = print_search_cb2;
|
||||
search_trie2(trie, 0, &visitor);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -192,12 +226,11 @@ void test_trie2()
|
|||
test_search2(&trie2, "cat*");
|
||||
test_search2(&trie2, ":ex@");
|
||||
test_search2(&trie2, "j*");
|
||||
test_search2(&trie2, "i@");
|
||||
test_search2(&trie2, "i@m");
|
||||
test_search2(&trie2, "i@d");
|
||||
test_search2(&trie2, "i@l");
|
||||
test_search2(&trie2, "@");
|
||||
test_search2(&trie2, "*");
|
||||
test_search2(&trie2, ":i@");
|
||||
test_search2(&trie2, ":i@m");
|
||||
test_search2(&trie2, ":i@d");
|
||||
test_search2(&trie2, ":i@l");
|
||||
test_search2(&trie2, "o@");
|
||||
test_search2(&trie2, ".@");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@
|
|||
|
||||
#define QK_LSFT 0x0200
|
||||
#define pgm_read_byte(address_short) *((uint8_t*)(address_short))
|
||||
#define PROGMEM
|
||||
#define KC_MAGIC_0 0x0100
|
||||
#define PROGMEM
|
||||
|
||||
static const char magic_chars[] = { '*', '@' };
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ const char unshifted_keycode_to_ascii_lut[53] PROGMEM = {
|
|||
' ', ' ', ' ', ' ', ' ', '-', '=', '[',
|
||||
// KC_RBRC KC_BSLS KC_NUHS KC_SCLN KC_QUOT KC_GRV KC_COMM KC_DOT
|
||||
']', '\\', ' ', ';', '\'', '`', ',', '.',
|
||||
// KC_SLSH
|
||||
// KC_SLSH
|
||||
'/'
|
||||
};
|
||||
const char shifted_keycode_to_ascii_lut[53] PROGMEM = {
|
||||
|
|
@ -41,7 +40,7 @@ const char shifted_keycode_to_ascii_lut[53] PROGMEM = {
|
|||
' ', ' ', ' ', ' ', ' ', '_', '+', '{',
|
||||
// KC_RCBR KC_PIPE KC_NUHS KC_COLN KC_DQUO KC_GRV KC_LABK KC_RABK
|
||||
'}', '|', ' ', ':', '"', '~', '<', '>',
|
||||
// KC_QUES
|
||||
// KC_QUES
|
||||
'?'
|
||||
};
|
||||
|
||||
|
|
@ -60,4 +59,4 @@ char keycode_to_char(uint16_t keycode)
|
|||
pgm_read_byte(&unshifted_keycode_to_ascii_lut[keycode]);
|
||||
}
|
||||
return ' ';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
char keycode_to_char(uint16_t code);
|
||||
#define KC_MAGIC_0 0x0100
|
||||
|
||||
char keycode_to_char(uint16_t code);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue