Yeah!... got my first module running... in the sandbox... anyway... thanks for the posts Writing modular code using "require" at http://forum.espruino.com/conversations/256773. I knew about and used the Web available modules from repository only, so far... Now I can easily QA the modules locally before thinking about publishing for use from the Web.
I created a folder, registered it in Web IDE Settings - Project - Sandbox, and placed the TOUCH.js module file in the sandbox's modules folder.
The TOUCH module is now at a stage where I need to combine the TOUCH SCREEN with the LCD for calibration purposes to finish the implementations of the onTouch, onTrack (while touching) and onUp functions. The TOUCH module goes into calibration mode on a very long touch - 5 [s] - with 'no' movement/dragging (<10%) anywhere on the screen. Calibration mode will show spots on the LCD to touch / tap. The spots' x-y coordinates are then formula-mapped to the related, read x-y coordinate values (0.000..0.999) for the calculation of the x-y pixel coordinates of the 240 horizontal x 320 vertical (2.8" TFT 262K Color) LCD.
The TOUCH module usage example (sampling/polling interval on tracking/while touching is 100 [ms] / 10Hz / 10 times per second - defined in .C.trkIv constant):
var cnt = -1, cnt2;
require("TOUCH").connect(C0,C1,C2,C3, // suggested default ADC pins
function(touch,x,y,t){ // --- onDown callback function
cnt2 = 0; console.log(++cnt,cnt2,"onDown:",x,"-",y,"@",t);
touch.onTrack(
function(touch,x,y,t){ // --- onTrack callback function
console.log(cnt,++cnt2,"onTrack:",x,"-",y,"@",t);
},function(touch,x,y,t){ // --- onUp callback function
// x, y, t values are the same as touch.x1, .y1, and .t1 values
console.log(cnt,++cnt2,"onUp:",touch.x0,"-",touch.y0," X ",touch.x1,"-",touch.y1);
console.log("...in ",touch.t1 - touch.t0,"[ms]");
touch.xy(); console.log("up:",touch.x,"-",touch.y);
});
});
The examples output:
The first number on line - cnt - counts the touches, second number counts the track events. Lines with 5 dots (.....) indicated removed ('redundandent/boring' ) output to keep post conciser.
All short touches / taps were actually longer then the tracking 100[ms] / 0.1[s] interval / 10Hz
onUp: row shows the down and up touch/untouch coordinate values.
The onUp: values are the same as the last onTrack ones...If there is no onTrack event - in other words: the touch was of shorter duration than the tracking interval (of 0.1 [s]) - then the values are the same as the onDown ones.
For first touch the measured (typical) values for up: are shown (not blanked out).
Tracking including the (slow) console output used less than 10% of elapsed time: the code made it to 46 of theoretical 50 track points before entering the calibration (placeholder).
More applications samples - from very simple to quite advanced will be posted at a later time.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Yeah!... got my first module running... in the sandbox... anyway... thanks for the posts Writing modular code using "require" at http://forum.espruino.com/conversations/256773. I knew about and used the Web available modules from repository only, so far... Now I can easily QA the modules locally before thinking about publishing for use from the Web.
I created a folder, registered it in Web IDE Settings - Project - Sandbox, and placed the TOUCH.js module file in the sandbox's modules folder.
The TOUCH module is now at a stage where I need to combine the TOUCH SCREEN with the LCD for calibration purposes to finish the implementations of the onTouch, onTrack (while touching) and onUp functions. The TOUCH module goes into calibration mode on a very long touch - 5 [s] - with 'no' movement/dragging (<10%) anywhere on the screen. Calibration mode will show spots on the LCD to touch / tap. The spots' x-y coordinates are then formula-mapped to the related, read x-y coordinate values (0.000..0.999) for the calculation of the x-y pixel coordinates of the 240 horizontal x 320 vertical (2.8" TFT 262K Color) LCD.
The TOUCH module so far:
The TOUCH module usage example (sampling/polling interval on tracking/while touching is 100 [ms] / 10Hz / 10 times per second - defined in .C.trkIv constant):
The examples output:
The first number on line - cnt - counts the touches, second number counts the track events. Lines with 5 dots (.....) indicated removed ('redundandent/boring' ) output to keep post conciser.
Notes:
#require #module #localmodule