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
Woazboat
firmware
Commits
a907a06e
Verified
Commit
a907a06e
authored
5 years ago
by
koalo
Committed by
rahix
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
feat(bhi160): Provide accelerometer samples for MicroPython
parent
f49e5e24
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pycardium/modules/bhi160-sys.c
+58
-1
58 additions, 1 deletion
pycardium/modules/bhi160-sys.c
pycardium/modules/py/bhi160.py
+18
-0
18 additions, 0 deletions
pycardium/modules/py/bhi160.py
pycardium/modules/qstrdefs.h
+4
-0
4 additions, 0 deletions
pycardium/modules/qstrdefs.h
with
80 additions
and
1 deletion
pycardium/modules/bhi160-sys.c
+
58
−
1
View file @
a907a06e
...
...
@@ -5,6 +5,15 @@
#include
"api/common.h"
#include
"mphalport.h"
extern
const
mp_obj_type_t
mp_type_bhi160_sample
;
typedef
struct
_bhi160_sample_obj_t
{
mp_obj_base_t
base
;
int
x
;
int
y
;
int
z
;
}
bhi160_sample_obj_t
;
STATIC
mp_obj_t
mp_bhi160_enable_sensor
(
size_t
n_args
,
const
mp_obj_t
*
args
)
{
int
sensor_type
=
mp_obj_get_int
(
args
[
0
]);
...
...
@@ -30,8 +39,56 @@ STATIC mp_obj_t mp_bhi160_read_sensor(mp_obj_t stream_id_in)
int
n
=
epic_stream_read
(
sd
,
buf
,
sizeof
(
buf
));
return
MP_OBJ_NEW_SMALL_INT
(
n
);
mp_obj_list_t
*
list
=
mp_obj_new_list
(
0
,
NULL
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
bhi160_sample_obj_t
*
o
=
m_new_obj
(
bhi160_sample_obj_t
);
o
->
base
.
type
=
&
mp_type_bhi160_sample
;
o
->
x
=
buf
[
i
].
x
;
o
->
y
=
buf
[
i
].
y
;
o
->
z
=
buf
[
i
].
z
;
mp_obj_list_append
(
list
,
MP_OBJ_FROM_PTR
(
o
));
}
return
MP_OBJ_FROM_PTR
(
list
);
}
STATIC
mp_obj_t
mp_bhi160_x
(
mp_obj_t
type
)
{
bhi160_sample_obj_t
*
self
=
MP_OBJ_TO_PTR
(
type
);
return
MP_OBJ_NEW_SMALL_INT
(
self
->
x
);
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_bhi160_x_obj
,
mp_bhi160_x
);
STATIC
mp_obj_t
mp_bhi160_y
(
mp_obj_t
type
)
{
bhi160_sample_obj_t
*
self
=
MP_OBJ_TO_PTR
(
type
);
return
MP_OBJ_NEW_SMALL_INT
(
self
->
y
);
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_bhi160_y_obj
,
mp_bhi160_y
);
STATIC
mp_obj_t
mp_bhi160_z
(
mp_obj_t
type
)
{
bhi160_sample_obj_t
*
self
=
MP_OBJ_TO_PTR
(
type
);
return
MP_OBJ_NEW_SMALL_INT
(
self
->
z
);
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_bhi160_z_obj
,
mp_bhi160_z
);
STATIC
const
mp_rom_map_elem_t
bhi160_sample_locals_dict_table
[]
=
{
{
MP_ROM_QSTR
(
MP_QSTR_x
),
MP_ROM_PTR
(
&
mp_bhi160_x_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_y
),
MP_ROM_PTR
(
&
mp_bhi160_y_obj
)
},
{
MP_ROM_QSTR
(
MP_QSTR_z
),
MP_ROM_PTR
(
&
mp_bhi160_z_obj
)
},
};
STATIC
MP_DEFINE_CONST_DICT
(
bhi160_sample_locals_dict
,
bhi160_sample_locals_dict_table
);
const
mp_obj_type_t
mp_type_bhi160_sample
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_BHI160Sample
,
.
locals_dict
=
(
mp_obj_dict_t
*
)
&
bhi160_sample_locals_dict
,
};
STATIC
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN
(
mp_bhi160_enable_sensor_obj
,
4
,
4
,
mp_bhi160_enable_sensor
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/py/bhi160.py
+
18
−
0
View file @
a907a06e
...
...
@@ -30,6 +30,24 @@ class BHI160Accelerometer:
interrupt
.
disable_callback
(
interrupt
.
BHI160_ACCELEROMETER
)
interrupt
.
set_callback
(
interrupt
.
BHI160_ACCELEROMETER
,
None
)
def
convert
(
self
,
value
):
return
2
*
value
/
32768.0
def
read
(
self
):
result
=
[]
if
self
.
acc_sd
is
not
None
:
for
sample
in
sys_bhi160
.
read_sensor
(
self
.
acc_sd
):
result
.
append
(
dict
(
{
"
x
"
:
self
.
convert
(
sample
.
x
()),
"
y
"
:
self
.
convert
(
sample
.
y
()),
"
z
"
:
self
.
convert
(
sample
.
z
()),
}
)
)
return
result
def
_accelerometer_interrupt
(
self
,
_
):
if
self
.
acc_sd
is
not
None
:
data
=
sys_bhi160
.
read_sensor
(
self
.
acc_sd
)
...
...
This diff is collapsed.
Click to expand it.
pycardium/modules/qstrdefs.h
+
4
−
0
View file @
a907a06e
...
...
@@ -64,6 +64,10 @@ Q(RTC_ALARM)
Q
(
sys_bhi160
)
Q
(
enable_sensor
)
Q
(
read_sensor
)
Q
(
BHI160Sample
)
Q
(
x
)
Q
(
y
)
Q
(
z
)
/* display */
Q
(
sys_display
)
...
...
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