mirror of
https://github.com/whowechina/chu_pico.git
synced 2025-01-31 12:03:43 +01:00
More commands
This commit is contained in:
parent
2eb1d66fcc
commit
3659448a82
Binary file not shown.
BIN
doc/cmd.png
BIN
doc/cmd.png
Binary file not shown.
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 41 KiB |
@ -64,6 +64,8 @@ static int match_prefix(const char *str[], int num, const char *prefix)
|
|||||||
|
|
||||||
static void handle_help(int argc, char *argv[])
|
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");
|
printf("Available commands:\n");
|
||||||
for (int i = 0; i < num_commands; i++) {
|
for (int i = 0; i < num_commands; i++) {
|
||||||
printf("%*s: %s\n", max_cmd_len + 2, commands[i], helps[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]);
|
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[])
|
static void handle_hid(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
const char *usage = "Usage: hid <joy|nkro|both>\n";
|
const char *usage = "Usage: hid <joy|nkro|both>\n";
|
||||||
@ -424,6 +448,7 @@ void cmd_init()
|
|||||||
register_command("?", handle_help, "Display this help message.");
|
register_command("?", handle_help, "Display this help message.");
|
||||||
register_command("display", handle_display, "Display all config.");
|
register_command("display", handle_display, "Display all config.");
|
||||||
register_command("fps", handle_fps, "Display FPS.");
|
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("hid", handle_hid, "Set HID mode.");
|
||||||
register_command("tof", handle_tof, "Set ToF config.");
|
register_command("tof", handle_tof, "Set ToF config.");
|
||||||
register_command("filter", handle_filter, "Set pre-filter config.");
|
register_command("filter", handle_filter, "Set pre-filter config.");
|
||||||
|
@ -22,11 +22,9 @@
|
|||||||
|
|
||||||
#define MPR121_ADDR 0x5A
|
#define MPR121_ADDR 0x5A
|
||||||
|
|
||||||
static uint16_t baseline[36];
|
|
||||||
static int16_t error[36];
|
|
||||||
static uint16_t readout[36];
|
static uint16_t readout[36];
|
||||||
static bool touched[36];
|
|
||||||
static uint16_t touch[3];
|
static uint16_t touch[3];
|
||||||
|
static unsigned touch_count[36];
|
||||||
|
|
||||||
void slider_init()
|
void slider_init()
|
||||||
{
|
{
|
||||||
@ -44,9 +42,21 @@ void slider_init()
|
|||||||
|
|
||||||
void slider_update()
|
void slider_update()
|
||||||
{
|
{
|
||||||
|
static uint16_t last_touched[3];
|
||||||
|
|
||||||
touch[0] = mpr121_touched(MPR121_ADDR);
|
touch[0] = mpr121_touched(MPR121_ADDR);
|
||||||
touch[1] = mpr121_touched(MPR121_ADDR + 1);
|
touch[1] = mpr121_touched(MPR121_ADDR + 1);
|
||||||
touch[2] = mpr121_touched(MPR121_ADDR + 2);
|
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()
|
const uint16_t *slider_raw()
|
||||||
@ -65,6 +75,19 @@ bool slider_touched(unsigned key)
|
|||||||
return touch[key / 12] & (1 << (key % 12));
|
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()
|
void slider_update_config()
|
||||||
{
|
{
|
||||||
for (int m = 0; m < 3; m++) {
|
for (int m = 0; m < 3; m++) {
|
||||||
|
@ -14,5 +14,8 @@ void slider_update();
|
|||||||
bool slider_touched(unsigned key);
|
bool slider_touched(unsigned key);
|
||||||
const uint16_t *slider_raw();
|
const uint16_t *slider_raw();
|
||||||
void slider_update_config();
|
void slider_update_config();
|
||||||
|
unsigned slider_count(unsigned key);
|
||||||
|
void slider_reset_stat();
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user