2023-02-28 04:16:44 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Camera Remote Menu
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Camera Settings
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
2023-02-26 03:24:29 +00:00
|
|
|
#include "CanonBLERemote.h"
|
|
|
|
#include <Arduino.h>
|
2023-03-05 00:04:55 +00:00
|
|
|
#include "McopySerial.h"
|
2023-02-26 03:24:29 +00:00
|
|
|
|
|
|
|
#define LOG_LOCAL_LEVEL ESP_LOG_INFO
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include <esp32-hal-log.h>
|
|
|
|
|
2023-03-03 15:13:40 +00:00
|
|
|
#define SHUTTTER_BTN 12
|
|
|
|
#define RELAY_PIN 14
|
2023-03-26 20:06:08 +00:00
|
|
|
#define RED_LED 23
|
2023-04-12 03:26:12 +00:00
|
|
|
#define GREEN_LED 22
|
2023-02-26 03:24:29 +00:00
|
|
|
|
|
|
|
|
2023-03-03 15:13:40 +00:00
|
|
|
const String name_remote = "mcopy";
|
2023-02-26 03:24:29 +00:00
|
|
|
CanonBLERemote canon_ble(name_remote);
|
2023-03-26 20:06:08 +00:00
|
|
|
|
2023-03-22 00:38:45 +00:00
|
|
|
McopySerial mc;
|
2023-03-05 00:25:50 +00:00
|
|
|
|
2023-03-03 15:13:40 +00:00
|
|
|
volatile boolean connected = false;
|
|
|
|
|
|
|
|
volatile long now;
|
|
|
|
volatile long last = -1;
|
2023-04-12 18:52:05 +00:00
|
|
|
volatile long cameraFrame = 2000;
|
2023-03-03 15:13:40 +00:00
|
|
|
|
2023-04-12 03:26:12 +00:00
|
|
|
volatile char cmdChar = 'z';
|
2023-02-26 03:24:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
esp_log_level_set("*", ESP_LOG_INFO);
|
|
|
|
|
2023-04-12 03:26:12 +00:00
|
|
|
pins();
|
2023-03-26 20:06:08 +00:00
|
|
|
mc.begin(mc.CAMERA_IDENTIFIER);
|
2023-04-12 03:26:12 +00:00
|
|
|
digitalWrite(RED_LED, HIGH);
|
2023-02-26 03:24:29 +00:00
|
|
|
canon_ble.init();
|
2023-03-26 20:06:08 +00:00
|
|
|
|
2023-02-26 03:24:29 +00:00
|
|
|
delay(1000);
|
2023-03-03 15:13:40 +00:00
|
|
|
}
|
2023-02-26 03:24:29 +00:00
|
|
|
|
2023-04-12 03:26:12 +00:00
|
|
|
void pins () {
|
|
|
|
pinMode(SHUTTTER_BTN, INPUT_PULLUP);
|
|
|
|
pinMode(RED_LED, OUTPUT);
|
|
|
|
pinMode(GREEN_LED, OUTPUT);
|
|
|
|
|
|
|
|
digitalWrite(RED_LED, LOW);
|
2023-04-12 18:52:05 +00:00
|
|
|
digitalWrite(GREEN_LED, LOW);
|
2023-04-12 03:26:12 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 15:13:40 +00:00
|
|
|
void connectBLE () {
|
2023-02-26 03:24:29 +00:00
|
|
|
do {
|
2023-04-12 18:52:05 +00:00
|
|
|
mc.log("Pairing...");
|
2023-02-26 03:24:29 +00:00
|
|
|
}
|
|
|
|
while(!canon_ble.pair(10));
|
|
|
|
|
2023-03-01 18:51:54 +00:00
|
|
|
connected = true;
|
|
|
|
|
2023-04-12 03:26:12 +00:00
|
|
|
digitalWrite(RED_LED, LOW);
|
2023-03-26 20:06:08 +00:00
|
|
|
digitalWrite(GREEN_LED, HIGH);
|
2023-02-26 03:24:29 +00:00
|
|
|
delay(1000);
|
2023-03-01 18:51:54 +00:00
|
|
|
|
2023-03-10 02:30:59 +00:00
|
|
|
mc.log("Camera paired");
|
|
|
|
mc.log(canon_ble.getPairedAddressString());
|
2023-02-26 03:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2023-03-03 15:13:40 +00:00
|
|
|
now = millis();
|
2023-04-12 03:26:12 +00:00
|
|
|
cmdChar = mc.loop();
|
2023-03-10 02:01:20 +00:00
|
|
|
|
2023-04-12 03:26:12 +00:00
|
|
|
cmd(cmdChar);
|
2023-03-10 02:18:10 +00:00
|
|
|
|
2023-02-26 03:24:29 +00:00
|
|
|
// Shutter
|
2023-03-03 15:13:40 +00:00
|
|
|
if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){
|
2023-04-12 18:52:05 +00:00
|
|
|
camera();
|
2023-02-26 03:24:29 +00:00
|
|
|
}
|
2023-03-10 02:30:59 +00:00
|
|
|
|
2023-04-12 18:52:05 +00:00
|
|
|
|
2023-03-01 18:51:54 +00:00
|
|
|
if (connected && !canon_ble.isConnected()) {
|
|
|
|
connected = false;
|
|
|
|
}
|
2023-03-03 15:13:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 03:26:12 +00:00
|
|
|
void cmd (char val) {
|
|
|
|
if (cmd == mc.CAMERA && connected) {
|
2023-04-12 18:52:05 +00:00
|
|
|
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();
|
2023-04-12 03:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-12 18:52:05 +00:00
|
|
|
void camera () {
|
|
|
|
long start = now;
|
|
|
|
long end;
|
|
|
|
|
2023-04-12 03:26:12 +00:00
|
|
|
digitalWrite(GREEN_LED, HIGH);
|
|
|
|
digitalWrite(RED_LED, HIGH);
|
2023-03-10 02:30:59 +00:00
|
|
|
mc.log("Shutter pressed");
|
2023-03-03 15:13:40 +00:00
|
|
|
|
|
|
|
if(!canon_ble.trigger()){
|
2023-04-12 18:52:05 +00:00
|
|
|
mc.log("camera() failed");
|
2023-03-03 15:13:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 18:52:05 +00:00
|
|
|
end = millis();
|
|
|
|
delay(cameraFrame - (end - start));
|
2023-03-26 20:06:08 +00:00
|
|
|
digitalWrite(GREEN_LED, HIGH);
|
2023-04-12 03:26:12 +00:00
|
|
|
digitalWrite(RED_LED, LOW);
|
2023-03-03 15:13:40 +00:00
|
|
|
last = millis();
|
2023-03-22 00:38:45 +00:00
|
|
|
mc.confirm(mc.CAMERA);
|
2023-04-12 18:52:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//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.CAMERA_EXPOSURE);
|
|
|
|
stateString += String(cameraFrame);
|
|
|
|
stateString += String(mc.STATE);
|
|
|
|
mc.print(stateString);
|
2023-02-26 03:24:29 +00:00
|
|
|
}
|