1
+ #include " drivers/mlx90640/mlx90640.hpp"
2
+
3
+ #include " micropython/modules/util.hpp"
4
+
5
+ using namespace pimoroni ;
6
+
7
+ extern " C" {
8
+ #include " mlx90640.h"
9
+ #include " pimoroni_i2c.h"
10
+
11
+ typedef struct _ModMLX90640_obj_t {
12
+ mp_obj_base_t base;
13
+ MLX90640 *breakout;
14
+ _PimoroniI2C_obj_t *i2c;
15
+ int address;
16
+ } ModMLX90640_obj_t;
17
+
18
+ mp_obj_t MLX90640_setup (mp_obj_t self_in, mp_obj_t fps) {
19
+ _ModMLX90640_obj_t *self = MP_OBJ_TO_PTR2 (self_in, _ModMLX90640_obj_t);
20
+
21
+ self->breakout ->setup (mp_obj_get_int (fps));
22
+
23
+ return mp_const_none;
24
+ }
25
+
26
+ mp_obj_t MLX90640_get_frame (mp_obj_t self_in) {
27
+ _ModMLX90640_obj_t *self = MP_OBJ_TO_PTR2 (self_in, _ModMLX90640_obj_t);
28
+
29
+ self->breakout ->get_frame ();
30
+
31
+ mp_obj_list_t *list = MP_OBJ_TO_PTR2 (mp_obj_new_list (MLX90640::WIDTH * MLX90640::HEIGHT, NULL ), mp_obj_list_t );
32
+
33
+ for (auto y = 0u ; y < MLX90640::HEIGHT; y++) {
34
+ for (auto x = 0u ; x < MLX90640::WIDTH; x++) {
35
+ int offset = y * MLX90640::WIDTH + x;
36
+ float v = self->breakout ->mlx90640To [offset];
37
+ list->items [offset] = mp_obj_new_float (v);
38
+ }
39
+ }
40
+
41
+ return list;
42
+ }
43
+
44
+ mp_obj_t MLX90640_make_new (const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
45
+ enum { ARG_i2c, ARG_address };
46
+ static const mp_arg_t allowed_args[] = {
47
+ { MP_QSTR_i2c, MP_ARG_OBJ, {.u_obj = nullptr } },
48
+ { MP_QSTR_address, MP_ARG_INT, {.u_int = MLX90640_DEFAULT_I2C_ADDRESS}}
49
+ };
50
+
51
+ mp_arg_val_t args[MP_ARRAY_SIZE (allowed_args)];
52
+ mp_arg_parse_all_kw_array (n_args, n_kw, all_args, MP_ARRAY_SIZE (allowed_args), allowed_args, args);
53
+
54
+ _ModMLX90640_obj_t *self = m_new_obj_with_finaliser (_ModMLX90640_obj_t);
55
+ self->base .type = &MLX90640_type;
56
+
57
+ self->i2c = PimoroniI2C_from_machine_i2c_or_native (args[ARG_i2c].u_obj );
58
+ self->address = args[ARG_address].u_int ;
59
+
60
+ self->breakout = m_new_class (MLX90640, (pimoroni::I2C *)(self->i2c ->i2c ), self->address );
61
+
62
+ return self;
63
+ }
64
+
65
+ }
0 commit comments