Use one request for locking and header

* Use one request for locking and FB header to save bandwidth
This commit is contained in:
iabdalkader 2014-11-01 15:58:52 +02:00
parent 33d354339e
commit cea31c1774
3 changed files with 18 additions and 19 deletions

View File

@ -55,6 +55,7 @@ void usbdbg_data_in(void *buffer, int length)
memcpy(buffer, fb, length); memcpy(buffer, fb, length);
cmd = USBDBG_NONE; cmd = USBDBG_NONE;
break; break;
case USBDBG_FRAME_DUMP: case USBDBG_FRAME_DUMP:
if (xfer_bytes < xfer_length) { if (xfer_bytes < xfer_length) {
memcpy(buffer, fb->pixels+xfer_bytes, length); memcpy(buffer, fb->pixels+xfer_bytes, length);
@ -124,14 +125,14 @@ void usbdbg_control(void *buffer, uint8_t request, uint16_t length)
break; break;
case USBDBG_FRAME_LOCK: case USBDBG_FRAME_LOCK:
if (fb->ready == 0) { // try to lock FB, return fb hdr if locked
// no valid frame if (fb->ready && mutex_try_lock(&fb->lock)) {
((uint8_t*)buffer)[0] = 0; fb->lock_tried = 0;
memcpy(buffer, fb, length);
} else { } else {
// try to lock FB, return 1 if locked // no valid frame or failed to lock, return 0
int locked = mutex_try_lock(&fb->lock); fb->lock_tried = 1;
fb->lock_tried = !locked; ((uint32_t*)buffer)[0] = 0;
((uint8_t*)buffer)[0] = locked;
} }
break; break;

View File

@ -2,17 +2,15 @@ import sensor, time
sensor.reset() sensor.reset()
# Set sensor parameters # Set sensor parameters
sensor.set_contrast(1) sensor.set_contrast(1)
sensor.set_gainceiling(8) sensor.set_gainceiling(16)
# Set sensor pixel format # Set sensor pixel format
sensor.set_framesize(sensor.QVGA) sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.JPEG) sensor.set_pixformat(sensor.JPEG)
sensor.set_quality(95) sensor.set_quality(98)
clock = time.clock() clock = time.clock()
while (True): while (True):
clock.tick() clock.tick()
image = sensor.snapshot() image = sensor.snapshot()
time.sleep(1) print(clock.fps())
print(clock.fps())

View File

@ -83,15 +83,15 @@ def fb_size():
size = struct.unpack("III", buf) size = struct.unpack("III", buf)
return size return size
def fb_lock(): def fb_state():
buf = __dev.ctrl_transfer(0xC1, __USBDBG_FRAME_LOCK, 0, __INTERFACE, 1, __TIMEOUT) buf = __dev.ctrl_transfer(0xC1, __USBDBG_FRAME_LOCK, 0, __INTERFACE, __FB_HDR_SIZE, __TIMEOUT)
return struct.unpack("B", buf)[0] return struct.unpack("III", buf)
def fb_dump(): def fb_dump():
if (fb_lock() == 0): size = fb_state()
if (not size[0]): # frame not ready
return None return None
size = fb_size()
if (size[2] > 2): #JPEG if (size[2] > 2): #JPEG
num_bytes = size[2] num_bytes = size[2]
else: else: