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)
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(): 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)