Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
meh
firmware
Commits
b927b5de
Commit
b927b5de
authored
Aug 25, 2019
by
fleur
Committed by
Rahix
Aug 25, 2019
Browse files
feat(light-sensor): Add API-call for direct readout
parent
83a19117
Changes
4
Hide whitespace changes
Inline
Side-by-side
epicardium/epicardium.h
View file @
b927b5de
...
...
@@ -102,6 +102,7 @@ typedef _Bool bool;
#define API_LIGHT_SENSOR_RUN 0x80
#define API_LIGHT_SENSOR_GET 0x81
#define API_LIGHT_SENSOR_STOP 0x82
#define API_LIGHT_SENSOR_READ 0x83
#define API_BUTTONS_READ 0x90
...
...
@@ -1399,6 +1400,14 @@ API(API_LIGHT_SENSOR_GET, int epic_light_sensor_get(uint16_t* value));
*/
API
(
API_LIGHT_SENSOR_STOP
,
int
epic_light_sensor_stop
());
/**
* Get the light level directly. Each call has an intrinsic delay of about 240us, I recommend another 100-300us delay via utime.sleep_ms() between calls. Whether or not the IR LED is fast enough is another issue.
*
* :return: Light level
*/
API
(
API_LIGHT_SENSOR_READ
,
uint16_t
epic_light_sensor_read
(
void
));
/**
* File
* ====
...
...
epicardium/modules/light_sensor.c
View file @
b927b5de
...
...
@@ -27,6 +27,13 @@ static int light_sensor_init()
return
0
;
}
uint16_t
epic_light_sensor_read
()
{
ADC_StartConvert
(
ADC_CH_7
,
0
,
0
);
ADC_GetData
(
&
last_value
);
return
last_value
;
}
static
void
readAdcCallback
()
{
if
(
hwlock_acquire
(
HWLOCK_ADC
,
0
)
!=
0
)
{
...
...
pycardium/modules/light_sensor.c
View file @
b927b5de
...
...
@@ -42,11 +42,18 @@ static mp_obj_t mp_light_sensor_stop()
}
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_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
...
...
pycardium/modules/qstrdefs.h
View file @
b927b5de
...
...
@@ -97,6 +97,7 @@ Q(light_sensor)
Q
(
start
)
Q
(
get_reading
)
Q
(
stop
)
Q
(
read
)
/* bme680 */
Q
(
bme680
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment