File tree 1 file changed +18
-3
lines changed
1 file changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -171,9 +171,24 @@ uint8_t Arduino_GigaDisplayTouch::getTouchPoints(GDTpoint_t* points) {
171
171
}
172
172
173
173
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 ();
177
192
}
178
193
179
194
uint8_t Arduino_GigaDisplayTouch::_gt911WriteOp (uint16_t reg, uint8_t data) {
You can’t perform that action at this time.
0 commit comments