Merge remote-tracking branch 'origin/canon_ble' into canon_ble

This commit is contained in:
Matt McWilliams 2023-04-12 14:52:40 -04:00
commit 08655898d4
1 changed files with 37 additions and 8 deletions

View File

@ -27,8 +27,6 @@
#define RED_LED 23 #define RED_LED 23
#define GREEN_LED 22 #define GREEN_LED 22
void blink();
volatile bool greenLEDstate;
const String name_remote = "mcopy"; const String name_remote = "mcopy";
CanonBLERemote canon_ble(name_remote); CanonBLERemote canon_ble(name_remote);
@ -39,6 +37,7 @@ volatile boolean connected = false;
volatile long now; volatile long now;
volatile long last = -1; volatile long last = -1;
volatile long cameraFrame = 2000;
volatile char cmdChar = 'z'; volatile char cmdChar = 'z';
@ -61,12 +60,12 @@ void pins () {
pinMode(GREEN_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT);
digitalWrite(RED_LED, LOW); digitalWrite(RED_LED, LOW);
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, LOW);
} }
void connectBLE () { void connectBLE () {
do { do {
Serial.println("Pairing..."); mc.log("Pairing...");
} }
while(!canon_ble.pair(10)); while(!canon_ble.pair(10));
@ -89,9 +88,10 @@ void loop()
// Shutter // Shutter
if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){ if (digitalRead(SHUTTTER_BTN) == LOW && last + 1000 < now){
shutter(); camera();
} }
if (connected && !canon_ble.isConnected()) { if (connected && !canon_ble.isConnected()) {
connected = false; connected = false;
} }
@ -99,21 +99,50 @@ void loop()
void cmd (char val) { void cmd (char val) {
if (cmd == mc.CAMERA && connected) { if (cmd == mc.CAMERA && connected) {
shutter(); camera();
} else if (val == mc.CAMERA_FORWARD) {
camera_direction(true);
} else if (val == mc.CAMERA_BACKWARD) {
camera_direction(false);
} else if (val == mc.STATE) {
state();
} }
} }
void shutter () { void camera () {
long start = now;
long end;
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, HIGH); digitalWrite(RED_LED, HIGH);
mc.log("Shutter pressed"); mc.log("Shutter pressed");
if(!canon_ble.trigger()){ if(!canon_ble.trigger()){
mc.log("Trigger Failed"); mc.log("camera() failed");
} }
end = millis();
delay(cameraFrame - (end - start));
digitalWrite(GREEN_LED, HIGH); digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW); digitalWrite(RED_LED, LOW);
last = millis(); last = millis();
mc.confirm(mc.CAMERA); mc.confirm(mc.CAMERA);
}
//null route direction
void camera_direction (boolean state) {
if (state) {
mc.confirm(mc.CAMERA_FORWARD);
mc.log("camera_direction(true)");
} else {
mc.confirm(mc.CAMERA_BACKWARD);
mc.log("camera_direction(false)");
}
}
void state () {
String stateString = String(mc.CAMERA_EXPOSURE);
stateString += String(cameraFrame);
stateString += String(mc.STATE);
mc.print(stateString);
} }