-
-
Save thcipriani/c914393c5f9381838dcb84757072fe61 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import serial | |
import select | |
import sys | |
import time | |
TIMEOUT = 0.1 | |
BAUDRATE = 500000 | |
PORT = '/dev/ttyUSB0' | |
PHASES = { | |
'Before_C2': { | |
'delay_seconds': 5*60, # 5 minutes | |
'shutter_down_seconds': 1, | |
}, | |
'After_C2': { # Baily's Beads, Diamond Ring, Pre-Totality | |
'delay_seconds': 2, | |
'shutter_down_seconds': 1, | |
}, | |
'Totality': { | |
'delay_seconds': 2, | |
'shutter_down_seconds': 1, | |
}, | |
} | |
def take_picture(camerathing, seconds=3): | |
print(f'snapping picture for {seconds}s...') | |
camerathing.write(bytes(f'trigger {seconds}\n', 'utf-8')) | |
time.sleep(seconds + 0.25) | |
while camerathing.out_waiting: | |
time.sleep(0.5) | |
while camerathing.in_waiting: | |
line = camerathing.readline().decode('utf-8').strip() | |
if line and line in ['>>>']: | |
continue | |
if line == 'Testing shutter': | |
print('Fired!') | |
def get_power(camerathing): | |
print('checking power...') | |
camerathing.write(bytes('pwr\n', 'utf-8')) | |
while camerathing.out_waiting: | |
time.sleep(TIMEOUT) | |
while camerathing.in_waiting: | |
line = camerathing.readline().decode('utf-8').strip() | |
if line.startswith('pwr:'): | |
return [l.strip() for l in line.split(' ') if l.strip()][1] | |
def setup_serial(): | |
camerathing = serial.Serial(port=PORT, baudrate=BAUDRATE, timeout=TIMEOUT) | |
if camerathing.isOpen(): | |
print('Connected to camera') | |
if camerathing.in_waiting: | |
print(camerathing.readline().decode('utf-8').strip()) | |
return camerathing | |
def main(): | |
settings = [ | |
'C3 → whitebalance: Daylight', | |
'Front dial → aperture: f/8', | |
'Back dpad/dial right → ISO: 100', | |
'Rear dial → shutter: 1/100"', | |
'Back dpad/dial left → Bracketing C 3.0 Steps 5 Pictures' | |
] | |
print('DON\'T FORGET TO SET THE CAMERA SETTINGS') | |
for setting in settings: | |
print(f'- {setting}') | |
input('Press enter to confirm...') | |
camerathing = setup_serial() | |
for phase, settings in PHASES.items(): | |
print(f'Phase: {phase}') | |
print('----------------------') | |
print('Delay to adjust shutter speed') | |
print('----------------------') | |
i, o, e = select.select([sys.stdin], [], [], 10) | |
if (i): | |
print("All set! Continuing...") | |
else: | |
print("Timeout. Continuing...") | |
while True: | |
try: | |
start = time.time() | |
print('Taking picture...') | |
take_picture(camerathing, settings['shutter_down_seconds']) | |
power = get_power(camerathing) | |
print('power:', power) | |
delta = settings['delay_seconds'] - (time.time() - start) | |
print(f'Waiting {delta} seconds...') | |
time.sleep(delta) | |
except KeyboardInterrupt: | |
print('Onward!') | |
break | |
# Covers: 1/100", 1/800", 1/13", 1/6400", 0.6" | |
# Covers: 1/250", 1/2000", 1/30", 1/8000", 1/4" | |
# Covers: 1/60", 1/500", 1/8", 1/4000", 1" | |
# Covers: 1/30", 1/250", 1/4", 1/2000", 2" | |
# Covers: 1/15", 1/125", 1/2", 1/1000", 4" | |
camerathing.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment