From b48c4985749c3610449a8079db513fa2a2636e7e Mon Sep 17 00:00:00 2001 From: mattmcw Date: Wed, 28 Jun 2023 12:41:54 -0400 Subject: [PATCH] Remove unneeded components from both ble sketches --- .../mcopy_cam_canon_ble.ino | 49 +------ .../mcopy_cam_canon_ble_nano.ino | 133 ++++++++++++++++++ 2 files changed, 140 insertions(+), 42 deletions(-) create mode 100644 ino/mcopy_cam_canon_ble_nano/mcopy_cam_canon_ble_nano.ino 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 e78e457..7dc425f 100644 --- a/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino +++ b/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino @@ -16,29 +16,20 @@ #include "CanonBLERemote.h" #include -//#include "McopySerial.h" #define LOG_LOCAL_LEVEL ESP_LOG_INFO #include "esp_log.h" #include -#define SHUTTTER_BTN 12 -#define RELAY_PIN 14 -#define RED_LED 23 -#define GREEN_LED 22 - const String name_remote = "mcopy"; CanonBLERemote canon_ble(name_remote); -McopySerial mc; - volatile boolean connected = false; volatile boolean bleInit = false; volatile long now; volatile long last = -1; -volatile long cameraFrame = 2000; volatile char cmdChar = 'z'; @@ -46,44 +37,18 @@ volatile char cmdChar = 'z'; void setup() { esp_log_level_set("*", ESP_LOG_NONE); - - pins(); - mc.begin(mc.CAMERA_IDENTIFIER); - - digitalWrite(RED_LED, HIGH); - digitalWrite(GREEN_LED, HIGH); - - delay(42); - - digitalWrite(RED_LED, LOW); - digitalWrite(GREEN_LED, LOW); -} - -void pins () { - pinMode(SHUTTTER_BTN, INPUT_PULLUP); - pinMode(RED_LED, OUTPUT); - pinMode(GREEN_LED, OUTPUT); - - digitalWrite(RED_LED, LOW); - digitalWrite(GREEN_LED, LOW); } void connectBLE () { - digitalWrite(RED_LED, HIGH); - digitalWrite(GREEN_LED, LOW); do { - mc.log("Pairing..."); + // } while(!canon_ble.pair(10)); connected = true; - - digitalWrite(RED_LED, LOW); - digitalWrite(GREEN_LED, HIGH); - delay(1000); - mc.log("Camera paired"); - mc.log(canon_ble.getPairedAddressString()); + //mc.log("Camera paired"); + //mc.log(canon_ble.getPairedAddressString()); } void loop() @@ -159,8 +124,8 @@ void camera_direction (boolean state) { } void state () { - String stateString = String(mc.CAMERA_EXPOSURE); - stateString += String(cameraFrame); - stateString += String(mc.STATE); - mc.print(stateString); + String stateString = String(mc.CAMERA_EXPOSURE); + stateString += String(cameraFrame); + stateString += String(mc.STATE); + mc.print(stateString); } \ No newline at end of file diff --git a/ino/mcopy_cam_canon_ble_nano/mcopy_cam_canon_ble_nano.ino b/ino/mcopy_cam_canon_ble_nano/mcopy_cam_canon_ble_nano.ino new file mode 100644 index 0000000..9940c34 --- /dev/null +++ b/ino/mcopy_cam_canon_ble_nano/mcopy_cam_canon_ble_nano.ino @@ -0,0 +1,133 @@ +/** + * + * Camera Remote Menu + * + * + * + * + * + * Camera Settings + * + * + * + * + * + **/ + +#include "McopySerial.h" + +#define SHUTTTER_BTN 12 +#define RELAY_PIN 14 +#define RED_LED 23 +#define GREEN_LED 22 + +McopySerial mc; + +volatile boolean connected = false; +volatile boolean bleInit = false; + +volatile long now; +volatile long last = -1; +volatile long cameraFrame = 2000; + +volatile char cmdChar = 'z'; + + +void setup() +{ + pins(); + mc.begin(mc.CAMERA_IDENTIFIER); + + digitalWrite(RED_LED, HIGH); + digitalWrite(GREEN_LED, HIGH); + + delay(42); + + digitalWrite(RED_LED, LOW); + digitalWrite(GREEN_LED, LOW); +} + +void pins () { + pinMode(SHUTTTER_BTN, INPUT_PULLUP); + pinMode(RED_LED, OUTPUT); + pinMode(GREEN_LED, OUTPUT); + + digitalWrite(RED_LED, LOW); + digitalWrite(GREEN_LED, LOW); +} + + +void loop() +{ + now = millis(); + cmdChar = mc.loop(); + + cmd(cmdChar); + + // Shutter + if (digitalRead(SHUTTTER_BTN) == LOW && connected){ + camera(); + } + + if (connected && !canon_ble.isConnected()) { + connected = false; + } + + if (!bleInit && mc.connected && mc.identified) { + bleInit = true; + delay(1000); + } + + if (!connected && mc.connected && mc.identified) { + mc.log("Connecting BLE..."); + } +} + +void cmd (char val) { + if (val == mc.CAMERA && connected) { + camera(); + } else if (val == mc.CAMERA_FORWARD) { + camera_direction(true); + } else if (val == mc.CAMERA_BACKWARD) { + camera_direction(false); + } else if (val == mc.STATE) { + state(); + } +} + +void camera () { + long start = now; + long end; + + digitalWrite(GREEN_LED, HIGH); + digitalWrite(RED_LED, HIGH); + mc.log("Shutter pressed"); + + + + end = millis(); + delay(cameraFrame - (end - start)); + digitalWrite(GREEN_LED, HIGH); + digitalWrite(RED_LED, LOW); + last = millis(); + mc.confirm(mc.CAMERA); +} + +//null route direction +void camera_direction (boolean state) { + if (state) { + mc.confirm(mc.CAMERA_FORWARD); + mc.log("camera_direction(true)"); + } else { + mc.confirm(mc.CAMERA_BACKWARD); + mc.log("camera_direction(false)"); + } +} + +void state () { + String stateString = String(mc.STATE); + stateString += String(mc.CAMERA_EXPOSURE); + stateString += String(cameraFrame); + stateString += String(mc.STATE); + mc.print(stateString); +} \ No newline at end of file