An example running on Myriota's FlexSense
board. This example demonstrates how to use the Battery API's. The BatterySample
job will sample if the device is externally or battery-powered FLEX_IsOnExternalPower
and the battery voltage FLEX_GetBatteryVoltage
. BatterySample
will be scheduled SAMPLES_PER_DAY
times per day.
#include <stdio.h>
#include "flex.h"
#define APPLICATION_NAME "Battery API Example"
#define SAMPLES_PER_DAY 4
static time_t BatterySample(void) {
bool is_on_external_power = false;
printf("Failed to read is on external power!\n");
}
int32_t battery_mv = 0;
printf("Failed to read battery voltage!\n");
}
printf("Battery API Sample: Is on external power = %d, Battery mV = %ld\n", is_on_external_power,
battery_mv);
}
static void on_external_power_handler(const bool *const is_ext_pwr) {
char buf[32] = {0};
snprintf(buf, sizeof(buf), "External Power: (%d)\n", *is_ext_pwr);
}
void FLEX_AppInit() {
printf("%s\n", APPLICATION_NAME);
}