Skip to content

Commit af9b5ba

Browse files
stc1988mkellner
authored andcommitted
migrate M5StackCoreTouch to ECMA 419
1 parent 9647b29 commit af9b5ba

3 files changed

Lines changed: 36 additions & 27 deletions

File tree

build/devices/esp32/targets/m5stack_cores3/M5StackCoreS3Touch.js

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022-2023 Moddable Tech, Inc.
2+
* Copyright (c) 2022-2025 Moddable Tech, Inc.
33
*
44
* This file is part of the Moddable SDK Runtime.
55
*
@@ -29,35 +29,28 @@ import Touch from "embedded:sensor/Touch/FT6x06";
2929
class M5StackCoreTouch extends Touch {
3030
#captured; // undefined or pressed button instance
3131

32-
constructor(options) {
33-
super({
34-
sensor: {
35-
...device.I2C.internal,
36-
io: device.io.SMBus
37-
}
38-
});
39-
}
40-
41-
read(points) {
42-
super.read(points);
32+
constructor(options) {
33+
super(options);
34+
}
4335

44-
if (!globalThis.button) {
45-
return;
46-
}
47-
if (this.#captured) {
48-
if (0 === points[0].state) {
49-
this.#captured.write(0);
50-
this.#captured = undefined;
36+
sample() {
37+
const points = super.sample();
38+
if (globalThis.button && points) {
39+
if (this.#captured) {
40+
if (0 === points.length) {
41+
this.#captured.write(0);
42+
this.#captured = undefined;
43+
}
44+
} else if (points.length && points[0].y >= 200) {
45+
this.#captured =
46+
button[
47+
String.fromCharCode("a".charCodeAt() + Math.idiv(points[0].x, 107))
48+
];
49+
this.#captured?.write(1);
5150
}
52-
} else if (1 === points[0].state && points[0].y >= 200) {
53-
this.#captured =
54-
button[
55-
String.fromCharCode("a".charCodeAt() + Math.idiv(points[0].x, 107))
56-
];
57-
this.#captured?.write(1);
5851
}
5952

60-
if (this.#captured) points[0].state = 0;
53+
return points;
6154
}
6255
}
6356

build/devices/esp32/targets/m5stack_cores3/host/provider.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import SMBus from "embedded:io/smbus";
2929
import SPI from "embedded:io/spi";
3030
import PulseWidth from "embedded:io/pulsewidth";
3131
import RTC from "embedded:RTC/BM8563"
32+
import Touch from "M5StackCoreS3Touch";
33+
3234

3335
const device = {
3436
I2C: {
@@ -94,6 +96,21 @@ const device = {
9496
});
9597
}
9698
}
99+
},
100+
sensor :{
101+
Touch: class {
102+
constructor(options) {
103+
const result = new Touch({
104+
...options,
105+
sensor: {
106+
...device.I2C.internal,
107+
io: device.io.SMBus,
108+
}
109+
});
110+
result.configure({threshold: 20});
111+
return result;
112+
}
113+
}
97114
}
98115
};
99116

build/devices/esp32/targets/m5stack_cores3/manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"frameSize": "QVGA"
2323
},
2424
"virtualButton": false,
25-
"touch": "M5StackCoreS3Touch",
2625
"startupSound": "bflatmajor.maud"
2726
},
2827
"modules": {

0 commit comments

Comments
 (0)