1
0
mirror of https://github.com/whowechina/chu_pico.git synced 2024-11-11 22:47:09 +01:00

Optimize AIME commands

This commit is contained in:
whowechina 2024-04-06 11:11:19 +08:00
parent f63dbe7418
commit 7c1c90d121
7 changed files with 68 additions and 26 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
chu_main-backups
Production/PCB/chu_main/*
*-backups
Production/PCB/*/*

Binary file not shown.

@ -1 +1 @@
Subproject commit 75dd5c6af5bd504e10c1dd927c0283efe8a37a37
Subproject commit b69e562e40aa8ec944c7d31f154a7701ecfec881

View File

@ -77,13 +77,14 @@ static void disp_hid()
static void disp_aime()
{
printf("[AIME]\n");
printf(" NFC Module: %s\n", nfc_module_name());
printf(" Virtual AIC: %s\n", chu_cfg->virtual_aic ? "ON" : "OFF");
printf(" NFC Module: %s\n", nfc_module_name());
printf(" Virtual AIC: %s\n", chu_cfg->aime.virtual_aic ? "ON" : "OFF");
printf(" Mode: %d\n", chu_cfg->aime.mode);
}
void handle_display(int argc, char *argv[])
{
const char *usage = "Usage: display [colors|style|tof|sense|hid]\n";
const char *usage = "Usage: display [colors|style|tof|sense|hid|aime]\n";
if (argc > 1) {
printf(usage);
return;
@ -425,25 +426,59 @@ static void handle_nfc()
printf("\n");
}
static void handle_virtual(int argc, char *argv[])
static bool handle_aime_mode(const char *mode)
{
const char *usage = "Usage: virtual <on|off>\n";
if (argc != 1) {
printf("%s", usage);
return;
if (strcmp(mode, "0") == 0) {
chu_cfg->aime.mode = 0;
} else if (strcmp(mode, "1") == 0) {
chu_cfg->aime.mode = 1;
} else {
return false;
}
const char *commands[] = { "on", "off" };
int match = cli_match_prefix(commands, 2, argv[0]);
if (match < 0) {
printf("%s", usage);
return;
}
chu_cfg->virtual_aic = (match == 0);
aime_virtual_aic(chu_cfg->virtual_aic);
aime_set_mode(chu_cfg->aime.mode);
config_changed();
return true;
}
static bool handle_aime_virtual(const char *onoff)
{
if (strcasecmp(onoff, "on") == 0) {
chu_cfg->aime.virtual_aic = 1;
} else if (strcasecmp(onoff, "off") == 0) {
chu_cfg->aime.virtual_aic = 0;
} else {
return false;
}
aime_virtual_aic(chu_cfg->aime.virtual_aic);
config_changed();
return true;
}
static void handle_aime(int argc, char *argv[])
{
const char *usage = "Usage:\n"
" aime mode <0|1>\n"
" aime virtual <on|off>\n";
if (argc != 2) {
printf("%s", usage);
return;
}
const char *commands[] = { "mode", "virtual" };
int match = cli_match_prefix(commands, 2, argv[0]);
bool ok = false;
if (match == 0) {
ok = handle_aime_mode(argv[1]);
} else if (match == 1) {
ok = handle_aime_virtual(argv[1]);
}
if (ok) {
disp_aime();
} else {
printf("%s", usage);
}
}
void commands_init()
@ -460,5 +495,5 @@ void commands_init()
cli_register("save", handle_save, "Save config to flash.");
cli_register("factory", handle_factory_reset, "Reset everything to default.");
cli_register("nfc", handle_nfc, "NFC debug.");
cli_register("virtual", handle_virtual, "Virtual AIC card.");
cli_register("aime", handle_aime, "AIME settings.");
}

View File

@ -38,7 +38,10 @@ static chu_cfg_t default_cfg = {
.joy = 1,
.nkro = 0,
},
.virtual_aic = false,
.aime = {
.mode = 0,
.virtual_aic = 0,
},
};
chu_runtime_t *chu_runtime;

View File

@ -38,7 +38,10 @@ typedef struct __attribute__((packed)) {
uint8_t joy : 4;
uint8_t nkro : 4;
} hid;
bool virtual_aic;
struct {
uint8_t mode : 4;
uint8_t virtual_aic : 4;
} aime;
} chu_cfg_t;
typedef struct {

View File

@ -220,7 +220,8 @@ void init()
i2c_select(I2C_PORT, 1 << 5); // PN532 on IR1 (I2C mux chn 5)
nfc_init();
aime_init(cdc_aime_putc);
aime_virtual_aic(chu_cfg->virtual_aic);
aime_virtual_aic(chu_cfg->aime.virtual_aic);
aime_set_mode(chu_cfg->aime.mode);
cli_init("chu_pico>", "\n << Chu Pico Controller >>\n"
" https://github.com/whowechina\n\n");