Skip to content
Snippets Groups Projects
Select Git revision
  • 12d0731b91d8e58ba20ec28adf2d6c1aa995d74a
  • wip-bootstrap default
  • dualcore
  • ch3/leds
  • ch3/time
  • master
6 results

vfs_fat.h

Blame
  • light_sensor.c 1.49 KiB
    #include "py/obj.h"
    #include "py/runtime.h"
    #include "py/builtin.h"
    #include "epicardium.h"
    
    STATIC mp_obj_t mp_light_sensor_start()
    {
        epic_light_sensor_run();
        return mp_const_none;
    }
    STATIC MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_start_obj, mp_light_sensor_start);
    
    STATIC mp_obj_t mp_light_sensor_get_reading()
    {
        uint16_t last;
        int status = epic_light_sensor_get(&last);
        if (status == -ENODATA)
        {
            mp_raise_ValueError("sensor not running");
            return mp_const_none;
        }
        return mp_obj_new_int_from_uint(last);
    }
    STATIC MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_get_obj, mp_light_sensor_get_reading);
    
    STATIC mp_obj_t mp_light_sensor_stop()
    {
        epic_light_sensor_stop();
        return mp_const_none;
    }
    STATIC MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_stop_obj, mp_light_sensor_stop);
    
    STATIC const mp_rom_map_elem_t light_sensor_module_globals_table[] = {
        { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_light_sensor) },
        { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&light_sensor_start_obj) },
        { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&light_sensor_stop_obj) },
        { MP_ROM_QSTR(MP_QSTR_get_reading), MP_ROM_PTR(&light_sensor_get_obj) }
    };
    STATIC MP_DEFINE_CONST_DICT(light_sensor_module_globals, light_sensor_module_globals_table);
    
    const mp_obj_module_t light_sensor_module = {
        .base       = { &mp_type_module },
        .globals    = (mp_obj_dict_t *)&light_sensor_module_globals,
    };
    
    MP_REGISTER_MODULE(MP_QSTR_light_sensor, light_sensor_module, MODULE_AMBIENT_ENABLED);