Skip to content
Snippets Groups Projects
Verified Commit e7144129 authored by rahix's avatar rahix
Browse files

refactor(bme680): Create a Python wrapper module


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 34341e8d
No related branches found
No related tags found
No related merge requests found
import sys_bme680
import ucollections
# Import old module for compatibility
from sys_bme680 import * # noqa
Bme680Data = ucollections.namedtuple(
"Bme680Data", ["temperature", "humidity", "pressure", "gas_resistance"]
)
class Bme680:
def __init__(self):
sys_bme680.init()
def __enter__(self):
return self
def __exit__(self, *args):
self.close()
def get_data(self):
return Bme680Data(*sys_bme680.get_data())
def close(self):
sys_bme680.deinit()
def temperature(self):
return self.get_data().temperature
def humidity(self):
return self.get_data().humidity
def pressure(self):
return self.get_data().pressure
def gas_resistance(self):
return self.get_data().gas_resistance
python_modules = files(
'bhi160.py',
'bme680.py',
'color.py',
'htmlcolor.py',
'display.py',
......
......@@ -104,7 +104,7 @@ Q(stop)
Q(read)
/* bme680 */
Q(bme680)
Q(sys_bme680)
Q(init)
Q(deinit)
Q(get_data)
......
......@@ -46,7 +46,7 @@ static mp_obj_t mp_bme680_get_data()
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___name__), MP_ROM_QSTR(MP_QSTR_sys_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) },
......@@ -59,4 +59,4 @@ const mp_obj_module_t bme680_module = {
};
/* Register the module to make it available in Python */
MP_REGISTER_MODULE(MP_QSTR_bme680, bme680_module, MODULE_BME680_ENABLED);
MP_REGISTER_MODULE(MP_QSTR_sys_bme680, bme680_module, MODULE_BME680_ENABLED);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment