Remove hex_to_keycode and move tap_random_base64 to send_string.c (#12079)

This commit is contained in:
Ryan 2021-03-12 18:03:44 +11:00 committed by GitHub
parent ea2a7c5ea4
commit 88dce24375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 103 deletions

View File

@ -269,31 +269,3 @@ void unicode_input_start (void) {
unregister_code(KC_LSFT);
unregister_code(KC_LCTL);
};
// Override method to use NEO_A instead of KC_A
uint16_t hex_to_keycode(uint8_t hex)
{
if(hex == 0x0) {
return KC_0;
}
else if(hex >= 0xA) {
switch(hex) {
case 0xA:
return NEO_A;
case 0xB:
return NEO_B;
case 0xC:
return NEO_C;
case 0xD:
return NEO_D;
case 0xE:
return NEO_E;
case 0xF:
return NEO_F;
default:
return KC_NO;
}
}
return KC_1 + (hex - 0x1);
}

View File

@ -158,7 +158,7 @@ __attribute__((weak)) void unicode_input_cancel(void) {
void register_hex(uint16_t hex) {
for (int i = 3; i >= 0; i--) {
uint8_t digit = ((hex >> (i * 4)) & 0xF);
tap_code16(hex_to_keycode(digit));
send_nibble(digit);
}
}
@ -171,10 +171,10 @@ void register_hex32(uint32_t hex) {
uint8_t digit = ((hex >> (i * 4)) & 0xF);
if (digit == 0) {
if (!onzerostart) {
tap_code16(hex_to_keycode(digit));
send_nibble(digit);
}
} else {
tap_code16(hex_to_keycode(digit));
send_nibble(digit);
onzerostart = false;
}
}

View File

@ -340,34 +340,6 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_
void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) { layer_state_set(update_tri_layer_state(layer_state, layer1, layer2, layer3)); }
void tap_random_base64(void) {
#if defined(__AVR_ATmega32U4__)
uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
#else
uint8_t key = rand() % 64;
#endif
switch (key) {
case 0 ... 25:
send_char(key + 'A');
break;
case 26 ... 51:
send_char(key - 26 + 'a');
break;
case 52:
send_char('0');
break;
case 53 ... 61:
send_char(key - 53 + '1');
break;
case 62:
send_char('+');
break;
case 63:
send_char('/');
break;
}
}
void matrix_init_quantum() {
#ifdef BOOTMAGIC_LITE
bootmagic_lite();
@ -469,40 +441,6 @@ void matrix_scan_quantum() {
# include "hd44780.h"
#endif
// Functions for spitting out values
//
void send_dword(uint32_t number) {
uint16_t word = (number >> 16);
send_word(word);
send_word(number & 0xFFFFUL);
}
void send_word(uint16_t number) {
uint8_t byte = number >> 8;
send_byte(byte);
send_byte(number & 0xFF);
}
void send_byte(uint8_t number) {
uint8_t nibble = number >> 4;
send_nibble(nibble);
send_nibble(number & 0xF);
}
void send_nibble(uint8_t number) { tap_code16(hex_to_keycode(number)); }
__attribute__((weak)) uint16_t hex_to_keycode(uint8_t hex) {
hex = hex & 0xF;
if (hex == 0x0) {
return KC_0;
} else if (hex < 0xA) {
return KC_1 + (hex - 0x1);
} else {
return KC_A + (hex - 0xA);
}
}
void api_send_unicode(uint32_t unicode) {
#ifdef API_ENABLE
uint8_t chunk[4];

View File

@ -238,8 +238,6 @@ layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_
void set_single_persistent_default_layer(uint8_t default_layer);
void tap_random_base64(void);
#define IS_LAYER_ON(layer) layer_state_is(layer)
#define IS_LAYER_OFF(layer) !layer_state_is(layer)
@ -276,12 +274,6 @@ void register_code16(uint16_t code);
void unregister_code16(uint16_t code);
void tap_code16(uint16_t code);
void send_dword(uint32_t number);
void send_word(uint16_t number);
void send_byte(uint8_t number);
void send_nibble(uint8_t number);
uint16_t hex_to_keycode(uint8_t hex);
void led_set_user(uint8_t usb_led);
void led_set_kb(uint8_t usb_led);
bool led_update_user(led_t led_state);

View File

@ -249,4 +249,58 @@ void send_char(char ascii_code) {
if (is_dead) {
tap_code(KC_SPACE);
}
}
}
void send_dword(uint32_t number) {
send_word(number >> 16);
send_word(number & 0xFFFFUL);
}
void send_word(uint16_t number) {
send_byte(number >> 8);
send_byte(number & 0xFF);
}
void send_byte(uint8_t number) {
send_nibble(number >> 4);
send_nibble(number & 0xF);
}
void send_nibble(uint8_t number) {
switch (number & 0xF) {
case 0 ... 9:
send_char(number + '0');
break;
case 10 ... 15:
send_char(number - 10 + 'a');
break;
}
}
void tap_random_base64(void) {
#if defined(__AVR_ATmega32U4__)
uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
#else
uint8_t key = rand() % 64;
#endif
switch (key) {
case 0 ... 25:
send_char(key + 'A');
break;
case 26 ... 51:
send_char(key - 26 + 'a');
break;
case 52:
send_char('0');
break;
case 53 ... 61:
send_char(key - 53 + '1');
break;
case 62:
send_char('+');
break;
case 63:
send_char('/');
break;
}
}

View File

@ -23,10 +23,10 @@
#define SEND_STRING_DELAY(string, interval) send_string_with_delay_P(PSTR(string), interval)
// Look-Up Tables (LUTs) to convert ASCII character to keycode sequence.
extern const uint8_t ascii_to_keycode_lut[128];
extern const uint8_t ascii_to_shift_lut[16];
extern const uint8_t ascii_to_altgr_lut[16];
extern const uint8_t ascii_to_dead_lut[16];
extern const uint8_t ascii_to_keycode_lut[128];
// clang-format off
#define KCLUT_ENTRY(a, b, c, d, e, f, g, h) \
@ -45,3 +45,10 @@ void send_string_with_delay(const char *str, uint8_t interval);
void send_string_P(const char *str);
void send_string_with_delay_P(const char *str, uint8_t interval);
void send_char(char ascii_code);
void send_dword(uint32_t number);
void send_word(uint16_t number);
void send_byte(uint8_t number);
void send_nibble(uint8_t number);
void tap_random_base64(void);