Skip to content

Commit

Permalink
Optimize AIME commands
Browse files Browse the repository at this point in the history
  • Loading branch information
whowechina committed Apr 6, 2024
1 parent a69bc79 commit ccf9fd5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
Binary file modified Production/firmware/mai_pico.uf2
Binary file not shown.
60 changes: 48 additions & 12 deletions firmware/src/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static void disp_aime()
printf("[AIME]\n");
printf(" NFC Module: %s\n", nfc_module_name());
printf(" Virtual AIC: %s\n", mai_cfg->aime.virtual_aic ? "ON" : "OFF");
printf(" Mode: %d\n", mai_cfg->aime.mode);
}

static void disp_gpio()
Expand Down Expand Up @@ -534,25 +535,60 @@ static void handle_touch(int argc, char *argv[])
}
}

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) {
mai_cfg->aime.mode = 0;
} else if (strcmp(mode, "1") == 0) {
mai_cfg->aime.mode = 1;
} else {
return false;
}
aime_set_mode(mai_cfg->aime.mode);
config_changed();
return true;
}

const char *commands[] = { "on", "off" };
int match = cli_match_prefix(commands, 2, argv[0]);
if (match < 0) {
static bool handle_aime_virtual(const char *onoff)
{
if (strcasecmp(onoff, "on") == 0) {
mai_cfg->aime.virtual_aic = 1;
} else if (strcasecmp(onoff, "off") == 0) {
mai_cfg->aime.virtual_aic = 0;
} else {
return false;
}
aime_virtual_aic(mai_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;
}

mai_cfg->aime.virtual_aic = (match == 0);
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]);
}

aime_virtual_aic(mai_cfg->aime.virtual_aic);
config_changed();
if (ok) {
disp_aime();
} else {
printf("%s", usage);
}
}

void commands_init()
Expand All @@ -571,5 +607,5 @@ void commands_init()
cli_register("gpio", handle_gpio, "Set GPIO pins for buttons.");
cli_register("touch", handle_touch, "Custimze touch mapping.");
cli_register("factory", config_factory_reset, "Reset everything to default.");
cli_register("virtual", handle_virtual, "Virtual AIC card on AIME.");
cli_register("aime", handle_aime, "AIME settings.");
}
3 changes: 2 additions & 1 deletion firmware/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ static mai_cfg_t default_cfg = {
.touch = TOUCH_MAP,
},
.aime = {
.virtual_aic = false,
.mode = 0,
.virtual_aic = 0,
}
};

Expand Down
3 changes: 2 additions & 1 deletion firmware/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ typedef struct __attribute__((packed)) {
uint8_t touch[36];
} alt;
struct {
bool virtual_aic;
uint8_t mode : 4;
uint8_t virtual_aic : 4;
} aime;
} mai_cfg_t;

Expand Down
1 change: 1 addition & 0 deletions firmware/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ void init()
nfc_attach_i2c(I2C_PORT);
nfc_init();
aime_init(cdc_aime_putc);
aime_set_mode(mai_cfg->aime.mode);
aime_virtual_aic(mai_cfg->aime.virtual_aic);

cli_init("mai_pico>", "\n << Mai Pico Controller >>\n"
Expand Down

0 comments on commit ccf9fd5

Please sign in to comment.