Fix dilatometer, other misc stuff
[matches/MCTX3420.git] / server / sensors / microphone.c
1 /**
2  * @file microphone.c
3  * @purpose Implementation of Pressure reading functions
4  */
5
6 #include "microphone.h"
7 #include "../bbb_pin.h"
8 #include "../log.h" // For Fatal()
9
10 #define MIC_ADC ADC2
11
12 double adc_raw[] = {524,668,733,991,1121,1264,1300,1437,1645,1789,1932,2033,2105,2148,2284,2528,3089};
13 double mic_cal[] = {70,73,75,76.8,77.7,80,81.2,83.3,85.5,87.5,90.7,92.6,94.3,96.2,100,102,125};
14
15 bool Microphone_Init(const char * name, int id)
16 {
17         assert(sizeof(adc_raw) == sizeof(mic_cal));
18         return ADC_Export(MIC_ADC);
19 }
20
21 bool Microphone_Cleanup(int id)
22 {
23         ADC_Unexport(MIC_ADC);
24         return true;
25 }
26
27 bool Microphone_Read(int id, double * value)
28 {
29         int adc = 0;
30         if (!ADC_Read(MIC_ADC, &adc))
31                 return false;
32         
33         *value = Data_Calibrate((double)adc, adc_raw, mic_cal, sizeof(adc_raw)/sizeof(double));
34         return true;
35 }
36
37 bool Microphone_Sanity(int id, double value)
38 {
39         return true;
40 }

UCC git Repository :: git.ucc.asn.au