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-06-28 19:06:11 +00:00
|
|
|
#define RXD2 16
|
2023-07-05 02:46:37 +00:00
|
|
|
#define TXD2 17
|
|
|
|
#define LED_BUILTIN 2
|
2023-06-28 19:06:11 +00:00
|
|
|
|
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
|
|
|
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-03 15:13:40 +00:00
|
|
|
volatile boolean connected = false;
|
2023-04-21 02:50:48 +00:00
|
|
|
volatile boolean bleInit = false;
|
2023-07-05 02:46:37 +00:00
|
|
|
volatile boolean blinkState = false;
|
2023-03-03 15:13:40 +00:00
|
|
|
|
|
|
|
volatile long now;
|
|
|
|
volatile long last = -1;
|
2023-07-05 02:46:37 +00:00
|
|
|
volatile long blinkLast = 0;
|
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
|
|
|
|
2023-06-28 19:06:11 +00:00
|
|
|
void setup () {
|
2023-04-21 02:50:48 +00:00
|
|
|
esp_log_level_set("*", ESP_LOG_NONE);
|
2023-07-05 02:46:37 +00:00
|
|
|
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
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-06-28 16:41:54 +00:00
|
|
|
//
|
2023-02-26 03:24:29 +00:00
|
|
|
}
|
|
|
|
while(!canon_ble.pair(10));
|
|
|
|
|
2023-03-01 18:51:54 +00:00
|
|
|
connected = true;
|
2023-06-28 19:06:11 +00:00
|
|
|
Serial2.println('C');
|
2023-02-26 03:24:29 +00:00
|
|
|
}
|
|
|
|
|
2023-06-28 19:06:11 +00:00
|
|
|
void loop () {
|
2023-03-03 15:13:40 +00:00
|
|
|
now = millis();
|
2023-03-10 02:18:10 +00:00
|
|
|
|
2023-06-28 19:06:11 +00:00
|
|
|
if (Serial2.available() > 0) {
|
|
|
|
cmdChar = Serial2.read();
|
2023-02-26 03:24:29 +00:00
|
|
|
}
|
2023-03-10 02:30:59 +00:00
|
|
|
|
2023-06-28 19:06:11 +00:00
|
|
|
if (connected && cmdChar == 'c') {
|
|
|
|
camera();
|
2023-03-01 18:51:54 +00:00
|
|
|
}
|
2023-04-14 00:39:24 +00:00
|
|
|
|
2023-07-05 02:46:37 +00:00
|
|
|
if (!bleInit && !connected) {
|
2023-04-21 02:50:48 +00:00
|
|
|
canon_ble.init();
|
|
|
|
bleInit = true;
|
|
|
|
}
|
|
|
|
|
2023-07-05 02:46:37 +00:00
|
|
|
if (bleInit && !connected && cmdChar == 'C') {
|
2023-04-14 00:39:24 +00:00
|
|
|
connectBLE();
|
|
|
|
}
|
2023-06-28 19:06:11 +00:00
|
|
|
|
|
|
|
if (connected && !canon_ble.isConnected()) {
|
|
|
|
connected = false;
|
2023-07-05 02:46:37 +00:00
|
|
|
Serial2.print('d');
|
2023-06-28 19:06:11 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 02:46:37 +00:00
|
|
|
blink();
|
|
|
|
|
2023-06-28 19:06:11 +00:00
|
|
|
cmdChar = 'z';
|
2023-03-03 15:13:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-12 18:52:05 +00:00
|
|
|
void camera () {
|
|
|
|
long start = now;
|
|
|
|
long end;
|
|
|
|
|
2023-06-28 19:06:11 +00:00
|
|
|
if (!canon_ble.trigger()) {
|
2023-07-05 02:46:37 +00:00
|
|
|
Serial2.print('E');
|
2023-03-03 15:13:40 +00:00
|
|
|
}
|
2023-07-05 02:46:37 +00:00
|
|
|
Serial2.print('c');
|
2023-03-03 15:13:40 +00:00
|
|
|
|
2023-04-12 18:52:05 +00:00
|
|
|
end = millis();
|
|
|
|
}
|
2023-07-05 02:46:37 +00:00
|
|
|
|
|
|
|
void blink () {
|
|
|
|
if (!connected && bleInit) {
|
|
|
|
if (now >= blinkLast + 200) {
|
|
|
|
if (blinkState) {
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
} else {
|
|
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
|
|
}
|
|
|
|
blinkState = !blinkState;
|
|
|
|
blinkLast = now;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|