aboutsummaryrefslogtreecommitdiff
path: root/cores/arduino
diff options
context:
space:
mode:
Diffstat (limited to 'cores/arduino')
-rwxr-xr-xcores/arduino/Arduino.h2
-rw-r--r--cores/arduino/Stream.h2
-rw-r--r--cores/arduino/WInterrupts.c30
-rw-r--r--cores/arduino/WString.cpp61
-rw-r--r--cores/arduino/WString.h10
-rw-r--r--cores/arduino/wiring_analog.c2
-rwxr-xr-xcores/arduino/wiring_private.h4
7 files changed, 97 insertions, 14 deletions
diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h
index b265825..3b9ccca 100755
--- a/cores/arduino/Arduino.h
+++ b/cores/arduino/Arduino.h
@@ -46,7 +46,7 @@ extern "C"{
#define EXTERNAL 1
#define INTERNAL 2
#else
-#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
+#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
#define INTERNAL1V1 2
#define INTERNAL2V56 3
#else
diff --git a/cores/arduino/Stream.h b/cores/arduino/Stream.h
index 58bbf75..007b4bc 100644
--- a/cores/arduino/Stream.h
+++ b/cores/arduino/Stream.h
@@ -37,7 +37,7 @@ readBytesBetween( pre_string, terminator, buffer, length)
class Stream : public Print
{
- private:
+ protected:
unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
unsigned long _startMillis; // used for timeout measurement
int timedRead(); // private method to read stream with timeout
diff --git a/cores/arduino/WInterrupts.c b/cores/arduino/WInterrupts.c
index de49cd1..d3fbf10 100644
--- a/cores/arduino/WInterrupts.c
+++ b/cores/arduino/WInterrupts.c
@@ -51,14 +51,14 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
// I hate doing this, but the register assignment differs between the 1280/2560
// and the 32U4. Since avrlib defines registers PCMSK1 and PCMSK2 that aren't
// even present on the 32U4 this is the only way to distinguish between them.
- case 0:
- EICRA = (EICRA & ~((1<<ISC00) | (1<<ISC01))) | (mode << ISC00);
- EIMSK |= (1<<INT0);
- break;
- case 1:
- EICRA = (EICRA & ~((1<<ISC10) | (1<<ISC11))) | (mode << ISC10);
- EIMSK |= (1<<INT1);
- break;
+ case 0:
+ EICRA = (EICRA & ~((1<<ISC00) | (1<<ISC01))) | (mode << ISC00);
+ EIMSK |= (1<<INT0);
+ break;
+ case 1:
+ EICRA = (EICRA & ~((1<<ISC10) | (1<<ISC11))) | (mode << ISC10);
+ EIMSK |= (1<<INT1);
+ break;
case 2:
EICRA = (EICRA & ~((1<<ISC20) | (1<<ISC21))) | (mode << ISC20);
EIMSK |= (1<<INT2);
@@ -67,6 +67,10 @@ void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
EICRA = (EICRA & ~((1<<ISC30) | (1<<ISC31))) | (mode << ISC30);
EIMSK |= (1<<INT3);
break;
+ case 4:
+ EICRB = (EICRB & ~((1<<ISC60) | (1<<ISC61))) | (mode << ISC60);
+ EIMSK |= (1<<INT6);
+ break;
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 2:
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
@@ -166,7 +170,10 @@ void detachInterrupt(uint8_t interruptNum) {
break;
case 3:
EIMSK &= ~(1<<INT3);
- break;
+ break;
+ case 4:
+ EIMSK &= ~(1<<INT6);
+ break;
#elif defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 2:
EIMSK &= ~(1 << INT0);
@@ -250,6 +257,11 @@ ISR(INT3_vect) {
intFunc[EXTERNAL_INT_3]();
}
+ISR(INT6_vect) {
+ if(intFunc[EXTERNAL_INT_4])
+ intFunc[EXTERNAL_INT_4]();
+}
+
#elif defined(EICRA) && defined(EICRB)
ISR(INT0_vect) {
diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp
index c6839fc..e19f543 100644
--- a/cores/arduino/WString.cpp
+++ b/cores/arduino/WString.cpp
@@ -100,6 +100,19 @@ String::String(unsigned long value, unsigned char base)
*this = buf;
}
+String::String(float value, int decimalPlaces)
+{
+ init();
+ char buf[33];
+ *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
+}
+
+String::String(double value, int decimalPlaces)
+{
+ init();
+ char buf[33];
+ *this = dtostrf(value, (decimalPlaces + 2), decimalPlaces, buf);
+}
String::~String()
{
free(buffer);
@@ -283,6 +296,20 @@ unsigned char String::concat(unsigned long num)
return concat(buf, strlen(buf));
}
+unsigned char String::concat(float num)
+{
+ char buf[20];
+ char* string = dtostrf(num, 8, 6, buf);
+ return concat(string, strlen(string));
+}
+
+unsigned char String::concat(double num)
+{
+ char buf[20];
+ char* string = dtostrf(num, 8, 6, buf);
+ return concat(string, strlen(string));
+}
+
/*********************************************/
/* Concatenate */
/*********************************************/
@@ -343,6 +370,19 @@ StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num)
return a;
}
+StringSumHelper & operator + (const StringSumHelper &lhs, float num)
+{
+ StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
+ if (!a.concat(num)) a.invalidate();
+ return a;
+}
+
+StringSumHelper & operator + (const StringSumHelper &lhs, double num)
+{
+ StringSumHelper &a = const_cast<StringSumHelper&>(lhs);
+ if (!a.concat(num)) a.invalidate();
+ return a;
+}
/*********************************************/
/* Comparison */
/*********************************************/
@@ -604,6 +644,22 @@ void String::replace(const String& find, const String& replace)
}
}
+void String::remove(unsigned int index){
+ if (index >= len) { return; }
+ int count = len - index;
+ remove(index, count);
+}
+
+void String::remove(unsigned int index, unsigned int count){
+ if (index >= len) { return; }
+ if (count <= 0) { return; }
+ if (index + count > len) { count = len - index; }
+ char *writeTo = buffer + index;
+ len = len - count;
+ strncpy(writeTo, buffer + index + count,len - index);
+ buffer[len] = 0;
+}
+
void String::toLowerCase(void)
{
if (!buffer) return;
@@ -643,3 +699,8 @@ long String::toInt(void) const
}
+float String::toFloat(void) const
+{
+ if (buffer) return float(atof(buffer));
+ return 0;
+}
diff --git a/cores/arduino/WString.h b/cores/arduino/WString.h
index 947325e..2d372c5 100644
--- a/cores/arduino/WString.h
+++ b/cores/arduino/WString.h
@@ -68,6 +68,8 @@ public:
explicit String(unsigned int, unsigned char base=10);
explicit String(long, unsigned char base=10);
explicit String(unsigned long, unsigned char base=10);
+ explicit String(float, int decimalPlaces=6);
+ explicit String(double, int decimalPlaces=6);
~String(void);
// memory management
@@ -100,6 +102,8 @@ public:
unsigned char concat(unsigned int num);
unsigned char concat(long num);
unsigned char concat(unsigned long num);
+ unsigned char concat(float num);
+ unsigned char concat(double num);
// if there's not enough memory for the concatenated value, the string
// will be left unchanged (but this isn't signalled in any way)
@@ -120,6 +124,8 @@ public:
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
+ friend StringSumHelper & operator + (const StringSumHelper &lhs, float num);
+ friend StringSumHelper & operator + (const StringSumHelper &lhs, double num);
// comparison (only works w/ Strings and "strings")
operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
@@ -147,6 +153,7 @@ public:
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
{getBytes((unsigned char *)buf, bufsize, index);}
+ const char * c_str() const { return buffer; }
// search
int indexOf( char ch ) const;
@@ -163,12 +170,15 @@ public:
// modification
void replace(char find, char replace);
void replace(const String& find, const String& replace);
+ void remove(unsigned int index);
+ void remove(unsigned int index, unsigned int count);
void toLowerCase(void);
void toUpperCase(void);
void trim(void);
// parsing/conversion
long toInt(void) const;
+ float toFloat(void) const;
protected:
char *buffer; // the actual char array
diff --git a/cores/arduino/wiring_analog.c b/cores/arduino/wiring_analog.c
index c99325f..8feead9 100644
--- a/cores/arduino/wiring_analog.c
+++ b/cores/arduino/wiring_analog.c
@@ -50,7 +50,7 @@ int analogRead(uint8_t pin)
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
#elif defined(__AVR_ATmega32U4__)
if (pin >= 18) pin -= 18; // allow for channel or pin numbers
-#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
+#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
if (pin >= 24) pin -= 24; // allow for channel or pin numbers
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
diff --git a/cores/arduino/wiring_private.h b/cores/arduino/wiring_private.h
index f678265..c366005 100755
--- a/cores/arduino/wiring_private.h
+++ b/cores/arduino/wiring_private.h
@@ -54,10 +54,10 @@ extern "C"{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define EXTERNAL_NUM_INTERRUPTS 8
-#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
+#elif defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
#define EXTERNAL_NUM_INTERRUPTS 3
#elif defined(__AVR_ATmega32U4__)
-#define EXTERNAL_NUM_INTERRUPTS 4
+#define EXTERNAL_NUM_INTERRUPTS 5
#else
#define EXTERNAL_NUM_INTERRUPTS 2
#endif