MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / onReady

Function onReady

examples/io/firmata/client/main.js:24–77  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 new FirmataClientTCP({
23 address: ServerAddress,
24 onReady() {
25 const poco = new this.Poco;
26 const black = poco.makeColor(0, 0, 0);
27 const blue = poco.makeColor(0, 0, 255);
28 const green = poco.makeColor(0, 255, 0);
29 poco.begin();
30 poco.fillRectangle(black, 0, 0, poco.width, poco.height);
31 poco.end();
32
33 /* let localButton = */ new DigitalBank({
34 pins: 0x01,
35 bank: 0,
36 mode: Digital.Input,
37 falls: 0x01,
38 onReadable() {
39 if (this.read())
40 return;
41
42 poco.begin();
43 poco.fillRectangle(black, 0, 0, poco.width, poco.height);
44 poco.end();
45 }
46 });
47
48 let i2c = new this.I2C({
49 address: 0x38,
50 onReadable() {
51 let data = new Uint8Array(this.read());
52 if (1 === data.length) { // returned number of touch points
53 if (data[0]) { // non-zero number of touch points
54 this.write(Uint8Array.of(3)) // register 3 - touch points
55 this.read(6 * data[0]); // 6 bytes for each touch point
56 return;
57 }
58 }
59 else { // returned touch point data
60 for (let offset = 0; offset < data.length; offset += 6) {
61 const id = data[offset + 2] >> 4;
62 // const state = data[offset] >> 6;
63 const x = ((data[offset] & 0x0F) << 8) | data[offset + 1];
64 const y = ((data[offset + 2] & 0x0F) << 8) | data[offset + 3];
65 poco.begin(x - 10, y - 10, 20, 20);
66 poco.fillRectangle(id ? blue : green, 0, 0, poco.width, poco.height);
67 poco.end();
68 }
69 }
70
71 this.write(Uint8Array.of(2)) // register 2 - number of touch points
72 this.read(1); // one byte
73 }
74 });
75 i2c.write(Uint8Array.of(2)) // register 2 - number of touch points
76 i2c.read(1); // read one byte
77 },
78 onReadyx() {
79 const poco = new this.Poco;
80 // const white = poco.makeColor(255, 255, 255);

Callers

nothing calls this directly

Calls 6

makeColorMethod · 0.95
beginMethod · 0.95
fillRectangleMethod · 0.95
endMethod · 0.95
writeMethod · 0.95
readMethod · 0.95

Tested by

no test coverage detected