Skip to content

Commit 6d7e8eb

Browse files
committed
Cleaned up and commented the Interrupt example
1 parent be5000b commit 6d7e8eb

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

libraries/ESP32/examples/Serial/Interrupt/Interrupt.ino

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
HardwareSerial hwSerial(0);
22
HardwareSerial hwSerial2(2);
33

4-
bool ok = true;
5-
64
static void IRAM_ATTR onSerialRX(uint8_t c, void* user_arg){
75
hwSerial.print(c);
8-
((HardwareSerial*)user_arg)->print(c);
6+
7+
// Cast the user_arg containing a void* to the Serial device, to HardwareSerial* to be used
8+
HardwareSerial* serial = (HardwareSerial*)user_arg;
9+
serial->print(c);
910
}
1011

1112
void setup()
1213
{
1314
hwSerial.begin(115200);
1415
hwSerial2.begin(115200);
16+
17+
// The user_arg is expected to be a void pointer (void*),
18+
// so take the reference of hwSerial2, and cast the HardwareSerial* to a void*
1519
hwSerial2.setRxInterrupt(onSerialRX, (void*)&hwSerial2);
1620
}
1721

0 commit comments

Comments
 (0)