def __init__(self): self.camera = GPhoto(subprocess) self.idy = Identify(subprocess) self.netinfo = NetworkInfo(subprocess) self.shot = 0 self.displaySet = False
def main(): #print "Testing Configs" #test_configs() print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) #ui = TimelapseUi() current_config = 11 ## <-- set this manually because we don't have an LCD to select it shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() #current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) #ui.backlight_off() try: filename = camera.capture_image_and_download() except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len( CONFIGS) - 1: current_config = current_config + 1 elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str( MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception, e: print "Error:", str(e)
def main(): #print "Testing Configs" #test_configs() print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) #ui = TimelapseUi() current_config = 11 ## <-- set this manually because we don't have an LCD to select it shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() #current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) #ui.backlight_off() try: filename = camera.capture_image_and_download() except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1: current_config = current_config + 1 elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str(MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception,e: print "Error:", str(e)
def __init__(self): self.LCDAttached = self.checkPanel() # Initialize the LCD using the pins # see https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi/usage if (self.LCDAttached == True): Adafruit_CharLCDPlate.__init__(self) self.camera = GPhoto(subprocess) self.idy = Identify(subprocess) self.netinfo = NetworkInfo(subprocess) self.shot = 0 self.displaySet = False
def main(): print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) ui = TimelapseUi() current_config = 11 shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) ui.backlight_on() ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) ui.backlight_off() filename = camera.capture_image_and_download() prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len(CONFIGS) - 1: current_config = current_config + 1 elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str(MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception,e: ui.show_error(str(e))
class NetworkInfoTestCase(unittest.TestCase): def setUp(self): self._test_subprocess = FakeSubprocess() self._network_info = NetworkInfo(self._test_subprocess) def tearDown(self): pass def test_no_network(self): assert self._network_info.network_status() == 'No Network' assert 'iwconfig' in self._test_subprocess.get_invocations() assert 'ifconfig wlan0' in self._test_subprocess.get_invocations() assert 'ifconfig eth0' in self._test_subprocess.get_invocations() def test_ethernet(self): data = ''.join(file('testdata/ifceth0', 'r').readlines()) popen = FakePopen(data, '', 0) self._test_subprocess.set_Popen_for_cmd('ifconfig eth0', popen) assert '10.1.10.15' in self._network_info.network_status() assert 'iwconfig' in self._test_subprocess.get_invocations() assert 'ifconfig wlan0' in self._test_subprocess.get_invocations() assert 'ifconfig eth0' in self._test_subprocess.get_invocations() def test_wlan(self): data = ''.join(file('testdata/ifceth0_nc', 'r').readlines()) popen = FakePopen(data, '', 0) self._test_subprocess.set_Popen_for_cmd('ifconfig eth0', popen) data = ''.join(file('testdata/ifcwlan0', 'r').readlines()) popen = FakePopen(data, '', 0) self._test_subprocess.set_Popen_for_cmd('ifconfig wlan0', popen) data = ''.join(file('testdata/iwc', 'r').readlines()) popen = FakePopen(data, '', 0) self._test_subprocess.set_Popen_for_cmd('iwconfig', popen) assert '10.1.10.15' in self._network_info.network_status() assert '146csbr' in self._network_info.network_status() assert 'iwconfig' in self._test_subprocess.get_invocations() assert 'ifconfig wlan0' in self._test_subprocess.get_invocations() assert 'ifconfig eth0' in self._test_subprocess.get_invocations()
def main(): # print "Testing Configs" # test_configs() print "Timelapse" camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) persist = Persist() #ui = TimelapseUi() initVal = 14 current_config = persist.readLastConfig(initVal) shot = 0 prev_acquired = None last_acquired = None last_started = None network_status = netinfo.network_status() #current_config = 0 #ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[1], config[3]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) #ui.backlight_off() try: filename = camera.capture_image_and_download() filenameWithCnt = "IMG_{:0>5d}.jpg".format(shot) os.rename(filename, filenameWithCnt) filename = filenameWithCnt except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len( CONFIGS) - 1: current_config = current_config + 1 persist.writeLastConfig(current_config) elif brightness > MAX_BRIGHTNESS and current_config > 0: current_config = current_config - 1 persist.writeLastConfig(current_config) else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str( MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception, e: #ui.show_error(str(e)) print str(e)
class App(): def __init__(self): self.camera = GPhoto(subprocess) self.idy = Identify(subprocess) self.netinfo = NetworkInfo(subprocess) self.shot = 0 self.displaySet = False def signal_handler(signal, frame): print('You pressed Ctrl+C!') # GPIO.cleanup() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) def startup(self): logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s') logging.info('Started %s' % __file__) logging.info("Timelapse Version %s" % __version__) time.sleep(SLEEP_TIME) self.getNetwork() self.getModel() self.shoot() def run(self): self.startup() def showConfig(self, current): config = CONFIGS[current] logging.info("Timelapse\nT:%s ISO:%d" % (config[1], int(config[3]))) def showStatus(self, shot, current): config = CONFIGS[current] logging.info("Shot %d\nT:%s ISO:%d" % (shot, config[1], int(config[3]))) def getNetwork(self): network_status = self.netinfo.network_status() logging.info(network_status) def handleLight(self, enabled): if (enabled): pass #GPIO.output(outPin,True) else: pass #GPIO.output(outPin,False) def turnLightOn(self): self.handleLight(True) def turnLightOff(self): self.handleLight(False) def stop(self, mode): logging.info("Goodbye!") if mode == "exit": logging.info("End") sys.exit() if mode == "shutdown": logging.info("Shutown") os.system("sudo shutdown -h now") def testConfigs(self): print("Testing Configs") camera = GPhoto(subprocess) for config in CONFIGS: print("Testing camera setting: Shutter: %s ISO %d" % (config[1], config[3])) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) time.sleep(SLEEP_TIME) def main(self): self.testConfigs() def getModel(self): model = "undef" try: model = self.camera.get_model() except Exception, e: raise Exception(str(e)) logging.info(model) time.sleep(SLEEP_TIME)
class App(Adafruit_CharLCDPlate): def __init__(self): self.LCDAttached = self.checkPanel() # Initialize the LCD using the pins # see https://learn.adafruit.com/adafruit-16x2-character-lcd-plus-keypad-for-raspberry-pi/usage if (self.LCDAttached == True): Adafruit_CharLCDPlate.__init__(self) self.camera = GPhoto(subprocess) self.idy = Identify(subprocess) self.netinfo = NetworkInfo(subprocess) self.shot = 0 self.displaySet = False def startup(self): if (self.LCDAttached == True): self.clear() self.backlight(self.WHITE) logging.basicConfig(filename='%s/timelapse.log' % os.path.dirname(os.path.realpath(__file__)), level=logging.INFO, format='%(asctime)s %(message)s') logging.info('Started %s' % __file__) logging.info("Timelapse Version %s"%__version__) if (self.LCDAttached == True): self.message("Timelapse\nVersion %s"%__version__) logging.info('LCD attached') else: logging.info('LCD NOT attached') time.sleep(SLEEP_TIME) self.getNetwork() self.getModel() self.shoot() def run(self): self.startup() def showConfig(self, current): config = CONFIGS[current] self.message("Timelapse\nT:%s ISO:%d" % (config[1], int(config[3]))) def showStatus(self, shot, current): config = CONFIGS[current] self.clear() self.message("Shot %d\nT:%s ISO:%d" % (shot, config[1], int(config[3]))) def printToLcd(self, message): self.message('\n'.join(textwrap.wrap(message, LCD_CHAR_LINE_SIZE))) def getNetwork(self): network_status = self.netinfo.network_status() if (self.LCDAttached == True): self.backlight(self.TEAL) self.clear() self.message(network_status) time.sleep(SLEEP_TIME) logging.info(network_status) def stop(self, mode): self.clear() logging.info("Goodbye!") self.message("Goodbye!") # flashy ending! for i in range(3): for col in (self.YELLOW, self.GREEN, self.TEAL, self.BLUE, self.VIOLET, self.WHITE, self.RED): self.backlight(col) time.sleep(.05) time.sleep(SLEEP_TIME) self.backlight(self.OFF) self.noDisplay() logging.info("Display off") if mode == "exit": logging.info("End") sys.exit() if mode == "shutdown": logging.info("Shutown") os.system("sudo shutdown -h now") def cleanUp(self, e): logging.error(str(e)) self.backlight(self.RED) self.clear() lines=[str(e)] displayScroll = Scroller(lines=lines) message = displayScroll.scroll() self.message(message) self.speed = .5 while True: # sel = 1, r = 2, d = 4, u = 8, l = 16 if self.buttonPressed(self.UP): self.stop('exit') self.clear() scrolled = displayScroll.scroll() self.message(scrolled) time.sleep(self.speed) raise Exception(str(e)) def chooseSetting(self, configs, current): ready = False while not ready: while True: if self.buttonPressed(self.UP): print "UP" current -= 1 if current < 0: current = 0 break if self.buttonPressed(self.DOWN): print "DOWN" current += 1 if current >= len(configs): current = len(configs) - 1 break if self.buttonPressed(self.SELECT): print "SELECT" ready = True break config = configs[current] logging.info("Settings done") self.printToLcd("Timelapse\nT: %s ISO: %s" % (config[1], config[3])) return current def testConfigs(): print "Testing Configs" camera = GPhoto(subprocess) for config in CONFIGS: print "Testing camera setting: Shutter: %s ISO %d" % (config[1], config[3]) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) time.sleep(SLEEP_TIME) lcd = Adafruit_CharLCDPlate() lcd.clear() lcd.backlight(lcd.TEAL) def main(): test_configs() def checkPanel(self): LCDAttached = False # Check if the LCD panel is connected # sudo apt-get install i2c-tools p = subprocess.Popen('sudo i2cdetect -y 1', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) for line in p.stdout.readlines(): if line[0:6] == "20: 20": LCDAttached=True retval = p.wait() return LCDAttached def getModel(self): model = "undef" try: model = self.camera.get_model() except Exception, e: if (self.LCDAttached == True): self.cleanUp(e) else: raise Exception(str(e)) self.clear() self.message(model) logging.info(model) time.sleep(SLEEP_TIME)
def main(): #print "Testing Configs" #test_configs() timestr = str(datetime.now()) print "No problem. Timelapse starts now, at " + timestr camera = GPhoto(subprocess) idy = Identify(subprocess) netinfo = NetworkInfo(subprocess) #ui = TimelapseUi() current_config = 28 shot = 0 prev_acquired = None last_acquired = None last_started = None #network_status = netinfo.network_status() #current_config = ui.main(CONFIGS, current_config, network_status) try: while True: last_started = datetime.now() config = CONFIGS[current_config] print "Shot: %d Shutter: %s ISO: %d" % (shot, config[0], config[1]) #ui.backlight_on() #ui.show_status(shot, CONFIGS, current_config) camera.set_shutter_speed(secs=config[0]) camera.set_iso(iso=str(config[1])) #ui.backlight_off() try: filename = camera.capture_image_and_download(shot) print "Capture signaled." except Exception, e: print "Error on capture." + str(e) print "Retrying..." # Occasionally, capture can fail but retries will be successful. continue prev_acquired = last_acquired brightness = float(idy.mean_brightness(filename)) last_acquired = datetime.now() print "-> %s Brightness: %s" % (filename, brightness) if brightness < MIN_BRIGHTNESS and current_config < len( CONFIGS) - 1: current_config = current_config + 1 print "WARNING: Brightness is below threshold " + strMIN_BRIGHTNESS + ", trying a brighter config NOW!" elif brightness > MAX_BRIGHTNESS and current_config > 0: print "WARNING: Brightness is above threshold " + strMAX_BRIGHTNESS + ", trying a darker config NOW!" else: if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS: print "Sleeping for %s" % str( MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)) time.sleep((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds) shot = shot + 1 except Exception, e: #ui.show_error(str(e)) print(str(e))
class App(): def __init__(self): self.camera = GPhoto(subprocess) self.idy = Identify(subprocess) self.netinfo = NetworkInfo(subprocess) self.shot = 0 self.displaySet = False def signal_handler(signal, frame): print('You pressed Ctrl+C!') GPIO.cleanup() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) def startup(self): logging.basicConfig(filename=LOG_FILENAME, level=logging.INFO, format='%(asctime)s %(message)s') logging.info('Started %s' % __file__) logging.info("Timelapse Version %s"%__version__) time.sleep(SLEEP_TIME) self.getNetwork() self.getModel() self.shoot() def run(self): self.startup() def showConfig(self, current): config = CONFIGS[current] logging.info("Timelapse\nT:%s ISO:%d" % (config[1], int(config[3]))) def showStatus(self, shot, current): config = CONFIGS[current] logging.info("Shot %d\nT:%s ISO:%d" % (shot, config[1], int(config[3]))) def getNetwork(self): network_status = self.netinfo.network_status() logging.info(network_status) def handleLight(self, enabled): if (enabled): GPIO.output(outPin,True) else: GPIO.output(outPin,False) def turnLightOn(self): self.handleLight(True) def turnLightOff(self): self.handleLight(False) def stop(self, mode): logging.info("Goodbye!") if mode == "exit": logging.info("End") sys.exit() if mode == "shutdown": logging.info("Shutown") os.system("sudo shutdown -h now") def testConfigs(self): print("Testing Configs") camera = GPhoto(subprocess) for config in CONFIGS: print("Testing camera setting: Shutter: %s ISO %d" % (config[1], config[3])) camera.set_shutter_speed(secs=config[1]) camera.set_iso(iso=str(config[3])) time.sleep(SLEEP_TIME) def main(self): self.testConfigs() def getModel(self): model = "undef" try: model = self.camera.get_model() except Exception, e: raise Exception(str(e)) logging.info(model) time.sleep(SLEEP_TIME)
def setUp(self): self._test_subprocess = FakeSubprocess() self._network_info = NetworkInfo(self._test_subprocess)