Default touch map when update from old version

This commit is contained in:
whowechina 2024-04-13 12:12:25 +08:00
parent ccf9fd547d
commit 92e93451f9
2 changed files with 25 additions and 0 deletions

Binary file not shown.

View File

@ -6,6 +6,8 @@
* Runtime is something to share between files.
*/
#include <string.h>
#include "config.h"
#include "save.h"
#include "touch.h"
@ -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 ||
@ -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()