mongoose-os-libs / esp32-touchpad

JS bindings for ESP32 touch pad sensor
Other
6 stars 0 forks source link

Trouble with identifying which touch pad triggered interrupt using sample code #2

Open coleg012 opened 4 years ago

coleg012 commented 4 years ago

I'm getting trouble with identifying which touch pad triggered interrupt using sample code:

TouchPad.isrRegister(function(st) {
  // st is a bitmap with 1 bit per sensor.
  print('Status:', st);
}, null);

I initialized 6 touch pads and tried to touch few of them and print output is always 'Status: 1008' which is binary 11 1111 0000‬. Two questions regarding this.

  1. I understand that only one bit shall be set if touching single touch pad. Why in my example 6 bits are set. Coincidentally, 6 pins has been initialized: 'Pin12-T5', 'Pin13-T4', 'Pin14-T6', 'Pin27-T7', 'Pin32-T9', 'Pin33-T8'.
  2. Shouldn't Status be of different value while touching different pins?

Environment: mos version: The Mongoose OS command line tool Version: 2.17.0 Build ID: 20200204-173507/2.17.0-g18c1939 Update channel: release OS: Windows 10 Home 64 bits

Let me know if more details are needed.

coleg012 commented 4 years ago

Here is modified code example to reproduce this issue (see lines //ISSUE: st will have bits set for all pads (i.e. 776 or 11 0000 1000), even if only one of them has been touched //Expected 10 0000 0000 for T9, 01 0000 0000 for T8, 00 0000 1000 for T4 ):

`load('api_esp32_touchpad.js');

let ts1 = TouchPad.GPIO[32]; //T9 let ts2 = TouchPad.GPIO[33]; //T8 let ts3 = TouchPad.GPIO[15]; //T4

TouchPad.init(); TouchPad.filterStart(10); TouchPad.setMeasTime(0x1000, 0xffff); TouchPad.setVoltage(TouchPad.HVOLT_2V4, TouchPad.LVOLT_0V8, TouchPad.HVOLT_ATTEN_1V5); TouchPad.config(ts1, 0); TouchPad.config(ts2, 0); TouchPad.config(ts3, 0); Sys.usleep(100000); // wait a bit for initial filtering. let noTouchVal1 = TouchPad.readFiltered(ts1); let touchThresh1 = noTouchVal1 2 / 3; let noTouchVal2 = TouchPad.readFiltered(ts2); let touchThresh2 = noTouchVal2 2 / 3; let noTouchVal3 = TouchPad.readFiltered(ts3); let touchThresh3 = noTouchVal3 * 2 / 3; TouchPad.setThresh(ts1, touchThresh1); TouchPad.setThresh(ts2, touchThresh2); TouchPad.setThresh(ts3, touchThresh3);

TouchPad.isrRegister(function(st) { // st is a bitmap with 1 bit per sensor. //ISSUE: st will have bits set for all pads (i.e. 776 or 11 0000 1000), even if only one of them has been touched //Expected 10 0000 0000 for T9, 01 0000 0000 for T8, 00 0000 1000 for T4
print('Status1:', st); }, null); TouchPad.intrEnable();`