50 #include <dev/battery-sensor.h>
55 PROCESS(battery_process,
"battery sensor");
58 const struct sensors_sensor battery_sensor;
60 #define BATTERY_SAMPLES 10
62 static uint16_t battery_samples[BATTERY_SAMPLES];
63 static uint8_t counter = 0;
65 static uint8_t sensor_status = 0;
73 for(i = 0; i < BATTERY_SAMPLES; ++i) {
74 tmp += battery_samples[i];
77 return tmp / BATTERY_SAMPLES;
81 configure(
int type,
int c)
84 AD1PCFG = 0b1111110111111111;
87 AD1CON1 = 0b0000000011100000;
89 AD1CHS = 0b00000000000010100000000000000000;
99 AD1CON1SET = 0b1000000000000000;
111 return sensor_status;
114 SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
128 AD1CON1SET = 0b0000000000000010;
130 while(!(AD1CON1 & 0b0000000000000001)) {
135 battery_samples[counter] = ADC1BUF0;
137 counter = (counter + 1) % BATTERY_SAMPLES;
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define NULL
The null pointer.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS(name, strname)
Declare a process.
void process_start(struct process *p, process_data_t data)
Start a process.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
#define CLOCK_SECOND
A second, measured in system clock time.