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) { async sendAsync(device, cmd) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log(`${device} -> ${cmd}`); //this.log.info(`${device} -> ${cmd}`)
this.queue[cmd] = (ms) => { this.queue[cmd] = (ms) => {
return resolve(ms); return resolve(ms);
}; };
@ -163,7 +163,7 @@ class Arduino {
} }
}.bind(this), 1000); }.bind(this), 1000);
} }
console.log(`${device} -> ${cmd}`); //this.log.info(`${device} -> ${cmd}`)
return this.serial[device].write(cmd, (err, results) => { return this.serial[device].write(cmd, (err, results) => {
if (err) { if (err) {
//this.log.error(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> #include <Arduino.h>
#define RXD2 16 #define RXD2 16
#define TXD2 -1 #define TXD2 17
#define LED_BUILTIN 2
#define LOG_LOCAL_LEVEL ESP_LOG_INFO #define LOG_LOCAL_LEVEL ESP_LOG_INFO
#include "esp_log.h" #include "esp_log.h"
@ -26,20 +27,21 @@
const String name_remote = "mcopy"; const String name_remote = "mcopy";
CanonBLERemote canon_ble(name_remote); CanonBLERemote canon_ble(name_remote);
HardwareSerial Serial2(1);
volatile boolean connected = false; volatile boolean connected = false;
volatile boolean bleInit = false; volatile boolean bleInit = false;
volatile boolean blinkState = false;
volatile long now; volatile long now;
volatile long last = -1; volatile long last = -1;
volatile long blinkLast = 0;
volatile char cmdChar = 'z'; volatile char cmdChar = 'z';
void setup () { void setup () {
esp_log_level_set("*", ESP_LOG_NONE); esp_log_level_set("*", ESP_LOG_NONE);
delay(500); Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
Serial2.begin(57600, SERIAL_8N1, RXD2, TXD2); pinMode(LED_BUILTIN, OUTPUT);
} }
void connectBLE () { void connectBLE () {
@ -63,21 +65,22 @@ void loop () {
camera(); camera();
} }
if (!bleInit && !connected && cmdChar == 'i') { if (!bleInit && !connected) {
canon_ble.init(); canon_ble.init();
bleInit = true; bleInit = true;
Serial2.println('i');
} }
if (!connected && cmdChar == 'C') { if (bleInit && !connected && cmdChar == 'C') {
connectBLE(); connectBLE();
} }
if (connected && !canon_ble.isConnected()) { if (connected && !canon_ble.isConnected()) {
connected = false; connected = false;
Serial2.println('d'); Serial2.print('d');
} }
blink();
cmdChar = 'z'; cmdChar = 'z';
} }
@ -86,9 +89,23 @@ void camera () {
long end; long end;
if (!canon_ble.trigger()) { if (!canon_ble.trigger()) {
Serial2.println('E'); Serial2.print('E');
} }
Serial2.println('c'); Serial2.print('c');
end = millis(); 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 #define SOFTWARE_TX 11
McopySerial mc; McopySerial mc;
SoftwareSerial softPort(SOFTWARE_RX, SOFTWARE_TX); SoftwareSerial SoftSerial(SOFTWARE_RX, SOFTWARE_TX);
volatile boolean attached = false;
volatile boolean connected = false; volatile boolean connected = false;
volatile boolean bleInit = false; volatile boolean bleInit = false;
@ -43,11 +42,13 @@ volatile long end;
volatile char cmdChar = 'z'; volatile char cmdChar = 'z';
volatile char sChar = 'z'; volatile char sChar = 'z';
volatile bool connectedOnce = false;
void setup () { void setup () {
pins(); pins();
mc.begin(mc.CAMERA_IDENTIFIER); mc.begin(mc.CAMERA_IDENTIFIER);
softPort.begin(57600); SoftSerial.begin(9600);
digitalWrite(RED_LED, HIGH); digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, HIGH);
@ -73,8 +74,8 @@ void loop () {
now = millis(); now = millis();
cmdChar = mc.loop(); cmdChar = mc.loop();
if (softPort.available() > 0) { if (SoftSerial.available() > 0) {
sChar = softPort.read(); sChar = SoftSerial.read();
} }
s_cmd(sChar); s_cmd(sChar);
@ -85,13 +86,10 @@ void loop () {
camera(); camera();
} }
if (!bleInit && mc.connected && mc.identified) { if (!connected && mc.connected && mc.identified && !connectedOnce) {
softPort.println('i');
}
if (bleInit && !connected && mc.connected && mc.identified) {
mc.log("Connecting BLE..."); mc.log("Connecting BLE...");
softPort.println('C'); SoftSerial.print('C');
connectedOnce = true;
} }
blink(); blink();
@ -107,19 +105,18 @@ void cmd (char val) {
} else if (val == mc.STATE) { } else if (val == mc.STATE) {
state(); state();
} }
cmdChar = 'z';
} }
void s_cmd (char val) { void s_cmd (char val) {
if (val == 'a') { if (val == 'C') {
attached = true;
} else if (val == 'i') {
bleInit = true;
} else if (val == 'C') {
connected = true; connected = true;
digitalWrite(RED_LED, LOW); digitalWrite(RED_LED, HIGH);
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, LOW);
} else if (val == 'd') { } else if (val == 'd') {
connected = false; connected = false;
digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, LOW);
} else if (val == 'c') { } else if (val == 'c') {
camera_end(); camera_end();
} }
@ -129,16 +126,16 @@ void s_cmd (char val) {
void camera () { void camera () {
start = now; start = now;
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, HIGH); digitalWrite(RED_LED, LOW);
mc.log("Shutter pressed"); mc.log("Shutter pressed");
softPort.println('c'); SoftSerial.print('c');
} }
void camera_end () { void camera_end () {
end = millis(); end = millis();
delay(cameraFrame - (end - start)); delay(cameraFrame - (end - start));
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, LOW);
digitalWrite(RED_LED, LOW); digitalWrite(RED_LED, HIGH);
last = millis(); last = millis();
mc.confirm(mc.CAMERA); mc.confirm(mc.CAMERA);
mc.log("camera()"); mc.log("camera()");