mirror of
https://github.com/whowechina/mai_pico.git
synced 2024-11-11 23:27:10 +01:00
Merge pull request #19 from Isoheptane/better-raw
Feature: raw command with individual sensor readings and zone readings
This commit is contained in:
commit
8ede2429fa
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user