mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Remove sensor arg from py_sensor
This commit is contained in:
parent
ddcf6919c1
commit
f0431b9b10
@ -1,10 +1,8 @@
|
||||
#include <libmp.h>
|
||||
#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 MID:0x%.2X%.2X PID:0x%.2X VER:0x%.2X>",
|
||||
sensor.id.MIDH, sensor.id.MIDL, sensor.id.PID, sensor.id.VER);
|
||||
//print(env, "<Sensor MID:0x%.2X%.2X PID:0x%.2X VER:0x%.2X>",
|
||||
//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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user