Skip to content

Commit

Permalink
Add a simple time-lapse webcam script
Browse files Browse the repository at this point in the history
  • Loading branch information
rgov committed Mar 27, 2018
1 parent ed3bdeb commit a888eee
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ behavior was reverse engineered from the iOS and Android versions of CamKing.

There should be other functions that I have not exposed yet. Most of the methods
do not return useful values, or do any error checking at all.

A much nicer project that works with a very similar camera is over at Steven
Hiscock's [yidashcam](https://github.com/kwirk/yidashcam).
5 changes: 5 additions & 0 deletions novatek.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def format_sd(self):
def reset_config(self):
x = self._get_xml(3011)

def cmd_3012(self):
# Version number? 'HT10 20160310 V1.0'
x = self._get_xml(3012)
return x.find('./String').text

def get_config(self):
x = self._get_xml(3014)
config = { k.text: v.text for k, v in \
Expand Down
49 changes: 49 additions & 0 deletions webcam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python

import datetime
import logging
import os
import re
import subprocess
import time

from novatek import Novatek


logging.basicConfig(
datefmt='%m-%d-%y %H:%M:%S',
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.INFO
)


logging.info('Configuring camera')
N = Novatek()
N.set_mode(Novatek.MODE['Video']) # needs to be in video mode to take photos??


def capture():
logging.info('Starting capture')
try:
N.take_photo()
except Exception as e:
logging.exception('Capture failed')

def get_remaining_captures():
try:
x = N.get_capture_num()
logging.info('Space remaining to store %i photos', x)
return x
except Exception as e:
logging.exception('Failed to get remaining space')
return 1000

# Capture
while True:
capture()
while get_remaining_captures() < 20:
files = N.get_file_list()
oldest = files[0] # big assumption that this is oldest
logging.warn('Disk space is too low, purging %s', oldest)
Novatek().delete_file(oldest)
time.sleep(60)

0 comments on commit a888eee

Please sign in to comment.