|
@@ -421,10 +421,6 @@ void ble_connect(bd_addr_t addr, bd_addr_type_t type) {
|
421
|
421
|
cyw43_thread_enter();
|
422
|
422
|
|
423
|
423
|
switch (state) {
|
424
|
|
- case TC_OFF:
|
425
|
|
- cyw43_thread_exit();
|
426
|
|
- return;
|
427
|
|
-
|
428
|
424
|
case TC_W4_SCAN:
|
429
|
425
|
cyw43_thread_exit();
|
430
|
426
|
ble_scan(0);
|
|
@@ -435,8 +431,13 @@ void ble_connect(bd_addr_t addr, bd_addr_type_t type) {
|
435
|
431
|
gap_disconnect(connection_handle);
|
436
|
432
|
break;
|
437
|
433
|
|
438
|
|
- default:
|
|
434
|
+ case TC_IDLE:
|
439
|
435
|
break;
|
|
436
|
+
|
|
437
|
+ default:
|
|
438
|
+ debug("invalid state for connect %d", state);
|
|
439
|
+ cyw43_thread_exit();
|
|
440
|
+ return;
|
440
|
441
|
}
|
441
|
442
|
|
442
|
443
|
debug("connecting to %s", bd_addr_to_str(addr));
|
|
@@ -461,7 +462,10 @@ void ble_disconnect(void) {
|
461
|
462
|
cyw43_thread_enter();
|
462
|
463
|
|
463
|
464
|
if (state == TC_READY) {
|
|
465
|
+ debug("disconnecting");
|
464
|
466
|
gap_disconnect(connection_handle);
|
|
467
|
+ } else {
|
|
468
|
+ debug("invalid state for disconnect %d", state);
|
465
|
469
|
}
|
466
|
470
|
|
467
|
471
|
cyw43_thread_exit();
|
|
@@ -578,8 +582,6 @@ int8_t ble_write(const uint8_t *service, const uint8_t *characteristic,
|
578
|
582
|
service_idx = srvc;
|
579
|
583
|
cyw43_thread_exit();
|
580
|
584
|
|
581
|
|
- debug("waiting for service discovery");
|
582
|
|
-
|
583
|
585
|
uint32_t start_time = to_ms_since_boot(get_absolute_time());
|
584
|
586
|
while (1) {
|
585
|
587
|
sleep_ms(1);
|
|
@@ -598,7 +600,6 @@ int8_t ble_write(const uint8_t *service, const uint8_t *characteristic,
|
598
|
600
|
cyw43_thread_exit();
|
599
|
601
|
|
600
|
602
|
if (state_cached == TC_READY) {
|
601
|
|
- debug("service discovery done");
|
602
|
603
|
break;
|
603
|
604
|
}
|
604
|
605
|
}
|
|
@@ -650,8 +651,6 @@ int8_t ble_write(const uint8_t *service, const uint8_t *characteristic,
|
650
|
651
|
characteristic_idx = ch;
|
651
|
652
|
cyw43_thread_exit();
|
652
|
653
|
|
653
|
|
- debug("waiting for characteristic discovery");
|
654
|
|
-
|
655
|
654
|
uint32_t start_time = to_ms_since_boot(get_absolute_time());
|
656
|
655
|
while (1) {
|
657
|
656
|
sleep_ms(1);
|
|
@@ -670,7 +669,6 @@ int8_t ble_write(const uint8_t *service, const uint8_t *characteristic,
|
670
|
669
|
cyw43_thread_exit();
|
671
|
670
|
|
672
|
671
|
if (state_cached == TC_READY) {
|
673
|
|
- debug("characteristic discovery done");
|
674
|
672
|
break;
|
675
|
673
|
}
|
676
|
674
|
}
|
|
@@ -699,8 +697,6 @@ int8_t ble_write(const uint8_t *service, const uint8_t *characteristic,
|
699
|
697
|
state = TC_W4_WRITE;
|
700
|
698
|
cyw43_thread_exit();
|
701
|
699
|
|
702
|
|
- debug("waiting for write");
|
703
|
|
-
|
704
|
700
|
uint32_t start_time = to_ms_since_boot(get_absolute_time());
|
705
|
701
|
while (1) {
|
706
|
702
|
sleep_ms(1);
|
|
@@ -719,7 +715,6 @@ int8_t ble_write(const uint8_t *service, const uint8_t *characteristic,
|
719
|
715
|
cyw43_thread_exit();
|
720
|
716
|
|
721
|
717
|
if ((state_cached == TC_WRITE_COMPLETE) || (state_cached == TC_READY)) {
|
722
|
|
- debug("write done (%s)", (state_cached == TC_READY) ? "error" : "success");
|
723
|
718
|
break;
|
724
|
719
|
}
|
725
|
720
|
}
|