Created
March 16, 2018 21:40
-
-
Save jackhumbert/1d9f9f16185bd28c61d662aaba411059 to your computer and use it in GitHub Desktop.
encoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static uint8_t encoder_state = 0; | |
static int8_t encoder_value = 0; | |
static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; | |
void matrix_init_user(void) { | |
encoder_state = PIND & 0x3; | |
} | |
void matrix_scan_user(void) { | |
encoder_state <<= 2; | |
encoder_state |= (PIND & 0x3); | |
encoder_value += encoder_LUT[encoder_state & 0xF]; | |
if (encoder_value >= 4) { | |
register_code(KC_PGUP); | |
unregister_code(KC_PGUP); | |
} | |
if (encoder_value <= -4) { | |
register_code(KC_PGDN); | |
unregister_code(KC_PGDN); | |
} | |
encoder_value %= 4; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment