Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fixed invalid syntax of function declaration #14
The function syntax is ES6 function syntax - all the Web Bluetooth code uses it and some got left in... but anything that supports Web Bluetooth should support ES6, so I'm surprised it caused you errors?
Also, the serial code definitely does work, so I'm not sure the positioning of
What system are you running on? and are you using it as a chrome extension?
If portToDevice is an empty array, presumably that means that no serial ports have been found? You could go into settings, enable the 'seruial over audio' and see if you can connect with that.
I'm running espruinotool on the command-line. If it uses the globally installed node.js, then that would be v0.10.26.
The problem with the ! without the extra brackets (that I added) is that it negates only the string serialPort. Therefore the error check is not working and the code crashes later on when trying to access the function open of an undefined variable currentDevice. Look at this:
node on my machine doesn't eat that function declaration:
Besides, this is the ONLY place in the repo where a function is declared by that syntax. There's a whole sequence of lines in serial_web_bluetooth.js which declare functions in the old fashion and just a few lines below there is this one arrow function declaration. That's also incosistent (adding to the fact that it doesn't compile on systems like mine).
I found what the problem was. The code of espruinotool (index.js) used to work this way: when no port is specified, it scans for ports and then connects to the first port found. That works fine. But if a port was specified, it does NOT scan for ports, it tries to connect right away. However the function openSerial in serial.js checks whether the specified port exists (by checking whether the string is an element of the array portToDevice). portToDevice is a variable in a higher scope and in this case an empty array, because the function getPorts that fills it has never been called.
I fixed it here:
Please let me know what you think.