canon_ble #82

Merged
mattmcw merged 149 commits from canon_ble into main 2023-08-01 03:38:52 +00:00
4 changed files with 49 additions and 35 deletions
Showing only changes of commit 58ce079330 - Show all commits

View File

@ -93,7 +93,7 @@ class Arduino {
**/
async sendAsync(device, cmd) {
return new Promise((resolve, reject) => {
console.log(`${device} -> ${cmd}`);
//this.log.info(`${device} -> ${cmd}`)
this.queue[cmd] = (ms) => {
return resolve(ms);
};
@ -163,7 +163,7 @@ class Arduino {
}
}.bind(this), 1000);
}
console.log(`${device} -> ${cmd}`);
//this.log.info(`${device} -> ${cmd}`)
return this.serial[device].write(cmd, (err, results) => {
if (err) {
//this.log.error(err)

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,8 @@
#include <Arduino.h>
#define RXD2 16
#define TXD2 -1
#define TXD2 17
#define LED_BUILTIN 2
#define LOG_LOCAL_LEVEL ESP_LOG_INFO
#include "esp_log.h"
@ -26,20 +27,21 @@
const String name_remote = "mcopy";
CanonBLERemote canon_ble(name_remote);
HardwareSerial Serial2(1);
volatile boolean connected = false;
volatile boolean bleInit = false;
volatile boolean blinkState = false;
volatile long now;
volatile long last = -1;
volatile long blinkLast = 0;
volatile char cmdChar = 'z';
void setup () {
esp_log_level_set("*", ESP_LOG_NONE);
delay(500);
Serial2.begin(57600, SERIAL_8N1, RXD2, TXD2);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
pinMode(LED_BUILTIN, OUTPUT);
}
void connectBLE () {
@ -63,21 +65,22 @@ void loop () {
camera();
}
if (!bleInit && !connected && cmdChar == 'i') {
if (!bleInit && !connected) {
canon_ble.init();
bleInit = true;
Serial2.println('i');
}
if (!connected && cmdChar == 'C') {
if (bleInit && !connected && cmdChar == 'C') {
connectBLE();
}
if (connected && !canon_ble.isConnected()) {
connected = false;
Serial2.println('d');
Serial2.print('d');
}
blink();
cmdChar = 'z';
}
@ -86,9 +89,23 @@ void camera () {
long end;
if (!canon_ble.trigger()) {
Serial2.println('E');
Serial2.print('E');
}
Serial2.println('c');
Serial2.print('c');
end = millis();
}
void blink () {
if (!connected && bleInit) {
if (now >= blinkLast + 200) {
if (blinkState) {
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
blinkState = !blinkState;
blinkLast = now;
}
}
}

View File

@ -24,9 +24,8 @@
#define SOFTWARE_TX 11
McopySerial mc;
SoftwareSerial softPort(SOFTWARE_RX, SOFTWARE_TX);
SoftwareSerial SoftSerial(SOFTWARE_RX, SOFTWARE_TX);
volatile boolean attached = false;
volatile boolean connected = false;
volatile boolean bleInit = false;
@ -43,11 +42,13 @@ volatile long end;
volatile char cmdChar = 'z';
volatile char sChar = 'z';
volatile bool connectedOnce = false;
void setup () {
pins();
mc.begin(mc.CAMERA_IDENTIFIER);
softPort.begin(57600);
SoftSerial.begin(9600);
digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, HIGH);
@ -73,8 +74,8 @@ void loop () {
now = millis();
cmdChar = mc.loop();
if (softPort.available() > 0) {
sChar = softPort.read();
if (SoftSerial.available() > 0) {
sChar = SoftSerial.read();
}
s_cmd(sChar);
@ -85,13 +86,10 @@ void loop () {
camera();
}
if (!bleInit && mc.connected && mc.identified) {
softPort.println('i');
}
if (bleInit && !connected && mc.connected && mc.identified) {
if (!connected && mc.connected && mc.identified && !connectedOnce) {
mc.log("Connecting BLE...");
softPort.println('C');
SoftSerial.print('C');
connectedOnce = true;
}
blink();
@ -107,19 +105,18 @@ void cmd (char val) {
} else if (val == mc.STATE) {
state();
}
cmdChar = 'z';
}
void s_cmd (char val) {
if (val == 'a') {
attached = true;
} else if (val == 'i') {
bleInit = true;
} else if (val == 'C') {
if (val == 'C') {
connected = true;
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, LOW);
} else if (val == 'd') {
connected = false;
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, LOW);
} else if (val == 'c') {
camera_end();
}
@ -129,16 +126,16 @@ void s_cmd (char val) {
void camera () {
start = now;
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, HIGH);
digitalWrite(RED_LED, LOW);
mc.log("Shutter pressed");
softPort.println('c');
SoftSerial.print('c');
}
void camera_end () {
end = millis();
delay(cameraFrame - (end - start));
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, HIGH);
last = millis();
mc.confirm(mc.CAMERA);
mc.log("camera()");