Skip to content

Commit

Permalink
Fixed ESP32/8266 compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kwagyeman committed Sep 11, 2020
1 parent 209c7e3 commit c5bb605
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/openmvrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
{
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions src/openmvrpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#define __OPENMVRPC__

#include <Arduino.h>
#ifndef ARDUINO_ARCH_ESP8266
#include <CAN.h>
#endif
#ifdef ARDUINO_ARCH_AVR
#include <SoftwareSerial.h>
#endif // ARDUINO_ARCH_AVR
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c5bb605

Please sign in to comment.