Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TODO These may not get called after the end of the threading #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import errno
import os
import sys
import threading
import time
from datetime import datetime
from time import sleep
import yaml

config = yaml.safe_load(open(os.path.join(sys.path[0], "config.yml")))
image_number = 0


def create_timestamped_dir(dir):
Expand Down Expand Up @@ -55,27 +54,20 @@ def set_camera_options(camera):

def capture_image():
try:
global image_number

# Set a timer to take another picture at the proper interval after this
# picture is taken.
if (image_number < (config['total_images'] - 1)):
thread = threading.Timer(config['interval'], capture_image).start()

# Start up the camera.
camera = PiCamera()
set_camera_options(camera)

# Capture a picture.
camera.capture(dir + '/image{0:05d}.jpg'.format(image_number))
camera.close()
for image_number in range(config['total_images']):
# Capture a picture.
camera.capture(dir + '/image{0:05d}.jpg'.format(image_number))

if (image_number < (config['total_images'] - 1)):
image_number += 1
else:
print '\nTime-lapse capture complete!\n'
# TODO: This doesn't pop user into the except block below :(.
sys.exit()
# Sleep after taking a picture for the proper interval
time.sleep(config['interval'])

# Done using the camera.
camera.close()
print '\nTime-lapse capture complete!\n'

except KeyboardInterrupt, SystemExit:
print '\nTime-lapse capture cancelled.\n'
Expand Down