Structure of both sketches is complete, need to test on hardware

This commit is contained in:
Matt McWilliams 2023-06-28 15:06:11 -04:00
parent bf320216cf
commit 777db577d7
2 changed files with 94 additions and 46 deletions

View File

@ -17,13 +17,16 @@
#include "CanonBLERemote.h" #include "CanonBLERemote.h"
#include <Arduino.h> #include <Arduino.h>
#define RXD2 16
#define TXD2 -1
#define LOG_LOCAL_LEVEL ESP_LOG_INFO #define LOG_LOCAL_LEVEL ESP_LOG_INFO
#include "esp_log.h" #include "esp_log.h"
#include <esp32-hal-log.h> #include <esp32-hal-log.h>
const String name_remote = "mcopy"; const String name_remote = "mcopy";
CanonBLERemote canon_ble(name_remote); CanonBLERemote canon_ble(name_remote);
HardwareSerial Serial2(1);
volatile boolean connected = false; volatile boolean connected = false;
volatile boolean bleInit = false; volatile boolean bleInit = false;
@ -33,10 +36,10 @@ volatile long last = -1;
volatile char cmdChar = 'z'; volatile char cmdChar = 'z';
void setup () {
void setup()
{
esp_log_level_set("*", ESP_LOG_NONE); esp_log_level_set("*", ESP_LOG_NONE);
delay(500);
Serial2.begin(57600, SERIAL_8N1, RXD2, TXD2);
} }
void connectBLE () { void connectBLE () {
@ -46,46 +49,46 @@ void connectBLE () {
while(!canon_ble.pair(10)); while(!canon_ble.pair(10));
connected = true; connected = true;
Serial2.println('C');
//mc.log("Camera paired");
//mc.log(canon_ble.getPairedAddressString());
} }
void loop() void loop () {
{
now = millis(); now = millis();
// Shutter if (Serial2.available() > 0) {
if (connected){ //&& cmdChar = Serial2.read();
}
if (connected && cmdChar == 'c') {
camera(); camera();
} }
if (!bleInit && !connected && cmdChar == 'i') {
canon_ble.init();
bleInit = true;
Serial2.println('i');
}
if (!connected && cmd == 'C') {
connectBLE();
}
if (connected && !canon_ble.isConnected()) { if (connected && !canon_ble.isConnected()) {
connected = false; connected = false;
Serial2.println('d');
} }
if (!bleInit && mc.connected && mc.identified) { cmdChar = 'z';
//mc.log("Initializing BLE...");
canon_ble.init();
bleInit = true;
delay(1000);
}
if (!connected && mc.connected && mc.identified) {
//mc.log("Connecting BLE...");
connectBLE();
}
} }
void camera () { void camera () {
long start = now; long start = now;
long end; long end;
//mc.log("Shutter pressed"); if (!canon_ble.trigger()) {
Serial2.println('E');
if(!canon_ble.trigger()){
//mc.log("camera() failed");
} }
Serial2.println('c');
end = millis(); end = millis();
} }

View File

@ -14,29 +14,40 @@
* *
**/ **/
#include <SoftwareSerial.h>
#include "McopySerial.h" #include "McopySerial.h"
#define SHUTTTER_BTN 12 #define SHUTTTER_BTN 5
#define RELAY_PIN 14 #define RED_LED 6
#define RED_LED 23 #define GREEN_LED 7
#define GREEN_LED 22 #define SOFTWARE_RX 10
#define SOFTWARE_TX 11
McopySerial mc; McopySerial mc;
SoftwareSerial softPort(SOFTWARE_RX, SOFTWARE_TX);
volatile boolean attached = false;
volatile boolean connected = false; volatile boolean connected = false;
volatile boolean bleInit = false; volatile boolean bleInit = false;
volatile boolean blinkState = false;
volatile long blinkLast = 0;
volatile long now; volatile long now;
volatile long last = -1; volatile long last = -1;
volatile long cameraFrame = 2000; volatile long cameraFrame = 2000;
volatile long start;
volatile long end;
volatile char cmdChar = 'z'; volatile char cmdChar = 'z';
volatile char sChar = 'z';
void setup() void setup () {
{
pins(); pins();
mc.begin(mc.CAMERA_IDENTIFIER); mc.begin(mc.CAMERA_IDENTIFIER);
softPort.begin(57600);
digitalWrite(RED_LED, HIGH); digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, HIGH);
@ -45,6 +56,7 @@ void setup()
digitalWrite(RED_LED, LOW); digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, LOW); digitalWrite(GREEN_LED, LOW);
blinkLast = millis();
} }
void pins () { void pins () {
@ -57,11 +69,15 @@ void pins () {
} }
void loop() void loop () {
{
now = millis(); now = millis();
cmdChar = mc.loop(); cmdChar = mc.loop();
if (softPort.available() > 0) {
sChar = softPort.read();
}
s_cmd(sChar);
cmd(cmdChar); cmd(cmdChar);
// Shutter // Shutter
@ -69,18 +85,16 @@ void loop()
camera(); camera();
} }
if (connected && !canon_ble.isConnected()) {
connected = false;
}
if (!bleInit && mc.connected && mc.identified) { if (!bleInit && mc.connected && mc.identified) {
bleInit = true; softPort.println('i');
delay(1000);
} }
if (!connected && mc.connected && mc.identified) { if (bleInit && !connected && mc.connected && mc.identified) {
mc.log("Connecting BLE..."); mc.log("Connecting BLE...");
softPort.println('C');
} }
blink();
} }
void cmd (char val) { void cmd (char val) {
@ -95,22 +109,39 @@ void cmd (char val) {
} }
} }
void camera () { void s_cmd (char val) {
long start = now; if (val == 'a') {
long end; 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(GREEN_LED, HIGH);
digitalWrite(RED_LED, HIGH); digitalWrite(RED_LED, HIGH);
mc.log("Shutter pressed"); mc.log("Shutter pressed");
softPort.println('c');
}
void camera_end () {
end = millis(); end = millis();
delay(cameraFrame - (end - start)); delay(cameraFrame - (end - start));
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW); digitalWrite(RED_LED, LOW);
last = millis(); last = millis();
mc.confirm(mc.CAMERA); mc.confirm(mc.CAMERA);
mc.log("camera()");
} }
//null route direction //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 () { void state () {
String stateString = String(mc.STATE); String stateString = String(mc.STATE);
stateString += String(mc.CAMERA_EXPOSURE); stateString += String(mc.CAMERA_EXPOSURE);