Feature: Add map_raw_to_zones(), minor code structure modification

This commit is contained in:
Isoheptane 2024-09-16 15:39:21 +08:00
parent a3e90fb696
commit 2aca017d13
No known key found for this signature in database
GPG Key ID: 21ECF6DDEED59BDF
3 changed files with 13 additions and 8 deletions

View File

@ -22,8 +22,6 @@
#define SENSE_LIMIT_MAX 9
#define SENSE_LIMIT_MIN -9
static uint8_t touch_map[] = TOUCH_MAP;
static void disp_rgb()
{
printf("[RGB]\n");
@ -408,14 +406,10 @@ static void print_readings(const char *title, const uint16_t *raw, int num)
static void handle_raw()
{
static uint16_t zones[36] = {0};
const uint16_t *raw = touch_raw();
const uint16_t *zones = map_raw_to_zones(raw);
printf("Touch raw readings:\n");
const uint16_t *raw = touch_raw();
for (int i = 0; i < 34; i++) {
zones[touch_map[i]] = raw[i];
}
printf(" Sensor: 0: %s, 1: %s 2: %s\n",
touch_sensor_ok(0) ? "OK" : "ERR",

View File

@ -167,6 +167,16 @@ const uint16_t *touch_raw()
return readout;
}
const uint16_t *map_raw_to_zones(const uint16_t* raw) {
static uint16_t zones[36];
for (int i = 0; i < 34; i++) {
zones[touch_map[i]] = raw[i];
}
return zones;
}
bool touch_touched(unsigned key)
{
if (key >= 34) {

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(const uint16_t *raw);
bool touch_sensor_ok(unsigned i);
void touch_update_config();