def do_POST(self): ctype, pdict = cgi.parse_header(self.headers.getheader("content-type")) if ctype == "multipart/form-data": postvars = cgi.parse_multipart(self.rfile, pdict) elif ctype == "application/x-www-form-urlencoded": length = int(self.headers.getheader("content-length")) postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1) else: postvars = {} base = os.path.basename(self.path) if base == "button": self.send_response(200) self.send_header("Content-type", "text/text") self.end_headers() self.wfile.write("ok") cmd = postvars["cmd"][0] try: tgt = postvars["tgt"][0] except: tgt = None if cmd == "exit" or cmd == "shutdowm" or cmd == "stacktrace": stacktraces() cmdQueue.put(cmd, target=tgt) return self.send_response(404) self.end_headers()
def capture(self): while True: try: for i in range(0,20): try: camera_file = gp.check_result(gp.gp_camera_capture_preview(self.camera, self.context)) break except gp.GPhoto2Error as ex: if i < 19: continue raise file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file)) pil_image = Image.open(io.BytesIO(file_data)) #pil_image.save("testimg2_" + str(i) + ".tif") im = np.array(pil_image) im = apply_gamma(im, 2.2) if self.fpshackiso > 0: self.set_config_value_checked('iso', 1600) self.set_config_value_checked('iso', 100) self.fpshackiso -= 1 return im, None except KeyboardInterrupt: break except gp.GPhoto2Error as ex: print "Unexpected error: " + sys.exc_info().__str__() print "code:", ex.code stacktraces() time.sleep(1) if ex.code == -7 or ex.code == -1: gp.gp_camera_exit(self.camera, self.context) self.prepare()
def cmd(self, cmd, x = None, y = None): try: if cmd in ["f-3", "f-2", "f-1", "f+3", "f+2", "f+1"]: if self.focuser is not None: self.focuser.cmd(cmd) if self.focuser is None or self.focuser.testmode: if cmd == "f-3": self.set_config_choice('manualfocusdrive', 2) if cmd == "f-2": self.set_config_choice('manualfocusdrive', 1) if cmd == "f-1": self.set_config_choice('manualfocusdrive', 0) if cmd == "f+1": self.set_config_choice('manualfocusdrive', 4) if cmd == "f+2": self.set_config_choice('manualfocusdrive', 5) if cmd == "f+3": self.set_config_choice('manualfocusdrive', 6) if cmd == "z1": zoom = 5 self.x = x * zoom - self.zoom_shape[1] / 2 self.y = y * zoom - self.zoom_shape[0] / 2 self.set_config_value('eoszoomposition', "%d,%d" % (self.x, self.y)) self.set_config_value('eoszoom', '5') time.sleep(.2) self.do_fps_hack() im, t = self.capture() while im.shape[0] != self.zoom_shape[0] or im.shape[1] != self.zoom_shape[1]: print "zoom shape", im.shape, self.zoom_shape im, t = self.capture() if cmd == "z0": zoom = 1 self.set_config_value('eoszoom', '1') time.sleep(.2) self.do_fps_hack() im, t = self.capture() while im.shape[0] != self.shape[0] or im.shape[1] != self.shape[1]: print "shape", im.shape, self.shape im, t = self.capture() if cmd == 'left': self.x = max(100, self.x - 100) self.set_config_value('eoszoomposition', "%d,%d" % (self.x, self.y)) if cmd == 'right': self.x = self.x + 100 self.set_config_value('eoszoomposition', "%d,%d" % (self.x, self.y)) if cmd == 'up': self.y = max(100, self.y - 100) self.set_config_value('eoszoomposition', "%d,%d" % (self.x, self.y)) if cmd == 'down': self.y = self.y + 100 self.set_config_value('eoszoomposition', "%d,%d" % (self.x, self.y)) if cmd.startswith('iso-'): self.status['iso'] = cmd[len('iso-'):] if cmd.startswith('test-iso-'): self.status['test-iso'] = cmd[len('test-iso-'):] if cmd.startswith('exp-sec-'): try: self.status['exp-sec'] = int(cmd[len('exp-sec-'):]) except: pass if cmd.startswith('test-exp-sec-'): try: self.status['test-exp-sec'] = int(cmd[len('test-exp-sec-'):]) except: pass if cmd.startswith('f-number-'): self.set_config_value('aperture', cmd[len('f-number-'):]) self.status['f-number'] = self.get_config_value('aperture') except gp.GPhoto2Error as ex: print "Unexpected error: " + sys.exc_info().__str__() stacktraces() time.sleep(1) if ex.code == -7 or ex.code == -1: gp.gp_camera_exit(self.camera, self.context) self.prepare()