Skip to content

Commit e3d48af

Browse files
authored
feat: add null pointer option to onDetect method
1 parent 4101b8a commit e3d48af

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/Arduino_GigaDisplayTouch.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,24 @@ uint8_t Arduino_GigaDisplayTouch::getTouchPoints(GDTpoint_t* points) {
171171
}
172172

173173
void Arduino_GigaDisplayTouch::onDetect(void (*handler)(uint8_t, GDTpoint_t*)) {
174-
_gt911TouchHandler = handler;
175-
t.start(callback(&queue, &events::EventQueue::dispatch_forever));
176-
_irqInt.rise(queue.event(mbed::callback(this, &Arduino_GigaDisplayTouch::_gt911onIrq)));
174+
if (handler == nullptr) {
175+
// Detach the interrupt and stop the event queue thread
176+
queue.break_dispatch();
177+
_irqInt.rise(nullptr);
178+
if (t.get_state() != rtos::Thread::Deleted) {
179+
t.join(); // prevent mbedOS from crashing
180+
}
181+
} else {
182+
_gt911TouchHandler = handler;
183+
t.start(callback(&queue, &events::EventQueue::dispatch_forever));
184+
_irqInt.rise(queue.event(mbed::callback(this, &Arduino_GigaDisplayTouch::_gt911onIrq)));
185+
}
186+
}
187+
188+
void Arduino_GigaDisplayTouch::detach() {
189+
queue.break_dispatch();
190+
_irqInt.rise(nullptr);
191+
t.terminate();
177192
}
178193

179194
uint8_t Arduino_GigaDisplayTouch::_gt911WriteOp(uint16_t reg, uint8_t data) {

0 commit comments

Comments
 (0)