diff --git a/Production/Firmware/chu_pico.uf2 b/Production/Firmware/chu_pico.uf2 index 8d162f6..2652006 100644 Binary files a/Production/Firmware/chu_pico.uf2 and b/Production/Firmware/chu_pico.uf2 differ diff --git a/doc/cmd.png b/doc/cmd.png index 991ec30..8efac07 100644 Binary files a/doc/cmd.png and b/doc/cmd.png differ diff --git a/firmware/src/cmd.c b/firmware/src/cmd.c index 6a80eaa..b7566d3 100644 --- a/firmware/src/cmd.c +++ b/firmware/src/cmd.c @@ -64,6 +64,8 @@ static int match_prefix(const char *str[], int num, const char *prefix) static void handle_help(int argc, char *argv[]) { + printf("\n << Chu Pico Controller >>\n"); + printf(" https://github.com/whowechina\n\n"); printf("Available commands:\n"); for (int i = 0; i < num_commands; i++) { printf("%*s: %s\n", max_cmd_len + 2, commands[i], helps[i]); @@ -183,6 +185,28 @@ static void handle_fps(int argc, char *argv[]) printf("FPS: core 0: %d, core 1: %d\n", fps[0], fps[1]); } +static void handle_stat(int argc, char *argv[]) +{ + if (argc == 0) { + for (int col = 0; col < 4; col++) { + printf(" %2dA |", col * 4 + 1); + for (int i = 0; i < 4; i++) { + printf("%6u|", slider_count(col * 8 + i * 2)); + } + printf("\n B |"); + for (int i = 0; i < 4; i++) { + printf("%6u|", slider_count(col * 8 + i * 2 + 1)); + } + printf("\n"); + } + } else if ((argc == 1) && + (strncasecmp(argv[0], "reset", strlen(argv[0])) == 0)) { + slider_reset_stat(); + } else { + printf("Usage: stat [reset]\n"); + } +} + static void handle_hid(int argc, char *argv[]) { const char *usage = "Usage: hid \n"; @@ -424,6 +448,7 @@ void cmd_init() register_command("?", handle_help, "Display this help message."); register_command("display", handle_display, "Display all config."); register_command("fps", handle_fps, "Display FPS."); + register_command("stat", handle_stat, "Display or reset statistics."); register_command("hid", handle_hid, "Set HID mode."); register_command("tof", handle_tof, "Set ToF config."); register_command("filter", handle_filter, "Set pre-filter config."); diff --git a/firmware/src/slider.c b/firmware/src/slider.c index d2ce142..ba55e29 100644 --- a/firmware/src/slider.c +++ b/firmware/src/slider.c @@ -22,11 +22,9 @@ #define MPR121_ADDR 0x5A -static uint16_t baseline[36]; -static int16_t error[36]; static uint16_t readout[36]; -static bool touched[36]; static uint16_t touch[3]; +static unsigned touch_count[36]; void slider_init() { @@ -44,9 +42,21 @@ void slider_init() void slider_update() { + static uint16_t last_touched[3]; + touch[0] = mpr121_touched(MPR121_ADDR); touch[1] = mpr121_touched(MPR121_ADDR + 1); touch[2] = mpr121_touched(MPR121_ADDR + 2); + + for (int m = 0; m < 3; m++) { + uint16_t just_touched = touch[m] & ~last_touched[m]; + last_touched[m] = touch[m]; + for (int i = 0; i < 12; i++) { + if (just_touched & (1 << i)) { + touch_count[m * 12 + i]++; + } + } + } } const uint16_t *slider_raw() @@ -65,6 +75,19 @@ bool slider_touched(unsigned key) return touch[key / 12] & (1 << (key % 12)); } +unsigned slider_count(unsigned key) +{ + if (key >= 32) { + return 0; + } + return touch_count[key]; +} + +void slider_reset_stat() +{ + memset(touch_count, 0, sizeof(touch_count)); +} + void slider_update_config() { for (int m = 0; m < 3; m++) { diff --git a/firmware/src/slider.h b/firmware/src/slider.h index 75518dc..abce09b 100644 --- a/firmware/src/slider.h +++ b/firmware/src/slider.h @@ -14,5 +14,8 @@ void slider_update(); bool slider_touched(unsigned key); const uint16_t *slider_raw(); void slider_update_config(); +unsigned slider_count(unsigned key); +void slider_reset_stat(); + #endif