From f0431b9b103e32a407901a24d5cf5c7cca4b2956 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Thu, 13 Feb 2014 03:11:24 +0200 Subject: [PATCH] Remove sensor arg from py_sensor --- src/py/py_sensor.c | 76 +++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/py/py_sensor.c b/src/py/py_sensor.c index 7075f2ff0..f87a7101e 100644 --- a/src/py/py_sensor.c +++ b/src/py/py_sensor.c @@ -1,10 +1,8 @@ #include #include "sensor.h" +#include "sccb.h" #include "py_sensor.h" -#include "py_imlib.h" - -/* sensor handle */ -struct sensor_dev sensor; +#include "py_image.h" struct sym_entry { const char *sym; @@ -50,73 +48,80 @@ static struct sym_entry gainceiling_constants[] = { }; mp_obj_t py_sensor_sinit() { - sensor_init(&sensor); + sensor_init(); /* hack */ - sensor_reset(&sensor); - sensor_set_pixformat(&sensor, PIXFORMAT_RGB565); - sensor_set_framesize(&sensor, FRAMESIZE_QQVGA); - sensor_set_framerate(&sensor, FRAMERATE_30FPS); - sensor_set_gainceiling(&sensor, GAINCEILING_16X); - sensor_set_brightness(&sensor, 3); + sensor_reset(); + sensor_set_pixformat(PIXFORMAT_RGB565); + sensor_set_framesize(FRAMESIZE_QQVGA); + sensor_set_framerate(FRAMERATE_30FPS); + sensor_set_gainceiling(GAINCEILING_16X); + sensor_set_brightness(3); return mp_const_none; } mp_obj_t py_sensor_reset() { - sensor_reset(&sensor); + sensor_reset(); return mp_const_none; } mp_obj_t py_sensor_snapshot() { - sensor_snapshot(&sensor); - struct frame_buffer *fb = &sensor.frame_buffer; - mp_obj_t image = py_image(fb->width, fb->height, fb->bpp, fb->pixels); + mp_obj_t image = py_image(0, 0, 0, 0); + sensor_snapshot((struct image*) py_image_cobj(image)); return image; } mp_obj_t py_sensor_set_pixformat(mp_obj_t pixformat) { - if (sensor_set_pixformat(&sensor, mp_obj_get_int(pixformat)) != 0) { + if (sensor_set_pixformat(mp_obj_get_int(pixformat)) != 0) { return mp_const_false; } return mp_const_true; } mp_obj_t py_sensor_set_framerate(mp_obj_t framerate) { - if (sensor_set_framerate(&sensor, mp_obj_get_int(framerate)) != 0) { + if (sensor_set_framerate(mp_obj_get_int(framerate)) != 0) { return mp_const_false; } return mp_const_true; } mp_obj_t py_sensor_set_framesize(mp_obj_t framesize) { - if (sensor_set_framesize(&sensor, mp_obj_get_int(framesize)) != 0) { + if (sensor_set_framesize(mp_obj_get_int(framesize)) != 0) { return mp_const_false; } return mp_const_true; } mp_obj_t py_sensor_set_gainceiling(mp_obj_t gainceiling) { - if (sensor_set_gainceiling(&sensor, mp_obj_get_int(gainceiling)) != 0) { + if (sensor_set_gainceiling(mp_obj_get_int(gainceiling)) != 0) { return mp_const_false; } return mp_const_true; } mp_obj_t py_sensor_set_brightness(mp_obj_t brightness) { - if (sensor_set_brightness(&sensor, mp_obj_get_int(brightness)) != 0) { + if (sensor_set_brightness(mp_obj_get_int(brightness)) != 0) { return mp_const_false; } return mp_const_true; } -void py_sensor_print(void (*print)(void *env, const char *fmt, ...), +mp_obj_t py_sensor_write_reg(mp_obj_t addr, mp_obj_t val) { + SCCB_Write(mp_obj_get_int(addr), mp_obj_get_int(val)); + return mp_const_none; +} + +mp_obj_t py_sensor_read_reg(mp_obj_t addr) { + return mp_obj_new_int(SCCB_Read(mp_obj_get_int(addr))); +} + +void py_sensor_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) { - print(env, "", - sensor.id.MIDH, sensor.id.MIDL, sensor.id.PID, sensor.id.VER); + //print(env, "", + //sensor.id.MIDH, sensor.id.MIDL, sensor.id.PID, sensor.id.VER); } static void rt_store_constants(mp_obj_t m, struct sym_entry *constants) { - /* Store module constants */ for (struct sym_entry *p = constants; p->sym != NULL; p++) { rt_store_attr(m, QSTR_FROM_STR_STATIC(p->sym), MP_OBJ_NEW_SMALL_INT((machine_int_t)p->val)); } @@ -125,19 +130,20 @@ static void rt_store_constants(mp_obj_t m, struct sym_entry *constants) mp_obj_t py_sensor_init() { /* Init sensor */ - /* hack */ - sensor_init(&sensor); - sensor_reset(&sensor); - sensor_set_pixformat(&sensor, PIXFORMAT_RGB565); - sensor_set_framesize(&sensor, FRAMESIZE_QQVGA); - sensor_set_framerate(&sensor, FRAMERATE_30FPS); - sensor_set_gainceiling(&sensor, GAINCEILING_16X); - sensor_set_brightness(&sensor, 3); + sensor_init(); + sensor_reset(); + + /* Use some default settings */ + sensor_set_pixformat(PIXFORMAT_RGB565); + sensor_set_framesize(FRAMESIZE_QQVGA); + sensor_set_framerate(FRAMERATE_30FPS); + sensor_set_gainceiling(GAINCEILING_16X); + sensor_set_brightness(3); /* Create module */ mp_obj_t m = mp_obj_new_module(qstr_from_str("sensor")); - /* Export functions */ + /* Store module functions */ rt_store_attr(m, qstr_from_str("init"), rt_make_function_n(0, py_sensor_sinit)); rt_store_attr(m, qstr_from_str("reset"), rt_make_function_n(0, py_sensor_reset)); rt_store_attr(m, qstr_from_str("snapshot"), rt_make_function_n(0, py_sensor_snapshot)); @@ -146,8 +152,10 @@ mp_obj_t py_sensor_init() rt_store_attr(m, qstr_from_str("set_framesize"), rt_make_function_n(1, py_sensor_set_framesize)); rt_store_attr(m, qstr_from_str("set_gainceiling"), rt_make_function_n(1, py_sensor_set_gainceiling)); rt_store_attr(m, qstr_from_str("set_brightness"), rt_make_function_n(1, py_sensor_set_brightness)); + rt_store_attr(m, qstr_from_str("__write_reg"), rt_make_function_n(2, py_sensor_write_reg)); + rt_store_attr(m, qstr_from_str("__read_reg"), rt_make_function_n(1, py_sensor_read_reg)); - /* Store constants */ + /* Store module constants */ rt_store_constants(m, pixformat_constants); rt_store_constants(m, framesize_constants); rt_store_constants(m, framerate_constants);