Skip to content
Snippets Groups Projects
Select Git revision
  • 125fd0f2aef688703d37ee61d21715527a8af207
  • master default protected
  • schneider/ir
  • rahix/user-space-ctx
  • schneider/iaq-python
  • schneider/ble-mini-demo
  • schneider/ble-ecg-stream-visu
  • schneider/mp-exception-print
  • schneider/sleep-display
  • schneider/deepsleep4
  • schneider/deepsleep2
  • schneider/deepsleep
  • schneider/ble-central
  • rahix/bluetooth-app-favorite
  • schneider/v1.17-changelog
  • schneider/ancs
  • schneider/png
  • schneider/freertos-list-debug
  • schneider/212-reset-hardware-when-entering-repl
  • schneider/bonding-fail-if-full
  • schneider/ble-fixes-2020-3
  • v1.18
  • v1.17
  • v1.16
  • v1.15
  • v1.14
  • v1.13
  • v1.12
  • v1.11
  • v1.10
  • v1.9
  • v1.8
  • v1.7
  • v1.6
  • v1.5
  • v1.4
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
41 results

DEV_Config.c

Blame
  • light_sensor.c 1.93 KiB
    #include "epicardium.h"
    
    #include "py/builtin.h"
    #include "py/obj.h"
    #include "py/runtime.h"
    
    static mp_obj_t mp_light_sensor_start()
    {
    	int status = epic_light_sensor_run();
    	if (status == -EBUSY) {
    		mp_raise_msg(
    			&mp_type_RuntimeError, "timer could not be scheduled"
    		);
    	}
    	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()
    {
    	int status = epic_light_sensor_stop();
    	if (status == -EBUSY) {
    		mp_raise_msg(
    			&mp_type_RuntimeError, "timer could not be stopped"
    		);
    	}
    	return mp_const_none;
    }
    static MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_stop_obj, mp_light_sensor_stop);
    
    static mp_obj_t mp_light_sensor_read()
    {
    	return mp_obj_new_int_from_uint(epic_light_sensor_read());
    }
    static MP_DEFINE_CONST_FUN_OBJ_0(light_sensor_read_obj, mp_light_sensor_read);
    
    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) },
    	{ MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&light_sensor_read_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,
    };
    
    /* clang-format off */
    MP_REGISTER_MODULE(MP_QSTR_light_sensor, light_sensor_module, MODULE_LIGHT_SENSOR_ENABLED);