ROI setting in CLI

This commit is contained in:
whowechina 2024-09-26 19:30:43 +08:00
parent 5c6411c847
commit 47b8ae203b
8 changed files with 49 additions and 4 deletions

Binary file not shown.

Binary file not shown.

View File

@ -77,7 +77,7 @@ void airkey_init()
tof_models[i] = TOF_VL53L1X; tof_models[i] = TOF_VL53L1X;
tof_init_ok[i] = vl53l1x_init_tof(); tof_init_ok[i] = vl53l1x_init_tof();
vl53l1x_setROISize(4, 4); vl53l1x_setROISize(geki_cfg->tof.roi, geki_cfg->tof.roi);
vl53l1x_setDistanceMode(Short); vl53l1x_setDistanceMode(Short);
vl53l1x_setMeasurementTimingBudget(20000); vl53l1x_setMeasurementTimingBudget(20000);
vl53l1x_startContinuous(20); vl53l1x_startContinuous(20);
@ -92,7 +92,7 @@ static bool readings[AIRKEY_NUM];
static void print_tof(const char *name, uint16_t mm) static void print_tof(const char *name, uint16_t mm)
{ {
printf("\t%s: %3d", name, mm > 1000 ? 0 : mm); //printf("\t%s: %3d", name, mm > 1000 ? 0 : mm);
} }
static void tof_read() static void tof_read()
@ -108,7 +108,7 @@ static void tof_read()
print_tof("L1x", tof_dist[i]); print_tof("L1x", tof_dist[i]);
} }
} }
printf("\n"); //printf("\n");
} }
#define BETWEEN(x, a, b) (((x) >= (a)) && ((x) <= (b))) #define BETWEEN(x, a, b) (((x) >= (a)) && ((x) <= (b)))
@ -176,3 +176,13 @@ const char *airkey_tof_model(unsigned tof_id)
return "Unknown"; return "Unknown";
} }
} }
void airkey_tof_update_roi()
{
for (int i = 0; i < TOF_NUM; i++) {
if (tof_models[i] == TOF_VL53L1X) {
vl53l1x_use(i);
vl53l1x_setROISize(geki_cfg->tof.roi, geki_cfg->tof.roi);
}
}
}

View File

@ -18,4 +18,6 @@ bool airkey_get(unsigned id);
unsigned airkey_tof_num(); unsigned airkey_tof_num();
const char *airkey_tof_model(); const char *airkey_tof_model();
void airkey_tof_update_roi();
#endif #endif

View File

@ -60,6 +60,8 @@ static void disp_tof()
printf(" TOF %d: %s", i, airkey_tof_model(i)); printf(" TOF %d: %s", i, airkey_tof_model(i));
} }
printf("\n"); printf("\n");
printf(" ROI: %d (only for VL53L1X)", geki_cfg->tof.roi);
printf("\n");
} }
static void disp_aime() static void disp_aime()
@ -244,6 +246,28 @@ static void handle_lever(int argc, char *argv[])
disp_lever(); disp_lever();
} }
static void handle_tof(int argc, char *argv[])
{
const char *usage = "Usage: tof roi <4..16>\n";
if ((argc != 2) || (strncasecmp(argv[0], "roi", strlen(argv[0])) != 0)) {
printf(usage);
return;
}
int roi = cli_extract_non_neg_int(argv[1], 0);
if ((roi < 4) || (roi > 16)) {
printf(usage);
return;
}
geki_cfg->tof.roi = roi;
airkey_tof_update_roi();
config_changed();
disp_tof();
}
static void handle_save() static void handle_save()
{ {
save_request(true); save_request(true);
@ -349,6 +373,7 @@ void commands_init()
cli_register("level", handle_level, "Set LED brightness level."); cli_register("level", handle_level, "Set LED brightness level.");
cli_register("hid", handle_hid, "Set HID mode."); cli_register("hid", handle_hid, "Set HID mode.");
cli_register("lever", handle_lever, "Lever related settings."); cli_register("lever", handle_lever, "Lever related settings.");
cli_register("tof", handle_tof, "Tof tweaks.");
cli_register("volume", handle_volume, "Sound feedback volume settings."); cli_register("volume", handle_volume, "Sound feedback volume settings.");
cli_register("save", handle_save, "Save config to flash."); cli_register("save", handle_save, "Save config to flash.");
cli_register("factory", handle_factory_reset, "Reset everything to default."); cli_register("factory", handle_factory_reset, "Reset everything to default.");

View File

@ -19,6 +19,10 @@ static geki_cfg_t default_cfg = {
.level = 128, .level = 128,
.reserved = { 0 }, .reserved = { 0 },
}, },
.tof = {
.roi = 12,
.reserved = { 0 },
},
.sound = { .sound = {
.volume = 127, .volume = 127,
.reserved = { 0 }, .reserved = { 0 },

View File

@ -30,6 +30,10 @@ typedef struct __attribute__((packed)) {
uint8_t volume; uint8_t volume;
uint8_t reserved[3]; uint8_t reserved[3];
} sound; } sound;
struct {
uint8_t roi;
uint8_t reserved[7];
} tof;
struct { struct {
uint8_t joy : 4; uint8_t joy : 4;
uint8_t nkro : 4; uint8_t nkro : 4;