From cc806cbe521383db3df68345f788157cbb00ee5b Mon Sep 17 00:00:00 2001 From: mattmcw Date: Thu, 20 Apr 2023 22:50:48 -0400 Subject: [PATCH] Initialize and connect only after mcopyserial connects. --- .../mcopy_cam_canon_ble.ino | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino b/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino index 67e3c94..e236a08 100644 --- a/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino +++ b/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino @@ -34,6 +34,7 @@ CanonBLERemote canon_ble(name_remote); McopySerial mc; volatile boolean connected = false; +volatile boolean bleInit = false; volatile long now; volatile long last = -1; @@ -44,13 +45,18 @@ volatile char cmdChar = 'z'; void setup() { - esp_log_level_set("*", ESP_LOG_INFO); + esp_log_level_set("*", ESP_LOG_NONE); pins(); mc.begin(mc.CAMERA_IDENTIFIER); - canon_ble.init(); - delay(1000); + digitalWrite(RED_LED, HIGH); + digitalWrite(GREEN_LED, HIGH); + + delay(42); + + digitalWrite(RED_LED, LOW); + digitalWrite(GREEN_LED, LOW); } void pins () { @@ -88,7 +94,7 @@ void loop() cmd(cmdChar); // Shutter - if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){ + if (digitalRead(SHUTTTER_BTN) == LOW && connected){ camera(); } @@ -96,7 +102,15 @@ void loop() connected = false; } - if (!connected) { + if (!bleInit && mc.connected && mc.identified) { + mc.log("Initializing BLE..."); + canon_ble.init(); + bleInit = true; + delay(1000); + } + + if (!connected && mc.connected && mc.identified) { + mc.log("Connecting BLE..."); connectBLE(); } }