Skip to content

Commit

Permalink
Merge pull request #506 from Yowkees/oled-pressing-keys-439
Browse files Browse the repository at this point in the history
merge and refine: print pressing keys
  • Loading branch information
koron authored Mar 21, 2024
2 parents 8d6a984 + 9d42880 commit 9ef51d9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
55 changes: 40 additions & 15 deletions qmk_firmware/keyboards/keyball/lib/keyball/keyball.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "keyball.h"
#include "drivers/pmw3360/pmw3360.h"

#include <string.h>

const uint8_t CPI_DEFAULT = KEYBALL_CPI_DEFAULT / 100;
const uint8_t CPI_MAX = pmw3360_MAXCPI + 1;
const uint8_t SCROLL_DIV_MAX = 7;
Expand All @@ -40,6 +42,8 @@ keyball_t keyball = {

.scroll_mode = false,
.scroll_div = 0,

.pressing_keys = {' ', ' ', ' ', 0},
};

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -385,15 +389,18 @@ void keyball_oled_render_ballinfo(void) {

void keyball_oled_render_keyinfo(void) {
#ifdef OLED_ENABLE
// Format: `Key : R{row} C{col} K{kc} '{name}`
// Format: `Key : R{row} C{col} K{kc} {name}{name}{name}`
//
// Where `kc` is lower 8 bit of keycode.
// Where `name` is readable label for `kc`, valid between 4 and 56.
// Where `name`s are readable labels for pressing keys, valid between 4 and 56.
//
// `row`, `col`, and `kc` indicates the last processed key,
// but `name`s indicate unreleased keys in best effort.
//
// It is aligned to fit with output of keyball_oled_render_ballinfo().
// For example:
//
// Key : R2 C3 K06 'c
// Key : R2 C3 K06 abc
// Ball: 0 0 0 0
//
uint8_t keycode = keyball.last_kc;
Expand All @@ -402,18 +409,14 @@ void keyball_oled_render_keyinfo(void) {
oled_write_char(to_1x(keyball.last_pos.row), false);
oled_write_P(PSTR(" C"), false);
oled_write_char(to_1x(keyball.last_pos.col), false);
if (keycode) {
oled_write_P(PSTR(" K"), false);
oled_write_char(to_1x(keycode >> 4), false);
oled_write_char(to_1x(keycode), false);
}
if (keycode >= 4 && keycode < 57) {
oled_write_P(PSTR(" '"), false);
char name = pgm_read_byte(code_to_name + keycode - 4);
oled_write_char(name, false);
} else {
oled_advance_page(true);
}
oled_write_P(PSTR(" K"), false);
oled_write_char(to_1x(keycode >> 4), false);
oled_write_char(to_1x(keycode), false);

oled_write_char(' ', false);

// Draw pressing keys.
oled_write(keyball.pressing_keys, false);
#endif
}

Expand Down Expand Up @@ -505,11 +508,33 @@ void housekeeping_task_kb(void) {
}
#endif

static void pressing_keys_update(uint16_t keycode, keyrecord_t *record) {
// Process only valid keycodes.
if (keycode >= 4 || keycode < 57) {
char value = pgm_read_byte(code_to_name + keycode - 4);
char where = ' ';
if (!record->event.pressed) {
// Swap `value` and `where` when releasing.
where = value;
value = ' ';
}
// Rewrite the last `where` of pressing_keys to `value` .
for (int i = KEYBALL_OLED_MAX_PRESSING_KEYCODES - 1; i >= 0; i--) {
if (keyball.pressing_keys[i] == where) {
keyball.pressing_keys[i] = value;
break;
}
}
}
}

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
// store last keycode, row, and col for OLED
keyball.last_kc = keycode;
keyball.last_pos = record->event.key;

pressing_keys_update(keycode, record);

if (!process_record_user(keycode, record)) {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions qmk_firmware/keyboards/keyball/lib/keyball/keyball.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# define KEYBALL_MODEL 44
#endif

#define KEYBALL_OLED_MAX_PRESSING_KEYCODES 3

//////////////////////////////////////////////////////////////////////////////
// Types

Expand Down Expand Up @@ -137,6 +139,9 @@ typedef struct {
uint16_t last_kc;
keypos_t last_pos;
report_mouse_t last_mouse;

// Buffer to indicate pressing keys.
char pressing_keys[KEYBALL_OLED_MAX_PRESSING_KEYCODES + 1];
} keyball_t;

typedef enum {
Expand Down

0 comments on commit 9ef51d9

Please sign in to comment.