canon work

This commit is contained in:
Matt McWilliams 2023-03-03 10:13:40 -05:00
parent 0e3bc563a7
commit dc746fe6f4
1 changed files with 38 additions and 21 deletions

View File

@ -14,8 +14,6 @@
* *
**/ **/
#include "CanonBLERemote.h" #include "CanonBLERemote.h"
#include <Arduino.h> #include <Arduino.h>
#include "TickTwo.h" #include "TickTwo.h"
@ -24,18 +22,22 @@
#include "esp_log.h" #include "esp_log.h"
#include <esp32-hal-log.h> #include <esp32-hal-log.h>
#define SHUTTTER_BTN 14 #define SHUTTTER_BTN 12
#define FOCUS_BTN 12 #define RELAY_PIN 14
#define LED 22 #define LED 22
void blink(); void blink();
bool ledState; volatile bool ledState;
String name_remote = "mcopy"; const String name_remote = "mcopy";
CanonBLERemote canon_ble(name_remote); CanonBLERemote canon_ble(name_remote);
TickTwo blinker(blink, 500); TickTwo blinker(blink, 500);
boolean connected = false; volatile boolean connected = false;
long last = -1;
volatile long now;
volatile long last = -1;
volatile byte cmd_char;
void blink(){ void blink(){
digitalWrite(LED, ledState); digitalWrite(LED, ledState);
@ -48,13 +50,14 @@ void setup()
esp_log_level_set("*", ESP_LOG_INFO); esp_log_level_set("*", ESP_LOG_INFO);
pinMode(SHUTTTER_BTN, INPUT_PULLUP); pinMode(SHUTTTER_BTN, INPUT_PULLUP);
pinMode(FOCUS_BTN, INPUT_PULLUP);
pinMode(LED, OUTPUT); pinMode(LED, OUTPUT);
canon_ble.init(); canon_ble.init();
delay(1000); delay(1000);
blinker.start(); blinker.start();
}
void connectBLE () {
do { do {
Serial.println("Pairing..."); Serial.println("Pairing...");
} }
@ -73,24 +76,38 @@ void setup()
void loop() void loop()
{ {
now = millis();
if (Serial.available()) {
/* read the most recent byte */
cmd_char = (char)Serial.read();
}
if (cmd_char == 'c' && last + 1000 < now) {
shutter();
cmd_char = 'z';
}
// Shutter // Shutter
if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < millis()){ if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){
digitalWrite(LED, LOW); shutter();
blinker.resume();
Serial.println("Shutter pressed");
if(!canon_ble.trigger()){
Serial.println("Trigger Failed");
}
blinker.pause();
digitalWrite(LED, HIGH);
last = millis();
} }
blinker.update(); blinker.update();
if (connected && !canon_ble.isConnected()) { if (connected && !canon_ble.isConnected()) {
connected = false; connected = false;
Serial.println("Disconnected"); Serial.println("Disconnected");
blinker.interval(500); blinker.interval(500);
blinker.resume();
} }
}
void shutter () {
digitalWrite(LED, LOW);
blinker.resume();
Serial.println("Shutter pressed");
if(!canon_ble.trigger()){
Serial.println("Trigger Failed");
}
blinker.pause();
digitalWrite(LED, HIGH);
last = millis();
} }