X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fsensors%2Fpressure.c;h=d93ceedd9f89a416454b8766c0b0e69a38702cea;hb=1788aa399989e919221f0bf4c8b6114bef4a49a9;hp=29b8d28d3213b6139af1fdca56b5275191ea89cb;hpb=7e9d726ccd53626251e56b92c8eec47772bfe0f9;p=matches%2FMCTX3420.git diff --git a/server/sensors/pressure.c b/server/sensors/pressure.c index 29b8d28..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,7 +46,7 @@ double Pressure_Callibrate(int id, int adc) { //double voltage = ADC_TO_VOLTS(adc); // convert reading to voltage - return (double)adc; + //TODO: Fix this switch (id) @@ -48,14 +54,20 @@ double Pressure_Callibrate(int id, int adc) case PRES_HIGH0: case PRES_HIGH1: { + /* static const double Vs = 5e3; // In mVs 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 @@ -105,3 +117,13 @@ bool Pressure_Read(int id, double * value) //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); +}