/*
* This file is part of Photoduino.
*
* Photoduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Photoduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Photoduino. If not, see .
*/
// Shoots the flash after wait a delay
void flash_shoot(unsigned int previousDelay, byte pin) {
delay(previousDelay);
digitalWrite(pin,HIGH);
delayMicroseconds(DEVICES_FLASHES_SHOOTING_PULSE);
digitalWrite(pin,LOW);
}
// Begins the shutter
void camera_shutterBegin(unsigned int shutterLag){
digitalWrite(PINS_SHUTTER,HIGH);
delay(shutterLag);
}
// Ends the shutter
void camera_shutterEnd(unsigned int preCloseTime){
delay(preCloseTime);
digitalWrite(PINS_SHUTTER,LOW);
}
// Begins the autofocus
void camera_autofocusBegin(unsigned int autofocusTime){
digitalWrite(PINS_AUTOFOCUS,HIGH);
delay(autofocusTime);
}
// Ends the autofocus
void camera_autofocusEnd(){
digitalWrite(PINS_AUTOFOCUS,LOW);
}
// Look-up the mirror
void camera_mirrorLockUp(unsigned int autofocusTime, unsigned int shutterLag){
digitalWrite(PINS_AUTOFOCUS,HIGH);
delay(autofocusTime);
digitalWrite(PINS_SHUTTER,HIGH);
delay(shutterLag);
digitalWrite(PINS_SHUTTER,LOW);
digitalWrite(PINS_AUTOFOCUS,LOW);
}
// Reads the value of a sensor
unsigned int sensor_read(byte sensorPin) {
unsigned int value = analogRead(sensorPin);
if (value>999) value = 999;
if (sensorPin == PINS_SENSOR_MIC) {
if (value > 500) value = (value-500)*2;
else value = (500-value)*2;
}
return value;
}
// Sets the sensor pin and sensor mode according the sensor type
void sensor_getConfiguration(byte sensorType, unsigned int **limitValue, byte *sensorPin, byte *sensorMode) {
if (sensorType == SENSOR_TYPE_AUDIO) { *sensorPin = PINS_SENSOR_MIC; *sensorMode = SENSOR_MODE_HIGHER; *limitValue = &sensorTriggerMode_sensorAudioLimit; }
else if (sensorType == SENSOR_TYPE_SHOCK) { *sensorPin = PINS_SENSOR_SHOCK; *sensorMode = SENSOR_MODE_HIGHER; *limitValue = &sensorTriggerMode_sensorShockLimit; }
else if (sensorType == SENSOR_TYPE_LIGHT) { *sensorPin = PINS_SENSOR_BARRIER; *sensorMode = SENSOR_MODE_HIGHER; *limitValue = &sensorTriggerMode_sensorLightLimit;}
else if (sensorType == SENSOR_TYPE_BARRIER) { *sensorPin = PINS_SENSOR_BARRIER; *sensorMode = SENSOR_MODE_LOWER; *limitValue = &sensorTriggerMode_sensorBarrierLimit;}
}
// Waits for sensor cross the limit
boolean sensor_waitFor(byte sensorType, unsigned int limitTime){
byte sensorPin;
byte sensorMode;
unsigned int *limitValue;
sensor_getConfiguration(sensorType, &limitValue, &sensorPin, &sensorMode);
unsigned long time = millis();
unsigned int sensorValue = sensor_read(sensorPin);
boolean result = false;
for(; !result && !cancelFlag && (millis()