mcopy/ino/mcopy_cam_canon_ble/mcopy_cam_canon_ble.ino

119 lines
1.9 KiB
Arduino
Raw Normal View History

2023-02-28 04:16:44 +00:00
/**
*
* Camera Remote Menu
*
*
*
*
*
* Camera Settings
*
*
*
*
*
**/
#include "CanonBLERemote.h"
#include <Arduino.h>
2023-03-05 00:04:55 +00:00
#include "McopySerial.h"
#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
#define GREEN_LED 22
void blink();
2023-03-26 20:06:08 +00:00
volatile bool greenLEDstate;
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
McopySerial mc;
2023-03-03 15:13:40 +00:00
volatile boolean connected = false;
volatile long now;
volatile long last = -1;
volatile char cmdChar = 'z';
void setup()
{
esp_log_level_set("*", ESP_LOG_INFO);
pins();
2023-03-26 20:06:08 +00:00
mc.begin(mc.CAMERA_IDENTIFIER);
digitalWrite(RED_LED, HIGH);
canon_ble.init();
2023-03-26 20:06:08 +00:00
delay(1000);
2023-03-03 15:13:40 +00:00
}
void pins () {
pinMode(SHUTTTER_BTN, INPUT_PULLUP);
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
}
2023-03-03 15:13:40 +00:00
void connectBLE () {
do {
Serial.println("Pairing...");
}
while(!canon_ble.pair(10));
connected = true;
digitalWrite(RED_LED, LOW);
2023-03-26 20:06:08 +00:00
digitalWrite(GREEN_LED, HIGH);
delay(1000);
mc.log("Camera paired");
mc.log(canon_ble.getPairedAddressString());
}
void loop()
{
2023-03-03 15:13:40 +00:00
now = millis();
cmdChar = mc.loop();
cmd(cmdChar);
// Shutter
2023-03-03 15:13:40 +00:00
if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){
shutter();
}
if (connected && !canon_ble.isConnected()) {
connected = false;
}
2023-03-03 15:13:40 +00:00
}
void cmd (char val) {
if (cmd == mc.CAMERA && connected) {
shutter();
}
}
2023-03-03 15:13:40 +00:00
void shutter () {
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, HIGH);
mc.log("Shutter pressed");
2023-03-03 15:13:40 +00:00
if(!canon_ble.trigger()){
mc.log("Trigger Failed");
2023-03-03 15:13:40 +00:00
}
2023-03-26 20:06:08 +00:00
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
2023-03-03 15:13:40 +00:00
last = millis();
mc.confirm(mc.CAMERA);
}