aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--boards.txt80
-rw-r--r--cores/arduino/HardwareSerial.cpp5
-rw-r--r--cores/arduino/HardwareSerial.h2
-rwxr-xr-xcores/arduino/Print.cpp182
-rwxr-xr-xcores/arduino/Print.h64
-rw-r--r--cores/arduino/Printable.h2
-rw-r--r--cores/arduino/Stream.cpp233
-rw-r--r--cores/arduino/Stream.h58
-rw-r--r--variants/eightanaloginputs/pins_arduino.h27
-rw-r--r--variants/mega/pins_arduino.h (renamed from pins/mega/pins_arduino.h)34
-rw-r--r--variants/standard/pins_arduino.h (renamed from pins/standard/pins_arduino.h)19
11 files changed, 579 insertions, 127 deletions
diff --git a/boards.txt b/boards.txt
index a96d823..bc14341 100644
--- a/boards.txt
+++ b/boards.txt
@@ -32,11 +32,11 @@ uno.bootloader.lock_bits=0x0F
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino
-uno.build.pins=standard
+uno.build.variant=standard
##############################################################
-atmega328.name=Arduino Duemilanove or Nano w/ ATmega328
+atmega328.name=Arduino Duemilanove w/ ATmega328
atmega328.upload.protocol=stk500
atmega328.upload.maximum_size=30720
@@ -53,11 +53,11 @@ atmega328.bootloader.lock_bits=0x0F
atmega328.build.mcu=atmega328p
atmega328.build.f_cpu=16000000L
atmega328.build.core=arduino
-atmega328.build.pins=standard
+atmega328.build.variant=standard
##############################################################
-diecimila.name=Arduino Diecimila, Duemilanove, or Nano w/ ATmega168
+diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168
diecimila.upload.protocol=stk500
diecimila.upload.maximum_size=14336
@@ -74,7 +74,49 @@ diecimila.bootloader.lock_bits=0x0F
diecimila.build.mcu=atmega168
diecimila.build.f_cpu=16000000L
diecimila.build.core=arduino
-diecimila.build.pins=standard
+diecimila.build.variant=standard
+
+##############################################################
+
+nano328.name=Arduino Nano w/ ATmega328
+
+nano328.upload.protocol=stk500
+nano328.upload.maximum_size=30720
+nano328.upload.speed=57600
+
+nano328.bootloader.low_fuses=0xFF
+nano328.bootloader.high_fuses=0xDA
+nano328.bootloader.extended_fuses=0x05
+nano328.bootloader.path=atmega
+nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex
+nano328.bootloader.unlock_bits=0x3F
+nano328.bootloader.lock_bits=0x0F
+
+nano328.build.mcu=atmega328p
+nano328.build.f_cpu=16000000L
+nano328.build.core=arduino
+nano328.build.variant=eightanaloginputs
+
+##############################################################
+
+nano.name=Arduino Nano w/ ATmega168
+
+nano.upload.protocol=stk500
+nano.upload.maximum_size=14336
+nano.upload.speed=19200
+
+nano.bootloader.low_fuses=0xff
+nano.bootloader.high_fuses=0xdd
+nano.bootloader.extended_fuses=0x00
+nano.bootloader.path=atmega
+nano.bootloader.file=ATmegaBOOT_168_diecimila.hex
+nano.bootloader.unlock_bits=0x3F
+nano.bootloader.lock_bits=0x0F
+
+nano.build.mcu=atmega168
+nano.build.f_cpu=16000000L
+nano.build.core=arduino
+nano.build.variant=eightanaloginputs
##############################################################
@@ -95,7 +137,7 @@ mega2560.bootloader.lock_bits=0x0F
mega2560.build.mcu=atmega2560
mega2560.build.f_cpu=16000000L
mega2560.build.core=arduino
-mega2560.build.pins=mega
+mega2560.build.variant=mega
##############################################################
@@ -116,7 +158,7 @@ mega.bootloader.lock_bits=0x0F
mega.build.mcu=atmega1280
mega.build.f_cpu=16000000L
mega.build.core=arduino
-mega.build.pins=mega
+mega.build.variant=mega
##############################################################
@@ -137,7 +179,7 @@ mini.bootloader.lock_bits=0x0F
mini.build.mcu=atmega168
mini.build.f_cpu=16000000L
mini.build.core=arduino
-mini.build.pins=standard
+mini.build.variant=eightanaloginputs
##############################################################
@@ -158,7 +200,7 @@ fio.bootloader.lock_bits=0x0F
fio.build.mcu=atmega328p
fio.build.f_cpu=8000000L
fio.build.core=arduino
-fio.build.pins=standard
+fio.build.variant=eightanaloginputs
##############################################################
@@ -180,7 +222,7 @@ bt328.bootloader.lock_bits=0x0F
bt328.build.mcu=atmega328p
bt328.build.f_cpu=16000000L
bt328.build.core=arduino
-bt328.build.pins=standard
+bt328.build.variant=eightanaloginputs
##############################################################
@@ -202,7 +244,7 @@ bt.bootloader.lock_bits=0x0F
bt.build.mcu=atmega168
bt.build.f_cpu=16000000L
bt.build.core=arduino
-bt.build.pins=standard
+bt.build.variant=eightanaloginputs
##############################################################
@@ -223,7 +265,7 @@ lilypad328.bootloader.lock_bits=0x0F
lilypad328.build.mcu=atmega328p
lilypad328.build.f_cpu=8000000L
lilypad328.build.core=arduino
-lilypad328.build.pins=standard
+lilypad328.build.variant=standard
##############################################################
@@ -244,7 +286,7 @@ lilypad.bootloader.lock_bits=0x0F
lilypad.build.mcu=atmega168
lilypad.build.f_cpu=8000000L
lilypad.build.core=arduino
-lilypad.build.pins=standard
+lilypad.build.variant=standard
##############################################################
@@ -265,7 +307,7 @@ pro5v328.bootloader.lock_bits=0x0F
pro5v328.build.mcu=atmega328p
pro5v328.build.f_cpu=16000000L
pro5v328.build.core=arduino
-pro5v328.build.pins=standard
+pro5v328.build.variant=standard
##############################################################
@@ -286,7 +328,7 @@ pro5v.bootloader.lock_bits=0x0F
pro5v.build.mcu=atmega168
pro5v.build.f_cpu=16000000L
pro5v.build.core=arduino
-pro5v.build.pins=standard
+pro5v.build.variant=standard
##############################################################
@@ -307,7 +349,7 @@ pro328.bootloader.lock_bits=0x0F
pro328.build.mcu=atmega328p
pro328.build.f_cpu=8000000L
pro328.build.core=arduino
-pro328.build.pins=standard
+pro328.build.variant=standard
##############################################################
@@ -328,7 +370,7 @@ pro.bootloader.lock_bits=0x0F
pro.build.mcu=atmega168
pro.build.f_cpu=8000000L
pro.build.core=arduino
-pro.build.pins=standard
+pro.build.variant=standard
##############################################################
@@ -349,7 +391,7 @@ atmega168.bootloader.lock_bits=0x0F
atmega168.build.mcu=atmega168
atmega168.build.f_cpu=16000000L
atmega168.build.core=arduino
-atmega168.build.pins=standard
+atmega168.build.variant=standard
##############################################################
@@ -369,4 +411,4 @@ atmega8.bootloader.lock_bits=0x0F
atmega8.build.mcu=atmega8
atmega8.build.f_cpu=16000000L
atmega8.build.core=arduino
-atmega8.build.pins=standard
+atmega8.build.variant=standard
diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp
index 77ccd06..48f5fd3 100644
--- a/cores/arduino/HardwareSerial.cpp
+++ b/cores/arduino/HardwareSerial.cpp
@@ -363,12 +363,13 @@ void HardwareSerial::flush()
;
}
-void HardwareSerial::write(uint8_t c)
+size_t HardwareSerial::write(uint8_t c)
{
int i = (_tx_buffer->head + 1) % SERIAL_BUFFER_SIZE;
// If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit
+ // ???: return 0 here instead?
while (i == _tx_buffer->tail)
;
@@ -376,6 +377,8 @@ void HardwareSerial::write(uint8_t c)
_tx_buffer->head = i;
sbi(*_ucsrb, _udrie);
+
+ return 1;
}
// Preinstantiate Objects //////////////////////////////////////////////////////
diff --git a/cores/arduino/HardwareSerial.h b/cores/arduino/HardwareSerial.h
index e8db76d..cadfa65 100644
--- a/cores/arduino/HardwareSerial.h
+++ b/cores/arduino/HardwareSerial.h
@@ -55,7 +55,7 @@ class HardwareSerial : public Stream
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
- virtual void write(uint8_t);
+ virtual size_t write(uint8_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
};
diff --git a/cores/arduino/Print.cpp b/cores/arduino/Print.cpp
index 06ac52a..8190d4f 100755
--- a/cores/arduino/Print.cpp
+++ b/cores/arduino/Print.cpp
@@ -30,167 +30,190 @@
// Public Methods //////////////////////////////////////////////////////////////
/* default implementation: may be overridden */
-void Print::write(const char *str)
+size_t Print::write(const char *str)
{
- while (*str)
- write(*str++);
+ size_t n = 0;
+ while (*str) {
+ n += write(*str++);
+ }
+ return n;
}
/* default implementation: may be overridden */
-void Print::write(const uint8_t *buffer, size_t size)
+size_t Print::write(const uint8_t *buffer, size_t size)
{
- while (size--)
- write(*buffer++);
+ size_t n = 0;
+ while (size--) {
+ n += write(*buffer++);
+ }
+ return n;
}
-void Print::print(const __FlashStringHelper *ifsh)
+size_t Print::print(const __FlashStringHelper *ifsh)
{
const prog_char *p = (const prog_char *)ifsh;
+ size_t n = 0;
while (1) {
unsigned char c = pgm_read_byte(p++);
- if (c == 0) return;
- write(c);
+ if (c == 0) break;
+ n += write(c);
}
+ return n;
}
-void Print::print(const String &s)
+size_t Print::print(const String &s)
{
+ size_t n = 0;
for (int i = 0; i < s.length(); i++) {
- write(s[i]);
+ n += write(s[i]);
}
+ return n;
}
-void Print::print(const char str[])
+size_t Print::print(const char str[])
{
- write(str);
+ return write(str);
}
-void Print::print(char c)
+size_t Print::print(char c)
{
- write(c);
+ return write(c);
}
-void Print::print(unsigned char b, int base)
+size_t Print::print(unsigned char b, int base)
{
- print((unsigned long) b, base);
+ return print((unsigned long) b, base);
}
-void Print::print(int n, int base)
+size_t Print::print(int n, int base)
{
- print((long) n, base);
+ return print((long) n, base);
}
-void Print::print(unsigned int n, int base)
+size_t Print::print(unsigned int n, int base)
{
- print((unsigned long) n, base);
+ return print((unsigned long) n, base);
}
-void Print::print(long n, int base)
+size_t Print::print(long n, int base)
{
if (base == 0) {
- write(n);
+ return write(n);
} else if (base == 10) {
if (n < 0) {
- print('-');
+ int t = print('-');
n = -n;
+ return printNumber(n, 10) + t;
}
- printNumber(n, 10);
+ return printNumber(n, 10);
} else {
- printNumber(n, base);
+ return printNumber(n, base);
}
}
-void Print::print(unsigned long n, int base)
+size_t Print::print(unsigned long n, int base)
{
- if (base == 0) write(n);
- else printNumber(n, base);
+ if (base == 0) return write(n);
+ else return printNumber(n, base);
}
-void Print::print(double n, int digits)
+size_t Print::print(double n, int digits)
{
- printFloat(n, digits);
+ return printFloat(n, digits);
}
-void Print::println(const __FlashStringHelper *ifsh)
+size_t Print::println(const __FlashStringHelper *ifsh)
{
- print(ifsh);
- println();
+ size_t n = print(ifsh);
+ n += println();
+ return n;
}
-void Print::print(const Printable& x)
+size_t Print::print(const Printable& x)
{
- x.printTo(*this);
+ return x.printTo(*this);
}
-void Print::println(void)
+size_t Print::println(void)
{
- print('\r');
- print('\n');
+ size_t n = print('\r');
+ n += print('\n');
+ return n;
}
-void Print::println(const String &s)
+size_t Print::println(const String &s)
{
- print(s);
- println();
+ size_t n = print(s);
+ n += println();
+ return n;
}
-void Print::println(const char c[])
+size_t Print::println(const char c[])
{
- print(c);
- println();
+ size_t n = print(c);
+ n += println();
+ return n;
}
-void Print::println(char c)
+size_t Print::println(char c)
{
- print(c);
- println();
+ size_t n = print(c);
+ n += println();
+ return n;
}
-void Print::println(unsigned char b, int base)
+size_t Print::println(unsigned char b, int base)
{
- print(b, base);
- println();
+ size_t n = print(b, base);
+ n += println();
+ return n;
}
-void Print::println(int n, int base)
+size_t Print::println(int num, int base)
{
- print(n, base);
- println();
+ size_t n = print(num, base);
+ n += println();
+ return n;
}
-void Print::println(unsigned int n, int base)
+size_t Print::println(unsigned int num, int base)
{
- print(n, base);
- println();
+ size_t n = print(num, base);
+ n += println();
+ return n;
}
-void Print::println(long n, int base)
+size_t Print::println(long num, int base)
{
- print(n, base);
- println();
+ size_t n = print(num, base);
+ n += println();
+ return n;
}
-void Print::println(unsigned long n, int base)
+size_t Print::println(unsigned long num, int base)
{
- print(n, base);
- println();
+ size_t n = print(num, base);
+ n += println();
+ return n;
}
-void Print::println(double n, int digits)
+size_t Print::println(double num, int digits)
{
- print(n, digits);
- println();
+ size_t n = print(num, digits);
+ n += println();
+ return n;
}
-void Print::println(const Printable& x)
+size_t Print::println(const Printable& x)
{
- print(x);
- println();
+ size_t n = print(x);
+ n += println();
+ return n;
}
// Private Methods /////////////////////////////////////////////////////////////
-void Print::printNumber(unsigned long n, uint8_t base) {
+size_t Print::printNumber(unsigned long n, uint8_t base) {
char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
char *str = &buf[sizeof(buf) - 1];
@@ -206,15 +229,17 @@ void Print::printNumber(unsigned long n, uint8_t base) {
*--str = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
- write(str);
+ return write(str);
}
-void Print::printFloat(double number, uint8_t digits)
+size_t Print::printFloat(double number, uint8_t digits)
{
+ size_t n = 0;
+
// Handle negative numbers
if (number < 0.0)
{
- print('-');
+ n += print('-');
number = -number;
}
@@ -228,18 +253,21 @@ void Print::printFloat(double number, uint8_t digits)
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
- print(int_part);
+ n += print(int_part);
// Print the decimal point, but only if there are digits beyond
- if (digits > 0)
- print(".");
+ if (digits > 0) {
+ n += print(".");
+ }
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
- print(toPrint);
+ n += print(toPrint);
remainder -= toPrint;
}
+
+ return n;
}
diff --git a/cores/arduino/Print.h b/cores/arduino/Print.h
index bf10b14..fce302e 100755
--- a/cores/arduino/Print.h
+++ b/cores/arduino/Print.h
@@ -34,37 +34,45 @@
class Print
{
private:
- void printNumber(unsigned long, uint8_t);
- void printFloat(double, uint8_t);
+ int write_error;
+ size_t printNumber(unsigned long, uint8_t);
+ size_t printFloat(double, uint8_t);
+ protected:
+ void setWriteError(int err = 1) { write_error = err; }
public:
- virtual void write(uint8_t) = 0;
- virtual void write(const char *str);
- virtual void write(const uint8_t *buffer, size_t size);
+ Print() : write_error(0) {}
+
+ int writeError() { return write_error; }
+ void clearWriteError() { setWriteError(0); }
+
+ virtual size_t write(uint8_t) = 0;
+ virtual size_t write(const char *str);
+ virtual size_t write(const uint8_t *buffer, size_t size);
- void print(const __FlashStringHelper *);
- void print(const String &);
- void print(const char[]);
- void print(char);
- void print(unsigned char, int = DEC);
- void print(int, int = DEC);
- void print(unsigned int, int = DEC);
- void print(long, int = DEC);
- void print(unsigned long, int = DEC);
- void print(double, int = 2);
- void print(const Printable&);
+ size_t print(const __FlashStringHelper *);
+ size_t print(const String &);
+ size_t print(const char[]);
+ size_t print(char);
+ size_t print(unsigned char, int = DEC);
+ size_t print(int, int = DEC);
+ size_t print(unsigned int, int = DEC);
+ size_t print(long, int = DEC);
+ size_t print(unsigned long, int = DEC);
+ size_t print(double, int = 2);
+ size_t print(const Printable&);
- void println(const __FlashStringHelper *);
- void println(const String &s);
- void println(const char[]);
- void println(char);
- void println(unsigned char, int = DEC);
- void println(int, int = DEC);
- void println(unsigned int, int = DEC);
- void println(long, int = DEC);
- void println(unsigned long, int = DEC);
- void println(double, int = 2);
- void println(const Printable&);
- void println(void);
+ size_t println(const __FlashStringHelper *);
+ size_t println(const String &s);
+ size_t println(const char[]);
+ size_t println(char);
+ size_t println(unsigned char, int = DEC);
+ size_t println(int, int = DEC);
+ size_t println(unsigned int, int = DEC);
+ size_t println(long, int = DEC);
+ size_t println(unsigned long, int = DEC);
+ size_t println(double, int = 2);
+ size_t println(const Printable&);
+ size_t println(void);
};
#endif
diff --git a/cores/arduino/Printable.h b/cores/arduino/Printable.h
index d332aad..e22e87e 100644
--- a/cores/arduino/Printable.h
+++ b/cores/arduino/Printable.h
@@ -30,7 +30,7 @@ class Print;
class Printable
{
public:
- virtual void printTo(Print& p) const = 0;
+ virtual size_t printTo(Print& p) const = 0;
};
#endif
diff --git a/cores/arduino/Stream.cpp b/cores/arduino/Stream.cpp
new file mode 100644
index 0000000..d267bf0
--- /dev/null
+++ b/cores/arduino/Stream.cpp
@@ -0,0 +1,233 @@
+/*
+ Stream.cpp - adds parsing methods to Stream class
+ Copyright (c) 2008 David A. Mellis. All right reserved.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ Created July 2011
+ parsing functions based on TextFinder library by Michael Margolis
+ */
+
+#include "Arduino.h"
+#include "Stream.h"
+
+#define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
+#define NO_SKIP_CHAR 1 // a magic char not found in a valid ASCII numeric field
+
+// private method to read stream with timeout
+int Stream::timedRead()
+{
+ //Serial.println(_timeout);
+ this->_startMillis = millis();
+ while(millis() - this->_startMillis < this->_timeout)
+ {
+ if (this->available() > 0) {
+ return this->read();
+ }
+ }
+ return -1; // -1 indicates timeout
+}
+
+// returns the next digit in the stream or -1 if timeout
+// discards non-numeric characters
+int Stream::getNextDigit()
+{
+ int c;
+ do{
+ c = timedRead();
+ if( c < 0)
+ return c; // timeout
+ }
+ while( c != '-' && (c < '0' || c > '9') ) ;
+
+return c;
+}
+
+// Public Methods
+//////////////////////////////////////////////////////////////
+
+void Stream::setTimeout( long timeout) // sets the maximum number of milliseconds to wait
+{
+ this->_timeout = timeout;
+}
+
+ // find returns true if the target string is found
+bool Stream::find(char *target)
+{
+ return findUntil(target, NULL);
+}
+
+// reads data from the stream until the target string of given length is found
+// returns true if target string is found, false if timed out
+bool Stream::find(char *target, size_t length)
+{
+ return findUntil(target, length, NULL, 0);
+}
+
+// as find but search ends if the terminator string is found
+bool Stream::findUntil(char *target, char *terminator)
+{
+ return findUntil(target, strlen(target), terminator, strlen(terminator));
+}
+
+// reads data from the stream until the target string of the given length is found
+// search terminated if the terminator string is found
+// returns true if target string is found, false if terminated or timed out
+bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen)
+{
+ size_t index = 0; // maximum target string length is 64k bytes!
+ size_t termIndex = 0;
+ int c;
+
+ if( *target == 0)
+ return true; // return true if target is a null string
+ while( (c = timedRead()) > 0){
+ if( c == target[index]){
+ //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
+ if(++index >= targetLen){ // return true if all chars in the target match
+ return true;
+ }
+ }
+ else{
+ index = 0; // reset index if any char does not match
+ }
+ if(termLen > 0 && c == terminator[termIndex]){
+ if(++termIndex >= termLen)
+ return false; // return false if terminate string found before target string
+ }
+ else
+ termIndex = 0;
+ }
+ return false;
+}
+
+
+// returns the first valid (long) integer value from the current position.
+// initial characters that are not digits (or the minus sign) are skipped
+// function is terminated by the first character that is not a digit.
+long Stream::parseInt()
+{
+ return parseInt(NO_SKIP_CHAR); // terminate on first non-digit character (or timeout)
+}
+
+// as above but a given skipChar is ignored
+// this allows format characters (typically commas) in values to be ignored
+long Stream::parseInt(char skipChar)
+{
+ boolean isNegative = false;
+ long value = 0;
+ int c;
+
+ c = getNextDigit();
+ // ignore non numeric leading characters
+ if(c < 0)
+ return 0; // zero returned if timeout
+
+ do{
+ if(c == skipChar)
+ ; // ignore this charactor
+ else if(c == '-')
+ isNegative = true;
+ else if(c >= '0' && c <= '9') // is c a digit?
+ value = value * 10 + c - '0';
+ c = timedRead();
+ }
+ while( (c >= '0' && c <= '9') || c == skipChar );
+
+ if(isNegative)
+ value = -value;
+ return value;
+}
+
+
+// as parseInt but returns a floating point value
+float Stream::parseFloat()
+{
+ parseFloat(NO_SKIP_CHAR);
+}
+
+// as above but the given skipChar is ignored
+// this allows format characters (typically commas) in values to be ignored
+float Stream::parseFloat(char skipChar){
+ boolean isNegative = false;
+ boolean isFraction = false;
+ long value = 0;
+ float fValue;
+ char c;
+ float fraction = 1.0;
+
+ c = getNextDigit();
+ // ignore non numeric leading characters
+ if(c < 0)
+ return 0; // zero returned if timeout
+
+ do{
+ if(c == skipChar)
+ ; // ignore
+ else if(c == '-')
+ isNegative = true;
+ else if (c == '.')
+ isFraction = true;
+ else if(c >= '0' && c <= '9') { // is c a digit?
+ value = value * 10 + c - '0';
+ if(isFraction)
+ fraction *= 0.1;
+ }
+ c = timedRead();
+ }
+ while( (c >= '0' && c <= '9') || c == '.' || c == skipChar );
+
+ if(isNegative)
+ value = -value;
+ if(isFraction)
+ return value * fraction;
+ else
+ return value;
+}
+
+// read characters from stream into buffer
+// terminates if length characters have been read, null is detected or timeout (see setTimeout)
+// returns the number of characters placed in the buffer (0 means no valid data found)
+int Stream::readBytes( char *buffer, size_t length)
+{
+ return readBytesUntil( 0, buffer, length);
+}
+
+
+// as readBytes with terminator character
+// terminates if length characters have been read, timeout, or if the terminator character detected
+// returns the number of characters placed in the buffer (0 means no valid data found)
+
+int Stream::readBytesUntil( char terminator, char *buffer, size_t length)
+{
+ int index = 0;
+ *buffer = 0;
+ while(index < length-1 ){
+ int c = timedRead();
+ if( c <= 0 ){
+ return 0; // timeout returns 0 !
+ }
+ else if( c == terminator){
+ buffer[index] = 0; // terminate the string
+ return index; // data got successfully
+ }
+ else{
+ buffer[index++] = (char)c;
+ }
+ }
+ buffer[index] = 0;
+ return index; // here if buffer is full before detecting the terminator
+}
+
diff --git a/cores/arduino/Stream.h b/cores/arduino/Stream.h
index 93d8275..1633f15 100644
--- a/cores/arduino/Stream.h
+++ b/cores/arduino/Stream.h
@@ -15,6 +15,8 @@
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+ parsing functions based on TextFinder library by Michael Margolis
*/
#ifndef Stream_h
@@ -23,13 +25,69 @@
#include <inttypes.h>
#include "Print.h"
+// compatability macros for testing
+/*
+#define getInt() parseInt()
+#define getInt(skipChar) parseInt(skipchar)
+#define getFloat() parseFloat()
+#define getFloat(skipChar) parseFloat(skipChar)
+#define getString( pre_string, post_string, buffer, length)
+readBytesBetween( pre_string, terminator, buffer, length)
+*/
+
class Stream : public Print
{
+ private:
+ long _timeout; // number of milliseconds to wait for the next char before aborting timed read
+ long _startMillis; // used for timeout measurement
+ int timedRead(); // private method to read stream with timeout
+ int getNextDigit(); // returns the next numeric digit in the stream or -1 if timeout
+
public:
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
virtual void flush() = 0;
+
+ Stream() {_timeout=1000;}
+
+// parsing methods
+
+ void setTimeout(long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
+
+ bool find(char *target); // reads data from the stream until the target string is found
+ // returns true if target string is found, false if timed out (see setTimeout)
+
+ bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
+ // returns true if target string is found, false if timed out
+
+ bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
+
+ bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
+
+
+ long parseInt(); // returns the first valid (long) integer value from the current position.
+ // initial characters that are not digits (or the minus sign) are skipped
+ // integer is terminated by the first character that is not a digit.
+
+ long parseInt(char skipChar); // as above but the given skipChar is ignored
+ // as above but the given skipChar is ignored
+ // this allows format characters (typically commas) in values to be ignored
+
+ float parseFloat(); // float version of parseInt
+
+ float parseFloat(char skipChar); // as above but the given skipChar is ignored
+
+ int readBytes( char *buffer, size_t length); // read chars from stream into buffer
+ // terminates if length characters have been read or timeout (see setTimeout)
+ // returns the number of characters placed in the buffer (0 means no valid data found)
+
+ int readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
+ // terminates if length characters have been read, timeout, or if the terminator character detected
+ // returns the number of characters placed in the buffer (0 means no valid data found)
+
+ // Arduino String functions to be added here
+
};
#endif
diff --git a/variants/eightanaloginputs/pins_arduino.h b/variants/eightanaloginputs/pins_arduino.h
new file mode 100644
index 0000000..52b37ef
--- /dev/null
+++ b/variants/eightanaloginputs/pins_arduino.h
@@ -0,0 +1,27 @@
+/*
+ pins_arduino.h - Pin definition functions for Arduino
+ Part of Arduino - http://www.arduino.cc/
+
+ Copyright (c) 2007 David A. Mellis
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ Boston, MA 02111-1307 USA
+
+ $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
+*/
+
+#include "../standard/pins_arduino.h"
+#undef NUM_ANALOG_INPUTS
+#define NUM_ANALOG_INPUTS 8
diff --git a/pins/mega/pins_arduino.h b/variants/mega/pins_arduino.h
index e3785e4..237173a 100644
--- a/pins/mega/pins_arduino.h
+++ b/variants/mega/pins_arduino.h
@@ -27,11 +27,20 @@
#include <avr/pgmspace.h>
+#define NUM_DIGITAL_PINS 70
+#define NUM_ANALOG_INPUTS 16
+#define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1)
+#define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))
+
const static uint8_t SS = 53;
const static uint8_t MOSI = 51;
const static uint8_t MISO = 50;
const static uint8_t SCK = 52;
+const static uint8_t SDA = 20;
+const static uint8_t SCL = 21;
+const static uint8_t LED = 13;
+
const static uint8_t A0 = 54;
const static uint8_t A1 = 55;
const static uint8_t A2 = 56;
@@ -49,6 +58,31 @@ const static uint8_t A13 = 67;
const static uint8_t A14 = 68;
const static uint8_t A15 = 69;
+// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
+// Only pins available for RECEIVE (TRANSMIT can be on any pin):
+// (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
+// Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
+
+#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \
+ (((p) >= 50) && ((p) <= 53)) || \
+ (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
+
+#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
+ ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
+ 0 ) )
+
+#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
+ ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
+ ((uint8_t *)0) ) )
+
+#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
+ ( ((p) == 50) ? 3 : \
+ ( ((p) == 51) ? 2 : \
+ ( ((p) == 52) ? 1 : \
+ ( ((p) == 53) ? 0 : \
+ ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
+ 0 ) ) ) ) ) )
+
#ifdef ARDUINO_MAIN
const uint16_t PROGMEM port_to_mode_PGM[] = {
diff --git a/pins/standard/pins_arduino.h b/variants/standard/pins_arduino.h
index 8fabb17..3999d1f 100644
--- a/pins/standard/pins_arduino.h
+++ b/variants/standard/pins_arduino.h
@@ -27,11 +27,25 @@
#include <avr/pgmspace.h>
+#define NUM_DIGITAL_PINS 20
+#define NUM_ANALOG_INPUTS 6
+#define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1)
+
+#if defined(__AVR_ATmega8__)
+#define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11)
+#else
+#define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
+#endif
+
const static uint8_t SS = 10;
const static uint8_t MOSI = 11;
const static uint8_t MISO = 12;
const static uint8_t SCK = 13;
+const static uint8_t SDA = 18;
+const static uint8_t SCL = 19;
+const static uint8_t LED = 13;
+
const static uint8_t A0 = 14;
const static uint8_t A1 = 15;
const static uint8_t A2 = 16;
@@ -41,6 +55,11 @@ const static uint8_t A5 = 19;
const static uint8_t A6 = 20;
const static uint8_t A7 = 21;
+#define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
+#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
+#define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
+#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
+
#ifdef ARDUINO_MAIN
// On the Arduino board, digital pins are also used