From 91075268b1e1836cab1653d331ee6e5eb3a2a927 Mon Sep 17 00:00:00 2001 From: Peter Hoddie Date: Thu, 16 Mar 2023 11:45:06 -0700 Subject: [PATCH] update JavaScript ECMA-419 touch driver to sync with #1065. Also, clean-up. --- modules/drivers/sensors/ft6206/ft6206.js | 68 +++++++++++++----------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/modules/drivers/sensors/ft6206/ft6206.js b/modules/drivers/sensors/ft6206/ft6206.js index bbb4d18a2f..6f75456f2a 100644 --- a/modules/drivers/sensors/ft6206/ft6206.js +++ b/modules/drivers/sensors/ft6206/ft6206.js @@ -24,41 +24,49 @@ class FT6206 { address: 0x38, ...sensor }); - io.buffer = new Uint8Array(12); // two touch points - - if (reset) { - io.reset = new reset.io({ - ...reset - }); + + try { + io.buffer = new Uint8Array(12); // two touch points + + if (reset) { + io.reset = new reset.io({ + ...reset + }); + + io.reset.write(0); + Timer.delay(5); + io.reset.write(1); + Timer.delay(150); + } - io.reset.write(0); - Timer.delay(5); - io.reset.write(1); - Timer.delay(150); - } + const vendor = io.readUint8(0xA8); + if ((17 !== vendor) && (1 !== vendor)) + throw new Error("unexpected vendor"); - if (17 !== io.readUint8(0xA8)) - throw new Error("unexpected vendor"); + const id = io.readUint8(0xA3); + if ((6 !== id) && (100 !== id)) + throw new Error("unexpected chip"); - const id = io.readUint8(0xA3); - if ((6 !== id) && (100 !== id)) - throw new Error("unexpected chip"); + if (interrupt && onSample) { + io.interrupt = new interrupt.io({ + ...interrupt, + edge: interrupt.io.Falling, + onReadable: onSample.bind(this) + }); + } + if (target) + this.target = target; - if (interrupt && onSample) { - io.interrupt = new interrupt.io({ - ...interrupt, - edge: interrupt.io.Falling, - onReadable: onSample.bind(this) + this.configure({ + active: false, + threshold: 128, + timeout: 10 }); } - if (target) - this.target = target; - - this.configure({ - active: false, - threshold: 128, - timeout: 10 - }); + catch (e) { + this.close(); + throw e; + } } close() { this.#io?.reset?.close(); @@ -125,7 +133,7 @@ class FT6206 { delete io.none; const data = io.buffer; - const count = io.readBuffer(0x03, data); + io.readBuffer(0x03, data); const result = new Array(length); for (let i = 0; i < length; i++) { const offset = i * 6;