Skip to content

Commit

Permalink
WIP: use modifier and code for every key
Browse files Browse the repository at this point in the history
  • Loading branch information
eworm-de committed May 25, 2023
1 parent b52e28c commit 1ef0b56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
13 changes: 9 additions & 4 deletions 3keys_1knob.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void USB_ISR(void) __interrupt(INT_NO_USB) {

// structur with key details
struct key {
uint8_t mod;
char code;
uint8_t last;
uint8_t count;
Expand Down Expand Up @@ -90,7 +91,8 @@ void handle_key(uint8_t current, struct key * key, uint8_t * neo) {
key->count = 0; // reset counter (to zero)
if(key->last) { // key was pressed?
if(neo) *neo = NEO_MAX; // light up corresponding NeoPixel
KBD_type(key->code); // press and release
//KBD_type(key->code); // press and release
KBD_type_mod_code(key->mod, key->code);
}
else { // key was released?
// nothing to do in this case
Expand All @@ -99,7 +101,8 @@ void handle_key(uint8_t current, struct key * key, uint8_t * neo) {
else if(key->last) { // key still being pressed?
if(neo) *neo = NEO_MAX; // keep NeoPixel on
if((key->count)++ > KEY_REPEAT_DELAY) { // key is still pressed, repeat!
KBD_type(key->code); // press and release (again)
//KBD_type(key->code); // press and release (again)
KBD_type_mod_code(key->mod, key->code);
key->count -= KEY_REPEAT_RATE; // reset counter (for rate)
}
}
Expand Down Expand Up @@ -132,7 +135,8 @@ void main(void) {

// TODO: Read eeprom for key characters
for (i = 0; i < 6; i++) {
keys[i].code = (char)eeprom_read_byte(i);
keys[i].mod = (char)eeprom_read_byte(i * 2);
keys[i].code = (char)eeprom_read_byte(i * 2 + 1);
keys[i].last = 0;
keys[i].count = 0;
}
Expand All @@ -158,7 +162,8 @@ void main(void) {
}

if(currentKnobKey) {
KBD_press(currentKnobKey->code); // press corresponding key ...
//KBD_press(currentKnobKey->code); // press corresponding key ...
KBD_type_mod_code(currentKnobKey->mod, currentKnobKey->code);
}
else {
KBD_releaseAll(); // ... or release last key
Expand Down
10 changes: 10 additions & 0 deletions include/usb_conkbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ void KBD_print(char* str) {
while(*str) KBD_type(*str++);
}

// TEST...
void KBD_type_mod_code(uint8_t mod, uint8_t code) {
KBD_report[1] = mod;
KBD_report[3] = code;
KBD_sendReport();
KBD_report[1] = 0;
KBD_report[3] = 0;
KBD_sendReport();
}

// ===================================================================================
// Press a consumer key on keyboard
// ===================================================================================
Expand Down
1 change: 1 addition & 0 deletions include/usb_conkbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void KBD_release(uint8_t key); // release a key on keyboard
void KBD_type(uint8_t key); // press and release a key on keyboard
void KBD_releaseAll(void); // release all keys on keyboard
void KBD_print(char* str); // type some text on the keyboard
void KBD_type_mod_code(uint8_t mod, uint8_t code);

void CON_press(uint16_t key); // press a consumer key on keyboard
void CON_release(uint16_t key); // release a consumer key on keyboard
Expand Down

0 comments on commit 1ef0b56

Please sign in to comment.