blob: acbf679b4af3e5905b5522ec53d3b6e865fe693a [file] [log] [blame]
brians0ab60bb2013-01-31 02:21:51 +00001#ifndef __ANALOG_H__
2#define __ANALOG_H__
3
Brian Silvermanf92396c2013-09-12 20:13:13 -07004#include <stdint.h>
5
Brian Silvermandb85c9a2013-11-02 14:38:43 -07006// Internal variable for holding the averaged value. USE analog TO GET TO THIS
7// IN CASE IT CHANGES!
8uint16_t averaged_values[4];
9
Brian Silverman74acd622013-10-26 14:47:14 -070010// Starts the hardware constantly doing conversions on all 4 of our analog
11// inputs.
Brian Silverman6ad00b82013-03-27 19:02:38 -070012void analog_init(void);
Brian Silverman74acd622013-10-26 14:47:14 -070013
14// Retrieves the most recent reading on channel (0-3).
15// Returns 0xFFFF for invalid channel.
Brian Silvermandb85c9a2013-11-02 14:38:43 -070016// 0 means 0V and 0xFFF means 3.3V.
17// These values are run through a low-pass filter with unreasonable readings
18// discarded first.
19uint16_t analog(int channel) {
20 if (channel < 0 || channel > 3) return 0xFFFF;
21 return averaged_values[channel];
22}
Austin Schuh63d0e9b2013-03-27 04:43:14 +000023
Brian Silverman6ad00b82013-03-27 19:02:38 -070024#endif // __ANALOG_H__