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);
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;

View File

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

View File

@ -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: