mcopy/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino

111 lines
1.8 KiB
Arduino
Raw Permalink Normal View History

2023-02-28 04:16:44 +00:00
/**
*
* Camera Remote Menu
*
*
*
*
*
* Camera Settings
*
*
*
*
*
**/
#include "CanonBLERemote.h"
#include <Arduino.h>
#define RXD2 16
2023-07-05 02:46:37 +00:00
#define TXD2 17
#define LED_BUILTIN 2
#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";
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;
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
volatile char cmdChar = 'z';
void setup () {
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-03-03 15:13:40 +00:00
void connectBLE () {
do {
//
}
while(!canon_ble.pair(10));
connected = true;
Serial2.println('C');
}
void loop () {
2023-03-03 15:13:40 +00:00
now = millis();
if (Serial2.available() > 0) {
cmdChar = Serial2.read();
}
if (connected && cmdChar == 'c') {
camera();
}
2023-04-14 00:39:24 +00:00
2023-07-05 02:46:37 +00:00
if (!bleInit && !connected) {
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();
}
if (connected && !canon_ble.isConnected()) {
connected = false;
2023-07-05 02:46:37 +00:00
Serial2.print('d');
}
2023-07-05 02:46:37 +00:00
blink();
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;
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;
}
}
}