@@ -132,6 +132,11 @@ void bt_mouse_connection_status_changed_callback(BtStatus status, void* context)
132
132
BtMouse * bt_mouse = context ;
133
133
134
134
bt_mouse -> connected = (status == BtStatusConnected );
135
+ if (!bt_mouse -> notifications ) {
136
+ tracking_end ();
137
+ return ;
138
+ }
139
+
135
140
if (bt_mouse -> connected ) {
136
141
notification_internal_message (bt_mouse -> notifications , & sequence_set_blue_255 );
137
142
tracking_begin ();
@@ -140,9 +145,6 @@ void bt_mouse_connection_status_changed_callback(BtStatus status, void* context)
140
145
tracking_end ();
141
146
notification_internal_message (bt_mouse -> notifications , & sequence_reset_blue );
142
147
}
143
-
144
- //with_view_model(
145
- // bt_mouse->view, void * model, { model->connected = connected; }, true);
146
148
}
147
149
148
150
bool bt_mouse_move (int8_t dx , int8_t dy , void * context ) {
@@ -160,46 +162,6 @@ bool bt_mouse_move(int8_t dx, int8_t dy, void* context) {
160
162
return true;
161
163
}
162
164
163
- void bt_mouse_enter_callback (void * context ) {
164
- furi_assert (context );
165
- BtMouse * bt_mouse = context ;
166
-
167
- bt_mouse -> bt = furi_record_open (RECORD_BT );
168
- bt_mouse -> notifications = furi_record_open (RECORD_NOTIFICATION );
169
- bt_set_status_changed_callback (
170
- bt_mouse -> bt , bt_mouse_connection_status_changed_callback , bt_mouse );
171
- furi_assert (bt_set_profile (bt_mouse -> bt , BtProfileHidKeyboard ));
172
- furi_hal_bt_start_advertising ();
173
- }
174
-
175
- bool bt_mouse_custom_callback (uint32_t event , void * context ) {
176
- UNUSED (event );
177
- furi_assert (context );
178
- BtMouse * bt_mouse = context ;
179
-
180
- tracking_step (bt_mouse_move , context );
181
- furi_delay_ms (3 ); // Magic! Removing this will break the buttons
182
-
183
- view_dispatcher_send_custom_event (bt_mouse -> view_dispatcher , 0 );
184
- return true;
185
- }
186
-
187
- void bt_mouse_exit_callback (void * context ) {
188
- furi_assert (context );
189
- BtMouse * bt_mouse = context ;
190
-
191
- tracking_end ();
192
- notification_internal_message (bt_mouse -> notifications , & sequence_reset_blue );
193
-
194
- furi_hal_bt_stop_advertising ();
195
- bt_set_profile (bt_mouse -> bt , BtProfileSerial );
196
-
197
- furi_record_close (RECORD_NOTIFICATION );
198
- bt_mouse -> notifications = NULL ;
199
- furi_record_close (RECORD_BT );
200
- bt_mouse -> bt = NULL ;
201
- }
202
-
203
165
static int8_t clamp (int t ) {
204
166
if (t < -128 ) {
205
167
return -128 ;
@@ -279,6 +241,50 @@ void bt_mouse_thread_stop(BtMouse* bt_mouse) {
279
241
furi_thread_join (bt_mouse -> thread );
280
242
furi_thread_free (bt_mouse -> thread );
281
243
furi_mutex_free (bt_mouse -> mutex );
244
+ bt_mouse -> mutex = NULL ;
245
+ bt_mouse -> thread = NULL ;
246
+ }
247
+
248
+ void bt_mouse_enter_callback (void * context ) {
249
+ furi_assert (context );
250
+ BtMouse * bt_mouse = context ;
251
+
252
+ bt_mouse -> bt = furi_record_open (RECORD_BT );
253
+ bt_mouse -> notifications = furi_record_open (RECORD_NOTIFICATION );
254
+ bt_set_status_changed_callback (
255
+ bt_mouse -> bt , bt_mouse_connection_status_changed_callback , bt_mouse );
256
+ furi_assert (bt_set_profile (bt_mouse -> bt , BtProfileHidKeyboard ));
257
+ furi_hal_bt_start_advertising ();
258
+ bt_mouse_thread_start (bt_mouse );
259
+ }
260
+
261
+ bool bt_mouse_custom_callback (uint32_t event , void * context ) {
262
+ UNUSED (event );
263
+ furi_assert (context );
264
+ BtMouse * bt_mouse = context ;
265
+
266
+ tracking_step (bt_mouse_move , context );
267
+ furi_delay_ms (3 ); // Magic! Removing this will break the buttons
268
+
269
+ view_dispatcher_send_custom_event (bt_mouse -> view_dispatcher , 0 );
270
+ return true;
271
+ }
272
+
273
+ void bt_mouse_exit_callback (void * context ) {
274
+ furi_assert (context );
275
+ BtMouse * bt_mouse = context ;
276
+
277
+ bt_mouse_thread_stop (bt_mouse );
278
+ tracking_end ();
279
+ notification_internal_message (bt_mouse -> notifications , & sequence_reset_blue );
280
+
281
+ furi_hal_bt_stop_advertising ();
282
+ bt_set_profile (bt_mouse -> bt , BtProfileSerial );
283
+
284
+ furi_record_close (RECORD_NOTIFICATION );
285
+ bt_mouse -> notifications = NULL ;
286
+ furi_record_close (RECORD_BT );
287
+ bt_mouse -> bt = NULL ;
282
288
}
283
289
284
290
BtMouse * bt_mouse_alloc (ViewDispatcher * view_dispatcher ) {
@@ -293,13 +299,11 @@ BtMouse* bt_mouse_alloc(ViewDispatcher* view_dispatcher) {
293
299
view_set_enter_callback (bt_mouse -> view , bt_mouse_enter_callback );
294
300
view_set_custom_callback (bt_mouse -> view , bt_mouse_custom_callback );
295
301
view_set_exit_callback (bt_mouse -> view , bt_mouse_exit_callback );
296
- bt_mouse_thread_start (bt_mouse );
297
302
return bt_mouse ;
298
303
}
299
304
300
305
void bt_mouse_free (BtMouse * bt_mouse ) {
301
306
furi_assert (bt_mouse );
302
- bt_mouse_thread_stop (bt_mouse );
303
307
view_free (bt_mouse -> view );
304
308
free (bt_mouse );
305
309
}
0 commit comments