File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -437,6 +437,31 @@ void TwoWire::onRequestService(i2c_t *obj)
437
437
}
438
438
}
439
439
440
+ #ifdef __cplusplus
441
+ // sets function called on slave write
442
+ void TwoWire::onReceive (cb_function_receive_t function)
443
+ {
444
+ user_onReceive = function;
445
+ }
446
+
447
+ void TwoWire::onReceive (void (*function)(int ))
448
+ {
449
+ cb_function_receive_t _c = function;
450
+ onReceive (_c);
451
+ }
452
+
453
+ // sets function called on slave read
454
+ void TwoWire::onRequest (cb_function_request_t function)
455
+ {
456
+ user_onRequest = function;
457
+ }
458
+
459
+ void TwoWire::onRequest (void (*function)(void ))
460
+ {
461
+ cb_function_request_t _c = function;
462
+ onRequest (_c);
463
+ }
464
+ #else
440
465
// sets function called on slave write
441
466
void TwoWire::onReceive (void (*function)(int ))
442
467
{
@@ -448,6 +473,7 @@ void TwoWire::onRequest(void (*function)(void))
448
473
{
449
474
user_onRequest = function;
450
475
}
476
+ #endif
451
477
452
478
/* *
453
479
* @brief Allocate the Rx/Tx buffer to the requested length if needed
Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ extern "C" {
28
28
#include " utility/twi.h"
29
29
}
30
30
31
+ #ifdef __cplusplus
32
+ #include < functional>
33
+ #endif
34
+
31
35
// Minimal buffer length. Buffers length will be increased when needed,
32
36
// but TX buffer is limited to a maximum to avoid too much stack consumption
33
37
// Note: Buffer length and max buffer length are limited by uin16_t type
@@ -56,8 +60,13 @@ class TwoWire : public Stream {
56
60
uint8_t ownAddress;
57
61
i2c_t _i2c;
58
62
63
+ #ifdef __cplusplus
64
+ std::function<void (int )> user_onReceive;
65
+ std::function<void (void )> user_onRequest;
66
+ #else
59
67
void (*user_onRequest)(void );
60
68
void (*user_onReceive)(int );
69
+ #endif
61
70
static void onRequestService (i2c_t *);
62
71
static void onReceiveService (i2c_t *);
63
72
@@ -113,6 +122,14 @@ class TwoWire : public Stream {
113
122
void onReceive (void (*)(int ));
114
123
void onRequest (void (*)(void ));
115
124
125
+ #ifdef __cplusplus
126
+ typedef std::function<void (int )> cb_function_receive_t ;
127
+ typedef std::function<void (void )> cb_function_request_t ;
128
+
129
+ void onReceive (cb_function_receive_t callback);
130
+ void onRequest (cb_function_request_t callback);
131
+ #endif
132
+
116
133
inline size_t write (unsigned long n)
117
134
{
118
135
return write ((uint8_t )n);
You can’t perform that action at this time.
0 commit comments