File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -438,13 +438,13 @@ void TwoWire::onRequestService(i2c_t *obj)
438438}
439439
440440// sets function called on slave write
441- void TwoWire::onReceive (void (* function)( int ) )
441+ void TwoWire::onReceive (cb_function_receive_t function)
442442{
443443 user_onReceive = function;
444444}
445445
446446// sets function called on slave read
447- void TwoWire::onRequest (void (* function)( void ) )
447+ void TwoWire::onRequest (cb_function_request_t function)
448448{
449449 user_onRequest = function;
450450}
Original file line number Diff line number Diff line change 2222#ifndef TwoWire_h
2323#define TwoWire_h
2424
25+ #include < functional>
26+
2527#include " Stream.h"
2628#include " Arduino.h"
2729extern " C" {
@@ -40,6 +42,10 @@ extern "C" {
4042#define WIRE_HAS_END 1
4143
4244class TwoWire : public Stream {
45+ public:
46+ typedef std::function<void (int )> cb_function_receive_t ;
47+ typedef std::function<void (void )> cb_function_request_t ;
48+
4349 private:
4450 uint8_t *rxBuffer;
4551 uint16_t rxBufferAllocated;
@@ -56,8 +62,9 @@ class TwoWire : public Stream {
5662 uint8_t ownAddress;
5763 i2c_t _i2c;
5864
59- void (*user_onRequest)(void );
60- void (*user_onReceive)(int );
65+ std::function<void (int )> user_onReceive;
66+ std::function<void (void )> user_onRequest;
67+
6168 static void onRequestService (i2c_t *);
6269 static void onReceiveService (i2c_t *);
6370
@@ -110,8 +117,9 @@ class TwoWire : public Stream {
110117 virtual int read (void );
111118 virtual int peek (void );
112119 virtual void flush (void );
113- void onReceive (void (*)(int ));
114- void onRequest (void (*)(void ));
120+
121+ void onReceive (cb_function_receive_t callback);
122+ void onRequest (cb_function_request_t callback);
115123
116124 inline size_t write (unsigned long n)
117125 {
You can’t perform that action at this time.
0 commit comments