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 4525a35..9436818 100644 --- a/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino +++ b/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino @@ -17,13 +17,16 @@ #include "CanonBLERemote.h" #include +#define RXD2 16 +#define TXD2 -1 + #define LOG_LOCAL_LEVEL ESP_LOG_INFO #include "esp_log.h" #include - const String name_remote = "mcopy"; CanonBLERemote canon_ble(name_remote); +HardwareSerial Serial2(1); volatile boolean connected = false; volatile boolean bleInit = false; @@ -33,10 +36,10 @@ volatile long last = -1; volatile char cmdChar = 'z'; - -void setup() -{ +void setup () { esp_log_level_set("*", ESP_LOG_NONE); + delay(500); + Serial2.begin(57600, SERIAL_8N1, RXD2, TXD2); } void connectBLE () { @@ -46,46 +49,46 @@ void connectBLE () { while(!canon_ble.pair(10)); connected = true; - - //mc.log("Camera paired"); - //mc.log(canon_ble.getPairedAddressString()); + Serial2.println('C'); } -void loop() -{ +void loop () { now = millis(); - // Shutter - if (connected){ //&& + if (Serial2.available() > 0) { + cmdChar = Serial2.read(); + } + + if (connected && cmdChar == 'c') { camera(); } + if (!bleInit && !connected && cmdChar == 'i') { + canon_ble.init(); + bleInit = true; + Serial2.println('i'); + } + + if (!connected && cmd == 'C') { + connectBLE(); + } + if (connected && !canon_ble.isConnected()) { connected = false; + Serial2.println('d'); } - 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(); - } + cmdChar = 'z'; } void camera () { long start = now; long end; - //mc.log("Shutter pressed"); - - if(!canon_ble.trigger()){ - //mc.log("camera() failed"); + if (!canon_ble.trigger()) { + Serial2.println('E'); } + Serial2.println('c'); end = millis(); } 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 index 9940c34..a834353 100644 --- 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 @@ -14,29 +14,40 @@ * **/ +#include #include "McopySerial.h" -#define SHUTTTER_BTN 12 -#define RELAY_PIN 14 -#define RED_LED 23 -#define GREEN_LED 22 +#define SHUTTTER_BTN 5 +#define RED_LED 6 +#define GREEN_LED 7 +#define SOFTWARE_RX 10 +#define SOFTWARE_TX 11 McopySerial mc; +SoftwareSerial softPort(SOFTWARE_RX, SOFTWARE_TX); +volatile boolean attached = false; volatile boolean connected = false; volatile boolean bleInit = false; +volatile boolean blinkState = false; +volatile long blinkLast = 0; + volatile long now; volatile long last = -1; volatile long cameraFrame = 2000; +volatile long start; +volatile long end; + volatile char cmdChar = 'z'; +volatile char sChar = 'z'; -void setup() -{ +void setup () { pins(); mc.begin(mc.CAMERA_IDENTIFIER); + softPort.begin(57600); digitalWrite(RED_LED, HIGH); digitalWrite(GREEN_LED, HIGH); @@ -45,6 +56,7 @@ void setup() digitalWrite(RED_LED, LOW); digitalWrite(GREEN_LED, LOW); + blinkLast = millis(); } void pins () { @@ -57,11 +69,15 @@ void pins () { } -void loop() -{ +void loop () { now = millis(); cmdChar = mc.loop(); + if (softPort.available() > 0) { + sChar = softPort.read(); + } + + s_cmd(sChar); cmd(cmdChar); // Shutter @@ -69,18 +85,16 @@ void loop() camera(); } - if (connected && !canon_ble.isConnected()) { - connected = false; - } - if (!bleInit && mc.connected && mc.identified) { - bleInit = true; - delay(1000); + softPort.println('i'); } - if (!connected && mc.connected && mc.identified) { + if (bleInit && !connected && mc.connected && mc.identified) { mc.log("Connecting BLE..."); + softPort.println('C'); } + + blink(); } void cmd (char val) { @@ -95,22 +109,39 @@ void cmd (char val) { } } -void camera () { - long start = now; - long end; +void s_cmd (char val) { + if (val == 'a') { + attached = true; + } else if (val == 'i') { + bleInit = true; + } else if (val == 'C') { + connected = true; + digitalWrite(RED_LED, LOW); + digitalWrite(GREEN_LED, HIGH); + } else if (val == 'd') { + connected = false; + } else if (val == 'c') { + camera_end(); + } + sChar = 'z'; +} +void camera () { + start = now; digitalWrite(GREEN_LED, HIGH); digitalWrite(RED_LED, HIGH); mc.log("Shutter pressed"); + softPort.println('c'); +} - - +void camera_end () { end = millis(); delay(cameraFrame - (end - start)); digitalWrite(GREEN_LED, HIGH); digitalWrite(RED_LED, LOW); last = millis(); mc.confirm(mc.CAMERA); + mc.log("camera()"); } //null route direction @@ -124,6 +155,20 @@ void camera_direction (boolean state) { } } +void blink () { + if (!connected) { + if (now >= blinkLast + 200) { + if (blinkState) { + digitalWrite(RED_LED, HIGH); + } else { + digitalWrite(RED_LED, LOW); + } + blinkState = !blinkState; + blinkLast = now; + } + } +} + void state () { String stateString = String(mc.STATE); stateString += String(mc.CAMERA_EXPOSURE);