Example #1
0
    def __init__(self):
        self.camera = GPhoto(subprocess)
        self.idy = Identify(subprocess)
        self.netinfo = NetworkInfo(subprocess)
        self.shot = 0

        self.displaySet = False
Example #2
0
class GPhotoTestCase(unittest.TestCase):
    def setUp(self):
        self._test_subprocess = FakeSubprocess()
        self._gphoto = GPhoto(self._test_subprocess)

    def tearDown(self):
        pass

    def test_set_shutter_speed(self):
        popen = FakePopen(
            'Label: Shutter Speed\nType: MENU\nCurrent: 30\nChoice: 0 Bulb\nChoice: 4 2',
            '', 0)
        self._test_subprocess.set_Popen_for_cmd(
            'gphoto2 --get-config /main/settings/shutterspeed', popen)

        self._gphoto.set_shutter_speed(secs="2")
        assert ['gphoto2 --get-config /main/settings/shutterspeed'
                ] in self._test_subprocess.get_invocations()
        assert ['gphoto2 --set-config /main/settings/shutterspeed=4'
                ] in self._test_subprocess.get_invocations()

    def test_get_camera_time(self):
        data = ''.join(file('testdata/datetime', 'r').readlines())
        popen = FakePopen(data, '', 0)
        self._test_subprocess.set_Popen_for_cmd(
            'gphoto2 --get-config /main/status/datetime', popen)
        tim = self._gphoto.get_camera_date_time()
        assert time.strptime("2013-01-10 07:16:59", "%Y-%m-%d %H:%M:%S") == tim
Example #3
0
def test_configs():
    camera = GPhoto(subprocess)

    for config in CONFIGS:
      camera.set_shutter_speed(secs=config[0])
      camera.set_iso(iso=str(config[1]))
      time.sleep(1)
Example #4
0
    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)
Example #5
0
 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
Example #6
0
    def __init__(self):
        self.camera = GPhoto(subprocess)
        self.idy = Identify(subprocess)
        self.netinfo = NetworkInfo(subprocess)
        self.shot = 0

        self.displaySet = False
Example #7
0
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)
Example #8
0
def test_configs():
    camera = GPhoto(subprocess)

    for config in CONFIGS:
        camera.set_shutter_speed(secs=config[0])
        camera.set_iso(iso=str(config[1]))
        time.sleep(1)
Example #9
0
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))
Example #10
0
class GPhotoTestCase(unittest.TestCase):

    def setUp(self):
        self._test_subprocess = FakeSubprocess()
        self._gphoto = GPhoto(self._test_subprocess)

    def tearDown(self):
        pass

    def test_set_shutter_speed(self):
        popen = FakePopen('Label: Shutter Speed\nType: MENU\nCurrent: 30\nChoice: 0 Bulb\nChoice: 4 2', '', 0)
        self._test_subprocess.set_Popen_for_cmd('gphoto2 --get-config /main/settings/shutterspeed', popen)

        self._gphoto.set_shutter_speed(secs="2")
        assert ['gphoto2 --get-config /main/settings/shutterspeed'] in self._test_subprocess.get_invocations()
        assert ['gphoto2 --set-config /main/settings/shutterspeed=4'] in self._test_subprocess.get_invocations()

    def test_get_camera_time(self):
        data = ''.join(file('testdata/datetime', 'r').readlines())
        popen = FakePopen(data, '', 0)
        self._test_subprocess.set_Popen_for_cmd('gphoto2 --get-config /main/status/datetime', popen)
        tim = self._gphoto.get_camera_date_time()
        assert time.strptime("2013-01-10 07:16:59", "%Y-%m-%d %H:%M:%S") == tim
Example #11
0
def test_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(1)
Example #12
0
    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)
Example #13
0
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)
Example #14
0
    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)
Example #15
0
def main():
    print "Frizlapse"
    camera = GPhoto(subprocess)
    #idy = Identify(subprocess)
    #netinfo = NetworkInfo(subprocess)
    #network_status = netinfo.network_status()

    shot = 0
    prev_acquired = None
    last_acquired = None
    last_started = None

    
    camera.set_shutter_speed(secs=CONFIG[0])
    camera.set_iso(iso=str(CONFIG[1]))

    try:
        while True:   
            print "Shot n. %d Shutter: %s ISO: %d" % (shot, CONFIG[0], CONFIG[1])

            last_started = datetime.now()        

            try:
              # Capture image
              filename = camera.capture_image_and_download(FOLDERPATH)
            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            
            last_acquired = datetime.now()

            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)
            else:
                print "No need to sleep, we are late %s" % str((last_acquired - last_started) - MIN_INTER_SHOT_DELAY_SECONDS)

            shot = shot + 1
            if shot == SHOTS:
                print "Picture sequence finished! " 
                print "Starting video ...  "
                # FFMPEG stuff
                print "Video %s finished " % str("filename.mp4") 
                break

    except Exception,e:
        print "Exception " + str(e)
Example #16
0
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))
Example #17
0
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)
Example #18
0
def main():
    print "Timelapse starting at %s" % (time.asctime())
    camera = GPhoto(subprocess)
    info = Analyse(subprocess)
    sysinfo = SystemStats(subprocess)

    current_config = 19
    shot = 0
    failures = 0
    prev_acquired = None
    last_acquired = None
    last_started = None

    try:
        while True:
            last_started = datetime.now()
            shot = shot + 1
            config = CONFIGS[current_config]
            print "Shot %d : %s" % (shot, time.asctime())
            print "Shot %d : Shutter: %ss , ISO: %d , Ap: %s" % (shot, config[0], config[1], config[2])
            sys.stdout.flush()

            camera.set_shutter_speed(secs=config[0])
            camera.set_iso(iso=str(config[1]))
            camera.set_aperture(ap=config[2])
            try:
                filename = camera.capture_image_and_download()
            except Exception, e:
                print "Error on capture: " + str(e)
                failures += 1
                if failures > 2:
                    print "3 successive failures: the camera doesn't work!"
                    sys.stdout.flush()
                    break
                print "Retrying..."
                sys.stdout.flush()
                # Occasionally, capture can fail but retries will be successful.
                continue
            failures = 0
            # print "Shot %d Filename: %s" % (shot, filename)
            sys.stdout.flush()

            prev_acquired = last_acquired
            brightness = float(info.mean_brightness("webkamera-tmp.jpg"))
            last_acquired = datetime.now()

            # health = sysinfo.stats()

            print "Shot %d : Brightness: %s " % (shot, brightness)
            sys.stdout.flush()

            if brightness < TARGET_BRIGHTNESS * 0.9 and current_config < len(CONFIGS) - 1:
                if TARGET_BRIGHTNESS - brightness > TARGET_BRIGHTNESS * 0.44 and current_config < len(CONFIGS) - 2:
                    current_config += 2
                    print "Shot %d : EV step: +2/3" % (shot)
                else:
                    current_config += 1
                    print "Shot %d : EV step: +1/3" % (shot)
            elif brightness > TARGET_BRIGHTNESS * 1.1 and current_config > 0:
                if brightness - TARGET_BRIGHTNESS > TARGET_BRIGHTNESS * 0.44 and current_config > 2:
                    current_config -= 2
                    print "Shot %d : EV step: -2/3" % (shot)
                else:
                    current_config -= 1
                    print "Shot %d : EV step: -1/3" % (shot)
            else:
                if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS:
                    sleep_for = max((MIN_INTER_SHOT_DELAY_SECONDS - (last_acquired - last_started)).seconds, 0)
                    print "Sleeping for %ss ..." % str(sleep_for)
                    sys.stdout.flush()
                    time.sleep(sleep_for)
    except Exception, e:
        print str(e)
Example #19
0
 def setUp(self):
     self._test_subprocess = FakeSubprocess()
     self._gphoto = GPhoto(self._test_subprocess)
Example #20
0
def main():
    print "Timelapse starting at %s" % (time.asctime())
    camera = GPhoto(subprocess)
    info = Analyse(subprocess)
    sysinfo = SystemStats(subprocess)

    current_config = 19
    shot = 0
    failures = 0
    prev_acquired = None
    last_acquired = None
    last_started = None

    try:
        while True:
            last_started = datetime.now()
            shot = shot + 1
            config = CONFIGS[current_config]
            print "Shot %d : %s" % (shot, time.asctime())
            print "Shot %d : Shutter: %ss , ISO: %d , Ap: %s" % (
                shot, config[0], config[1], config[2])
            sys.stdout.flush()

            camera.set_shutter_speed(secs=config[0])
            camera.set_iso(iso=str(config[1]))
            camera.set_aperture(ap=config[2])
            try:
                filename = camera.capture_image_and_download()
            except Exception, e:
                print "Error on capture: " + str(e)
                failures += 1
                if failures > 2:
                    print "3 successive failures: the camera doesn't work!"
                    sys.stdout.flush()
                    break
                print "Retrying..."
                sys.stdout.flush()
                # Occasionally, capture can fail but retries will be successful.
                continue
            failures = 0
            #print "Shot %d Filename: %s" % (shot, filename)
            sys.stdout.flush()

            prev_acquired = last_acquired
            brightness = float(info.mean_brightness('webkamera-tmp.jpg'))
            last_acquired = datetime.now()

            #health = sysinfo.stats()

            print "Shot %d : Brightness: %s " % (shot, brightness)
            sys.stdout.flush()

            if brightness < TARGET_BRIGHTNESS * 0.9 and current_config < len(
                    CONFIGS) - 1:
                if TARGET_BRIGHTNESS - brightness > TARGET_BRIGHTNESS * 0.44 and current_config < len(
                        CONFIGS) - 2:
                    current_config += 2
                    print "Shot %d : EV step: +2/3" % (shot)
                else:
                    current_config += 1
                    print "Shot %d : EV step: +1/3" % (shot)
            elif brightness > TARGET_BRIGHTNESS * 1.1 and current_config > 0:
                if brightness - TARGET_BRIGHTNESS > TARGET_BRIGHTNESS * 0.44 and current_config > 2:
                    current_config -= 2
                    print "Shot %d : EV step: -2/3" % (shot)
                else:
                    current_config -= 1
                    print "Shot %d : EV step: -1/3" % (shot)
            else:
                if last_started and last_acquired and last_acquired - last_started < MIN_INTER_SHOT_DELAY_SECONDS:
                    sleep_for = max((MIN_INTER_SHOT_DELAY_SECONDS -
                                     (last_acquired - last_started)).seconds,
                                    0)
                    print "Sleeping for %ss ..." % str(sleep_for)
                    sys.stdout.flush()
                    time.sleep(sleep_for)
    except Exception, e:
        print str(e)
Example #21
0
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)
Example #22
0
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))
Example #23
0
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)
Example #24
0
 def setUp(self):
     self._test_subprocess = FakeSubprocess()
     self._gphoto = GPhoto(self._test_subprocess)
Example #25
0
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)