From 1a4e8854057dfba022b36c5c9e9a2ba0ce62f9da Mon Sep 17 00:00:00 2001 From: Cristian Maglie <c.maglie@arduino.cc> Date: Wed, 8 Oct 2014 10:28:45 +0200 Subject: [PATCH] Merge branch 'ide-1.5.x' into zero --- cores/arduino/Server.h | 9 ++++++--- cores/arduino/WString.cpp | 32 ++++++++++++++++++-------------- variants/arduino_zero/variant.h | 10 +++++++++- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/cores/arduino/Server.h b/cores/arduino/Server.h index bdd860d2..69e3e39f 100644 --- a/cores/arduino/Server.h +++ b/cores/arduino/Server.h @@ -1,5 +1,6 @@ /* - Copyright (c) 2014 Arduino. All right reserved. + Server.h - Base class that provides Server + Copyright (c) 2011 Adrian McEwen. 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 @@ -8,8 +9,8 @@ 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. + 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 @@ -19,6 +20,8 @@ #ifndef server_h #define server_h +#include "Print.h" + class Server : public Print { public: virtual void begin() =0; diff --git a/cores/arduino/WString.cpp b/cores/arduino/WString.cpp index 1c626ab1..53f16cdc 100644 --- a/cores/arduino/WString.cpp +++ b/cores/arduino/WString.cpp @@ -1,5 +1,8 @@ /* - Copyright (c) 2014 Arduino. All right reserved. + WString.cpp - String library for Wiring & Arduino + ...mostly rewritten by Paul Stoffregen... + Copyright (c) 2009-10 Hernando Barragan. All rights reserved. + Copyright 2011, Paul Stoffregen, paul@pjrc.com This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -8,8 +11,8 @@ 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. + 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 @@ -213,10 +216,10 @@ void String::move(String &rhs) String & String::operator = (const String &rhs) { if (this == &rhs) return *this; - + if (rhs.buffer) copy(rhs.buffer, rhs.len); else invalidate(); - + return *this; } @@ -238,7 +241,7 @@ String & String::operator = (const char *cstr) { if (cstr) copy(cstr, strlen(cstr)); else invalidate(); - + return *this; } @@ -481,7 +484,7 @@ unsigned char String::equalsIgnoreCase( const String &s2 ) const const char *p2 = s2.buffer; while (*p1) { if (tolower(*p1++) != tolower(*p2++)) return 0; - } + } return 1; } @@ -512,7 +515,7 @@ char String::charAt(unsigned int loc) const return operator[](loc); } -void String::setCharAt(unsigned int loc, char c) +void String::setCharAt(unsigned int loc, char c) { if (loc < len) buffer[loc] = c; } @@ -618,10 +621,10 @@ String String::substring(unsigned int left, unsigned int right) const left = temp; } String out; - if (left > len) return out; + if (left >= len) return out; if (right > len) right = len; char temp = buffer[right]; // save the replaced character - buffer[right] = '\0'; + buffer[right] = '\0'; out = buffer + left; // pointer arithmetic buffer[right] = temp; //restore character return out; @@ -683,15 +686,16 @@ 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); + // Pass the biggest integer as the count. The remove method + // below will take care of truncating it at the end of the + // string. + remove(index, (unsigned int)-1); } void String::remove(unsigned int index, unsigned int count){ if (index >= len) { return; } if (count <= 0) { return; } - if (index + count > len) { count = len - index; } + if (count > len - index) { count = len - index; } char *writeTo = buffer + index; len = len - count; strncpy(writeTo, buffer + index + count,len - index); diff --git a/variants/arduino_zero/variant.h b/variants/arduino_zero/variant.h index ab7050ce..075e66f2 100644 --- a/variants/arduino_zero/variant.h +++ b/variants/arduino_zero/variant.h @@ -57,13 +57,21 @@ extern "C" #define digitalPinToPort(P) ( &(PORT->Group[g_APinDescription[P].ulPort]) ) #define digitalPinToBitMask(P) ( 1 << g_APinDescription[P].ulPin ) -#define digitalPinToTimer(P) ( ) //#define analogInPinToBit(P) ( ) #define portOutputRegister(port) ( &(port->OUT.reg) ) #define portInputRegister(port) ( &(port->IN.reg) ) #define portModeRegister(port) ( &(port->DIR.reg) ) #define digitalPinHasPWM(P) ( g_APinDescription[P].ulPWMChannel != NOT_ON_PWM || g_APinDescription[P].ulTCChannel != NOT_ON_TIMER ) +/* + * digitalPinToTimer(..) is AVR-specific and is not defined for SAMD + * architecture. If you need to check if a pin supports PWM you must + * use digitalPinHasPWM(..). + * + * https://github.com/arduino/Arduino/issues/1833 + */ +// #define digitalPinToTimer(P) + // Interrupts #define digitalPinToInterrupt(P) ( g_APinDescription[P].ulExtInt ) -- GitLab