-
I use Espruino with TypeScript and was a bit disappointed at the time that the Typescript goal of the last campaign was not reached.
So I tried to generated a file
espruino.d.ts
by myself but gave up. It's seems not possible to generate good TypeScript definitions from the other type files (e.g. espruino.json). There are more informations required than available:// This class should be automatically generated. class I2C { // ... readFrom( address: number | { address: number, stop: boolean }, quantity: number ): Uint8Array; }
But the corresponding jswrap comment is
/*JSON{ "type" : "method", "class" : "I2C", "name" : "readFrom", "generate" : "jswrap_i2c_readFrom", "params" : [ ["address","JsVar","The 7 bit address of the device to request bytes from, or an object of the form `{address:12, stop:false}` to send this data without a STOP signal."], ["quantity","int32","The number of bytes to request"] ], "return" : ["JsVar","The data that was returned - as a Uint8Array"], "return_object" : "Uint8Array" } Request bytes from the given slave device, and return them as a Uint8Array (packed array of bytes). This is like using Arduino Wire's requestFrom, available and read functions. Sends a STOP */
The important information of parameter address is only in the description. :-(
Currently it is required to write the TypeScript type definition by hand but there is always the risk that the type file will become outdated.
@Gordon: Do you have an idea how it can go on in the long term?
-
Breakout board with MAX30100
http://www.ebay.de/itm/182342028548 -
When using the switch you need pin 5 of the rotary too.
Rotary → Pico
5 → 3.3V
3 → B5 (or any other input pin)As @ClearMemory041063 mentioned above it is easy to watch a pin:
// some untested code pinMode(B5, "input_pulldown"); setWatch( function( event ) { console.log( event.state ? "Button released" : "Button pressed") }, B5, { repeat: true, debounce: 50 });
-
-
-
-
-
@user70843
Are you serious about that? My first thought was: It's a joke. But why on Dec 3rd? May be April Fools' Day in another country? :-)Java was used in a variety of things ...
My two cents to the importance of Java - unrelated to Espruino.
Java is really dead - running as applet in the browser!
On the server side it is very popular. The biggest shopping systems, ERP, telecommunication, banking, energy sector applications, .. a majority of the "enterprise" things run on Java.
By the way the most popular mobile platform is largely built with Java.Java and JavaScript are both not common in embedded programming. But latter is changing with Espruino. ;-)
-
Yes, that's possible.
There is indeed some kind of caching inside the WebIDE. I use a minification proxy so I can see all requests to http://www.espruino.com/modules. Normally a press to "Send to Espruino" fetches the required modules. But sometimes it doesn't. Even a restart of the WebIDE and the controller does not help in this case!
After a while it works again.It would really help to know the reason and have some kind of (manually) cache clearing.
-
I don't know the current state of the WebIDE but a few weeks ago the "Advanced" option did not work in general. The reason is that calls to the Espruino API will be minified/renamed too.
http://forum.espruino.com/conversations/292590/#comment13205984
-
What minification settings are used to make this trick work?
There are no special minification settings required. Your module will be minified during the build of the website with the Google Closure Compiler, more precisly the Closure Compiler Service API in optimization level 'SIMPLE_OPTIMIZATIONS'.
The minifier knows among other things that
CONFIG.OS_NOTBUSY
is not used and removed this variable/property. This works without additional development effort.If you want further minification (about 1/3 smaller) then you could use ADVANCED_MINIFACTION. You have to create an *.externs file which references your public module API. This is an easy task, but additional testing of the minified module is required!
For the ADS1X15 it would look like:
ADS1X15.externs:
var ads = exports.connect( null ); ads.setGain; ads.getADC; ads.setAddr; ads.getADCVoltage;
The BME280 is a module which uses advance minification:
https://github.com/espruino/EspruinoDocs/blob/f09eaf4d68c9d772f020291341439b2560100d20/devices/BME280.externs
https://github.com/espruino/EspruinoDocs/blob/f09eaf4d68c9d772f020291341439b2560100d20/devices/BME280.js -
I'm in the process of migrating my modules from using callbacks to promises. The code looks much tidier.
But I run into trouble with
Promise.all(..)
First question: Why is there no output?
var promise = new Promise( function(resolve,reject) { resolve(); } ); Promise.all( [promise] ).then( function() { print( "never called :-(" ); } );
It works when I wrap the code into a function call:
function start() { var promise = new Promise( function(resolve,reject) { resolve(); } ); Promise.all( [promise] ).then( function() { print( "called :-)" ); } ); } start();
Second question: The results of the promises seems to be circular shifted.
function start() { var promiseTwo = new Promise( function(resolve,reject) { resolve(1); } ) .then( function( n ) { return 2; } ); var promiseFour = new Promise( function( resolve, reject ) { resolve(4); } ); Promise.all( [promiseTwo, promiseFour] ).then( function( numbers ) { console.log( "expecting 2, got " + numbers[0] ); // got 4 console.log( "expecting 4, got " + numbers[1] ); // got 2 } ); } start();
-
-
I had a similar problem with an infrared temperature sensor a few month ago - sadly without finding the bug: http://forum.espruino.com/conversations/280634/#comment12743705
@ChristianW
Could you try out the pin configurationI2C1.setup( { scl: B8, sda: B9 } );
?
This would be really nice and would help to verify/falsify my voodoo theory that I2C1 is different in some kind of initialisation and that the cause are not the concrete pins (B6, B7).For completeness: I have a lot of (>10) different I2C devices which work on I2C1 without any problem.
-
If you need a higher data rate then a different sensor could be an alternative.
The DHT22 is not state-of-the-art anymore (proprietary protocol, power consumption, low temperature accuracy, no heating support to prevent condensation). It was one of the first affordable humidity sensors but today there are many better alternatives with Espruino support (SHT2x, SHT3x, HTU21D, BME280, ..).One of the cheapest is the HTU21D/SHT21: http://www.ebay.com/itm/112049178633
-
In general: If you want to minify a JavaScript program with Google Closure Compiler in "Advanced Minification" mode then you need an *.externs file for every library which is not part of the minification step. The builtin functions are not part of the minification. So an extern file is required. Advanced minification is useless without an externs file.
I've attached an espruino.externs file which I use for module minification. But it must be built into the WebIDE code to be sent to the minification service.
I did it for module minification some time ago:
https://github.com/espruino/EspruinoDocs/blob/master/bin/minify.js#L18
https://github.com/espruino/EspruinoDocs/blob/master/bin/minify.js#L41The same simple logic must be built into the WebIDE. Then advanced minification would work there too. But I don't know the source code of the WebIDE. Sorry.
-
-
The sample code above is the result of a two-step transpilation (TypeScript, Google Closure with advanced minification): mod.ts → mod.js → mod.min.js.
The original TypeScript code is
class SHT1x { constructor( options: SHT1xOptions, onReady?: () => void ) { … } // Propiatary CRC checksum calculation for SHTx - has nothing to do with a real CRC calculation! private static calculateCrcChecksum( data: number, initialCrcValue: number ): number { … } }
I can remove the "static" keyword but it wouldn't be 100% semantically correct because there could be more instances of SHT1x and the checksum method does not need any instance variables. Nevertheless it's a good workaround.
Otherwise it would be good to know the origin of the problem. So the current Espruino rule to work around the bug is: Don't use class methods at all?
I have to check other modules I contributed:
-
The following module code throws an exception:
// constructor function function PengMod(a) { // "a" will be resolved with the method a not with the locale variable a. console.log( a ); if (a !== "hello" ) throw Error("Bug!"); } // This function masks the local variable a in the constructor!!! PengMod.a = function () { }; new PengMod( "hello" );
The code is a snippet from a larger module which must be minified because of its size. I cannot rename the method oder variable because the names come from a minification step with name mangling. The transpiler always starts in every new scope with a, b, c, .
Any ideas?
-
I would like to use the new Promise API introduced in 1v86 but I'm not able to get even the simplest scenarios to work.
Should the Espruino promises work like the normal ES6 promises?The following code should output 1 1 2 4 but does 1 1 1 1. A bug or a feature? ;-)
var p = new Promise( function(resolve) { resolve(1); }); p.then( function(value) { console.log(value); // 1 return value + 1; }).then( function(value) { console.log(value); // 2 return new Promise( function( resolve ) { resolve( 4 ); } ); }).then( function( value ) { console.log( value ); // 4 } ); p.then(function(value) { console.log(value); // 1 });
-
I don't have a Micro:bit up to now but I've read that the magnetometer chip in the Micro:bit is the MAG3110 from Freescale. We have an Espruino module for the MAG3110 which supports all features of the sensor (e.g. different operation modes). It's fully tested with a MAG3110 evaluation board.
@Stev
If the Micro:bit has enough memory for using the MAG3110-module then you could experiment with this. -
-
Yes, the HTU21D is a SHT2x clone or vice versa.
Tomorrow I can check the module with a real sensor, but I already think it will work for me. There hasn't been any code change since I last tried it.
@Jean-Philippe_Rey
Could you try the other methods? Especially the synchronous variants
readTemperature
andreadHumidity
. I'm a little surprised, as the CRC-check didn't show any errors.Which board do you use? I tested the module with a Pico.