Skip to content
Snippets Groups Projects
Select Git revision
  • genofire/ble-rewrite
  • master default protected
  • koalo/bhi160
  • rahix/simple_menu
  • ch3/splashscreen
  • koalo/bhi160-works-but-dirty
  • ios-workarounds
  • koalo/wip/i2c-for-python
  • renze/safe_mode
  • renze/hatchery_apps
  • schneider/fundamental-test
  • koalo/factory-reset
  • msgctl/gfx_rle
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • schneider/bsec
  • rahix/bma
  • rahix/bhi
  • v1.3
  • v1.2
  • v1.1
  • v1.0
  • release-1
  • bootloader-v1
  • v0.0
27 results

bme680.c

Blame
  • Forked from card10 / firmware
    1210 commits behind the upstream repository.
    • chris007's avatar
      866e3788
      feat(bme680): Add bme680 support · 866e3788
      chris007 authored and rahix's avatar rahix committed
      Integrated the BME680 Sensor as Python module.  Performs a single read of
      temperature (°C), humidity (% r.h.), air pressure (hPa) and gas resistance
      (Ohm).
      866e3788
      History
      feat(bme680): Add bme680 support
      chris007 authored and rahix's avatar rahix committed
      Integrated the BME680 Sensor as Python module.  Performs a single read of
      temperature (°C), humidity (% r.h.), air pressure (hPa) and gas resistance
      (Ohm).
    bme680.c 1.60 KiB
    #include "py/obj.h"
    #include "py/objlist.h"
    #include "py/runtime.h"
    
    #include "epicardium.h"
    
    static mp_obj_t mp_bme680_init()
    {
    	int ret = epic_bme680_init();
    
    	if (ret < 0) {
    		mp_raise_OSError(-ret);
    	}
    
    	return 0;
    }
    static MP_DEFINE_CONST_FUN_OBJ_0(bme680_init_obj, mp_bme680_init);
    
    static mp_obj_t mp_bme680_deinit()
    {
    	int ret = epic_bme680_deinit();
    
    	if (ret < 0) {
    		mp_raise_OSError(-ret);
    	}
    
    	return 0;
    }
    static MP_DEFINE_CONST_FUN_OBJ_0(bme680_deinit_obj, mp_bme680_deinit);
    
    static mp_obj_t mp_bme680_get_data()
    {
    	struct bme680_sensor_data data;
    	int ret = epic_bme680_read_sensors(&data);
    
    	if (ret < 0) {
    		mp_raise_OSError(-ret);
    	}
    
    	mp_obj_t values_list[] = { mp_obj_new_float(data.temperature),
    				   mp_obj_new_float(data.humidity),
    				   mp_obj_new_float(data.pressure),
    				   mp_obj_new_float(data.gas_resistance) };
    	return mp_obj_new_tuple(4, values_list);
    }
    static MP_DEFINE_CONST_FUN_OBJ_0(bme680_get_data_obj, mp_bme680_get_data);
    
    static const mp_rom_map_elem_t bme680_module_globals_table[] = {
    	{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bme680) },
    	{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&bme680_init_obj) },
    	{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&bme680_deinit_obj) },
    	{ MP_ROM_QSTR(MP_QSTR_get_data), MP_ROM_PTR(&bme680_get_data_obj) },
    };
    static MP_DEFINE_CONST_DICT(bme680_module_globals, bme680_module_globals_table);
    
    const mp_obj_module_t bme680_module = {
    	.base    = { &mp_type_module },
    	.globals = (mp_obj_dict_t *)&bme680_module_globals,
    };
    
    /* Register the module to make it available in Python */
    MP_REGISTER_MODULE(MP_QSTR_bme680, bme680_module, MODULE_BME680_ENABLED);