Git Product home page Git Product logo

bitlash's Introduction

Bitlash Release Notes

Questions / Bug Reports / Pull Requests welcome! https://github.com/billroy/bitlash/issues

March 19, 2013: Type checking for string arguments

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<=arg(0)) {print i,arg(i),isstr(i);i++}}
saved
> stringy("foo",1,2,3,"bar","baz")
1 541 1
2 1 0
3 2 0
4 3 0
5 545 1
6 549 1

There 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 <= getarg(0); i++) {
		if (isstringarg(i)) sp((const char *) getstringarg(i));
		else printInteger(getarg(i), 0, ' ');
		speol();
	}
}

void setup(void) {
	initBitlash(57600);	
	addBitlashFunction("echo", (bitlash_function) func_echo);	
}

void loop(void) {
	runBitlash();
}

NOTE: The changes consume a little space on the expression evaluation stack, so some complex expressions that formerly worked may see an expression overflow. Please report this if you see it.

March 18, 2013: Bitlash running on Due

  • Applied contributed Due patches; Bitlash should run on Due now. Thanks, Bruce.

  • Bumped copyright date in the startup banner.

Feb 2013

  • Added commander and ethernetcommander example sketches for Bitlash Commander.
  • Added blinkm example sketch
  • Added seriallcd example sketch

November 10, 2012

  • Fixed prog_char bug that broke compile on Ubuntu with avr-gcc 4.7.0

November 3, 2012

Recent Bitlash changes of note:

  • Published a new tool, "bloader.js", a program loader and serial monitor for Bitlash based on node.js. See https://github.com/billroy/bloader.js

  • Published a new tool, "serial-web-terminal", which provides a browser-based serial terminal monitor for a usb-connected Arduino. See https://github.com/billroy/serial-web-terminal.git

  • Fixed a millis rollover bug in the background task scheduler. You can cherry-pick the fix at line 103 in src/bitlash-taskmgr.c -- also, there is a new example named examples/rollover that lets you set millis() to a value just before the rollover to test.

  • Added getkey([prompt]) and getint([prompt]) to get user input.

  • Compiles and runs on Linux and OS X, and there is a web-based Bitlash terminal you can run on Heroku so you can play with Bitlash in your browser. See README-UNIX.md

  • Compiles on the tiny core, with many feature amputations. Not tested. See README-TINY.md

Bitlash Due Version compiles under Arduino 1.5

  • Bitlash builds under the github working code for the new Arduino 1.5 IDE, both for the customary AVR targets and for the new ARM targets for the Arduino Due. You may still get errors with the current Arduino 1.5 beta until a refresh is announced. See the forum thread below to test using the latest github IDE code.

  • The ARM has no eeprom. Bitlash function storage in this alpha is in a 4k ram buffer that simulates EEPROM, except it vanishes at power-off.

  • Without a Due here, I cannot test it, but field reports are welcome.

  • Forum thread here: http://arduino.cc/forum/index.php/topic,128543.msg966899.html#msg966899

September 10, 2012

  • Let's call it "2.0"

  • The Bitlash User's Guide is available as a pdf book at: http://bitlash.net/bitlash-users-guide.pdf

  • Examples are updated for Arduino 1.0.1

  • Bitlash is now licensed under the MIT license

  • Released new wiki and landing page on Github

  • New morse and morse2 examples: printf() to morse, blocking and non-blocking

  • Check out the Textwhacker project at https://github.com/billroy/textwhacker for scrolling text output from Bitlash on a SparkFun LED matrix

2.0 RC5 Release Notes -- April 3, 2012

  • Stalking Arduino 1.0: more #include fixes and warnings cleanup

    • The bitlashdemo example compiles and runs correctly in 1.0
    • Seeking bug reports
  • The default for MAX_USER_FUNCTIONS is now 20 [bitlash-functions.c @ 268]

  • RF12 support for NanodeRF; see examples/bitlash_rf

    • very early alpha code

2.0 RC4 Release Notes -- September 29, 2011

  • Arduino 1.0 status

    • The bitlashdemo.pde example compiles and runs properly on Arduino 1.0b4
    • There are known issues with some examples:
      • The BitlashWebServer.pde example does not work for either the Arduino or Nanode ethernet interfaces
      • SD card support is untested and at risk due to size constraints
      • Most other examples need touching for the Arduino.h fix at least
  • The BitlashWebServer example now works on Nanode, as well as the official shield

  • SD card support is, by default, disabled. To enable it:

    • Edit libraries/bitlash/src/bitlash-instream.c to turn on the SDFILE define at or near line 32, make this: //#define SDFILE look like this: #define SDFILE
  • printf() and fprintf() now respect the width argument, including leading 0:

    printf("%3d\n", 99); 99 printf("%03d\n", 99); 099

  • You can define symbolic names for pins at compile time to suit your project

    • Turn on PIN_ALIASES at line 401 in src/bitlash-parser.c
    • Add your aliases to the pinnames and pinvalues tables
    • Now you can say led=1 or x=vin
    • Don't forget to set the pinmode()
  • You can define built-in named functions in Bitlash script at compile time to suit your project

    • Think of it as a built-in customizable dictionary of Bitlash functions
    • These BUILT_IN functions live in flash (PROGMEM) so you can free up EEPROM
    • Flash space is the limiting factor; the internal bitlash 2 limit is 2^28-1 bytes
    • Add to the table in src/bitlash-builtins.c and see the notes there

2.0 RC3d Release Notes -- June 4, 2011

Quick Start for SD Card Support:

Quick Start without SD Card Support:

  • Download and install Bitlash 2.0 RC3d from http://bitlash.net
  • Edit libraries/bitlash/src/bitlash-instream.c to turn off the SDFILE define at or near line 32, make this: #define SDFILE look like this: //#define SDFILE
  • If you are using a Mega2560, edit SdFat/SdFatConfig.h @ line 85, make this change: #define MEGA_SOFT_SPI 1
  • Restart Arduino 0022, open examples->bitlash->bitlashdemo and upload to your Arduino

Summary for this version:

  • 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

    • Tested on Sparkfun OpenLog 1.0 and Adafruit Datalogger Shield hardware
  • 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:

      • turn off the SDFAT define in bitlash-instream.c
      • open and upload the bitlashdemo example
  • BUGFIX: 0xb broken by 0b1000! print 0xbbbbbbbb 0

  • BUGFIX: MAX_USER_FUNCTIONS error allowed only n-1 functions

    • bumped MAX_USER_FUNCTIONS to 8
  • 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

    • printing strings with :s
  • unary & operator

  • unary * operator

  • // comments

  • doCommand()

    • is re-entrant
    • returns numvar (-1L on error)
  • printf("format string\n", "foo", "bar",3)

    • format specifiers %s %d %u %x %c %b %% work as per C printf()
    • BUG/FEAT: width specifier is not handled for numeric printing
      • %4s works but %4d or anything else doesn't
    • see also fprintf() below for printing to file on sd card
  • 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);

Running Bitlash scripts from sd card

- 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"

2.0 RC2 -- 06 March 2011

This release fixes a bug in RC1 which broke function definition in some cases.

Please report bugs to [email protected]

BUG: Function definition was broken if the line contained ; or additionalcommands

If the command defining the function was the last thing on a line, RC1 worked correctly:

function hello {print "Hello, world!"}		<-- worked

If there were characters after the closing } of the function definition, the bug caused the function text to be mismeasured and spurious text would be appended to the function definition, causing it to fail in use:

> function hello { print "Hello, world!"};	<-- this is legal but it triggered bug in RC1
saved
> ls
function hello { print "Hello, world"}};	<-- BUG: extra } saved at the end

The function text is measured more accurately in RC2.

Users are encouraged to upgrade to fix this bug.

Existing functions may need to be fixed, as well. Make sure the {} balance.

Defining a function within a function fails. That's ok, for now.

Noting a behavior that may change in a future release: an attempt to define a function from within a function will fail silently or worse. Don't do that.

function foo {function bar{print "bar"};bar};	<-- don't do this!
> foo
saved
> ls
function foo {function bar{print "bar"};bar};
function bar {};	<-- sorry, doesn't work in 2.0
> 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.

2.0 RC1 -- 05 Feb 2011

  • 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

    • Bitlash web and telnet server
  • Small Beans

    • Input buffer is 140 characters, up from 80. twitter is the new Hollerith
    • Binary constants of the form 0b01010101 are supported

1.1 -- 04 Feb 2010

  • User Functions (addBitlashFunction)

1.0 -- 17 Jan 2010

  • Fixed filenames in the examples/ folder to remove '-'
  • Updated copyright date in signon banner
  • Doc set update: see http://bitlash.net

1.0rc2 -- 22 Jun 2009

  • Fixed bug which botched handling of escaped characters in string constants.

1.0rc1 -- 01 Jun 2009

0.9 -- 23 Nov 2008

  • License updated to LGPL 2.1
  • Added functions:
    • beep(pin, freq, duration)
    • shiftout()
  • SOFTWARE_SERIAL_RX: build-time configurable software serial rx on pins D0-D7
    • to support Ethernet integration
  • Adafruit XPort Direct Ethernet integration works pretty well
  • Sanguino integration
    • Compile for Sanguino Does The Right Thing re: serial ports
    • (there are some serial port interrupt issues pending)

0.8 -- 31 Oct 2008

  • SOFTWARE_TX:
    • baud(pin, baud)
    • print #pin:expr

bitlash's People

Contributors

billroy avatar d00616 avatar murix avatar paulstoffregen avatar remcoder 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitlash's Issues

bitlash without serial port

It seems that Bitlash can not work without real serial port connected. I've made setup where bitlash'ed nano connected with 'console' throught RF24 radio using setOutputHandler and doCharacter. It works fine when nano connected to computer and serial port can be initialized. When it powered from wall adapter, both of setOutputHandler and doCharacter does nothing. http://forum.arduino.cc/index.php?topic=199311.0

Deleted-cant add user functions to memory

An issue that has been deleted from here:
If you create a user function there is no way to add it to memory for startup operation, you get an error on boot for every user function in memory.

Interpret from memory

Hi, can this used to interpret programs from SDcard?
I mean programmatically, not via the shell.

Cannot 'run' api added functions

given the below sketch, typing 'run hi' from the console complains that it can't find the identifier 'hi'. Typing 'hi' at the console does the right thing. If you wrap the 'hi' function inside of a 'function hi wrap { hi; }', running hi wrap works.

numvar hi(void) {
Serial.println("hello!");
}

void setup() {
initBitlash(115200);
addBitlashFunction("hi",(bitlash_function)hi);
}

void loop() {
runBitlash();
}

Problem of output buffer when using bitlash

I am using matlab's serial command to communicate with COm3 on arduino uno already loaded with bitlash. Unlike interactive Serial terminal windows, whenI send char to COM3 to do comand, these is no output on screen, and they are stored in output buffer.

Sometimes I need to read the output of a command such as
% get pin 12 level:
aStr = 'print d12';
fprintf(obj1,'%s\n',aStr);
tline = fgetl(obj1)
tline = fgetl(obj1)
tline = fgetl(obj1)
tline = fgetl(obj1)
tline = fgetl(obj1)
tline = fgetl(obj1)
tline = fgetl(obj1)
...

I need to run a lot of tline = fgetl(obj1) . Each calling will return a echo history that take place at early stages, and after try many times I can get the most fresh output buffer: the pin level.

So this is very inconvenient for me to get the output I want.

Is there a way to auto-flush the output buffer so that only the last line remains in output buffer, so that I can read it directly.

Call the tline = fgetl(obj1) repeatly is a bad idea because I cannot tell how much times to call. And when it returns the last ftresh line of output buffer, more calling will block the matlab untill timeout, which is very unwanted.

Serial flash support?

Hello. And what about support for running a program from serial flash memory, for example from Winbond 25Q32BVSIG.
Thanks

How to use the second serial?

The docs unfortunately don't tell how to use the second serial port (if available), or I have missed it in the docs.

line overflow

when trying to type the following line:

function startup {pinmode(13,1); pinmode(a0,0); pinmode(a1,1); run toggle13,1000; run readtemp,1000; run readlight,1000; }

by the end I get the message: line overflow

function startup {pinmode(13,1); pinmode(a0,0); pinmode(a1,1); run toggle13,1000; run readtemp,1000; run readlight,1000line overflow

and a bunch of weird characters.

I'm using gnu screen

LED was very dim when using bitlash

Hi, I use bitlash and send a command:

d7=1 * turn on pin 7
The D7 pin was connected to LED, but I found the LED was very dim.

Then I run arduino IED and upload the sample Blink to test if arduino is OK,I found that the LED was bright as normal.

It's weired. Can anyone help me, thanks.

SD example out of date?

It looks like the SD example is out of date. Get the following error when I try to compile after following the install procedure.

bitlashsd.cpp: In function ‘numvar scriptgetpos()’:
bitlashsd.cpp:168:1: error: ‘fpos_t’ was not declared in this scope
bitlashsd.cpp:168:8: error: expected ‘;’ before ‘pos’
bitlashsd.cpp:170:21: error: ‘pos’ was not declared in this scope

I think this type changed to FatPos_t in a recent mod to SdFat.h.

In order to aviod these dependencies, I freeze all required packages in with the GIT repo like this:

~/GIT/bitlash/libraries/
bitlash/
examples
SdFat/
examples
...

then import them with quotes

include "SdFat.h"

So that it searches local directories first.

Ideally this will use the "SD.h" library that comes pre-installed.

Thank you for bitlash!

Justin

Can't change eeprom size without changing bitlash code

When using bitlash in a project, I have to change the library's code in order to set the start/end offset for the EEPROM. While this works more or less fine when using bitlash in a single project, it becomes unmanageable when I use bitlash in more than one project, where I would need to adjust the #defines back and forth.

eeprom overflow error with bitlash run command for a user defined function

Hello, I am using an arduino mega. I have the following code. Which works as expected.

#include <bitlash.h>

void setup(void) {
    initBitlash(9600);
}

int count =1;

void loop(void) {
  runBitlash();

  if (count ==1){
    doCommand("{pinMode(13, 1); dw(13,1);  if(a0< 200){print \"level=\"a0;}; snooze(2000); }");
    //doCommand("function iot {pinMode(13, 1); dw(13,1);  if(a0< 200){print \"level=\"a0;}; snooze(2000); }");
    //doCommand("run iot")
    count =0;  
  }  
  delay(1000);   
}

When I try to run it as a function in background using;

if (count ==1){
   doCommand("function iot {pinMode(13, 1); dw(13,1);  if(a0< 200){print \"level=\"a0;}; snooze(2000); }");
   doCommand("run iot;")
   count =0;  
  }

even though the first doCommand should return 'saved', it returns 'eeprom overflow'. I checked the eeprom using eeprom read and write and also used eeprom clear. Everything is fine. (Plugged out and connected and all the other programs works fine, so does the arduino doCommands. Error occurs only when I try to run a function in background. I have used "ps;" to check whether there are anyother background functions running. There are none.)

I should also mention that the background run command and saving worked perfectly for few attempts. Then it started giving the 'eeprom overflow' instead of 'saved'.

Am I missing something here ?
Any insight will be much appreciated. Thank You

Question about using arguments in the called function

Hello,

just wanted to thank you for making bitlash available, I can see it has a lot of potential.
I have a question about using arguments in the called function: I am trying to create a function that passes the pin number to blink an LED.

This function works on the command prompt: function toggle {x = dr(arg(1)); dw(arg(1),!x);}

However I cannot run it in the background, I receive this error message:

run toggle(13),200
-------------------^
unexpected number

I tried passing two arguments including one for a delay like this:
function toggle {x = dr(arg(1)); dw(arg(1),!x); snooze(arg(2));}
but no change...

I tried to look up any info but came up empty. Any ideas?

unexpected char leads to flooding

hello,

every time I give a unexpected key press (any arrows for example) or if I call a nonexistent function, bitlash becomes unresponsive and starts flooding my screen (I'm using gnu scree) with weird characters.

bitlash demo - blink does not blink

Hi, I followed the tutorial and run a blink startup function to make LED connected to D7 pin blink.

After I run startup, I found that the LED was always on, and no blink.

Then I run a command to modify the callee toggle7 to see if something changed:

function toggle7 {d7=0;} // I founs that LED was suddenly off
function toggle7 {d7=1;}// I founs that LED was suddenly on
function toggle7 {d7=!d7;} // I expect LEDto blink, but it failed.

Port to spark-core or esp-8266

I would love to use bitlash on my various wifi-enabled development boards. They all have a port of arduino's wireing which I imagine is most the work porting bitlash, but I'm wondering what else would be required and if anyone has tried this before.

For example, when trying to import the bitlash header into an ESP8266 project using the Arduino IDE, I get errors about bitlash trying to include avr.h.

I'd be willing to do the work to port what's left, but I'm looking for some guidance.

Led Blinking example is not working on Arduino Due

the basic example from the user guide is not working on the arduino due :

function toggle13 {d13=!d13;}
function startup {pinmode(13,1); run toggle13,1000;}
boot

Moreover the function are not saved when rebooting.

Run code from eeprom

Hello! I have tried bitlash and it can be more wonderful if your program can execute code from eeprom. Please add this feature to the program! Thank you so much!

Maintained fork?

Hello,

It looks like there hasn't been any updates to bitlash since 3rd Feb 2014.
Quite a lot has changed in Arduino, since this was first written - for example the Serial API has stabilised and WProgram.h is long gone.

Has anyone been working on a modern fork, that works with ESP etc?

Thanks,

nick.

Cannot use backspace in terminal

It'd be very nice to be able to use backspace in the terminal. Currently nothing happens upon pressing backspace. I guess bitlash should echo backspace towards the client and shorten the command buffer by one character.

A Pinoccio user :)

About reading Arduino local variables from bitlash.

Hello, I am planning to use bitlash in my home to read sensors remotely.

Some sensors are not than simple as reading a pin, so for example a sensor who works via I2C or SPI... One wire temperature sensors...

So, I can run in arduino a function that communicates with the sensor in the specified protocol, reads the value and stores the result in a local variable. An unsigned int Sensor1Value for ex...

¿¿Do you know any way from remote terminal to say Bitlash that returns me the value of Sensor1Value stored in arduino RAM??

run bitlash code stored in flash

hi Bill,
have you ever built a version that would interpret bitlash code that is stored in the unused part of flash (on a 32K mcu)? it seems to me that would be a good place to put a larger program.

not compiling under new gcc

follows the diff to make it work.
basically, adding const to every line containing progmem and related changes on the main header

diff --git a/src/bitlash-builtins.c b/src/bitlash-builtins.c
index af92cb0..3778d09 100644
--- a/src/bitlash-builtins.c
+++ b/src/bitlash-builtins.c
@@ -54,7 +54,7 @@ like this, from the command line:
// use this define to add to the builtin_table
#define BUILT_IN(name, script) name "\0" script "\0"

-prog_char builtin_table[] PROGMEM = {
+const prog_char builtin_table[] PROGMEM = {

// The banner must be first.  Add new builtins below.
BUILT_IN("banner",  

@@ -76,7 +76,7 @@ prog_char builtin_table[] PROGMEM = {

byte findbuiltin(char *name) {
-prog_char *wordlist = builtin_table;
+const prog_char *wordlist = builtin_table;

while (pgm_read_byte(wordlist)) {
    int result = strcmp_P(name, wordlist);

diff --git a/src/bitlash-cmdline.c b/src/bitlash-cmdline.c
index df4de0c..4bb938e 100644
--- a/src/bitlash-cmdline.c
+++ b/src/bitlash-cmdline.c
@@ -37,12 +37,12 @@ char lbuf[LBUFLEN];
// Help text
//
#ifdef ARDUINO_BUILD
-prog_char helptext[] PROGMEM = { "http://bitlash.net\r\nSee LICENSE for license\r\nPins: d0-22,a0-22 Variables: a-z, 32 bit long integers\r\nOperators: + - * / ( ) < <= > >= == != << >> ! ^ & | ++ -- :=\r\nCommands: \0" };
+const prog_char helptext[] PROGMEM = { "http://bitlash.net\r\nSee LICENSE for license\r\nPins: d0-22,a0-22 Variables: a-z, 32 bit long integers\r\nOperators: + - * / ( ) < <= > >= == != << >> ! ^ & | ++ -- :=\r\nCommands: \0" };
#else
-prog_char helptext[] PROGMEM = { "http://bitlash.net\r\n\0" };
+const prog_char helptext[] PROGMEM = { "http://bitlash.net\r\n\0" };
#endif

-void showdict(prog_char *addr) {
+void showdict(const prog_char *addr) {
byte c;
for (;;) {
c = pgm_read_byte(addr++);
diff --git a/src/bitlash-functions.c b/src/bitlash-functions.c
index 8a1136d..84757c8 100644
--- a/src/bitlash-functions.c
+++ b/src/bitlash-functions.c
@@ -188,7 +188,7 @@ numvar func_bitwrite(void) { reqargs(3); return arg3 ? func_bitset() : func_bitc
// MAINTENANCE NOTE: This dictionary must be sorted in alpha order
// and must be 1:1 with function_table below.
//
-prog_char functiondict[] PROGMEM = {
+const prog_char functiondict[] PROGMEM = {
"abs\0"
"ar\0"
"aw\0"
@@ -226,7 +226,7 @@ prog_char functiondict[] PROGMEM = {
// this must be 1:1 with the symbols above, which in turn must be in alpha order
//

-bitlash_function function_table[] PROGMEM = {
+const bitlash_function function_table[] PROGMEM = {
func_abs,
func_ar,
func_aw,
diff --git a/src/bitlash-parser.c b/src/bitlash-parser.c
index 2c958cc..80cc299 100644
--- a/src/bitlash-parser.c
+++ b/src/bitlash-parser.c
@@ -51,7 +51,7 @@ char idbuf[IDLEN+1];

-prog_char strings[] PROGMEM = {
+const prog_char strings[] PROGMEM = {
#ifdef TINY85
"exp \0unexp \0mssng \0str\0 uflow \0oflow \0\0\0\0exp\0op\0\0eof\0var\0num\0)\0\0eep\0:="\0> \0line\0char\0stack\0startup\0id\0prompt\0\r\n\0\0\0"
#else
@@ -60,8 +60,8 @@ prog_char strings[] PROGMEM = {
};

// get the address of the nth message in the table
-prog_char *getmsg(byte id) {

  • prog_char *msg = strings;
    +const prog_char *getmsg(byte id) {
  • const prog_char *msg = strings;
    while (id) { msg += strlen_P(msg) + 1; id--; }
    return msg;
    }
    @@ -70,7 +70,7 @@ prog_char *getmsg(byte id) {
    #if defined(HARDWARE_SERIAL_TX) || defined(SOFTWARE_SERIAL_TX)
    // print the nth string from the message table, e.g., msgp(M_missing);
    void msgp(byte id) {
  • prog_char *msg = getmsg(id);
  • const prog_char *msg = getmsg(id);
    for (;;) {
    char c = pgm_read_byte(msg++);
    if (!c) break;
    @@ -105,7 +105,7 @@ tokenhandler tokenhandlers[TOKENTYPES] = {
    // The code corresponding to a character specifies which of the token handlers above will
    // be called when the character is seen as the initial character in a symbol.

define np(a,b) ((a<<4)+b)

-prog_char chartypes[] PROGMEM = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F
+const prog_char chartypes[] PROGMEM = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F
np(3,4), np(4,4), np(4,4), np(4,4), np(4,0), np(0,4), np(4,0), np(4,4), //0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
np(4,4), np(4,4), np(4,4), np(4,4), np(4,4), np(4,4), np(4,4), np(4,4), //1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
np(0,8), np(7,7), np(4,7), np(8,5), np(7,7), np(7,8), np(7,8), np(7,8), //2 SP ! " # $ % & ' ( ) * + , - . slash
@@ -352,11 +352,11 @@ void releaseargblock(void) {
// MUST BE IN ALPHABETICAL ORDER!
//

ifdef TINY85

-prog_char reservedwords[] PROGMEM = { "boot\0if\0run\0stop\0switch\0while\0" };
-prog_uchar reservedwordtypes[] PROGMEM = { s_boot, s_if, s_run, s_stop, s_switch, s_while };
+const prog_char reservedwords[] PROGMEM = { "boot\0if\0run\0stop\0switch\0while\0" };
+const prog_uchar reservedwordtypes[] PROGMEM = { s_boot, s_if, s_run, s_stop, s_switch, s_while };

else

-prog_char reservedwords[] PROGMEM = { "arg\0boot\0else\0function\0help\0if\0ls\0peep\0print\0ps\0return\0rm\0run\0stop\0switch\0while\0" };
-prog_uchar reservedwordtypes[] PROGMEM = { s_arg, s_boot, s_else, s_function, s_help, s_if, s_ls, s_peep, s_print, s_ps, s_return, s_rm, s_run, s_stop, s_switch, s_while };
+const prog_char reservedwords[] PROGMEM = { "arg\0boot\0else\0function\0help\0if\0ls\0peep\0print\0ps\0return\0rm\0run\0stop\0switch\0while\0" };
+const prog_uchar reservedwordtypes[] PROGMEM = { s_arg, s_boot, s_else, s_function, s_help, s_if, s_ls, s_peep, s_print, s_ps, s_return, s_rm, s_run, s_stop, s_switch, s_while };

endif

// find id in PROGMEM wordlist. result in symval, return true if found.
@@ -474,8 +474,8 @@ void chrconst(void) {
}

-prog_char twochartokens[] PROGMEM = { "&&||==!=++--:=>=>><=<<//" };
-prog_uchar twocharsyms[] PROGMEM = {
+const prog_char twochartokens[] PROGMEM = { "&&||==!=++--:=>=>><=<<//" };
+const prog_uchar twocharsyms[] PROGMEM = {
s_logicaland, s_logicalor, s_logicaleq, s_logicalne, s_incr,
s_decr, s_define, s_ge, s_shiftright, s_le, s_shiftleft, s_comment
};
@@ -485,7 +485,7 @@ void parseop(void) {
sym = inchar; // think horse not zebra
fetchc(); // inchar has second char of token or ??

  • prog_char *tk = twochartokens;
  • const prog_char *tk = twochartokens;
    byte index = 0;
    for (;;) {
    byte c1 = pgm_read_byte(tk++);
    diff --git a/src/bitlash.h b/src/bitlash.h
    index 9eea130..1c70b1e 100644
    --- a/src/bitlash.h
    +++ b/src/bitlash.h
    @@ -488,8 +488,8 @@ void dofunctioncall(byte);
    numvar func_free(void);
    void beep(unumvar, unumvar, unumvar);

-extern prog_char functiondict[] PROGMEM;
-extern prog_char aliasdict[] PROGMEM;
+const extern prog_char functiondict[] PROGMEM;
+const extern prog_char aliasdict[] PROGMEM;

void stir(byte);

@@ -592,7 +592,7 @@ void traceback(void);

numvar func_fprintf(void);

-prog_char getmsg(byte);
+const prog_char *getmsg(byte);
void parsestring(void (
)(char));
void msgp(byte);
void msgpl(byte);
@@ -604,7 +604,7 @@ byte is_end(void);
numvar getarg(numvar);
void releaseargblock(void);
void parsearglist(void);
-extern prog_char reservedwords[];
+const extern prog_char reservedwords[];

No support for bypass serial

Only output bypass is available using serial handler. For some odd reason you can not bypass the serial to decide if you want bitlash to intepreter the data or just do it yourself. This really limits your options since you cant decide yourself when you want bitlash to be involved.

Increasing MAX_USER_FUNCTIONS?

We're using addBitlashFunction so heavily with Pinoccio that we've hit the MAX wall hard, and have plans to go well above 256 even... I looked at bitlash-functions.c and couldn't see any quick fix to increase it higher due to how it masks the last function into the symval byte.

Do you have any ideas on what could be done to easily bump the limit even higher?

Software serial higher bitrates fail

When using the software serial support, using:

baud(2, 19200)
print #2, "abcd"

My USB TTL converter receives garbage. Running at 9600 works, but at higher speeds (I also tried 14400) it fails. When I raise the bitrate a bit (on the bitlash end), things start to work. Setting 20100 in bitlash and 19200 in my TTL adapter seems to work reliably.

This seems to suggest that the delay employed by the softwareserial is slightly too high (since a higher baudrate causes a lower delay). I guess the bittime calculation should account for more than 50 clockcycles overhead? 50 cycles of overhead seems a lot already, but I think that it's mainly the digitalWrite that takes a long time...

   bittime[pin] = (1000000/baud) - clockCyclesToMicroseconds(50); 

Note that I'm running on GCC 4.8, which might also cause differences in overhead...

Serial output does not use Arduino's Print class

While looking over the code, I found that the serial output code is using an "sp" function to print strings to various locations, optionally doing software serial on arbitrary pins.

Is there any reason you're not using Arduino's Print class, possibly combined with the SoftwareSerial library to do this stuff? Sounds like you'd get cleaner code and also get printing numbers, String objects, Printable objects, etc. for free? Also, you could then just pass in a Print& on startup, instead of selecting a serial port through defines etc.

Mind you, I haven't looked long enough to know wether this is actually feasible, but before I look closer and invest more time, I thought I'd ask around first.

Perhaps one reason for not doing this is compatibility with older Arduino versions, but perhaps those are not longer so relevant nowadays?

"bitlashsd" with Wire library cause restart

Hi, we are planning to use bitlash with a SD card while using the arduino Wire library for I2C communication. But once the Wire library is included to "bitlashsd" code, the arduino restarts continuously. Any idea on how to fix this problem?

Thanks!

func_free does not include dynamic memory

The current implementation of the free function does not include any dynamic memory. It just includes the bss section (static memory using __bss_end) and the stack. Even though bitlash itself doesn't use dynamic memory, sketches may and this should be accounted for in the free output. The func_free implementation already links to a page that does this, using the __brkval variable.

No need to wait after Wire.requestFrom().

These lines in the file "bitlash/src/eeprom.c" can be removed.

while(Wire.available() == 0)
{}

There is no need to wait after Wire.requestFrom(). When the Wire.requestFrom() returns, the I2C transaction has completely finished.

Talk to arduino without >command

Hi,
I am trying to use bitlash with C#. Everything is perfect and works except one thing which ruins everything for me. Bilash by default thinks that I am in terminal and echos my commands and > sign. However in order for it to be usable when talking with C# program over serial it must send only result of the command. Currently when I write printf("a0:%d", a0) as a response I will get:
printf("a0:%d", a0)
a0:551

I want to get:
a0:551

I am sure I am missing something obvious but I cannot seem to find a solution. Whats the catch?

Thanks in advance!

Not working on new Arduino..

On the new boards using ARM processors, like the Zero, which are the future of MCU's, you get an error on compilation :

fatal error: avr/io.h: No such file or directory
#include "avr/io.h"

Wonder if its possible at all ?

Can't save user functions to startup?

I hope I am getting it wrong, but after trying many times, I could define a new user function and fire it, but I could not set the system to fire it on startup, no matter what .

So in Arduino :

addBitlashFunction("ran", (bitlash_function) ran);

and the function

numvar ran(void) {


//also print not working .
 digitalWrite(13, HIGH);   // delay only for this matter
  delay(1000);                
  digitalWrite(13, LOW);     
  delay(1000);  

}

When you try to run it , it works, but if you try to

function startup { ran; } // here you get back "saved"

you get on boot the error - "unexpected number" , no matter what you do in this function.

I hope I am doing it wrong, otherwise whats the benefit of user functions ?

Thanks anyway!

========^ unexpected number error for functions

Please Help! I thought I was writing my functions properly. Also, example "timer1" doesn't work either. I'm using an Authentic Arduino Mega2560 R3.

I/O

bitlash here! v2.0 (c) 2013 Bill Roy -type HELP- 6044 bytes free
> print needle()

--------------^
unexpected number
> print NEEDLE()

--------------^
unexpected number
> echo(100,1,"Spam, Spam Spam", 42)
100
1
Spam, Spam Spam
42
> print timer1(), timer1(), timer1()

--------------^
unexpected number

Code

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif
#include "bitlash.h"
#include "../bitlash/src/bitlash.h"  // for sp() and printInteger()

numvar func_NEEDLE(void)
{
    return analogRead(A8);
}

// The ECHO() function echoes back its arguments for debugging, with proper handling for strings
numvar func_ECHO(void) {
  for (int i=1; i <= getarg(0); i++) {
    if (isstringarg(i))
      sp((const char *) getstringarg(i));
    else printInteger(getarg(i), 0, ' ');
      speol();
  }
}

numvar timer1(void) {
    return TCNT1; 	// return the value of Timer 1
}

void loadBitlashFunctions()
{
  addBitlashFunction("ECHO", (bitlash_function) func_ECHO);     // The ECHO() function echoes back its arguments, \
                                                                   with proper handling for strings
  addBitlashFunction("NEEDLE", (bitlash_function) func_NEEDLE);
  addBitlashFunction("timer1", (bitlash_function) timer1);
}

void setup(void) {
  initBitlash(57600);   // must be first to initialize serial port
  loadBitlashFunctions();
}

void loop(void) {
  runBitlash();
}

Function size limit

1 issue, 1 improvement, 1 question and 1 happy user!

I'm very happy with bitlash, this provides me a shell for Arduino and expands the possibilities by making the Arduino almost a dynamic device which can be re-programmed on the field. The snooze based semi-multitasking is awesome!

1 issue:
I just subscribed to the project and noticed it is alive, which is quite good :) I noticed that the functions are size limited but it seems like a bug because it is neither documented nor an error message is issued when the limit is encountered. I currently own an Arduino compatible SainSmart ATMEGA2560 with W5100 Ethernet Shield. I uploaded the bitlash Web Server example and started using it. If I try to input a function longuer or equal to 60 characters, the function appears as function name {} after issuing ls. Nothing else I could notice, it always does that, whatever the function name is. Shorter functions work perfectly, longuer won't work (do nothing) and appear in "peep" as empty too.

1 improvement:
Maybe it would be nice to indicate in the documentation that to use analog pins in functions they should use higher numbered pin numbers, that took me a while to figure out by myself. For example in for loops and specially in pinmode!!

1 question:
Is it possible to store function in RAM actually? Maybe with a prefix? Or maybe in the main flash in the future?

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.