Skip to content

Commit

Permalink
Default touch map when update from old version
Browse files Browse the repository at this point in the history
  • Loading branch information
whowechina committed Apr 13, 2024
1 parent ccf9fd5 commit 92e9345
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Binary file modified Production/firmware/mai_pico.uf2
Binary file not shown.
25 changes: 25 additions & 0 deletions firmware/src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Runtime is something to share between files.
*/

#include <string.h>

#include "config.h"
#include "save.h"
#include "touch.h"
Expand Down Expand Up @@ -47,6 +49,23 @@ static inline bool in_range(int val, int min, int max)
return (val >= min) && (val <= max);
}

static bool touch_map_valid()
{
uint64_t mask = 0;
for (int i = 0; i < sizeof(mai_cfg->alt.touch); i++) {
if (mai_cfg->alt.touch[i] < 34) {
mask |= 1ULL << mai_cfg->alt.touch[i];
}
}
int keys = 0;
for (int i = 0; i < 34; i++) {
if (mask & (1ULL << i)) {
keys++;
}
}
return keys > 10; // bad data results in low touch key coverage
}

static void config_loaded()
{
if ((mai_cfg->sense.filter & 0x0f) > 3 ||
Expand Down Expand Up @@ -76,6 +95,12 @@ static void config_loaded()
mai_cfg->rgb = default_cfg.rgb;
config_changed();
}

if (!touch_map_valid()) {
memcpy(mai_cfg->alt.touch, default_cfg.alt.touch,
sizeof(mai_cfg->alt.touch));
config_changed();
}
}

void config_changed()
Expand Down

0 comments on commit 92e9345

Please sign in to comment.