From c5bb6052d624ba2ef627484624bbb77180fbe8f8 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Thu, 10 Sep 2020 22:28:43 -0700 Subject: [PATCH] Fixed ESP32/8266 compile errors --- library.properties | 2 +- src/openmvrpc.cpp | 14 ++++++++++++++ src/openmvrpc.h | 6 ++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/library.properties b/library.properties index f1432c3..38911d8 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=OpenMV Arduino RPC -version=1.0.1 +version=1.0.2 author=OpenMV maintainer=OpenMV sentence=OpenMV Arduino RPC Interface Library diff --git a/src/openmvrpc.cpp b/src/openmvrpc.cpp index 2b5e30a..e6db034 100644 --- a/src/openmvrpc.cpp +++ b/src/openmvrpc.cpp @@ -27,6 +27,14 @@ // Master <-- Slave magic DATA ack, n-byte payload, CRC // +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif + +#ifndef max +#define max(a,b) ((a)>(b)?(a):(b)) +#endif + using namespace openmv; uint8_t *openmv::__buff = NULL; @@ -669,6 +677,7 @@ bool rpc_slave::loop(unsigned long recv_timeout, unsigned long send_timeout) return false; } +#ifndef ARDUINO_ARCH_ESP8266 void rpc_can_master::_flush() { for (int i = 0, ii = CAN.parsePacket(); i < ii; i++) CAN.read(); @@ -740,6 +749,7 @@ bool rpc_can_slave::put_bytes(uint8_t *data, size_t size, unsigned long timeout) return i == size; } +#endif void rpc_i2c_master::_flush() { @@ -763,7 +773,9 @@ bool rpc_i2c_master::get_bytes(uint8_t *buff, size_t size, unsigned long timeout for (size_t j = 0; j < request_size; j++) buff[i+j] = Wire.read(); } +#if (!defined(ARDUINO_ARCH_ESP32)) && (!defined(ARDUINO_ARCH_ESP8266)) Wire.end(); +#endif if (ok) ok = ok && (!_same(buff, size)); if (!ok) delay(_get_short_timeout); return ok; @@ -786,7 +798,9 @@ bool rpc_i2c_master::put_bytes(uint8_t *data, size_t size, unsigned long timeout if ((Wire.write(data + i, request_size) != request_size) || Wire.endTransmission(request_stop)) { ok = false; break; } } +#if (!defined(ARDUINO_ARCH_ESP32)) && (!defined(ARDUINO_ARCH_ESP8266)) Wire.end(); +#endif return ok; } diff --git a/src/openmvrpc.h b/src/openmvrpc.h index 3a712d7..82f1fe0 100644 --- a/src/openmvrpc.h +++ b/src/openmvrpc.h @@ -8,7 +8,9 @@ #define __OPENMVRPC__ #include +#ifndef ARDUINO_ARCH_ESP8266 #include +#endif #ifdef ARDUINO_ARCH_AVR #include #endif // ARDUINO_ARCH_AVR @@ -215,6 +217,7 @@ class rpc_slave : public rpc bool __register_callback(uint32_t hash, rpc_callback_type_t type, void *value); }; +#ifndef ARDUINO_ARCH_ESP8266 class rpc_can_master : public rpc_master { public: @@ -248,6 +251,7 @@ class rpc_can_slave : public rpc_slave long __bit_rate; rpc_can_slave(const rpc_can_slave &); }; +#endif class rpc_i2c_master : public rpc_master { @@ -276,7 +280,9 @@ class rpc_i2c_slave : public rpc_slave virtual bool get_bytes(uint8_t *buff, size_t size, unsigned long timeout) override; virtual bool put_bytes(uint8_t *data, size_t size, unsigned long timeout) override; virtual void begin() override { Wire.onReceive(onReceiveHandler); Wire.onRequest(onRequestHandler); Wire.begin(__slave_addr); } +#if (!defined(ARDUINO_ARCH_ESP32)) && (!defined(ARDUINO_ARCH_ESP8266)) virtual void end() override { Wire.end(); } +#endif protected: virtual uint32_t _stream_writer_queue_depth_max() override { return 1; } private: