mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Add command to return script running flag.
* Return script running flag to disable/enable execute and stop buttons. * Up ABI version
This commit is contained in:
parent
d76fa2b558
commit
cf641af6b0
@ -24,6 +24,7 @@ static int xfer_length;
|
||||
static enum usbdbg_cmd cmd;
|
||||
|
||||
static volatile bool script_ready;
|
||||
static volatile bool script_running;
|
||||
static volatile bool irq_enabled;
|
||||
static vstr_t script_buf;
|
||||
mp_obj_t mp_const_ide_interrupt = MP_OBJ_NULL;
|
||||
@ -37,6 +38,7 @@ void usbdbg_init()
|
||||
{
|
||||
irq_enabled=false;
|
||||
script_ready=false;
|
||||
script_running=false;
|
||||
vstr_init(&script_buf, 32);
|
||||
mp_const_ide_interrupt = mp_obj_new_exception_msg(&mp_type_Exception, "IDE interrupt");
|
||||
}
|
||||
@ -118,6 +120,12 @@ void usbdbg_data_in(void *buffer, int length)
|
||||
}
|
||||
break;
|
||||
|
||||
case USBDBG_SCRIPT_RUNNING: {
|
||||
uint32_t *buf = buffer;
|
||||
buf[0] = (uint32_t) script_running;
|
||||
cmd = USBDBG_NONE;
|
||||
break;
|
||||
}
|
||||
default: /* error */
|
||||
break;
|
||||
}
|
||||
@ -137,9 +145,13 @@ void usbdbg_data_out(void *buffer, int length)
|
||||
xfer_bytes += length;
|
||||
if (xfer_bytes == xfer_length) {
|
||||
// Set script ready flag
|
||||
script_ready = 1;
|
||||
script_ready = true;
|
||||
// Set script running flag
|
||||
script_running = true;
|
||||
|
||||
// Disable IDE IRQ (re-enabled by pyexec or main).
|
||||
usbdbg_set_irq_enabled(false);
|
||||
|
||||
// interrupt running script/REPL
|
||||
mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
|
||||
pendsv_nlr_jump_hard(mp_const_ide_interrupt);
|
||||
@ -231,8 +243,12 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
|
||||
|
||||
case USBDBG_SCRIPT_STOP:
|
||||
if (usbdbg_get_irq_enabled()) {
|
||||
// Set script running flag
|
||||
script_running = false;
|
||||
|
||||
// Disable IDE IRQ (re-enabled by pyexec or main).
|
||||
usbdbg_set_irq_enabled(false);
|
||||
|
||||
// interrupt running code by raising an exception
|
||||
mp_obj_exception_clear_traceback(mp_const_ide_interrupt);
|
||||
pendsv_nlr_jump_hard(mp_const_ide_interrupt);
|
||||
@ -242,6 +258,12 @@ void usbdbg_control(void *buffer, uint8_t request, uint32_t length)
|
||||
|
||||
case USBDBG_SCRIPT_SAVE:
|
||||
/* save running script */
|
||||
// TODO
|
||||
break;
|
||||
|
||||
case USBDBG_SCRIPT_RUNNING:
|
||||
xfer_bytes = 0;
|
||||
xfer_length =length;
|
||||
break;
|
||||
|
||||
case USBDBG_TEMPLATE_SAVE:
|
||||
|
||||
@ -17,8 +17,8 @@
|
||||
* Note: incrementing the major version will require a fw upgrade,
|
||||
* the IDE will Not connect if the major version number is different.
|
||||
*/
|
||||
#define FIRMWARE_VERSION_MAJOR (1)
|
||||
#define FIRMWARE_VERSION_MINOR (1)
|
||||
#define FIRMWARE_VERSION_MAJOR (2)
|
||||
#define FIRMWARE_VERSION_MINOR (0)
|
||||
#define FIRMWARE_VERSION_PATCH (0)
|
||||
|
||||
/**
|
||||
@ -39,6 +39,7 @@ enum usbdbg_cmd {
|
||||
USBDBG_SCRIPT_EXEC =0x05,
|
||||
USBDBG_SCRIPT_STOP =0x06,
|
||||
USBDBG_SCRIPT_SAVE =0x07,
|
||||
USBDBG_SCRIPT_RUNNING =0x87,
|
||||
USBDBG_TEMPLATE_SAVE =0x08,
|
||||
USBDBG_DESCRIPTOR_SAVE =0x09,
|
||||
USBDBG_ATTR_READ =0x8A,
|
||||
|
||||
@ -30,8 +30,8 @@ else:
|
||||
IDE_DIR=os.path.dirname(os.path.realpath(__file__))
|
||||
BUNDLE_DIR = IDE_DIR
|
||||
|
||||
FIRMWARE_VERSION_MAJOR = 1
|
||||
FIRMWARE_VERSION_MINOR = 1
|
||||
FIRMWARE_VERSION_MAJOR = 2
|
||||
FIRMWARE_VERSION_MINOR = 0
|
||||
FIRMWARE_VERSION_PATCH = 0
|
||||
|
||||
DATA_DIR = os.path.join(os.path.expanduser("~"), "openmv") #use home dir
|
||||
@ -74,8 +74,12 @@ class OMVGtk:
|
||||
# set buttons
|
||||
self.save_button = self.builder.get_object('save_file_toolbutton')
|
||||
self.connect_button = self.builder.get_object('connect_button')
|
||||
self.exec_button = self.builder.get_object('exec_button')
|
||||
self.stop_button = self.builder.get_object('stop_button')
|
||||
|
||||
self.save_button.set_sensitive(False)
|
||||
self.exec_button.set_sensitive(False)
|
||||
self.stop_button.set_sensitive(False)
|
||||
self.connect_button.set_sensitive(True)
|
||||
|
||||
# set control buttons
|
||||
@ -83,7 +87,6 @@ class OMVGtk:
|
||||
self.builder.get_object('reset_button'),
|
||||
self.builder.get_object('bootloader_button'),
|
||||
self.builder.get_object('exec_button'),
|
||||
self.builder.get_object('stop_button'),
|
||||
self.builder.get_object('zoomin_button'),
|
||||
self.builder.get_object('zoomout_button'),
|
||||
self.builder.get_object('bestfit_button'),
|
||||
@ -293,6 +296,7 @@ class OMVGtk:
|
||||
|
||||
self.connected = False
|
||||
self._update_title()
|
||||
self.stop_button.set_sensitive(False)
|
||||
self.connect_button.set_sensitive(True)
|
||||
map(lambda x:x.set_sensitive(False), self.controls)
|
||||
|
||||
@ -407,9 +411,13 @@ class OMVGtk:
|
||||
buf = self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter())
|
||||
# exec script
|
||||
openmv.exec_script(buf)
|
||||
self.exec_button.set_sensitive(False)
|
||||
self.stop_button.set_sensitive(True)
|
||||
|
||||
def stop_clicked(self, widget):
|
||||
openmv.stop_script();
|
||||
self.exec_button.set_sensitive(True)
|
||||
self.stop_button.set_sensitive(False)
|
||||
|
||||
def zoomin_clicked(self, widget):
|
||||
global SCALE
|
||||
@ -524,6 +532,18 @@ class OMVGtk:
|
||||
|
||||
return True
|
||||
|
||||
def update_exec_button(self):
|
||||
if (self.connected):
|
||||
try:
|
||||
# read drawingarea
|
||||
running = (openmv.script_running()==1)
|
||||
self.stop_button.set_sensitive(running)
|
||||
self.exec_button.set_sensitive(not running)
|
||||
except Exception as e:
|
||||
self.disconnect()
|
||||
self._update_title()
|
||||
|
||||
return True
|
||||
|
||||
def on_ctrl_scale_value_changed(self, adjust):
|
||||
openmv.set_attr(adjust.attr, int(adjust.value))
|
||||
@ -741,4 +761,5 @@ if __name__ == "__main__":
|
||||
omvgtk.window.show_all()
|
||||
omvgtk.check_for_updates()
|
||||
gobject.gobject.timeout_add(30, omvgtk.update_drawing)
|
||||
gobject.gobject.timeout_add(500, omvgtk.update_exec_button)
|
||||
gtk.main()
|
||||
|
||||
@ -25,6 +25,7 @@ __USBDBG_FRAME_UPDATE = 0x04
|
||||
__USBDBG_SCRIPT_EXEC = 0x05
|
||||
__USBDBG_SCRIPT_STOP = 0x06
|
||||
__USBDBG_SCRIPT_SAVE = 0x07
|
||||
__USBDBG_SCRIPT_RUNNING = 0x87
|
||||
__USBDBG_TEMPLATE_SAVE = 0x08
|
||||
__USBDBG_DESCRIPTOR_SAVE= 0x09
|
||||
__USBDBG_ATTR_READ = 0x8A
|
||||
@ -100,6 +101,10 @@ def exec_script(buf):
|
||||
def stop_script():
|
||||
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_SCRIPT_STOP, 0))
|
||||
|
||||
def script_running():
|
||||
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_SCRIPT_RUNNING, 4))
|
||||
return struct.unpack("I", __serial.read(4))[0]
|
||||
|
||||
def save_template(x, y, w, h, path):
|
||||
buf = struct.pack("IIII", x, y, w, h) + path
|
||||
__serial.write(struct.pack("<BBI", __USBDBG_CMD, __USBDBG_TEMPLATE_SAVE, len(buf)))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user