diff --git a/README.md b/README.md index 39e858d..5f8b34a 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/novatek.py b/novatek.py index c4361d0..bffe923 100755 --- a/novatek.py +++ b/novatek.py @@ -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 \ diff --git a/webcam.py b/webcam.py new file mode 100755 index 0000000..2fa9ce7 --- /dev/null +++ b/webcam.py @@ -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)