From 0674d428d2985ca8de014d976db7af7dab52f202 Mon Sep 17 00:00:00 2001 From: GroG Date: Sun, 6 Nov 2016 01:17:45 +0000 Subject: [PATCH] compiles ! --- MrlCmd.cpp | 3 +- MrlComm.cpp | 22 ++-- MrlComm.h | 2 +- MrlI2cBus.h | 2 +- MrlIo.cpp | 2 +- MrlIo.h | 2 +- MrlNeopixel.cpp | 11 +- virtual/Arduino.cpp | 20 ++++ virtual/Arduino.h | 30 ++++- virtual/Emulator.cpp | 109 ++++++++++++++++++ virtual/HardwareSerial.cpp | 4 + virtual/HardwareSerial.h | 27 +++++ virtual/Serial.h | 8 +- virtual/Servo.h | 8 +- virtual/Stream.h | 0 virtual/String.h | 56 +++++++++ virtual/WString.h | 225 +++++++++++++++++++++++++++++++++++++ virtual/Wire.cpp | 14 +++ virtual/Wire.h | 28 +++++ 19 files changed, 547 insertions(+), 26 deletions(-) create mode 100644 virtual/Arduino.cpp create mode 100644 virtual/HardwareSerial.cpp create mode 100644 virtual/HardwareSerial.h create mode 100644 virtual/Stream.h create mode 100644 virtual/String.h create mode 100644 virtual/WString.h create mode 100644 virtual/Wire.cpp create mode 100644 virtual/Wire.h diff --git a/MrlCmd.cpp b/MrlCmd.cpp index 54760a9..ca0a77b 100644 --- a/MrlCmd.cpp +++ b/MrlCmd.cpp @@ -72,4 +72,5 @@ unsigned char MrlCmd::getIoCmd(int pos){ int MrlCmd::getMsgSize(){ return msgSize; -} +} + diff --git a/MrlComm.cpp b/MrlComm.cpp index 4b395b6..92bd2d4 100644 --- a/MrlComm.cpp +++ b/MrlComm.cpp @@ -395,17 +395,17 @@ void MrlComm::setPWMFrequency(int address, int prescalar) { // sets frequency of pwm of analog // FIXME - us ifdef appropriate uC which // support these clocks TCCR0B - int clearBits = 0x07; - if (address == 0x25) { - TCCR0B &= ~clearBits; - TCCR0B |= prescalar; - } else if (address == 0x2E) { - TCCR1B &= ~clearBits; - TCCR1B |= prescalar; - } else if (address == 0xA1) { - TCCR2B &= ~clearBits; - TCCR2B |= prescalar; - } + // int clearBits = 0x07; + // if (address == 0x25) { + // TCCR0B &= ~clearBits; + // TCCR0B |= prescalar; + // } else if (address == 0x2E) { + // TCCR1B &= ~clearBits; + // TCCR1B |= prescalar; + // } else if (address == 0xA1) { + // TCCR2B &= ~clearBits; + // TCCR2B |= prescalar; + // } } // SET_SERIAL_RATE diff --git a/MrlComm.h b/MrlComm.h index 16aa59d..8dc4d88 100644 --- a/MrlComm.h +++ b/MrlComm.h @@ -86,4 +86,4 @@ class MrlComm{ int getCustomMsgSize(); }; -#endif +#endif diff --git a/MrlI2cBus.h b/MrlI2cBus.h index d73131b..04ed829 100644 --- a/MrlI2cBus.h +++ b/MrlI2cBus.h @@ -36,4 +36,4 @@ class MrlI2CBus : public Device { void update(); }; -#endif +#endif diff --git a/MrlIo.cpp b/MrlIo.cpp index 9e069c6..75db101 100644 --- a/MrlIo.cpp +++ b/MrlIo.cpp @@ -108,4 +108,4 @@ void MrlIo::flush() { serial->flush(); } - + diff --git a/MrlIo.h b/MrlIo.h index 525b2b1..c6ff953 100644 --- a/MrlIo.h +++ b/MrlIo.h @@ -31,4 +31,4 @@ class MrlIo { void test(); }; -#endif +#endif diff --git a/MrlNeopixel.cpp b/MrlNeopixel.cpp index 4963a75..736c354 100644 --- a/MrlNeopixel.cpp +++ b/MrlNeopixel.cpp @@ -61,6 +61,7 @@ bool MrlNeopixel::deviceAttach(unsigned char config[], int configSize) { } inline void MrlNeopixel::sendBitB(bool bitVal) { +#ifndef VIRTUAL_ARDUINO_H uint8_t bit = bitmask; if (bitVal) { // 0 bit PORTB |= bit; @@ -104,9 +105,12 @@ inline void MrlNeopixel::sendBitB(bool bitVal) { sei(); //activate interrupts } + + #endif } inline void MrlNeopixel::sendBitC(bool bitVal) { +#ifndef VIRTUAL_ARDUINO_H uint8_t bit = bitmask; if (bitVal) { // 0 bit PORTC |= bit; @@ -153,6 +157,8 @@ inline void MrlNeopixel::sendBitC(bool bitVal) { // Note that the inter-bit gap can be as long as you want as long as it doesn't exceed the 5us reset timeout (which is A long time) // Here I have been generous and not tried to squeeze the gap tight but instead erred on the side of lots of extra time. // This has thenice side effect of avoid glitches on very long strings becuase + + #endif } #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_ADK) @@ -515,6 +521,7 @@ inline void MrlNeopixel::sendBitA(bool bitVal) { #endif inline void MrlNeopixel::sendBitD(bool bitVal) { +#ifndef VIRTUAL_ARDUINO_H uint8_t bit = bitmask; if (bitVal) { // 0 bit PORTD |= bit; @@ -558,7 +565,7 @@ inline void MrlNeopixel::sendBitD(bool bitVal) { sei(); //activate interrupts } - +#endif } inline void MrlNeopixel::sendByte(unsigned char byte) { @@ -839,4 +846,4 @@ void MrlNeopixel::animationIronman() { else lastShow = millis(); newData = true; } - + diff --git a/virtual/Arduino.cpp b/virtual/Arduino.cpp new file mode 100644 index 0000000..2eaf83c --- /dev/null +++ b/virtual/Arduino.cpp @@ -0,0 +1,20 @@ +#include "Arduino.h" + +unsigned long micros(){return 0;} +unsigned long millis(){return 0;} +void digitalWrite(int pin, int value){}; +void analogWrite(int pin, int value){}; +void pinMode(int pin, int value){}; +int digitalRead(int pin){return 0;}; +int analogRead(int pin){return 0;}; +void delay(int){}; + +uint8_t digitalPinToBitMask(int){return 0;}; + +void cli(){}; +void sei(){}; +bool bitRead(unsigned char, unsigned char){return 0;}; +unsigned int random(unsigned int){return 0;}; + +int __brkval=0; +int __heap_start=0; \ No newline at end of file diff --git a/virtual/Arduino.h b/virtual/Arduino.h index eab3bf4..9fa2d64 100644 --- a/virtual/Arduino.h +++ b/virtual/Arduino.h @@ -6,13 +6,21 @@ #define TCCR0B 0 #define TCCR1B 0 #define TCCR2B 0 +#define HIGH 0x1 +#define LOW 0x0 + +#define INPUT 0x0 +#define OUTPUT 0x1 +#define INPUT_PULLUP 0x2 typedef unsigned char byte; +typedef unsigned char uint8_t; -#include "Serial.h" +//#include "Serial.h" +#include #include "Servo.h" #include "HardwareSerial.h" -#include "WString.h" +#include "String.h" unsigned long micros(); unsigned long millis(); @@ -21,6 +29,22 @@ void analogWrite(int pin, int value); void pinMode(int pin, int value); int digitalRead(int pin); int analogRead(int pin); +void delay(int); + +uint8_t digitalPinToBitMask(int); + +#define PORTB 0 +#define PORTC 0 +#define PORTD 0 +#define F_CPU 1 + + +void cli(); +void sei(); +bool bitRead(unsigned char, unsigned char); +unsigned int random(unsigned int); + + -#endif VIRTUAL_ARDUINO_H +#endif /*VIRTUAL_ARDUINO_H*/ diff --git a/virtual/Emulator.cpp b/virtual/Emulator.cpp index 3b1d491..7f20cbc 100644 --- a/virtual/Emulator.cpp +++ b/virtual/Emulator.cpp @@ -16,3 +16,112 @@ Emulator::~Emulator() { // TODO Auto-generated destructor stub } + + +/** +* MRLComm.c +* ----------------- +* This file is part of MyRobotLab. +* (myrobotlab.org) +* +* Enjoy ! +* @authors +* GroG +* Kwatters +* Mats +* calamity +* and many others... +* +* MRL Protocol definition +* ----------------- +* MAGIC_NUMBER|NUM_BYTES|FUNCTION|DATA0|DATA1|....|DATA(N) +* NUM_BYTES - is the number of bytes after NUM_BYTES to the end +* +* more info - http://myrobotlab.org/content/myrobotlab-api +* +* General Concept +* ----------------- +* Arduino is a slave process to MyRobotLab Arduino Service - this file receives +* commands and sends back data. +* Refactoring has made MRLComm.c far more general +* there are only 2 "types" of things - controllers and pins - or writers and readers +* each now will have sub-types +* +* Controllers +* ----------------- +* digital pins, pwm, pwm/dir dc motors, pwm/pwm dc motors +* +* Sensors +* ----------------- +* digital polling pins, analog polling pins, range pins, oscope, trigger events +* +* Combination +* ----------------- +* pingdar, non-blocking pulsin +* +* Requirements: MyRobotLab running on a computer & a serial connection +* +* TODO - need a method to identify type of board http://forum.arduino.cc/index.php?topic=100557.0 +* TODO - getBoardInfo() - returns board info ! +* TODO - getPinInfo() - returns pin info ! +* TODO - implement with std::vector vs linked list - https://github.com/maniacbug/StandardCplusplus/blob/master/README.md +* TODO - make MRLComm a c++ library +*/ + + +// Included as a 3rd party arduino library from here: https://github.com/ivanseidel/LinkedList/ +#include "../LinkedList.h" +#include "../MrlComm.h" +//#include + #include + +/*********************************************************************** + * GLOBAL VARIABLES + * TODO - work on reducing globals and pass as parameters +*/ +MrlComm mrlComm; +/*********************************************************************** + * STANDARD ARDUINO BEGIN + * setup() is called when the serial port is opened unless you hack the + * serial port on your arduino + * + * Here we default out serial port to 115.2kbps. +*/ +void setup() { + // TODO: the arduino service might get a few garbage bytes before we're able + // to run, we should consider some additional logic here like a "publishReset" + // publish version on startup so it's immediately available for mrl. + // TODO: see if we can purge the current serial port buffers + mrlComm.publishVersion(); + // publish the board type (uno/mega) + mrlComm.publishBoardInfo(); + +} + +/** + * STANDARD ARDUINO LOOP BEGIN + * This method will be called over and over again by the arduino, it is the + * main loop any arduino sketch runs + */ +void loop() { + // increment how many times we've run + // TODO: handle overflow here after 32k runs, i suspect this might blow up? + mrlComm.loopCount++; + // get a command and process it from the serial port (if available.) + mrlComm.readCommand(); + // update devices + mrlComm.updateDevices(); + // send back load time and memory + mrlComm.publishBoardStatus(); +} // end of big loop + +int main() { + setup(); + for (int i = 0; i < 100; i++){ + loop(); + // printf("Worky!!!\n"); + std::cout << "Hello World!"; + } + + return 0; +} \ No newline at end of file diff --git a/virtual/HardwareSerial.cpp b/virtual/HardwareSerial.cpp new file mode 100644 index 0000000..2a1bc4b --- /dev/null +++ b/virtual/HardwareSerial.cpp @@ -0,0 +1,4 @@ +#include "HardwareSerial.h" + + +HardwareSerial Serial; \ No newline at end of file diff --git a/virtual/HardwareSerial.h b/virtual/HardwareSerial.h new file mode 100644 index 0000000..04acf6a --- /dev/null +++ b/virtual/HardwareSerial.h @@ -0,0 +1,27 @@ +/* + * HardwareSerial_h.h + * + * Created on: Nov 3, 2016 + * Author: gperry + */ + +#ifndef VIRTUAL_HARDWARE_SERIAL_H_ +#define VIRTUAL_HARDWARE_SERIAL_H_ + +class HardwareSerial { +public: + HardwareSerial(){}; + virtual ~HardwareSerial(){}; + void begin(int){}; + void write(unsigned char){}; + void write(unsigned char*, int){}; + unsigned char read(){return 0;}; + int available(){return 0;}; + void end(){}; + void flush(){}; +}; + + +extern HardwareSerial Serial; + +#endif /* VIRTUAL_HARDWARE_SERIAL_H_ */ diff --git a/virtual/Serial.h b/virtual/Serial.h index a650d9e..4265f65 100644 --- a/virtual/Serial.h +++ b/virtual/Serial.h @@ -8,10 +8,12 @@ #ifndef VIRTUAL_SERIAL_H_ #define VIRTUAL_SERIAL_H_ -class Serial { +class VSerial { public: - Serial(); - virtual ~Serial(); + VSerial(); + virtual ~VSerial(); }; +extern VSerial Serial; + #endif /* VIRTUAL_SERIAL_H_ */ diff --git a/virtual/Servo.h b/virtual/Servo.h index 1248281..910a880 100644 --- a/virtual/Servo.h +++ b/virtual/Servo.h @@ -10,8 +10,12 @@ class Servo { public: - Servo(); - virtual ~Servo(); + Servo(){}; + virtual ~Servo(){}; + void detach(){}; + void write(int){}; + void attach(int){}; + void writeMicroseconds(int){}; }; #endif /* VIRTUAL_SERVO_H_ */ diff --git a/virtual/Stream.h b/virtual/Stream.h new file mode 100644 index 0000000..e69de29 diff --git a/virtual/String.h b/virtual/String.h new file mode 100644 index 0000000..9f3cba4 --- /dev/null +++ b/virtual/String.h @@ -0,0 +1,56 @@ +/* + * String.h + * + * Created on: Nov 3, 2016 + * Author: gperry + */ + +#ifndef VIRTUAL_STRING_H_ +#define VIRTUAL_STRING_H_ + +#define F(literal) literal +class StringSumHelper; + +class String { +public: + String(){}; + String(const char *cstr = ""){}; + String(const String &str){}; + explicit String(char c){}; + explicit String(unsigned char, unsigned char base=10){}; + explicit String(int, unsigned char base=10){}; + 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, unsigned char decimalPlaces=2){}; + explicit String(double, unsigned char decimalPlaces=2){}; + virtual ~String(){}; + int length(){return 0;}; + unsigned char operator[](int){return 0;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, char c){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, int num){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, long num){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, float num){StringSumHelper &a= const_cast(lhs); return a;}; + friend StringSumHelper & operator + (const StringSumHelper &lhs, double num){StringSumHelper &a= const_cast(lhs); return a;}; +}; + +class StringSumHelper : public String +{ +public: + StringSumHelper(const String &s) : String(s) {} + StringSumHelper(const char *p) : String(p) {} + StringSumHelper(char c) : String(c) {} + StringSumHelper(unsigned char num) : String(num) {} + StringSumHelper(int num) : String(num) {} + StringSumHelper(unsigned int num) : String(num) {} + StringSumHelper(long num) : String(num) {} + StringSumHelper(unsigned long num) : String(num) {} + StringSumHelper(float num) : String(num) {} + StringSumHelper(double num) : String(num) {} +}; +#endif /* VIRTUAL_SERIAL_H_ */ diff --git a/virtual/WString.h b/virtual/WString.h new file mode 100644 index 0000000..8050c9f --- /dev/null +++ b/virtual/WString.h @@ -0,0 +1,225 @@ +/* + WString.h - String library for Wiring & Arduino + ...mostly rewritten by Paul Stoffregen... + Copyright (c) 2009-10 Hernando Barragan. All right 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 + 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 +*/ + +#ifndef String_class_h +#define String_class_h +#ifdef __cplusplus + +#include +#include +#include +//#include + +// When compiling programs with this class, the following gcc parameters +// dramatically increase performance and memory (RAM) efficiency, typically +// with little or no increase in code size. +// -felide-constructors +// -std=c++0x + +class __FlashStringHelper; +//#define F(string_literal) (reinterpret_cast(PSTR(string_literal))) +#define F(string_literal) string_literal + +// An inherited class for holding the result of a concatenation. These +// result objects are assumed to be writable by subsequent concatenations. +class StringSumHelper; + +// The string class +class String +{ + // use a function pointer to allow for "if (s)" without the + // complications of an operator bool(). for more information, see: + // http://www.artima.com/cppsource/safebool.html + typedef void (String::*StringIfHelperType)() const; + void StringIfHelper() const {} + +public: + // constructors + // creates a copy of the initial value. + // if the initial value is null or invalid, or if memory allocation + // fails, the string will be marked as invalid (i.e. "if (s)" will + // be false). + String(const char *cstr = ""); + String(const String &str); + String(const __FlashStringHelper *str); + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) + String(String &&rval); + String(StringSumHelper &&rval); + #endif + explicit String(char c); + explicit String(unsigned char, unsigned char base=10); + explicit String(int, unsigned char base=10); + 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, unsigned char decimalPlaces=2); + explicit String(double, unsigned char decimalPlaces=2); + ~String(void); + + // memory management + // return true on success, false on failure (in which case, the string + // is left unchanged). reserve(0), if successful, will validate an + // invalid string (i.e., "if (s)" will be true afterwards) + unsigned char reserve(unsigned int size); + inline unsigned int length(void) const {return len;} + + // creates a copy of the assigned value. if the value is null or + // invalid, or if the memory allocation fails, the string will be + // marked as invalid ("if (s)" will be false). + String & operator = (const String &rhs); + String & operator = (const char *cstr); + String & operator = (const __FlashStringHelper *str); + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) + String & operator = (String &&rval); + String & operator = (StringSumHelper &&rval); + #endif + + // concatenate (works w/ built-in types) + + // returns true on success, false on failure (in which case, the string + // is left unchanged). if the argument is null or invalid, the + // concatenation is considered unsucessful. + unsigned char concat(const String &str); + unsigned char concat(const char *cstr); + unsigned char concat(char c); + unsigned char concat(unsigned char c); + unsigned char concat(int num); + 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); + unsigned char concat(const __FlashStringHelper * str); + + // if there's not enough memory for the concatenated value, the string + // will be left unchanged (but this isn't signalled in any way) + String & operator += (const String &rhs) {concat(rhs); return (*this);} + String & operator += (const char *cstr) {concat(cstr); return (*this);} + String & operator += (char c) {concat(c); return (*this);} + String & operator += (unsigned char num) {concat(num); return (*this);} + String & operator += (int num) {concat(num); return (*this);} + String & operator += (unsigned int num) {concat(num); return (*this);} + String & operator += (long num) {concat(num); return (*this);} + String & operator += (unsigned long num) {concat(num); return (*this);} + String & operator += (float num) {concat(num); return (*this);} + String & operator += (double num) {concat(num); return (*this);} + String & operator += (const __FlashStringHelper *str){concat(str); return (*this);} + + friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs); + friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr); + friend StringSumHelper & operator + (const StringSumHelper &lhs, char c); + friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num); + friend StringSumHelper & operator + (const StringSumHelper &lhs, int num); + 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); + friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs); + + // comparison (only works w/ Strings and "strings") + operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; } + int compareTo(const String &s) const; + unsigned char equals(const String &s) const; + unsigned char equals(const char *cstr) const; + unsigned char operator == (const String &rhs) const {return equals(rhs);} + unsigned char operator == (const char *cstr) const {return equals(cstr);} + unsigned char operator != (const String &rhs) const {return !equals(rhs);} + unsigned char operator != (const char *cstr) const {return !equals(cstr);} + unsigned char operator < (const String &rhs) const; + unsigned char operator > (const String &rhs) const; + unsigned char operator <= (const String &rhs) const; + unsigned char operator >= (const String &rhs) const; + unsigned char equalsIgnoreCase(const String &s) const; + unsigned char startsWith( const String &prefix) const; + unsigned char startsWith(const String &prefix, unsigned int offset) const; + unsigned char endsWith(const String &suffix) const; + + // character acccess + char charAt(unsigned int index) const; + void setCharAt(unsigned int index, char c); + char operator [] (unsigned int index) const; + char& operator [] (unsigned int index); + 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; + int indexOf( char ch, unsigned int fromIndex ) const; + int indexOf( const String &str ) const; + int indexOf( const String &str, unsigned int fromIndex ) const; + int lastIndexOf( char ch ) const; + int lastIndexOf( char ch, unsigned int fromIndex ) const; + int lastIndexOf( const String &str ) const; + int lastIndexOf( const String &str, unsigned int fromIndex ) const; + String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); }; + String substring( unsigned int beginIndex, unsigned int endIndex ) const; + + // 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 + unsigned int capacity; // the array length minus one (for the '\0') + unsigned int len; // the String length (not counting the '\0') +protected: + void init(void); + void invalidate(void); + unsigned char changeBuffer(unsigned int maxStrLen); + unsigned char concat(const char *cstr, unsigned int length); + + // copy and move + String & copy(const char *cstr, unsigned int length); + String & copy(const __FlashStringHelper *pstr, unsigned int length); + #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) + void move(String &rhs); + #endif +}; + +class StringSumHelper : public String +{ +public: + StringSumHelper(const String &s) : String(s) {} + StringSumHelper(const char *p) : String(p) {} + StringSumHelper(char c) : String(c) {} + StringSumHelper(unsigned char num) : String(num) {} + StringSumHelper(int num) : String(num) {} + StringSumHelper(unsigned int num) : String(num) {} + StringSumHelper(long num) : String(num) {} + StringSumHelper(unsigned long num) : String(num) {} + StringSumHelper(float num) : String(num) {} + StringSumHelper(double num) : String(num) {} +}; + +#endif // __cplusplus +#endif // String_class_h diff --git a/virtual/Wire.cpp b/virtual/Wire.cpp new file mode 100644 index 0000000..8cf4b48 --- /dev/null +++ b/virtual/Wire.cpp @@ -0,0 +1,14 @@ +#include "Wire.h" + + VWire::VWire(){}; + VWire::~VWire(){}; + void VWire::begin(){}; + void VWire::setClock(long){}; + void VWire::beginTransmission(unsigned char){}; + void VWire::write(unsigned char){}; + void VWire::endTransmission(){}; + int VWire::requestFrom(unsigned char, unsigned char){return 0;}; + unsigned char VWire::read(){return 0;}; + + +VWire Wire; \ No newline at end of file diff --git a/virtual/Wire.h b/virtual/Wire.h new file mode 100644 index 0000000..fd53118 --- /dev/null +++ b/virtual/Wire.h @@ -0,0 +1,28 @@ +/* + * Wire.h + * + * Created on: Nov 3, 2016 + * Author: gperry + */ + +#ifndef VIRTUAL_WIRE_H_ +#define VIRTUAL_WIRE_H_ + + +class VWire { +public: + VWire(); + virtual ~VWire(); + void begin(); + void setClock(long); + void beginTransmission(unsigned char); + void write(unsigned char); + void endTransmission(); + int requestFrom(unsigned char, unsigned char); + unsigned char read(); + +}; + +extern VWire Wire; + +#endif /* VIRTUAL_WIRE_H_ */