diff --git a/src/omv/usbdbg.c b/src/omv/usbdbg.c index 90154dd43..387d910d2 100644 --- a/src/omv/usbdbg.c +++ b/src/omv/usbdbg.c @@ -55,6 +55,7 @@ void usbdbg_data_in(void *buffer, int length) memcpy(buffer, fb, length); cmd = USBDBG_NONE; break; + case USBDBG_FRAME_DUMP: if (xfer_bytes < xfer_length) { memcpy(buffer, fb->pixels+xfer_bytes, length); @@ -124,14 +125,14 @@ void usbdbg_control(void *buffer, uint8_t request, uint16_t length) break; case USBDBG_FRAME_LOCK: - if (fb->ready == 0) { - // no valid frame - ((uint8_t*)buffer)[0] = 0; + // try to lock FB, return fb hdr if locked + if (fb->ready && mutex_try_lock(&fb->lock)) { + fb->lock_tried = 0; + memcpy(buffer, fb, length); } else { - // try to lock FB, return 1 if locked - int locked = mutex_try_lock(&fb->lock); - fb->lock_tried = !locked; - ((uint8_t*)buffer)[0] = locked; + // no valid frame or failed to lock, return 0 + fb->lock_tried = 1; + ((uint32_t*)buffer)[0] = 0; } break; diff --git a/usr/examples/fb_viewer.py b/usr/examples/fb_viewer.py index afd2083c3..db8ed3c50 100644 --- a/usr/examples/fb_viewer.py +++ b/usr/examples/fb_viewer.py @@ -2,17 +2,15 @@ import sensor, time sensor.reset() # Set sensor parameters sensor.set_contrast(1) -sensor.set_gainceiling(8) +sensor.set_gainceiling(16) # Set sensor pixel format sensor.set_framesize(sensor.QVGA) sensor.set_pixformat(sensor.JPEG) -sensor.set_quality(95) +sensor.set_quality(98) clock = time.clock() - while (True): - clock.tick() - image = sensor.snapshot() - time.sleep(1) - print(clock.fps()) + clock.tick() + image = sensor.snapshot() + print(clock.fps()) diff --git a/usr/openmv.py b/usr/openmv.py index 113d13f9d..3d1bfd1d3 100755 --- a/usr/openmv.py +++ b/usr/openmv.py @@ -83,15 +83,15 @@ def fb_size(): size = struct.unpack("III", buf) return size -def fb_lock(): - buf = __dev.ctrl_transfer(0xC1, __USBDBG_FRAME_LOCK, 0, __INTERFACE, 1, __TIMEOUT) - return struct.unpack("B", buf)[0] +def fb_state(): + buf = __dev.ctrl_transfer(0xC1, __USBDBG_FRAME_LOCK, 0, __INTERFACE, __FB_HDR_SIZE, __TIMEOUT) + return struct.unpack("III", buf) def fb_dump(): - if (fb_lock() == 0): + size = fb_state() + if (not size[0]): # frame not ready return None - size = fb_size() if (size[2] > 2): #JPEG num_bytes = size[2] else: