Bitlash: 一个可编程的命令 shell 适用于 Arduino
Questions / Bug Reports / Pull Requests welcome! https://github.com/billroy/bitlash/issues
Bitlash supports string constants in function argument lists, but until now there hasn't been a way to distinguish such string arguments from numeric arguments once you're inside the called function, making it easy to reference forbidden memory by mistake.
The new isstr() Bitlash function helps handle this problem by letting you check the type of a specified argument to the function it's called in:
> function stringy {i=1;while (i stringy("foo",1,2,3,"bar","baz")
1 541 1
2 1 0
3 2 0
4 3 0
5 545 1
6 549 1There is a corresponding C api for C User Functions:
numvar isstringarg(numvar);And a companion to getarg() that fetches an argument but throws an error if the argument is not a string:
numvar getstringarg(numvar);Here is an example sketch with a User Function called echo() that uses isstringarg() and getstringarg() to print string arguments separately from numeric ones. The echo() function echoes back its arguments, with proper handling for strings:
#include "Arduino.h"
#include "bitlash.h"
#include "src/bitlash.h" // for sp() and printInteger()
numvar func_echo(void) {
for (int i=1; i printf("%3d\n", 99);
99
> printf("%03d\n", 99);
099
>You can define symbolic names for pins at compile time to suit your project
You can define built-in named functions in Bitlash script at compile time to suit your project
Runs scripts from SDCard file systems
Has a language worth running from a file
String arguments! printf("%d:%d:%d\n",h,m,s)
Can write SDFILE from script, too: fprintf("logfile.dat","%d:%d:%d\n",h,m,s)
Tested on and requires Arduino 0022
This version runs scripts from SDCARD as well as EEPROM
bitlashsd sd card demo REQUIRES SDFat Beta 20110604 available from:
download link: http://beta-lib.googlecode.com/files/SdFatBeta20110604.zip
to install, copy the "SDFat" library from the SDFatBeta distribution into the Arduino/libraries directory and restart Arduino
open the "bitlashsd" example and upload
to disable SDFILE support:
BUGFIX: 0xb broken by 0b1000! print 0xbbbbbbbb 0
BUGFIX: MAX_USER_FUNCTIONS error allowed only n-1 functions
BUGFIX: bloader.py was not well-synchronized at the start of a file upload as a result it could lose the first several lines of a file it now syncs correctly with the command prompt on the arduino
string arguments
unary & operator
unary * operator
// comments
doCommand()
printf("format string\n", "foo", "bar",3)
EXAMPLE: commands supported in the bitlashsd sd card demo
dir exists("filename") del("filename") create("filename", "first line\nsecondline\n") append("filename", "another line\n") type("filename") cd("dirname") md("dirname") fprintf("filename", "format string %s%d\n", "foo", millis);
- put your multi-line script on an SD card and run it from the command line
- example: bitlashcode/memdump
- example: bitlashcode/vars
- //comments work (comment to end of line)
- functions are looked up in this priority / order:
- internal function table
- user C function table (addBitlashFunction(...))
- Bitlash functions in EEPROM
- Bitlash functions in files on SD card
- beware name conflicts: a script on SD card can't override a function in EEPROM
- BUG: the run command only works with EEPROM functions
- it does not work with file functions
- for now, to use run with a file function, use this workaround:
- make a small EEPROM function to call your file function
- run the the EEPROM function
- startup and prompt functions on sd card are honored, if they exist
- you can upload files using bitlashcode/bloader.py
- python bloader.py memdump md
... uploads memdump as "md"This release fixes a bug in RC1 which broke function definition in some cases.
Please report bugs to [email protected]
If the command defining the function was the last thing on a line, RC1 worked correctly:
function hello {print "Hello, world!"} function hello { print "Hello, world!"}; ls
function hello { print "Hello, world"}}; foo
saved
> ls
function foo {function bar{print "bar"};bar};
function bar {}; bar
> This isn't new: Bitlash 1.1 has the same internal implementation limitation, but it was nearly impossible for a human to get the backslash-quote combinations right to attempt the test.
Syntax overhaul: the Bitlash 2.0 language is considerably different, and old macros will need to be updated to run in v2
if (expression) { stmt;...;stmt;} else {stmt;...;stmt;} while (expression) { stmt; } switch (expression) { stmt0; stmt1; ... stmtN; } function hello {print "Hello, world!";}
Macros are now Functions, they take arguments and can return a value arg(0) is the count of args you got arg(1..n) are the args return expression; to return a value; zero is assumed User Functions in C use this same scheme now
Function (/macro) definition syntax has changed: function printmyargs {i=0; while ++i<arg(0) {print arg(i);}}
New Functions bc: bitclear bs: bitset br: bitread bw: bitwrite
New API calls setOutputHandler() api allows capture of serial output doCharacter() api allows char-at-a-time input to Bitlash
New Examples
Small Beans
暂无开放 Issues,或尚未同步最近议题。