-
-
-
Actually ESP8266 12-F, as it good enough run a web server with a few pages and do some limited measurements and control some stuff.
I asked the question to the official section as it's about the editor itself, and not directly related to a specific board. And since I always wondered what it's for I simply had to ask. Thanks.
-
-
-
Hi
my IDE has the default setting "http://www.espruino.com/json". What's the purpose of it?
I build my own firmware with graphics, telnet and ota removed, and didn't run into any issues. Shall I provide my own BOARD.json file, and what's the purpose of this setting, generally? -
My code:
var foo = `bar`;
If I paste it on the left side of the IDE (Web IDE version 0.70.6) it works fine, if I try to upload it from the edit panel it gives the error message "Error: Line 1: Unexpected token ILLEGAL".
I'm using more complex strings also containing both single and double quotes, e.g.
var foo = `console.log('This is "cool".');`; var bar =`Line1 Line2`; //storage.write, storage.read eval(foo); console.log(bar);
A workaround would be
var foo = 'console.log("This is \\\"cool\\\".");';
and
bar="Line1\nLine2"
, but that's hard to write. What's the cause of this error? -
-
-
@Robin: You didn't understood the example, #3 and #4 show something completely different. But I'm sure you'll find a way to get the right numbers somehow.
-
While
((uint64_t)val << 19) / 32000000
does no rounding, but you still have some loss in accuracy unless the number is an integer multiple of "32000000". The final result has only three bytes, as needed for the next steps.I'm too lazy to test the result in JavaScript using a 64 bit math module vs. normal numbers, but in C it is like this:
_#include <stdio.h> //remove the underscore at pos 1, needed for formatting here only int main() { printf("Hello World\n"); __uint64_t a; double b; __uint64_t c; for (long i = 1; i < 0xFFFFFFFF; ++i) { //no errors a = ((__uint64_t)i << 19) / 32000000; b = (__uint64_t)((double)i * 0.016384); c = a - b; if (c != 0) { printf("Err: %d, %d \n", i, c); } } printf("Done\n"); return 0; }
If you want to see more than "Hello World", "Done" change
b = (__uint64_t)((double)i * 0.016384);
tob = (__uint64_t)((float)i * 0.016384);
.It appears that attempting to use floating point to solve a 2's compliment equation is not the way to go as the need is, to shift ones and zeros and not a representation of a number using a mantissa and characteristic.
For me it doesn't look like there's any need to shift ones and zeros. Think about it.
@AkosLukacs:
The source is most likely this file here, found by searching for "<< 19) / 32000000".
For the linked code: A 32 bit frequency value is taken as input, converted to 24 bit (three byte values) with a loss in accuracy of 8 bit. -
A re-implementation from the original C line
uint64_t frf = ((uint64_t)val << 19) / 32000000;
can be re-written to C code using floating point numbers
uint64_t frf = (uint64_t)((float)val * 0.016384);
and then converted to JavaScript:
var frf = Math.round(val * 0.016384);
(0.016384 is equal to Math.pow(2, 19) / 32000000)
-
-
-
is the same size as
var data; data.set(read(register, length));```
This function is used quite often in the examples:
https://www.espruino.com/Reference#l_ArrayBufferView_set -
Just a code snipped:
var addr = 0x76; //chip addr read = function(reg, len) { i2c.writeTo(addr, reg); return i2c.readFrom(addr, len); }; write = function(reg, data) { i2c.writeTo(addr, [reg, data]); }; var register = 0x12 var length = 8 var data = new Uint8Array(length); data.set(read(register, length)); var a1 = (data[0] << 12) | (data[1] << 4) | (data[2] >> 4);
I didn't try/check your code in detail, but I'd suggest to define data (or b) as Uint8Array.
-
In JavaScript there is only "var" to define are a variable, and if it happens to be a number stored/converted to floating point for math operations.
In C you have different data types, there are float and double for floating point numbers, and of course byte, integer, uint64_t etc. A byte is stored using 8 bits. And if you store the number 3 in your byte and divide it by the result is 1, not 1.5. The same is true for uint64_t.
Compiled C should work with uint64_t. I wouldn't go this way and stick with JavaScript for simplicity.
-
Offtopic: Try 0.1+0.2 in nodejs(v10.15.1) and in Espruino (2v04.6).
Results are 0.30000000000000004 for nodejs and 0.3 for Espruino.That's Javascript, and you should always keep in mind how numbers are represented internally.
Ontopic (Espruino 2v04.6)
>Math.pow(2,19) =524288 >915E6*Math.pow(2,19) =479723519999999.9375 >915E6*524288 =479723520000000
and one fix is to manually round the pow result:
>915E6*Math.round(Math.pow(2,19)) =479723520000000 //because >524288 === Math.pow(2,19) =false >524288 === Math.round(Math.pow(2,19)) =true
Another fix is to use 524288 instead of Math.pow(2,19) for this calculation.
And of course that result should be rounded before it is used for binary operations. -
-
A I2C slave isn't that hard to implement, see e.g.
https://github.com/JDat/AtTiny-I2C-master-slave-USI/blob/master/usi_i2c_slave.cI'd say it can be converted to Javascript.
-
No, there's no USB Master stack available on Espruino.
https://www.espruino.com/USB -
setWatch calls a function when the digital input changes, from low to high, from high to low, or in both cases. If you want to read a value every 20ms you'll have to use setInterval. I'd change to:
1) Run every 10ms using setInterval
a) read pot
b)read button/set led
c) send dataIf you move your fader or not, messages are sent every 10ms.
-
-
This code works if there's not much data transfer. But it fails as soon as the bus becomes busy, the event queue will simply overflow (getting events at the bus clock frequency). And you skipped the CS detection in this code completely.
To make it work you must add a logical AND gate with CS and MOSI as inputs, and MOSI as output to the electrical circuit. (Javascript is not fast enough to enable this code (or a setWatch) only after CS was detected).
Or change the Master code and wiring: Instead of using one MOSI and multiple CS change to multiple MOSI lines (one for each slave) without CS.