Add enable/disable JPEG to preferences dialog.

This commit is contained in:
iabdalkader 2016-02-18 05:10:10 +02:00
parent 5aa3555a36
commit 7f9e95fdd5
3 changed files with 62 additions and 10 deletions

View File

@ -1117,7 +1117,6 @@ Kwabena W. Agyeman</property>
</object>
<object class="GtkDialog" id="preferences_dialog">
<property name="width_request">300</property>
<property name="height_request">150</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Preferences</property>
@ -1129,7 +1128,7 @@ Kwabena W. Agyeman</property>
<object class="GtkVBox" id="dialog-vbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<property name="spacing">20</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area5">
<property name="visible">True</property>
@ -1175,8 +1174,9 @@ Kwabena W. Agyeman</property>
<object class="GtkTable" id="table111">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="n_rows">3</property>
<property name="n_rows">4</property>
<property name="n_columns">2</property>
<property name="row_spacing">4</property>
<child>
<object class="GtkLabel" id="label111">
<property name="visible">True</property>
@ -1272,16 +1272,30 @@ Kwabena W. Agyeman</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="jpeg_check">
<property name="label" translatable="yes">Enable JPEG</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="image_position">right</property>
<property name="active">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
<action-widgets>

View File

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

View File

@ -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("<BBI", __USBDBG_CMD, __USBDBG_FW_VERSION, 12))
return struct.unpack("III", __serial.read(12))
def enable_jpeg(enable):
__serial.write(struct.pack("<BBIH", __USBDBG_CMD, __USBDBG_JPEG_ENABLE, 0, enable))
if __name__ == '__main__':
if len(sys.argv)!= 2:
print ('usage: openmv.py <script>')