diff --git a/usr/openmv-ide.glade b/usr/openmv-ide.glade index 24d3414af..9f6b5a243 100644 --- a/usr/openmv-ide.glade +++ b/usr/openmv-ide.glade @@ -1117,7 +1117,6 @@ Kwabena W. Agyeman 300 - 150 False 5 Preferences @@ -1129,7 +1128,7 @@ Kwabena W. Agyeman True False - 2 + 20 True @@ -1175,8 +1174,9 @@ Kwabena W. Agyeman True False - 3 + 4 2 + 4 True @@ -1272,16 +1272,30 @@ Kwabena W. Agyeman 3 + + + Enable JPEG + True + True + False + right + False + True + + + 2 + 3 + 4 + GTK_FILL + + True True - 1 + 2 - - - diff --git a/usr/openmv-ide.py b/usr/openmv-ide.py index 6c771e5d2..4c3cae3d1 100755 --- a/usr/openmv-ide.py +++ b/usr/openmv-ide.py @@ -54,7 +54,9 @@ serial_port = /dev/openmvcam recent = last_fw_path = baudrate = 921600 +enable_jpeg = True ''' +CONFIG_KEYS = ['board', 'serial_port', 'recent', 'last_fw_path', 'baudrate', 'enable_jpeg'] RELEASE_TAG_NAME = 'v1.1' RELEASE_URL = 'https://api.github.com/repos/openmv/openmv/releases/latest' @@ -191,8 +193,30 @@ class OMVGtk: if not os.path.isdir(SCRIPTS_DIR): os.makedirs(SCRIPTS_DIR) + # set config parser + self.config = configparser.ConfigParser() + + config_valid = True + + # check if config file exists + if os.path.isfile(CONFIG_PATH): + try: + # load config + self.config.read(CONFIG_PATH) + except Exception as e: + print ("Failed to open config file %s"%(e)) + sys.exit(1) + + # Check config keys, if one is missing set invalid + for key in CONFIG_KEYS: + if not self.config.has_option('main', key): + config_valid = False + break + else: + config_valid = False + # create fresh config if needed - if not os.path.isfile(CONFIG_PATH): + if config_valid == False: try: with open(CONFIG_PATH, "w") as f: f.write(DEFAULT_CONFIG) @@ -200,8 +224,7 @@ class OMVGtk: print ("Failed to create config file %s"%(e)) sys.exit(1) - # load config - self.config = configparser.ConfigParser() + # load or reload the config file try: self.config.read(CONFIG_PATH) except Exception as e: @@ -237,6 +260,9 @@ class OMVGtk: self.baudrate = int(self.config.get("main", "baudrate")) + # set enable/disable JPEG + self.enable_jpeg = self.config.get("main", "enable_jpeg") == 'True' + # load helloworld.py self._load_file(os.path.join(EXAMPLES_DIR, "helloworld.py")) self.save_button.set_sensitive(False) @@ -306,6 +332,9 @@ class OMVGtk: # interrupt any running code openmv.stop_script() + # set enable JPEG + openmv.enable_jpeg(self.enable_jpeg) + self.connected = True self._update_title() self.connect_button.set_sensitive(False) @@ -462,6 +491,7 @@ class OMVGtk: sport_combo = self.builder.get_object("sport_combo") baud_combo = self.builder.get_object("baud_combo") dialog = self.builder.get_object("preferences_dialog") + jpeg_check = self.builder.get_object("jpeg_check") # Fill serial ports combo sport_combo.get_model().clear() @@ -472,11 +502,15 @@ class OMVGtk: if len(serial_ports): sport_combo.set_active(0) + jpeg_check.set_active(self.enable_jpeg) + # Save config if dialog.run() == gtk.RESPONSE_OK: self.config.set("main", "board", board_combo.get_active_text()) self.config.set("main", "serial_port", sport_combo.get_active_text()) self.config.set("main", "baudrate", baud_combo.get_active_text()) + self.config.set("main", "enable_jpeg", jpeg_check.get_active()) + print(jpeg_check.get_active()) self.save_config() dialog.hide() diff --git a/usr/openmv.py b/usr/openmv.py index a74ce5931..d917bc65e 100755 --- a/usr/openmv.py +++ b/usr/openmv.py @@ -31,6 +31,7 @@ __USBDBG_ATTR_READ = 0x8A __USBDBG_ATTR_WRITE = 0x0B __USBDBG_SYS_RESET = 0x0C __USBDBG_SYS_BOOT = 0x0D +__USBDBG_JPEG_ENABLE = 0x0E __USBDBG_TX_BUF_LEN = 0x8E __USBDBG_TX_BUF = 0x8F @@ -135,6 +136,9 @@ def fw_version(): __serial.write(struct.pack("')