1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2025-01-31 12:13:47 +01:00

AIC Touch detection and some better naming

This commit is contained in:
whowechina 2024-05-23 20:26:29 +08:00
parent 0a8595ba68
commit e80de1c961
5 changed files with 73 additions and 56 deletions

View File

@ -38,21 +38,23 @@ static void handle_display()
{
printf("[NFC Module]\n");
printf(" %s (%s)\n", nfc_module_name(), nfc_module_version());
printf("[Config]\n");
printf(" Light: RGB-%s LED-%s\n",
printf("[Light]\n");
printf(" RGB-%s, LED-%s\n",
aic_cfg->light.rgb ? "ON" : "OFF",
aic_cfg->light.led ? "ON" : "OFF");
printf(" Level: [%d ~ %d]\n", aic_cfg->light.min, aic_cfg->light.max);
printf("[Reader]\n");
printf(" Virtual AIC: %s\n", aic_cfg->virtual_aic ? "ON" : "OFF");
printf(" Level: Idle-%d, Active-%d\n", aic_cfg->light.level_idle, aic_cfg->light.level_active);
printf(" Mode: %s\n", mode_name(aic_cfg->mode));
if (aic_cfg->mode == MODE_AUTO) {
printf("[Reader]\n");
printf(" Virtual AIC: %s\n", aic_cfg->reader.virtual_aic ? "ON" : "OFF");
printf(" Mode: %s\n", mode_name(aic_cfg->reader.mode));
if (aic_cfg->reader.mode == MODE_AUTO) {
printf(" Detected: %s\n", mode_name(aic_runtime.mode));
}
if ((aic_runtime.mode == MODE_AIME0) || (aic_runtime.mode == MODE_AIME1)) {
printf(" AIME Pattern: %s\n", aime_get_mode_string());
}
if (keypad_is_stuck()) {
printf("\nWarning: Keypad disabled due to key STUCK!\n");
}
@ -99,9 +101,9 @@ static void handle_virtual(int argc, char *argv[])
return;
}
aic_cfg->virtual_aic = (match == 0);
aic_cfg->reader.virtual_aic = (match == 0);
aime_virtual_aic(aic_cfg->virtual_aic);
aime_virtual_aic(aic_cfg->reader.virtual_aic);
config_changed();
}
@ -117,27 +119,29 @@ static void handle_mode(int argc, char *argv[])
return;
}
reader_mode_t newmode = MODE_NONE;
const char *commands[] = { "auto", "aime0", "aime1", "bana" };
int match = cli_match_prefix(commands, 4, argv[0]);
switch (match) {
case 0:
aic_cfg->mode = MODE_AUTO;
newmode = MODE_AUTO;
break;
case 1:
aic_cfg->mode = MODE_AIME0;
newmode = MODE_AIME0;
break;
case 2:
aic_cfg->mode = MODE_AIME1;
newmode = MODE_AIME1;
break;
case 3:
aic_cfg->mode = MODE_BANA;
newmode = MODE_BANA;
break;
default:
printf("%s", usage);
return;
}
aic_runtime.mode = aic_cfg->mode == MODE_AUTO ? MODE_NONE : aic_cfg->mode;
aic_cfg->reader.mode = newmode;
aic_runtime.mode = (newmode == MODE_AUTO) ? MODE_NONE : newmode;
config_changed();
}
@ -184,23 +188,16 @@ static void handle_level(int argc, char *argv[])
return;
}
int min = cli_extract_non_neg_int(argv[0], 0);
if ((min < 0) || (min > 255)) {
printf(usage);
return;
}
int max = cli_extract_non_neg_int(argv[1], 0);
if (max > 255) {
int idle = cli_extract_non_neg_int(argv[0], 0);
int active = cli_extract_non_neg_int(argv[1], 0);
if ((idle < 0) || (idle > 255) ||
(active < 0) || (active > 255)) {
printf(usage);
return;
}
if (max < min) {
max = min;
}
aic_cfg->light.min = min;
aic_cfg->light.max = max;
aic_cfg->light.level_idle = idle;
aic_cfg->light.level_active = active;
config_changed();
handle_display();

View File

@ -13,23 +13,19 @@
aic_cfg_t *aic_cfg;
static aic_cfg_t default_cfg = {
.light = { .min = 24, .max = 128, .rgb = true, .led = true },
.virtual_aic = true,
.mode = MODE_AUTO,
.light = { .level_idle = 24, .level_active = 128, .rgb = true, .led = true },
.reader = { .virtual_aic = true, .mode = MODE_AUTO },
.lcd = { .backlight = 200, }
};
aic_runtime_t aic_runtime;
static void config_loaded()
{
if (aic_cfg->light.min > aic_cfg->light.max) {
aic_cfg->light = default_cfg.light;
config_changed();
}
if ((aic_cfg->mode != MODE_AIME0) &&
(aic_cfg->mode != MODE_AIME1) &&
(aic_cfg->mode != MODE_BANA)) {
aic_cfg->mode = MODE_AUTO;
if ((aic_cfg->reader.mode != MODE_AIME0) &&
(aic_cfg->reader.mode != MODE_AIME1) &&
(aic_cfg->reader.mode != MODE_BANA)) {
aic_cfg->reader.mode = MODE_AUTO;
config_changed();
}
}

View File

@ -13,13 +13,18 @@
typedef struct __attribute__((packed)) {
struct {
uint8_t min;
uint8_t max;
uint8_t level_idle;
uint8_t level_active;
bool rgb;
bool led;
} light;
bool virtual_aic;
uint8_t mode;
struct {
bool virtual_aic;
uint8_t mode;
} reader;
struct {
uint8_t backlight;
} lcd;
uint32_t reserved;
} aic_cfg_t;

View File

@ -265,7 +265,7 @@ static void fade_control(uint32_t delta_ms)
static void fade_render()
{
uint32_t color = apply_level(fading.color, aic_cfg->light.max);
uint32_t color = apply_level(fading.color, aic_cfg->light.level_active);
for (int i = 0; i < RGB_NUM; i++) {
rgb_buf[i] = color;

View File

@ -73,7 +73,7 @@ void report_hid_key()
return;
}
uint16_t keys = keypad_read();
uint16_t keys = aic_runtime.touch ? 0 : keypad_read();
for (int i = 0; i < keypad_key_num(); i++) {
uint8_t code = keymap[i];
uint8_t byte = code / 8;
@ -114,7 +114,7 @@ static void light_mode_update()
bool cardio = cardio_is_available();
if (cardio && !was_cardio) {
light_rainbow(1, 1, aic_cfg->light.min);
light_rainbow(1, 1, aic_cfg->light.level_idle);
}
was_cardio = cardio;
@ -125,12 +125,15 @@ static void core1_loop()
{
while (1) {
if (mutex_try_enter(&core1_io_lock, NULL)) {
if (aic_runtime.touch) {
/* touch screen related things */
}
light_update();
mutex_exit(&core1_io_lock);
}
light_mode_update();
cli_fps_count(1);
sleep_us(500);
sleep_us(100); // critical for flash programming
}
}
@ -188,9 +191,9 @@ static void cardio_run()
if (cardio_is_available()) {
if (card.card_type != NFC_CARD_NONE) {
light_rainbow(30, 0, aic_cfg->light.max);
light_rainbow(30, 0, aic_cfg->light.level_active);
} else {
light_rainbow(1, 3000, aic_cfg->light.min);
light_rainbow(1, 3000, aic_cfg->light.level_idle);
}
}
@ -229,7 +232,7 @@ static void reader_poll_data()
static void reader_detect_mode()
{
if (aic_cfg->mode == MODE_AUTO) {
if (aic_cfg->reader.mode == MODE_AUTO) {
static bool was_active = true; // so first time mode will be cleared
bool is_active = aime_is_active() || bana_is_active();
if (was_active && !is_active) {
@ -237,7 +240,7 @@ static void reader_detect_mode()
}
was_active = is_active;
} else {
aic_runtime.mode = aic_cfg->mode;
aic_runtime.mode = aic_cfg->reader.mode;
}
if (aic_runtime.mode == MODE_NONE) {
@ -323,11 +326,20 @@ static void core0_loop()
save_loop();
cli_fps_count(0);
sleep_ms(1);
}
}
static void identify_touch()
{
gpio_init(AIC_TOUCH_EN);
gpio_set_function(AIC_TOUCH_EN, GPIO_FUNC_SIO);
gpio_set_dir(AIC_TOUCH_EN, GPIO_IN);
gpio_pull_up(AIC_TOUCH_EN);
sleep_us(0);
aic_runtime.touch = !gpio_get(AIC_TOUCH_EN);
}
void init()
{
tusb_init();
@ -337,10 +349,14 @@ void init()
mutex_init(&core1_io_lock);
save_init(0xca340a1c, &core1_io_lock);
light_init();
light_rainbow(1, 0, aic_cfg->light.min);
identify_touch();
keypad_init();
light_init();
light_rainbow(1, 0, aic_cfg->light.level_idle);
if (!aic_runtime.touch) {
keypad_init();
}
nfc_init_i2c(I2C_PORT, I2C_SCL, I2C_SDA, I2C_FREQ);
nfc_init_spi(SPI_PORT, SPI_MISO, SPI_SCK, SPI_MOSI, SPI_RST, SPI_NSS, SPI_BUSY);
@ -348,10 +364,13 @@ void init()
nfc_set_wait_loop(wait_loop);
aime_init(cdc_reader_putc);
aime_virtual_aic(aic_cfg->virtual_aic);
aime_virtual_aic(aic_cfg->reader.virtual_aic);
bana_init(cdc_reader_putc);
if (aic_runtime.touch) {
/* touch screen related things */
}
cli_init("aic_pico>", "\n << AIC Pico >>\n"
" https://github.com/whowechina\n\n");