Merge pull request #19 from Isoheptane/better-raw

Feature: raw command with individual sensor readings and zone readings
This commit is contained in:
whowechina 2024-09-17 20:27:43 +08:00 committed by GitHub
commit 8ede2429fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 33 additions and 13 deletions

View File

@ -395,30 +395,40 @@ static void handle_debounce(int argc, char *argv[])
disp_sense();
}
static void print_raw_zones(const char *title, const uint16_t *raw, int num)
static void print_readings(const char *title, const uint16_t *raw, int num)
{
printf(" %s |", title);
for (int i = 0; i < num; i++) {
printf(" %3d |", raw[i]);
printf(" %4d |", raw[i]);
}
printf("\n");
}
static void handle_raw()
{
printf("Touch raw readings:\n");
const uint16_t *raw = touch_raw();
const uint16_t *zones = map_raw_to_zones(raw);
printf("Touch raw readings:\n");
printf(" Sensor: 0: %s, 1: %s 2: %s\n",
touch_sensor_ok(0) ? "OK" : "ERR",
touch_sensor_ok(1) ? "OK" : "ERR",
touch_sensor_ok(2) ? "OK" : "ERR");
printf(" Sensor readings:\n");
printf(" |___1__|___2__|___3__|___4__|___5__|___6__|___7__|___8__|___9__|__10__|__11__|__12__|\n");
print_readings("0", raw, 12);
print_readings("1", raw + 12, 12);
print_readings("2", raw + 24, 12);
printf(" |__1__|__2__|__3__|__4__|__5__|__6__|__7__|__8__|\n");
print_raw_zones("A", raw, 8);
print_raw_zones("B", raw + 8, 8);
print_raw_zones("C", raw + 16, 2);
print_raw_zones("D", raw + 18, 8);
print_raw_zones("E", raw + 26, 8);
printf(" Zone readings:\n");
printf(" |___1__|___2__|___3__|___4__|___5__|___6__|___7__|___8__|\n");
print_readings("A", zones, 8);
print_readings("B", zones + 8, 8);
print_readings("C", zones + 16, 2);
print_readings("D", zones + 18, 8);
print_readings("E", zones + 26, 8);
}
static void handle_whoami()

View File

@ -155,17 +155,26 @@ bool touch_sensor_ok(unsigned i)
const uint16_t *touch_raw()
{
static uint16_t readout[36];
uint16_t buf[36];
static uint16_t readout[36] = {0};
// Do not use readout as buffer directly, update readout with buffer when operation finishes
uint16_t buf[36] = {0};
for (int i = 0; i < 3; i++) {
sensor_ok[i] = mpr121_raw(MPR121_BASE_ADDR + i, buf + i * 12, 12);
}
memcpy(readout, buf, sizeof(readout));
return readout;
}
const uint16_t *map_raw_to_zones(uint16_t* raw) {
static uint16_t zones[36];
for (int i = 0; i < 34; i++) {
readout[touch_map[i]] = buf[i];
zones[touch_map[i]] = raw[i];
}
return readout;
return zones;
}
bool touch_touched(unsigned key)

View File

@ -29,6 +29,7 @@ uint64_t touch_touchmap();
void touch_set_map(unsigned sensor, unsigned key);
const uint16_t *touch_raw();
const uint16_t *map_raw_to_zones(uint16_t *raw);
bool touch_sensor_ok(unsigned i);
void touch_update_config();