-
Thanks, so this will ensure that not messing up global vars with the same name.
analogReadMedian = function(p, sampleCount) { var i, median; var samples = Math.floor(sampleCount); var analogValues = new Array(samples); // read analog values into array i = samples; while(i--) analogValues[i] = analogRead(p); //sort array, smalest first and largest last analogValues.sort(function(a, b){return a-b;}); // set median i = Math.floor(samples/2); if ( samples % 2 ){ //even median = (analogValues[i]+analogValues[i+1])/2; } else { // odd median = analogValues[i]; } return median; };
-
Thanks for naming the median filtering technic, using this now for several devices running Espruino. Works fine for me with sampleCount = 21.
analogReadMedian = function(p, sampleCount) { var samples = Math.floor(sampleCount); var analogValues = new Array(samples); // read analog values into array i = samples; while(i--) analogValues[i] = analogRead(p); //sort array, smalest first and largest last analogValues.sort(function(a, b){return a-b;}); // set median i = Math.floor(samples/2); if ( samples % 2 ){ //even median = (analogValues[i]+analogValues[i+1])/2; } else { // odd median = analogValues[i]; } return median; };
-
can confirm that fix is working as expected
test snippet:
var Wifi = require("Wifi"); var i = 1; var sleep = 7000; setInterval(function(){ console.log("run:",i++); Wifi.ping("192.168.194.1", function(rc){ console.log("ping result",rc); }); console.log("process.memory().free",process.memory().free); },sleep);
output:
run: 1 process.memory().free 1524 ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 20, "seqNo": 341, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0, "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 11, "seqNo": 343, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 3, "seqNo": 344, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0, "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 } run: 2 process.memory().free 1524 ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0, "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0, "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 27, "seqNo": 348, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1, "seqNo": 349, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1, "seqNo": 350, "timeoutCount": 0, "bytes": 32, "error": 0 } run: 3 process.memory().free 1524 ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 6, "seqNo": 351, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1, "seqNo": 352, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1, "seqNo": 353, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 4, "seqNo": 354, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2, "seqNo": 355, "timeoutCount": 0, "bytes": 32, "error": 0 } run: 4 process.memory().free 1524 ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 5, "seqNo": 356, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2, "seqNo": 357, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2, "seqNo": 358, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2, "seqNo": 359, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1, "seqNo": 360, "timeoutCount": 0, "bytes": 32, "error": 0 } run: 5 process.memory().free 1524 ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 9, "seqNo": 361, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 3, "seqNo": 362, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2, "seqNo": 363, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 3, "seqNo": 364, "timeoutCount": 0, "bytes": 32, "error": 0 } ping result { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2, "seqNo": 365, "timeoutCount": 0, "bytes": 32, "error": 0 }
-
@Gordon, thanks for checking and fixing it !
-
-
@Gordon is 9600 the transfer rate the IDE switch to when setting to slow communication?
-
-
-
-
-
-
Wow this sound great to me and I am a big fan of your resizable vector font as this is one of Espruino's unique features.
Like this very much about the new resizable font:
It uses half as much flash memory
You can choose the line width you want
It's faster to render when drawing single pixel width fontsWell things always change.
What about: you keep
g.setFontVector(s)
and calculate the scaling factor to have a backward like compatibility as this could help not to mess up with the formatting of existing projects. -
Try E.setTimeZone() to correct the time zone.
-
-
-
Hi @btrut
when I try to connect i reports no_ap_found (and list command to find ap's reports an empty array),
please make sure you use latest Wifi.scan() syntax
-
check your flash_id and lookup your memory
esptool.py --port "$COMPORT" --baud 460800 flash_id Manufacturer: e0 Device: 4016 Detected flash size: 4MB
- get a new release of esptool.py
- read README_flash.txt which is part of the tgz file in comment #11
Hope this helps you to find the correct setting to flash your board.
- get a new release of esptool.py
-
-
Hi SergeP,
as Gordon pointed out:
Read the documentation first
there is no return for setTimeout()Guess you are looking for setInterval().
-
-
-
Like to share how to write a module containing a class
// modules/stopWatch.js class stopWatch { constructor() { var timeStart = 0; var timeStop = 0; } // Method start() start() { this.timeStart = Date.now(); this.timeStop = 0; } // Method stop() stop() { this.timeStop = Date.now(); } // Method duration() duration(){ return this.timeStop-this.timeStart; } } exports = stopWatch
and use it.
// projects/test_class_stopWatch.js stopWatch = new (require('stopWatch'))(); function onInit(){ stopWatch.start(); setTimeout( function(){ stopWatch.stop(); console.log('duration in sec: ', ( stopWatch.duration() / 1000 ).toFixed(2) ); }, 1000); } setTimeout(onInit,1000);
// output
duration in sec: 1.00
From @allObjects: Date().toDateString() Formatting pattern characters