X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fsensors%2Fpressure.c;h=d93ceedd9f89a416454b8766c0b0e69a38702cea;hb=1788aa399989e919221f0bf4c8b6114bef4a49a9;hp=ddb46df039f3e037bcb3fbe48ed0fe79f4024bc2;hpb=450583abb79d5fedb0debabed073d9b191dac80c;p=matches%2FMCTX3420.git diff --git a/server/sensors/pressure.c b/server/sensors/pressure.c index ddb46df..d93ceed 100644 --- a/server/sensors/pressure.c +++ b/server/sensors/pressure.c @@ -6,9 +6,15 @@ #include "pressure.h" #include "../bbb_pin.h" #include "../log.h" // For Fatal() +#include "../data.h" #define PSI_TO_KPA 6.89475729 +/** Uncalibrated values in ADC readings **/ +static double high_raw[] = {642,910,1179,1445,1712,1980}; +/** Calibrated values in kPa **/ +static double high_cal[] = {95, 190, 285, 380, 474, 560}; + /** * Get the ADC number of a Pressure sensor * @param id - Id of the sensor @@ -40,19 +46,28 @@ double Pressure_Callibrate(int id, int adc) { //double voltage = ADC_TO_VOLTS(adc); // convert reading to voltage + + + //TODO: Fix this switch (id) { case PRES_HIGH0: case PRES_HIGH1: { + /* static const double Vs = 5e3; // In mVs - static const double Pmin = 0.0; + static const double Pmin = 0.0 * PSI_TO_KPA; static const double Pmax = 150.0 * PSI_TO_KPA; double Vout = ADC_TO_MVOLTS(adc); return ((Vout - 0.1*Vs)/(0.8*Vs))*(Pmax - Pmin) + Pmin; + */ + return adc; + //return Data_Calibrate((double)adc, high_raw, high_cal, sizeof(high_raw)/sizeof(double)); } case PRES_LOW0: - return (200.0 * (adc / ADC_RAW_MAX)); + // Not calibrated! + //return (200.0 * ((double)adc / ADC_RAW_MAX)); + return adc; default: Fatal("Unknown Pressure id %d", id); return -1; // Should never happen @@ -93,11 +108,22 @@ bool Pressure_Read(int id, double * value) //static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; //pthread_mutex_lock(&mutex); bool result = false; - if (ADC_Read(Pressure_GetADC(id), value)) + int adc = 0; + if (ADC_Read(Pressure_GetADC(id), &adc)) { - *value = Pressure_Callibrate(id, *value); + *value = Pressure_Callibrate(id, adc); result = true; } //pthread_mutex_unlock(&mutex); return result; } + +/** + * Sanity check the pressure reading + * @param value - The pressure reading (calibrated) + * @returns true iff the value is safe, false if it is dangerous + */ +bool Pressure_Sanity(int id, double value) +{ + return (value < 590); +}