File tree 2 files changed +14
-6
lines changed
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)
438
438
}
439
439
440
440
// sets function called on slave write
441
- void TwoWire::onReceive (void (* function)( int ) )
441
+ void TwoWire::onReceive (cb_function_receive_t function)
442
442
{
443
443
user_onReceive = function;
444
444
}
445
445
446
446
// sets function called on slave read
447
- void TwoWire::onRequest (void (* function)( void ) )
447
+ void TwoWire::onRequest (cb_function_request_t function)
448
448
{
449
449
user_onRequest = function;
450
450
}
Original file line number Diff line number Diff line change 22
22
#ifndef TwoWire_h
23
23
#define TwoWire_h
24
24
25
+ #include < functional>
26
+
25
27
#include " Stream.h"
26
28
#include " Arduino.h"
27
29
extern " C" {
@@ -40,6 +42,10 @@ extern "C" {
40
42
#define WIRE_HAS_END 1
41
43
42
44
class 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
+
43
49
private:
44
50
uint8_t *rxBuffer;
45
51
uint16_t rxBufferAllocated;
@@ -56,8 +62,9 @@ class TwoWire : public Stream {
56
62
uint8_t ownAddress;
57
63
i2c_t _i2c;
58
64
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
+
61
68
static void onRequestService (i2c_t *);
62
69
static void onReceiveService (i2c_t *);
63
70
@@ -110,8 +117,9 @@ class TwoWire : public Stream {
110
117
virtual int read (void );
111
118
virtual int peek (void );
112
119
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);
115
123
116
124
inline size_t write (unsigned long n)
117
125
{
You can’t perform that action at this time.
0 commit comments