Planning on abstracting this behind hardware setup APIs, but this works for a simple demo until then
27 lines
637 B
C
27 lines
637 B
C
#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;
|
|
}
|