Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using Print and Stream classes internally #31

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
70abf9d
Remove conioh.h and mygetch.c, these were unused
matthijskooijman Jan 31, 2014
884003d
Only add the "baud" function when SOFTWARE_SERIAL_TX is defined
matthijskooijman Jan 30, 2014
7bed082
Don't reference find_user_function with TINY_BUILD
matthijskooijman Jan 30, 2014
8d9477d
Fix use of AVR GPIO registers
matthijskooijman Jan 30, 2014
43ecc8a
Don't include Arduino.h in bitlash.cpp
matthijskooijman Jan 30, 2014
9eff105
Don't include bitlash-unix.c from bitlash.cpp
matthijskooijman Jan 30, 2014
6474885
Rename all source files from .c to .cpp
matthijskooijman Jan 29, 2014
5a7c30b
Update the UNIX build Makefile to work with .cpp files
matthijskooijman Jan 30, 2014
3f641e3
Make sure all functions are properly declared
matthijskooijman Jan 29, 2014
d8f6b1d
Explicitely set -DUNIX_BUILD in the Makefile
matthijskooijman Jan 30, 2014
b4a9ac4
Only enable fprintf and save when SERIAL_OVERRIDE is enabled
matthijskooijman Jan 30, 2014
41c7ee2
Add a bit more structure to the Makefile
matthijskooijman Jan 31, 2014
874c548
Replace char * with const char * where applicable
matthijskooijman Feb 5, 2014
0902ccf
Remove some unused commented code
matthijskooijman Jan 31, 2014
d020260
Remove SOFTWARE_SERIAL_RX support
matthijskooijman Jan 29, 2014
c96a55f
Remove support for the Adafruit ethernet shield
matthijskooijman Jan 29, 2014
1af5165
Remove ethernet shield support
matthijskooijman Jan 29, 2014
8243671
Remove unused function declarations
matthijskooijman Feb 7, 2014
b387c9c
Clean up support for older Arduino versions
matthijskooijman Feb 7, 2014
fd3cd7f
Use Stream and Print classes for input and output
matthijskooijman Jan 29, 2014
bf55c69
Allow removing support for arbitrary console Streams
matthijskooijman Jan 30, 2014
f13c252
Optimize when SERIAL_OVERRIDE and/or SOFTWARE_SERIAL_TX are disabled
matthijskooijman Jan 30, 2014
6e178c8
Drop code for Arduino version < 012
matthijskooijman Feb 7, 2014
2f5c7df
Don't include WConstants.h
matthijskooijman Feb 7, 2014
9f340cd
In chkbreak, no longer gobble an input
matthijskooijman Jan 29, 2014
8409415
Fix UNIX_BUILD by using the ArduinoUnix library
matthijskooijman Feb 5, 2014
6d1603f
Add vim swapfiles to .gitignore
matthijskooijman Feb 7, 2014
b51c5b1
Remove unneeded macro check in numvar declaration
matthijskooijman Feb 8, 2014
3ac8e24
Restructure the header files
matthijskooijman Feb 7, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.swp
*.swo
*/.DS_Store
examples/bitlashdemo/applet
examples/*/applet
Expand Down
5 changes: 5 additions & 0 deletions README-UNIX.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Here are some notes on experimental Unix support for Bitlash.
- the basic functions work
- on OS X, numvar is 64 bits, so everything is 64 bits wide
- Makefile in src/ will build the binary as src/bin/bitlash
- Requires the ArduinoUnix library, which can be cloned from
https://github.com/matthijskooijman/ArduinoUnix. The makefile
normally looks for a directory called "ArduinoUnix" next to
the bitlash directory, but this can be changed by setting
ARDUINO_UNIX_PATH when calling make.
- there are some precompiled binaries in src/bin/

- eeprom is simulated
Expand Down
37 changes: 13 additions & 24 deletions bitlash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,16 @@


***/
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#ifdef UNIX_BUILD
#include "src/bitlash-unix.c"
//#else
//#include "src/bitlash-arduino.c"
#endif

#include "src/bitlash-cmdline.c"
#include "src/bitlash-eeprom.c"
#include "src/bitlash-error.c"
#include "src/bitlash-functions.c"
#include "src/bitlash-builtins.c"
#include "src/bitlash-interpreter.c"
#include "src/bitlash-instream.c"
#include "src/bitlash-parser.c"
#include "src/bitlash-serial.c"
#include "src/bitlash-taskmgr.c"
#include "src/bitlash-api.c"
#include "src/eeprom.c"

#include "src/bitlash-cmdline.cpp"
#include "src/bitlash-eeprom.cpp"
#include "src/bitlash-error.cpp"
#include "src/bitlash-functions.cpp"
#include "src/bitlash-builtins.cpp"
#include "src/bitlash-interpreter.cpp"
#include "src/bitlash-instream.cpp"
#include "src/bitlash-parser.cpp"
#include "src/bitlash-serial.cpp"
#include "src/bitlash-taskmgr.cpp"
#include "src/bitlash-api.cpp"
#include "src/eeprom.cpp"
72 changes: 2 additions & 70 deletions bitlash.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,78 +33,10 @@
OTHER DEALINGS IN THE SOFTWARE.

***/
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#define prog_char char PROGMEM
#define prog_uchar unsigned char PROGMEM
#else
#include "WProgram.h"
#endif

#include "src/bitlash-public.h"

// Un-comment the line below to expose all the internals
// of the Bitlash core to your sketch.
//
//#include "src/bitlash.h"

///////////////////////
// Start Bitlash, and give it cycles to do stuff
//
void initBitlash(unsigned long baud); // start up and set baud rate
void runBitlash(void); // call this in loop(), frequently

// Bitlash variables are of type "numvar"
//
typedef long int numvar; // bitlash returns things of type numvar
typedef unsigned long int unumvar; // sometimes unsigned interpretation is best (like millis)


///////////////////////
// Pass a command to Bitlash for interpretation
//
numvar doCommand(char *); // execute a command from your sketch
void doCharacter(char); // pass an input character to the line editor

///////////////////////
// Access to Numeric Variables
//
// NOTE: access to variables a..z is via an index 0..25, not the variable names. Got it?
//
numvar getVar(unsigned char); // return value of bitlash variable. id is [0..25] for [a..z]
void assignVar(unsigned char, numvar); // assign value to variable. id is [0..25] for [a..z]
numvar incVar(unsigned char); // increment variable. id is [0..25] for [a..z]


///////////////////////
// Access to the Bitlash symbol table
//
// Lookup id and return TRUE if it exists
//
byte findscript(char *); // returns TRUE if a script exists with this ID
int getValue(char *key); // return location of macro value in EEPROM or -1

///////////////////////
// Add a user function to Bitlash
//
typedef numvar (*bitlash_function)(void);
void addBitlashFunction(const char *, bitlash_function);
numvar getarg(numvar);
numvar isstringarg(numvar);
numvar getstringarg(numvar which);

///////////////////////
// Serial Output Capture
//
typedef void (*serialOutputFunc)(byte);
byte serialIsOverridden(void);
void setOutputHandler(serialOutputFunc);
void setOutput(byte pin);
void resetOutputHandler(void);
numvar func_printf_handler(byte, byte);

///////////////////////
// File functions
//
numvar sdcat(void);
numvar sdwrite(char *filename, char *contents, byte append);
numvar func_fprintf(void);
//#include "src/bitlash-private.h"
4 changes: 0 additions & 4 deletions examples/bitlash_rf/bitlash_rf.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@
//#define RADIO_VIRTUALWIRE
//#include "VirtualWire.h"

// Arduino detector
//
#define ARDUINO_BUILD 1

#include <avr/io.h>
#include <avr/interrupt.h>
#include "pkt.h"
Expand Down
17 changes: 14 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
all:
gcc -pthread *.c -o bin/bitlash
ARDUINO_UNIX_PATH ?= ../../ArduinoUnix

include $(ARDUINO_UNIX_PATH)/Makefile.mk

CFLAGS := -DUNIX_BUILD -pthread -I$(ARDUINO_UNIX_INCLUDE_PATH)
LDFLAGS := -lstdc++ -pthread
SOURCES := $(wildcard *.cpp) $(ARDUINO_UNIX_SOURCES)
BINARY := bin/bitlash
PREFIX := /usr/local
BINPATH := $(PREFIX)/bin

all:
gcc $(LDFLAGS) $(CFLAGS) $(SOURCES) -o $(BINARY)

install:
sudo cp bin/bitlash /usr/local/bin/
sudo cp $(BINARY) $(BINPATH)
Binary file modified src/bin/bitlash
Binary file not shown.
27 changes: 17 additions & 10 deletions src/bitlash-api.c → src/bitlash-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
OTHER DEALINGS IN THE SOFTWARE.

***/
#include "bitlash.h"
#include "bitlash-private.h"


// Exception handling state
Expand All @@ -45,19 +45,12 @@ jmp_buf env;
//
// doCommand: main entry point to execute a bitlash command
//
numvar doCommand(char *cmd) {
numvar doCommand(const char *cmd) {
return execscript(SCRIPT_RAM, (numvar) cmd, 0);
}


void initBitlash(unsigned long baud) {

#if defined(TINY_BUILD)
beginSerial(9600);
#else
beginSerial(baud);
#endif

static void initBitlashInternal() {
#if defined(ARM_BUILD)
eeinit();
#endif
Expand All @@ -76,3 +69,17 @@ void initBitlash(unsigned long baud) {
initlbuf();
}

#ifndef DEFAULT_CONSOLE_ONLY
void initBitlash(Stream& stream) {
blout = bloutdefault = blconsole = &stream;
initBitlashInternal();
}
#endif

void initBitlash(unsigned long baud) {
#if defined(TINY_BUILD)
baud = 9600;
#endif
DEFAULT_CONSOLE.begin(baud);
initBitlashInternal();
}
4 changes: 2 additions & 2 deletions src/bitlash-builtins.c → src/bitlash-builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
OTHER DEALINGS IN THE SOFTWARE.

***/
#include "bitlash.h"
#include "bitlash-private.h"

/**********

Expand Down Expand Up @@ -87,7 +87,7 @@ const prog_char builtin_table[] PROGMEM = {



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

while (pgm_read_byte(wordlist)) {
Expand Down
8 changes: 4 additions & 4 deletions src/bitlash-cmdline.c → src/bitlash-cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
OTHER DEALINGS IN THE SOFTWARE.

***/
#include "bitlash.h"
#include "bitlash-private.h"


// Serial command line buffer
Expand Down Expand Up @@ -106,7 +106,7 @@ void initlbuf(void) {
prompt();

// flush any pending serial input
while (serialAvailable()) serialRead();
while (blconsole->read() >= 0) /* nothing */;
}


Expand All @@ -125,7 +125,7 @@ byte putlbuf(char c) {

void pointToError(void) {
if (fetchtype == SCRIPT_RAM) {
int i = (char *) fetchptr - lbuf;
int i = (const char *) fetchptr - lbuf;
if ((i < 0) || (i >= LBUFLEN)) return;
speol();
while (i-- >= 0) spb('-');
Expand Down Expand Up @@ -197,7 +197,7 @@ void doCharacter(char c) {
void runBitlash(void) {

// Pipe the serial input into the command handler
if (serialAvailable()) doCharacter(serialRead());
if (blconsole->available()) doCharacter(blconsole->read());

// Background macro handler: feed it one call each time through
runBackgroundTasks();
Expand Down
Loading