Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
François Revol
firmware
Commits
dcc5c745
Commit
dcc5c745
authored
4 years ago
by
schneider
Browse files
Options
Downloads
Patches
Plain Diff
feat(bsec): Add micropython access
parent
f7dd7f3e
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pycardium/modules/py/bme680.py
+75
-1
75 additions, 1 deletion
pycardium/modules/py/bme680.py
pycardium/modules/qstrdefs.h
+1
-0
1 addition, 0 deletions
pycardium/modules/qstrdefs.h
pycardium/modules/sys_bme680.c
+23
-0
23 additions, 0 deletions
pycardium/modules/sys_bme680.c
with
99 additions
and
1 deletion
pycardium/modules/py/bme680.py
+
75
−
1
View file @
dcc5c745
...
...
@@ -8,6 +8,19 @@ Bme680Data = ucollections.namedtuple(
"
Bme680Data
"
,
[
"
temperature
"
,
"
humidity
"
,
"
pressure
"
,
"
gas_resistance
"
]
)
BSECData
=
ucollections
.
namedtuple
(
"
BSECData
"
,
[
"
temperature
"
,
"
humidity
"
,
"
pressure
"
,
"
gas_resistance
"
,
"
iaq
"
,
"
iaq_accuracy
"
,
"
eco2
"
,
],
)
class
Bme680
:
"""
...
...
@@ -58,6 +71,13 @@ class Bme680:
- ``pressure``: Barometric pressure in *hPa*
- ``gas_resistance``: Gas resistance in *Ω*
If the Bosch BSEC libary is active the following extra fields will
be returned:
- ``iaq``: Indoor air quality indication
- ``iaq_accuracy``: Accuracy of indoor air quality
- ``eco2``: Equivalent CO2 content in *ppm*
**Example**:
.. code-block:: python
...
...
@@ -70,7 +90,11 @@ class Bme680:
print(
"
T: {}
"
.format(data.temperature))
print(
"
H: {}
"
.format(data.humidity))
"""
return
Bme680Data
(
*
sys_bme680
.
get_data
())
try
:
return
BSECData
(
*
sys_bme680
.
bsec_get_data
())
except
:
return
Bme680Data
(
*
sys_bme680
.
get_data
())
def
close
(
self
):
"""
...
...
@@ -132,3 +156,53 @@ class Bme680:
print(str(environment.gas_resistance()))
"""
return
self
.
get_data
().
gas_resistance
def
iaq
(
self
):
"""
Retrieve indoor air quality as defined by the Bosch BSEC libaray.
BSEC needs to be enable in ``card10.cfg``. Otherwise this method
will raise an ``OSError`` exception.
**Example**:
.. code-block:: python
environment = bme680.Bme680()
print(str(environment.iaq()))
"""
return
BSECData
(
*
sys_bme680
.
bsec_get_data
()).
iaq
def
iaq_accuracy
(
self
):
"""
Retrieve indoor air quality accuracy as defined by the Bosch BSEC libaray.
BSEC needs to be enable in ``card10.cfg``. Otherwise this method
will raise an ``OSError`` exception.
**Example**:
.. code-block:: python
environment = bme680.Bme680()
print(str(environment.iaq_accuracy()))
"""
return
BSECData
(
*
sys_bme680
.
bsec_get_data
()).
iaq_accuracy
def
eco2
(
self
):
"""
Retrieve equivalant CO2 as defined by the Bosch BSEC libaray.
BSEC needs to be enable in ``card10.cfg``. Otherwise this method
will raise an ``OSError`` exception.
**Example**:
.. code-block:: python
environment = bme680.Bme680()
print(str(environment.eco2()))
"""
return
BSECData
(
*
sys_bme680
.
bsec_get_data
()).
eco2
This diff is collapsed.
Click to expand it.
pycardium/modules/qstrdefs.h
+
1
−
0
View file @
dcc5c745
...
...
@@ -116,6 +116,7 @@ Q(sys_bme680)
Q
(
init
)
Q
(
deinit
)
Q
(
get_data
)
Q
(
bsec_get_data
)
/* file */
Q
(
__del__
)
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/sys_bme680.c
+
23
−
0
View file @
dcc5c745
...
...
@@ -45,11 +45,34 @@ static mp_obj_t mp_bme680_get_data()
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
bme680_get_data_obj
,
mp_bme680_get_data
);
static
mp_obj_t
mp_bsec_get_data
()
{
struct
bsec_sensor_data
data
;
int
ret
=
epic_bsec_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
),
mp_obj_new_int
(
data
.
indoor_air_quality
),
mp_obj_new_int
(
data
.
accuracy
),
mp_obj_new_float
(
data
.
co2_equivalent
),
};
return
mp_obj_new_tuple
(
7
,
values_list
);
}
static
MP_DEFINE_CONST_FUN_OBJ_0
(
bsec_get_data_obj
,
mp_bsec_get_data
);
static
const
mp_rom_map_elem_t
bme680_module_globals_table
[]
=
{
{
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
)
},
{
MP_ROM_QSTR
(
MP_QSTR_bsec_get_data
),
MP_ROM_PTR
(
&
bsec_get_data_obj
)
},
};
static
MP_DEFINE_CONST_DICT
(
bme680_module_globals
,
bme680_module_globals_table
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment