Giter Club home page Giter Club logo

espruinotools's Introduction

Espruino JavaScript for Microcontrollers

 _____                 _
|   __|___ ___ ___ _ _|_|___ ___
|   __|_ -| . |  _| | | |   | . |
|_____|___|  _|_| |___|_|_|_|___|
          |_|

https://www.espruino.com           Join the chat at https://gitter.im/espruino/Espruino

About

Espruino is a JavaScript interpreter for microcontrollers. It is designed for devices with as little as 128kB Flash and 8kB RAM.

Please support Espruino by ordering one of our official boards or donating.

Documentation

If you have an Espruino board, please read the Quick Start Guide first.

Browse the Espruino Website (try using search in the top right), and read the FAQ.

There's also a Reference for JavaScript commands as well as Tutorials. However the documentation on the Espruino website will match the version available for download but not the latest version on GitHub.

Builds for the Espruino Board and Pico Board (built automatically for each Git commit) are available from here.

Other documentation of use is:

Support / Bugs

First, please try and check that your problem hasn't already been found or covered on our forum.

Submit bugs with clear steps to reproduce them: a small test case (not your whole program), and an actual and expected result. If you can't come up with these, please post on the forum first as it may just be something in your code that we can help out with.

Work on Espruino is supported by sales of our boards.

If your board isn't made by us but came pre-installed with Espruino then you should contact the manufacturers.

We try and support users of the boards we sell, but if you bought a non-official board your issue may not get addressed. In this case, please consider donating to help cover the time it takes to fix problems (even so, we can't guarantee to fix every problem).

License

Please see the LICENSE file.

Building

Check out the page on building Espruino.

Testing

There are a bunch of tests in the tests directory. See tests/README.md for examples on how to run them.

Current State

The officially supported boards are the best supported. They come pre-installed with Espruino and you are able to easily download and flash the latest versions of Espruino to them.

While Espruino can run on other boards, we make no money from them and so cannot afford to test, fix or support the firmware on them. We're dependent on the community.

You can download binaries from https://www.espruino.com/Download.

If you are a board manufacturer interested in getting your board officially supported, please check out this page.

For a list of supported boards, please see the boards folder.

Main supported platforms are:

  • STM32 (F1, F3, F4, L4)
  • nRF52
  • nRF51
  • ESP8266
  • ESP32
  • Linux

Espruino has been ported to other boards and platforms (such as EFM32 and SAMD), but these have a habit of being contributed and then never maintained. All boards that this has happened to reside in the UNMAINTAINED_BOARDS branch.

Modification

Check out the documentation on the build process first - this should clear up a lot of potential questions about the Espruino architecture.

Please see CONTRIBUTING.md for some hints about code style/etc.

You can auto-build documentation for all source files - see doxygen/README.md

Any more questions? ask on the forum.

Porting to new devices

If you're using an existing architecture everything can be done from boards/BOARDNAME.py. See a similar board's .py file as an example.

However for a new architecture there are a bunch of different files to modify.

  • boards/*.py files describe the CPU, available pins, and connections - so the relevant linker script, headers + docs can be created
  • boards/pins/*.csv are copies of the 'pin definitions' table in the chip's datasheet. They are read in for STM32 chips by the boards/*.py files, but they are not required - see boards/MICROBIT.py for an example.
  • Global build options are handled in Makefile
  • The make directory contains arch-specific Makefile fragments
  • Extra libraries like USB/LCD/filesystem are in Makefile
  • Processor-specific code in targets/ARCH - eg. targets/stm32, targets/linux
  • Processor-specific libs (like the SDK) in targetlibs/ARCH
  • src/jshardware.h is effectively a simple abstraction layer for SPI/I2C/etc, which should be implemented in targets/ARCH/jshardware.c

Adding libraries

  • Create jswrap_mylib.c/h in libs/
  • Create library functions (see examples in other jswrap files, also the comments in scripts/common.py)

See libs/README.md for a short tutorial on how to add your own libraries.

Using Espruino in your Projects

If you're using Espruino for your own personal projects - go ahead, we hope you have fun - and please let us know what you do with it on https://www.espruino.com/Forum!

If you're planning on selling the Espruino software on your own board, please:

  • Let us know, we might be able to help.
  • Read the terms of the MPLv2 Licence that Espruino is distributed under, and make sure you comply with it
  • MPLv2 dictates that any files that you modify must be made available in source form. New files that you create don't need to be made available (although we'd encourage it!)
  • You won't be able to call your board an 'Espruino' board unless it's agreed with us (we own the trademark)
  • You must explain clearly in your documentation that your device uses Espruino internally
  • Please don't fork Espruino - improvements get very hard to share, and in the long run everyone loses.
  • Please give something back to the project - be it code improvements, documentation or support.

We spend a lot of time supporting Espruino on the forums, but can only do so because we make money from the sales of Espruino boards. If your users request support from us then we have absolutely no obligation to help them. However, we'll be a lot more motivated if you're actively helping to improve Espruino for all its users (not just your own).

espruinotools's People

Contributors

2114l3 avatar beaufortfrancois avatar canyoncasa avatar chalkers avatar d3nd3 avatar ernstnaezer avatar fanoush avatar franzo- avatar g1itcher avatar gfwilliams avatar goodwid avatar haraldkubota avatar ignigena avatar jurelik avatar mariusgundersen avatar nkrkv avatar opichals avatar pankleks avatar pastaclub avatar pelrun avatar reillyeon avatar rigrig avatar rm-rf-etc avatar rsmeral avatar totalus avatar trevorjtclarke avatar xorbit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

espruinotools's Issues

Compiler: cache symbol table lookups

Currently, if I write:

function f() {
  "compiled";
  a = 1;
  a = 2;
  a = 3;
}

It does 3 symbol table lookups for a. Ideally it'd look a up once and then stick it on the stack for future use.

Refactor Serial port libraries

  1. Move throttling into a common module
  2. Allow multiple different interfaces to appear in one 'getPorts' - enabling stuff like TCPIP and Audio connections to be shown alongside standard Serial

Serial port implementation is not returning ArrayBuffers

Receiving this error intermittently, seems to occur while typing a command:
Serial port implementation is not returning ArrayBuffers

Running espruino like this:
espruino -p /dev/cu.usbmodem1411

Is the problem in the serial.js file?

Dave

FTDI Name conflict with port validation

I came across a strange issue that blocks me from uploading to an Adafruit Huzzah breakout (ESP8266) via FTDI.

FTDI Name: /dev/tty.usbserial-A103QO50

The port flag is validating with: next.indexOf("-")

Solution would be to allow '-', but not allow flags. I have fixed this locally by changing to:
next.substring(0,1) !== '-'. I am not certain this will work in all scenarios, but it is allowing my FTDI to communicate properly.

See: https://github.com/espruino/EspruinoTools/blob/gh-pages/bin/espruino-cli.js#L17

As noted, I have it working locally, and will send a PR for review shortly.
Cheers!

gyp error while installing in node on OSX (missing windows.h)

I have node v6.9.1 installed on my mac (running OSX 10.11.6). While I am installing espruino command line tools with npm install -g espruino i get the error below. Why is windows.h needed?

chatwin:~ piovac$ npm install -g espruino
/usr/local/var/nvm/versions/node/v6.9.1/bin/espruino -> /usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/espruino/bin/espruino-cli.js

> [email protected] install /usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/espruino/node_modules/xpc-connection
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  CXX(target) Release/obj.target/binding/src/XpcConnection.o
../src/XpcConnection.cpp:143:44: warning: 'GetRealNamedProperty' is deprecated
      [-Wdeprecated-declarations]
      Local<Value> propertyValue = object->GetRealNamedProperty(property...
                                           ^
/Users/piovac/.node-gyp/6.9.1/include/node/v8.h:2923:30: note:
      'GetRealNamedProperty' has been explicitly marked deprecated here
                Local<Value> GetRealNamedProperty(Local<String> key));
                             ^
1 warning generated.
  SOLINK_MODULE(target) Release/binding.node
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9

> [email protected] install /usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/espruino/node_modules/serialport
> node-pre-gyp install --fallback-to-build

[serialport] Success: "/usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/espruino/node_modules/serialport/build/Release/serialport.node" is installed via remote

> [email protected] install /usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/espruino/node_modules/winnus
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
  CXX(target) Release/obj.target/winnus/cpp/winnus.o
../cpp/winnus.cpp:3:9: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma warning (disable: 4068)
        ^
../cpp/winnus.cpp:10:10: fatal error: 'windows.h' file not found
#include <windows.h>
         ^
1 warning and 1 error generated.
make: *** [Release/obj.target/winnus/cpp/winnus.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
gyp ERR! System Darwin 15.6.0
gyp ERR! command "/usr/local/var/nvm/versions/node/v6.9.1/bin/node" "/usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/var/nvm/versions/node/v6.9.1/lib/node_modules/espruino/node_modules/winnus
gyp ERR! node -v v6.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
/usr/local/var/nvm/versions/node/v6.9.1/lib
└─┬ [email protected]
  ├── [email protected]
  ├── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ └── [email protected]
  │ └─┬ [email protected]
  │   └── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ └── [email protected]
  │ └── [email protected]
  ├── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ └── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├─┬ [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ └── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ └── [email protected]
  │ │ └─┬ [email protected]
  │ │   └── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ └── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ └── [email protected]
  │ │ └─┬ [email protected]
  │ │   ├── [email protected]
  │ │   ├── [email protected]
  │ │   ├── [email protected]
  │ │   ├─┬ [email protected]
  │ │   │ └── [email protected]
  │ │   ├── [email protected]
  │ │   ├─┬ [email protected]
  │ │   │ └── [email protected]
  │ │   ├── [email protected]
  │ │   ├── [email protected]
  │ │   └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ └── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├─┬ [email protected]
  │ │ └── [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ └── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ └── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ └─┬ [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   └── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ ├── [email protected]
  │ │ │ │ │ └─┬ [email protected]
  │ │ │ │ │   └── [email protected]
  │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ └── [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ └── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ └── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ ├── [email protected]
  │ │ │ │ │ ├── [email protected]
  │ │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ │ └── [email protected]
  │ │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ │ └── [email protected]
  │ │ │ │ │ └── [email protected]
  │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ ├── [email protected]
  │ │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ │ └── [email protected]
  │ │ │ │ │ ├── [email protected]
  │ │ │ │ │ └── [email protected]
  │ │ │ │ └─┬ [email protected]
  │ │ │ │   └── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ ├── [email protected]
  │ │ │ │ ├─┬ [email protected]
  │ │ │ │ │ ├── [email protected]
  │ │ │ │ │ ├── [email protected]
  │ │ │ │ │ └── [email protected]
  │ │ │ │ └─┬ [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   ├── [email protected]
  │ │ │ │   └── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ ├── [email protected]
  │ │ │ └── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ └─┬ [email protected]
  │ │ │   ├── [email protected]
  │ │ │   ├─┬ [email protected]
  │ │ │   │ └── [email protected]
  │ │ │   ├── [email protected]
  │ │ │   ├─┬ [email protected]
  │ │ │   │ └─┬ [email protected]
  │ │ │   │   ├── [email protected]
  │ │ │   │   └── [email protected]
  │ │ │   ├─┬ [email protected]
  │ │ │   │ └── [email protected]
  │ │ │   └── [email protected]
  │ │ ├── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ ├── [email protected]
  │ │ │ ├─┬ [email protected]
  │ │ │ │ └── [email protected]
  │ │ │ └── [email protected]
  │ │ └─┬ [email protected]
  │ │   ├─┬ [email protected]
  │ │   │ └── [email protected]
  │ │   ├─┬ [email protected]
  │ │   │ ├── [email protected]
  │ │   │ └── [email protected]
  │ │   ├─┬ [email protected]
  │ │   │ ├── [email protected]
  │ │   │ └─┬ [email protected]
  │ │   │   └─┬ [email protected]
  │ │   │     ├── [email protected]
  │ │   │     └── [email protected]
  │ │   ├─┬ [email protected]
  │ │   │ └── [email protected]
  │ │   ├─┬ [email protected]
  │ │   │ ├── [email protected]
  │ │   │ ├── [email protected]
  │ │   │ ├── [email protected]
  │ │   │ ├── [email protected]
  │ │   │ ├── [email protected]
  │ │   │ ├── [email protected]
  │ │   │ └── [email protected]
  │ │   └── [email protected]
  │ └─┬ [email protected]
  │   ├─┬ [email protected]
  │   │ └── [email protected]
  │   ├── [email protected]
  │   └── [email protected]
  ├─┬ [email protected]
  │ ├── [email protected]
  │ ├─┬ [email protected]
  │ │ ├── [email protected]
  │ │ ├── [email protected]
  │ │ ├─┬ [email protected]
  │ │ │ └── [email protected]
  │ │ └─┬ [email protected]
  │ │   └─┬ [email protected]
  │ │     ├── [email protected]
  │ │     ├─┬ [email protected]
  │ │     │ └── [email protected]
  │ │     ├─┬ [email protected]
  │ │     │ └─┬ [email protected]
  │ │     │   ├── [email protected]
  │ │     │   └── [email protected]
  │ │     ├── [email protected]
  │ │     └── [email protected]
  │ ├── [email protected]
  │ └─┬ [email protected]
  │   └── [email protected]
  └── [email protected]

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bluetooth-hci-socket@^0.5.1 (node_modules/espruino/node_modules/noble/node_modules/bluetooth-hci-socket):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux,android,win32","arch":"any"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/espruino/node_modules/winnus):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

would connect over usb-uart or tcp, but get a bluetooth Error

Hi,

i use a ESP32 and a Windows7 Laptop and Espruino Command-line Tool 0.1.13.
In the web ide the devices get connected, over COM7 USB2UART or tcp://192....:23

As far as I've read BLE is not supportet yet for the ESP32.
But this should not couse problems, because I don't use Bluetooth at all.

Equaly if I try

espruino -p COM7
espruino -p "COM7"
espruino -p "tcp://192.168.178.56:23"
espruino -p "tcp://192.168.178.56:2323" (why the other Port? I've seen it here)

I get:

Espruino Command-line Tool 0.1.13
-----------------------------------

connecting to ''tcp://192.168.178.56:23''                                   
C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\bluetoo
th-hci-socket\lib\usb.js:70                                                 
throw new Error('No compatible USB Bluetooth 4.0 device found!');       
^                                                                       
                                                                        
Error: No compatible USB Bluetooth 4.0 device found!
at BluetoothHciSocket.bindUser (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\bluetooth-hci-socket\lib\usb.js:70:11)
at BluetoothHciSocket.bindRaw (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\bluetooth-hci-socket\lib\usb.js:28:8)
at Hci.init (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\noble\lib\hci-socket\hci.js:101:35)
at NobleBindings.init (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\noble\lib\hci-socket\bindings.js:82:13)
at Noble.<anonymous> (C:\Users\name\AppData\Roaming\npm\node_modules\espruino\node_modules\noble\lib\noble.js:57:24)

at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:695:11)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3

But why?

Merge modules before minification

Add a minification option that converts module code of the form:

// these lines currently get added by the ide
Modules.removeAllCached();
Modules.addModule("x","exports.foo = function() {console.log('Hello'); };exports.unused = 42;");
// actual code
var a = require("x");
a.foo();

to something like:

// these lines currently get added by the ide
var required_x = (function(){
  var exports = {}; 
  exports.foo = function() {console.log('Hello'); }; 
  exports.unused = 42;
  return exports; 
})();
// actual code
var a = required_x;
a.foo();

This might need some tweaking, but the idea is that when the minifier runs, it can:

  • Inline small functions/variables in modules
  • Make function names in modules a single name
  • Detect unused functions and totally remove them

This would massively decrease the size of uploaded code.

'Sending...' indicator in CLI

When using -w it's not obvious when data is being sent - the CLI is just unresponsive. It's more of a big deal on BLE when it can take a while to upload.

It'd be better to have some kind of indicator on the console... preferably a percent bar.

websocket doesn't like JSON

Hi,

if I send

socket.send({key:"value"});

to my espruino board and receive it there in a

ws.on('message',function(msg) {
     console.log("msg",msg, "typeof msg",typeof msg);
});

I get

msg [object Object] string

So I have no access to the content. There is a bad toString() before it.
Perhaps, I thought, I should use the rawData Callback. But this is realy raw and not for me.

At the moment I go around this in writing only key:value and split(":") them afterwards. But it would be nice if JSON were possible.

Compiler: ASM.js support

With #7 we should be able to detect variable types specified using stuff like |0 notation.

This would open the door to detecting and compiling ASM.js code (original bug for this was on Espruino here, but this can all be done in EspruinoTools so moving here)

close websockets at reset

Hi,
the websocketserver does not die propper on reset() or reset(true).

Say I have this Server.

function onPageRequest(req, res) {
   res.writeHead(200, {'Content-Type': 'text/html'});
    res.end("Hi. Ask the other Server");
}

var server = require('ws').createServer(onPageRequest);
server.listen(80);
console.log("server listen on port",80);

server.on("websocket", function(ws) {
ws.on('message',function(msg) {
    console.log("msg",msg);
    });
});

I deploy the code with espruino -m -p tcp://192.168.178.56 socketTest.js to the Board, everything is fine.
I could connect to this SocketServer and can send Messages.

But if I want to deploy the next commit, I get a

>ERROR: Socket bind failed
--] Uncaught InternalError: Unable to create socket

This only happens if I establish a connection in between.
If the socketServer is unloaded, it should close ists connections.

I could store the sockets. But this variable isn't accessible at the next upload.

I use Espruino Command-line Tool 0.1.13 and Espruino 1.99

Connect over TCP Address

Using Espruino Web IDE we can connect to ESP over TCP/IP address.
It will be useful here too.

Compiler: don't use jspeiFindInScopes

jspeiFindInScopes doesn't handle built-in functions/variables. Instead we probably need what's in jspeFactorSingleId. jspGetNamedField/jspGetVarNamedField need exporting too so we can do objects/arrays.

CLI seems to require puck address in lower case

I realise now that this has caught me out a few times... Not sure if this is intentional or unintentional behaviour but suggest it would make it easier for beginners if the CLI could accept puck addresses in upper case to facilitate copy paste from scan tools some of which report in upper case.

See below

pi@raspberrypi:~/puck $ espruino -p d1:b2:18:9f:88:ea
Espruino Command-line Tool 0.0.26
-----------------------------------

Connecting to 'd1:b2:18:9f:88:ea'
Connected
noble: unknown peripheral null connected!
>
Press Ctrl-C again to exit
>noble: unknown peripheral null connected!

pi@raspberrypi:~/puck $ espruino -p D1:B2:18:9F:88:EA
Espruino Command-line Tool 0.0.26
-----------------------------------

Connecting to 'D1:B2:18:9F:88:EA'
Port "D1:B2:18:9F:88:EA" not found
Unable to connect!
pi@raspberrypi:~/puck $ 

Add `-d DeviceName` option to allow connection based on name, not port

Some devices actually have names (eg. BLE devices).

It'd make more sense to be able to specify espruino -d Puck.js to (for instance) automatically connect to any device with Puck.js in the name - rather than having to list, find the device and address, and then call it again with -p address

Compiler: data flow

We currently have a nasty stack-based hack.

Ideally we'd build a data flow diagram and would then compress this down to assembler. Hopefully it could also keep track of data types such that things like integers could be 'unwrapped' from JsVars.

Built-in variables

Specifically __CURRENT_TIME__, so you could set up the RTC automatically when you flashed your code:

setTime(__CURRENT_TIME__);
...
new Date().toString()

same same, but different

running two types of WebIDE with Chrome on MAC OS X , one from Chrome Web Store and the other as latest pull and unpacked from local folder.

bildschirmfoto 2016-01-29 um 11 52 19

Web Store App can connect serial and network attached devices, unpacked not.

Any idea how to investigate ?

SETTINGS > CONSOLE

Connecting...
Set Slow Write = true
[object Object]
Connected [object Object]
Got ""
No Prompt found, got undefined - issuing Ctrl-C to try and break out
Sending...
---> " \u0003echo(0);\nconsole.log("<","<<",JSON.stringify(process.env),">>",">");\n"
Sent
WARNING: No result found - just got ""
Device found (connectionId=4)
Connected to port /dev/cu.usbserial-A50285BI

Using first port on windows give no access to cntrl-c

On Windows 10, with a micro:bit, running espruino without options takes first port.
It is not possible to cntrl-c out of the connection and only way out is close the cmd prompt when the first port is a usb and not an mbed port


Background
Trying to understand the levels of software to use bluetooth with an electron installation on Windows 10 in preperation for a puck.js
Current understanding is the electron or npm start version of EspruinoWebIDE will allow for bluetooth connection as bluetooth support on Windows Chrome is not available yet.

This is probably the start of some issues to achieve an easy installation of EspruinoWebIDE on Windows with full usage of bluetooth on espruino products and side issue on micro:bit

C:\Users\owen\source\repos\github\espruino>espruino
Espruino Command-line Tool 0.0.30
-----------------------------------

Using first port, {"path":"COM3","usb":[1199,null],"description":"Microsoft"}
Connecting to 'COM3'
No result found - just got "\u0003\u0010console.log(\"<\",\"<<\",JSON.stringify(process.env),\">>\",\">\")\n"
Connected

Writing output file causes errors

sending code with -o causes errors while without it works ok

➜  dcf-timer git:(master) ✗ espruino -m dcfTimeSwitchFlash.js -o out.js
Espruino Command-line Tool 0.0.35
-----------------------------------

Espruino.Core.Utils.getURL: got HTTP status code 404 for https://www.espruino.com/modules/Flash.min.js
Espruino.Core.Utils.getURL: got HTTP status code 404 for https://www.espruino.com/modules/Flash.js
Module Flash not found
Writing output to out.js
File written. Exiting.
➜  dcf-timer git:(master) ✗ espruino -m dcfTimeSwitchFlash.js          
Espruino Command-line Tool 0.0.35
-----------------------------------
Using first port, {"path":"/dev/cu.usbmodem15","usb":[1155,22336],"description":"Espruino board"}
Connecting to '/dev/cu.usbmodem15'
Connected
--] 
--]  _____                 _ 
--] |   __|___ ___ ___ _ _|_|___ ___ 
--] |   __|_ -| . |  _| | | |   | . |
--] |_____|___|  _|_| |___|_|_|_|___|
--]           |_| http://espruino.com
--]  1v94 Copyright 2016 G.Williams
--] 
--] >
--] =undefined
--] Erasing Flash.....
--] Writing...............................
--] Compressed 81600 bytes to 29444

Error when installing package

`npm install -g espruino
npm WARN deprecated [email protected]: ⚠️ WARNING ⚠️ tar.gz module has been deprecated and your application is vulnerable. Please use tar module instead: https://npmjs.com/tar
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/espruino/node_modules/winnus):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"win32","arch":"any"} (current: {"os":"darwin","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/espruino/node_modules/bluetooth-hci-socket):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"linux,android,win32","arch":"any"} (current: {"os":"darwin","arch":"x64"})

npm ERR! path /usr/local/bin/espruino
npm ERR! code EEXIST
npm ERR! Refusing to delete /usr/local/bin/espruino: ../lib/node_modules/node-espruino/cli symlink target is not controlled by npm /usr/local/bin
npm ERR! File exists: /usr/local/bin/espruino
npm ERR! Move it away, and try again.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/attepohjanmaa/.npm/_logs/2018-01-05T19_41_32_252Z-debug.log`

What should be done?

which version of node to use?

Currently not possible to install:

npm install -g espruino

Node version 4 or 5 clearly don't work.

With version 0.12 you get this error, i.e: serial port wants 0.10 or less:

npm WARN engine [email protected]: wanted: {"node":"0.10.x"} (current: {"node":"0.12.8","npm":"2.14.9"})

However, if you run with 0.10 then you get this error:

npm WARN engine [email protected]: wanted: {"node":">=0.12.0"} (current: {"node":"0.10.40","npm":"1.4.28"})

i.e: escodegen needs node 12.0 or larger!

So, we need a node version x, where: x is <= 0.10 and x is >= 0.12 ??

Parsing from Acorn when uploading copy/pasted code via CLI

The attached code generated a strange error when uploaded via CLI. Note that I had to rename from .js to .txt to attach here.

The error reported with this code was repeatable and as follows:

Connected
Acorn parse for plugins/compiler.js failed.<br/>Check the editor window for syntax errors
undefined:44
    utf8.encode(c).split('').forEach(function(c) {
    ^

ReferenceError: utf8 is not defined
    at escapeChar (eval at loadJS (/usr/lib/node_modules/espruino/index.js:10:10), <anonymous>:44:5)
.....(lfurther info deleted here)

This error was resolved by re-typing the code manually so my guess is some unexpected characters picked up when copy pasting from forum.

temp.txt

Output spam when using "SAVE_ON_SEND": 1

I am using espruino -j myprog.json with an ESP8266.
If I use "SAVE_ON_SEND": 0 everything works as expected.
If I use "SAVE_ON_SEND": 1 everything works as expected but the output is spammed 'forever' as shown below, until CTRL+C is provided.

Connecting to '/dev/cu.SLAB_USBtoUART'
--]  the internted to the ied to the inNot connecteROR: Not coOR: Not connted to the  connected tted to the i Not connecernet
--] ERhe internet
No result found - just got "onnected to the interneot connecteR: Not connected to theRROR: Not cthe internet\r\nERROR: Nornet\r\n
Connected
--] ERROR: N to the intpyright 2016 G.Williams
--] 
--] Espruinrasing Flaot connecte internet
--] internet
--]  the internternet
--] Eet
--] ERROR Not connected to the internet
--] ERROR: Not connected tothe internetNot connecteot connectedo the interet
--] ERROR: Not connected to the internet
--]  the intern Not connectRROR: Not ct
--] ERROR: ed to the inROR: Not co to the intet connectedto the inteected to the connected R: Not connERROR: Notet
--] ERRORet
--] ERROR:ted to the inet
--] ERROcted to thERROR: Not: Not connecNot connectRROR: Not co
--] ERROR: ROR: Not conto the inteERROR: Not internet
--] >ted to the it
--] ERROR: ERROR: Not ced to the iRROR: Not coot connecteted to the iERROR: Not cnected to trnet
--] ERROERROR: Not connected to Not connectt connected ERROR: Not c the interne Not connectot connected to the intnected to the i
--] ERROR: Noo the interet
--] ERRORted to the internet
--] nternet
--] ENot connect
--] ERROR: NOR: Not cont connected to the intennected to ternet
--] ERternet
--] ERot connecte to the intcted to the internet
--] >RROR: Not cthe internected to theternet
--] ERROR: Not coERROR: Notthe internet
--] ERROR: ot connected to the intnected to tRROR: Not che internet to the internet
t connectedt connected rnett
--] ERROnet
--] ERRORconnected to the interneNot connecteternet
--] ERROR: Not conernet
--] ERROR: Not connected to thected to the internet
--] to the intercted to the internet
--] >cted to theERROR: Not o the internet

404 errors on deploy

Hello,

I am trying to deploy a program as
espruino -p /dev/cu.SLAB_USBtoUART src/myprogram.js

This program requires Wifi as well a few others. During the deploy, I get greeted by such messages:

Espruino Command-line Tool 0.0.32
-----------------------------------

Connecting to '/dev/cu.SLAB_USBtoUART'
No result found - just got ""
Connected
Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/ESP8266.min.js
Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/Wifi.min.js
Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/http.min.js
Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/ESP8266.js
Module ESP8266 not found
Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/http.js
Module http not found
Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/Wifi.js
Module Wifi not found 

Do I need to provide the correct paths somewhere

Port not found - Unable to connect

I'm trying to connect to my Puck.js in a couple of ways but having no joy.

Running espruino -p c6:b9:c8:38:94:2b -v gives me the following output.

Acorn library not found - you'll need it for compiled code
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/libs/targz.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/libs/utf8.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/espruino.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/codeWriter.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/config.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/env.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/flasher.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/modules.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/notifications.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_audio.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_chrome.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_noble.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_nodeserial.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_socket.js
No chrome.sockets - serial_socket disabled
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_web_bluetooth.js
No navigator.bluetooth - Web Bluetooth not enabled
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_websocket.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/serial_winnus.js
'winnus' module not found, no Windows Bluetooth Low Energy { Error: Cannot find module 'winnus'
    at Function.Module._resolveFilename (module.js:472:15)
    at Function.Module._load (module.js:420:25)
    at Module.require (module.js:500:17)
    at require (internal/module.js:20:19)
    at eval (eval at loadJS (/Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/index.js:10:10), <anonymous>:5:14)
    at eval (eval at loadJS (/Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/index.js:10:10), <anonymous>:126:3)
    at loadJS (/Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/index.js:10:10)
    at loadDir (/Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/index.js:20:7)
    at Object.init (/Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/index.js:93:3)
    at Object.<anonymous> (/Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/bin/espruino-cli.js:386:24) code: 'MODULE_NOT_FOUND' }
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/settingsAbout.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/status.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/terminal.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/core/utils.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/_examplePlugin.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/assembler.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/boardJSON.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/compiler.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/getGitHub.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/localModules.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/minify.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/npmModules.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/saveOnSend.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/setTime.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/uiMode.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/unicode.js
Found /Users/joshfarrant/.nvm/versions/node/v7.0.0/lib/node_modules/espruino/plugins/versionChecker.js
Initialising CodeWriter
Initialising Config
Initialising Env
Initialising Flasher
Initialising Modules
Initialising Notifications
Initialising Serial
  - Initialising Serial Noble
  - Initialising Serial Node Serial
Initialising SettingsAbout
Initialising Status
Initialising Utils
Initialising ExamplePlugin
Initialising Assembler
Initialising BoardJSON
Initialising Compiler
Initialising GetGitHub
Initialising LocalModules
Initialising Minify
Initialising NPMModules
Initialising SaveOnSend
Initialising SetTime
Initialising UiMode
Initialising Unicode
Initialising VersionChecker
Connecting to 'c6:b9:c8:38:94:2b'
noble starting scan
Port "c6:b9:c8:38:94:2b" not found - checking ports again (2 attempts left)
noble starting scan
Port "c6:b9:c8:38:94:2b" not found - checking ports again (1 attempts left)
Port "c6:b9:c8:38:94:2b" not found
Unable to connect!

I get the same thing if I try to connect using a simple node app. Also I get the same if I use the output of espruino --list (/dev/cu.Bluetooth-Incoming-Port) instead of the MAC address.

I feel like I might be missing something, but this appears to be what the README suggests should work.

Change minification method in espruino-cli.js to ESPRIMA

It is absolutely desirable to have minification, at least to strip the comments.
The current hard coded method for minification in the CLI is SIMPLE_OPTIMIZATIONS, which is not always working. ESPRIMA seems to be much more reliable.

Refuse to run with -j and a .js file

For people using autocomplete, prog.js will come as result before 'prog.json'.
This is in itself not such an issue.
However, using espruino -j prog.js whicle meaning ``espruino -j prog.json` wipes any pre-existing prog.json without warning.

I would suggest to not overwrite unless the user confirms or provides a -f flag to prevent loosing previously created deplly config (.json).

So in short, a first espruino -j myprog.js would work all fine and create a .json file. A second call would fail unless -f|--force is provided.

Improve assembler syntax check

Currently, the assembler doesn't complain enough about an incorrect syntax. For example:
mul r1, r2, r3, r4, r5, r5
does not exist. Yet, it does not complain about that many arguments.

web-bluetooth: switch to DataView

As you can see at WebBluetoothCG/web-bluetooth#201, we are switching BluetoothGattCharacteristic.value to a DataView instead of an ArrayBuffer in Chrome 50+.

You might want to have a small check until Chrome 50 reaches Stable channel:

      rxCharacteristic.addEventListener('characteristicvaluechanged', function(event) {
        var value = event.target.value;
        // In Chrome 50+, a DataView is returned instead of an ArrayBuffer.
        value = value.buffer ? value.buffer : value;
        console.log("BT> RX:"+JSON.stringify(ab2str(value)));
        receiveCallback(value);
      });

Can't provide programatically exact baud rate

I'm currently making repo with espruino build examples without ide, and found that it is possible to provide build scripts based on this repo. Attempting to provide basic helloworld build I could find where to provide configuration object(if it is exists, of course).

My build script currently looks like this

var esp = require('espruino');
var Promise = require('bluebird');

var port = '/dev/cu.SLAB_USBtoUART';
var filename = './helloworld.js';

new Promise(function(resolve, reject) {
  esp.init(function() {
    resolve(Espruino)
  })
})
.then(function(Espruino) {
  Espruino.Config.BAUD_RATE = "115200"
})
.then(function() {
  esp.sendFile(port, filename, function() {
    esp.expr(port, "save()", function(result) {
      console.log('file hase been uploaded');
      console.log(result);
    })
  })
})

I suspect that build script is not working because of incorrect baud rate. In my case it should be 115200 but it seems that there are no such option.

winnus does not fail with inactive Bluetooth adapter

Bluetooth adapter is not available to Windows 10 (dedicated to VM machine)

  • No error is given with winnus loading

Further tests may involve disabling bluetooth adapter in bios or removing driver
to find a possible PR

Found C:\source\repos\github\OwenBrotherwood\EspruinoTools/core/serial_noble.js
'noble' module couldn't be loaded, no node.js Bluetooth Low Energy
 { Error: LIBUSB_ERROR_NOT_SUPPORTED
    at Device.usb.Device.open (C:\source\repos\github\OwenBrotherwood\EspruinoTools\node_modules\usb\usb.js:33:7)
    at BluetoothHciSocket.bindUser (C:\source\repos\github\OwenBrotherwood\EspruinoTools\node_modules\bluetooth-hci-socket\lib\usb.js:81:19)
    at BluetoothHciSocket.bindRaw (C:\source\repos\github\OwenBrotherwood\EspruinoTools\node_modules\bluetooth-hci-socket\lib\usb.js:28:8)
    at Hci.init (C:\source\repos\github\OwenBrotherwood\EspruinoTools\node_modules\noble\lib\hci-socket\hci.js:101:35)
    at NobleBindings.init (C:\source\repos\github\OwenBrotherwood\EspruinoTools\node_modules\noble\lib\hci-socket\bindings.js:82:13)
    at new Noble (C:\source\repos\github\OwenBrotherwood\EspruinoTools\node_modules\noble\lib\noble.js:50:18)
    at Object.<anonymous> (C:\source\repos\github\OwenBrotherwood\EspruinoTools\node_modules\noble\index.js:4:18)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32) errno: -12 }
Found C:\source\repos\github\OwenBrotherwood\EspruinoTools/core/serial_nodeserial.js
Found C:\source\repos\github\OwenBrotherwood\EspruinoTools/core/serial_socket.js
No chrome.sockets - serial_socket disabled
Found C:\source\repos\github\OwenBrotherwood\EspruinoTools/core/serial_websocket.js
Found C:\source\repos\github\OwenBrotherwood\EspruinoTools/core/serial_web_bluetooth.js
No navigator.bluetooth - Web Bluetooth not enabled
Found C:\source\repos\github\OwenBrotherwood\EspruinoTools/core/serial_winnus.js

Use jsdom rather than node-jsdom

I noticed that the tools depend on node-jsdom not jsdom and I'm guessing that the reason was because jsdom chased io.js. Given that they have converged I don't see any need for node-jsdom to be used and that the original can be swapped back in.

In my (simple) testing it seems to work just fine, although I haven't tried from the WebIDE, only the cli tools.

The reason that I'd like to see it switch back to just jsdom is that node-jsdom depends on contextify which is a real pain to get working smoothly on Windows, but has now been merged into node.js core so isn't required.

Local 'JIT' compiled JavaScript

Recently I've been wondering a bit about ways to get more 'native' speed out of Espruino. While it's fast enough for most things, sometimes you still notice problems - when doing things like manipulating images or decoding raw waveforms from the radio.

So, right now the solutions seem to fall into:

  • Download the Espruino source, compile it yourself and write C/C++ (works right now, perfectly)
  • Use the inline assembler (here now, although the assembler doesn't support a bunch of opcodes)
  • Have some way to compile C code in the Web IDE (not done, and raises issues about how to integrate it with native Espruino functionality)
  • Faster JS interpreter/JIT compile (none of which seem easy to get in the memory footprint we have)
  • ASM.JS

I've been talking to a few people about this, and another option has come up that's kind of a hybrid of the last 3 approaches... What if we could compile JavaScript to assembler inside the Web IDE, where there's more memory available?

It wouldn't have to be 100% full JS coverage - just enough that the stuff that needs to run quickly can do.

I just did a very quick proof of concept of this using acorn for the parsing. It's 150 lines so far, and if you type the following code:

  function foo(a,b) {
    "compiled";
    foo = foo + 1;
    return "Hello"+(a-b)+foo;
  }

Then when you click 'upload' it'll get parsed and will be converted to the following 'pseudo-assembler':

 ] MOVL r0, const_0
] BL jspeiFindInScopes
] PUSH {r0}
] MOVL r0, const_0
] BL jspeiFindInScopes
] PUSH {r0}
] MOVL r0, const_1
] BL jsvNewFromInteger
] PUSH {r0}
] POP {r0}
] POP {r1}
] MOVL r2, 43/* + */
] BL jsvMathsOp
] PUSH {r0}
] POP {r0}
] POP {r1}
] BL jspReplaceWith
] PUSH {r0}
] POP {r0}
] BL jsvUnLock
] MOVL r0, const_2
] BL jsvNewFromString
] PUSH {r0}
] MOVL r0, const_3
] BL jspeiFindInScopes
] PUSH {r0}
] MOVL r0, const_4
] BL jspeiFindInScopes
] PUSH {r0}
] POP {r0}
] POP {r1}
] MOVL r2, 45/* - */
] BL jsvMathsOp
] PUSH {r0}
] POP {r0}
] POP {r1}
] MOVL r2, 43/* + */
] BL jsvMathsOp
] PUSH {r0}
] MOVL r0, const_0
] BL jspeiFindInScopes
] PUSH {r0}
] POP {r0}
] POP {r1}
] MOVL r2, 43/* + */
] BL jsvMathsOp
] PUSH {r0}
] POP {r0}
] BX LR
] const_0:
]   .word 0x6f6f66 ; "foo\u0000"
] const_1:
]   .word 0x1 ; "\u0001\u0000\u0000\u0000"
] const_2:
]   .word 0x6c6c6548 ; "Hell"
]   .word 0x6f ; "o\u0000"
] const_3:
]   .word 0x61 ; "a\u0000"
] const_4:
]   .word 0x62 ; "b\u0000"

There's obviously still a bit to do before it's useful, but it's surprisingly close. While the generated code isn't super-fast, it'll still be a massive improvement over interpreting.

TODO

  • Work out a way of 'exporting' jsvMathsOp/jspeiFindInScopes/etc from the interpreter. This could just be a struct somewhere in memory with this stuff in a predefined order.
  • handle jsvUnLock properly when calling functions
  • Have a special case for function parameters, which will need to be taken out of reg0-3 and stored on the stack
  • Generate actual Thumb assembler that can be parsed by the assembler.js
  • Remove the original JS function declaration from the source and replace it with the assembler's output

And a few obvious optimisations

  • Peephole optimise push/pop to the same register
  • Make sure a referenced global variable is only looked up once
  • Peephole optimise constant expressions
  • Optimise stack push/pop into registers where possible
  • It should be possible to work out what variables are numbers/integers, and then to do the relevant operations right on them

Anyway, the hacky proof of concept is in https://github.com/espruino/EspruinoTools/tree/js_compiler. To use it, just add plugins/compiler.js to the Web IDE's main.html file and it'll spring into life

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.