Add basic ADC support
Planning on abstracting this behind hardware setup APIs, but this works for a simple demo until then
This commit is contained in:
parent
17b3f0a89f
commit
d439778949
9 changed files with 151 additions and 0 deletions
27
routines/photosensor.c
Normal file
27
routines/photosensor.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include <zephyr/kernel.h>
|
||||
|
||||
#include "includes/ble.h"
|
||||
#include "includes/routine.h"
|
||||
#include "includes/hardware/adc.h"
|
||||
|
||||
routine_return_e
|
||||
photosensor()
|
||||
{
|
||||
while (routine_status() == ROUTINE_STATUS_RUNNING) {
|
||||
int32_t adc_mv = adc_get_mv(0);
|
||||
char buf[16];
|
||||
size_t print_len;
|
||||
|
||||
if (adc_mv == INT32_MIN) {
|
||||
ble_set_telemetry_data("Reading failed", 14);
|
||||
} else {
|
||||
print_len = snprintk(buf, sizeof(buf), "%dmV", adc_mv);
|
||||
ble_set_telemetry_data(buf, print_len);
|
||||
}
|
||||
|
||||
routine_delay(500);
|
||||
routine_yield();
|
||||
}
|
||||
|
||||
return ROUTINE_RETURN_SUCCESS;
|
||||
}
|
||||
|
|
@ -4,8 +4,10 @@
|
|||
|
||||
/** Extern all of your routines here so they can be included in the list **/
|
||||
extern routine_return_e input_echo();
|
||||
extern routine_return_e photosensor();
|
||||
|
||||
const routine_listing_t routine_list[] = {
|
||||
{ .entry = input_echo, .name = "Input Echo" },
|
||||
{ .entry = photosensor, .name = "Photosensor" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue