git.ucc.asn.au
/
matches
/
MCTX3420.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of github:szmoore/MCTX3420 into report
[matches/MCTX3420.git]
/
server
/
sensors
/
pressure.c
diff --git
a/server/sensors/pressure.c
b/server/sensors/pressure.c
index
61cdbcf
..
699dda3
100644
(file)
--- 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 "pressure.h"
#include "../bbb_pin.h"
#include "../log.h" // For Fatal()
+#include "../data.h"
#define PSI_TO_KPA 6.89475729
#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
/**
* Get the ADC number of a Pressure sensor
* @param id - Id of the sensor
@@
-40,18
+46,26
@@
double Pressure_Callibrate(int id, int adc)
{
//double voltage = ADC_TO_VOLTS(adc); // convert reading to voltage
{
//double voltage = ADC_TO_VOLTS(adc); // convert reading to voltage
+
+
+ //TODO: Fix this
switch (id)
{
case PRES_HIGH0:
case PRES_HIGH1:
{
switch (id)
{
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;
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 Data_Calibrate((double)adc, high_raw, high_cal, sizeof(high_raw)/sizeof(double));
}
case PRES_LOW0:
}
case PRES_LOW0:
+ // Not calibrated!
return (200.0 * (adc / ADC_RAW_MAX));
default:
Fatal("Unknown Pressure id %d", id);
return (200.0 * (adc / ADC_RAW_MAX));
default:
Fatal("Unknown Pressure id %d", id);
@@
-102,3
+116,13
@@
bool Pressure_Read(int id, double * value)
//pthread_mutex_unlock(&mutex);
return result;
}
//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);
+}
UCC
git Repository :: git.ucc.asn.au