--- /dev/null
+@misc{uwaRef,
+ author = "Example Reference,
+ year = 2013,
+ month = Aug,
+ title = "Harvard Citation Style",
+ howpublished = "\url{http://guides.is.uwa.edu.au/harvard}",
+ note = "UWA Reference guide"
+}
+
+@misc{UserCake,
+ author = "Tyson et. al"
+ year = 2012
+ title = "UserCake: The fully open source user management script",
+ howpublished = "\url{http://usercake.com}"
+}
+
+@misc{github,
+ author = "Sam Moore and Jeremy Tan and Justin Kruger and Callum Schofield and James Rosher and Rowan Heinrich",
+ year = 2013,
+ title = "MCTX3420 2013 Git Repository on GitHub",
+ howpublished = "\url{https://github.com/szmoore/MCTX3420}"
+}
++
+
--- /dev/null
- return PWM_Set(PREGULATOR_PWM, false, PREGULATOR_PERIOD, value*(PREGULATOR_PERIOD));
+ #include "pregulator.h"
+ #include "../bbb_pin.h"
+
++
++#include "../data.h"
+ #define PREGULATOR_PWM ECAP0
+ #define PREGULATOR_PERIOD 500000
+ //16666667
+
++/** PWM duty cycles raw **/
++static double pwm_raw[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6};
++/** Calibrated pressure values match with pwm_raw **/
++static double preg_cal[] = {96, 190, 285, 380, 475, 569};
++
+ /**
+ * Initiliase the pressure regulator
+ */
+ bool Pregulator_Init(const char * name, int id)
+ {
+ return PWM_Export(PREGULATOR_PWM) && PWM_Set(PREGULATOR_PWM, false, PREGULATOR_PERIOD, 0);
+ }
+
+ bool Pregulator_Cleanup(int id)
+ {
+ if (!PWM_Set(PREGULATOR_PWM, false, PREGULATOR_PERIOD, 0))
+ return false;
+ PWM_Unexport(PREGULATOR_PWM);
+ return true;
+ }
+
+ bool Pregulator_Set(int id, double value)
+ {
- return (value >= 0.0 && value <= 1.0);
++ double anti_calibrated = Data_Calibrate(value, preg_cal, pwm_raw, sizeof(pwm_raw)/sizeof(double));
++ if (anti_calibrated < 0)
++ anti_calibrated = 0;
++ if (anti_calibrated > 1)
++ anti_calibrated = 1;
++ return PWM_Set(PREGULATOR_PWM, false, PREGULATOR_PERIOD, anti_calibrated*(PREGULATOR_PERIOD));
+ }
+
+ bool Pregulator_Sanity(int id, double value)
+ {
++ return (value >= 0 && value < 570);
+ }
+
}
return JSON;
}
++
++/**
++ * Binary search for index of a double in an array
++ * @param value - The value
++ * @param x - The array
++ * @param size - Sizeof the array
++ */
++int FindClosest(double value, double x[], int size)
++{
++ int upper = size-1;
++ int lower = 0;
++ int index = 0;
++ while (upper - lower > 1)
++ {
++ index = lower + ((upper - lower)/2);
++ double look = x[index];
++ if (look > value)
++ upper = index;
++ else if (look < value)
++ lower = index;
++ else
++ return index;
++ }
++
++ if (x[index] > value && index > 0)
++ --index;
++ return index;
++
++}
++
++/**
++ * Get calibrated value by interpolation in array y
++ * @param value - Raw measured value
++ * @param x - x values (raw values) of the data
++ * @param y - calibrated values
++ * @param size - Number of values in the arrays
++ * @returns interpolated calibrated value
++ */
++double Data_Calibrate(double value, double x[], double y[], int size)
++{
++ int i = FindClosest(value, x, size);
++ if (i >= size-1)
++ {
++ i = size-2;
++ }
++ double dist = (value - x[i])/(x[i+1] - x[i]);
++ return y[i] + dist*(y[i+1]-y[i]);
++}
extern DataFormat Data_GetFormat(FCGIValue * fmt); // Helper; convert human readable format string to DataFormat
++extern double Data_Callibrate(double value, double map[], int map_size);
++
#endif //_DATAPOINT_H
--- /dev/null
--- /dev/null
++#include "common.h"
++
++
--- /dev/null
--- /dev/null
++/**
++ * @file microphone.c
++ * @purpose Implementation of Pressure reading functions
++ */
++
++#include "microphone.h"
++#include "../bbb_pin.h"
++#include "../log.h" // For Fatal()
++
++#define MIC_ADC ADC2
++
++double adc_raw[] = {524,668,733,991,1121,1264,1300,1437,1645,1789,1932,2033,2105,2148,2284,2528,3089};
++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};
++
++bool Microphone_Init(const char * name, int id)
++{
++ assert(sizeof(adc_raw) == sizeof(mic_cal));
++ return ADC_Export(MIC_ADC);
++}
++
++bool Microphone_Cleanup(int id)
++{
++ ADC_Unexport(MIC_ADC);
++ return true;
++}
++
++bool Microphone_Read(int id, double * value)
++{
++ int adc = 0;
++ if (!ADC_Read(MIC_ADC, &adc))
++ return false;
++
++ *value = Data_Calibrate((double)adc, adc_raw, mic_cal, sizeof(adc_raw)/sizeof(double));
++ return true;
++}
++
++bool Microphone_Sanity(int id, double value)
++{
++ return true;
++}
--- /dev/null
--- /dev/null
++#ifndef _MICROPHONE_H
++#define _MICROPHONE_H
++
++extern bool Microphone_Init(const char * name, int id);
++extern bool Microphone_Cleanup(int id);
++extern bool Microphone_Read(int id, double * value);
++extern bool Microphone_Sanity(int id, double value);
++
++#endif //_MICROPHONE_H
++
++
#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
{
//double voltage = ADC_TO_VOLTS(adc); // convert reading to voltage
- return (double)adc;
++
+
+ //TODO: Fix this
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;
++ */
++
++ return Data_Calibrate((double)adc, high_raw, high_cal, sizeof(high_raw)/sizeof(double));
}
case PRES_LOW0:
++ // Not calibrated!
return (200.0 * (adc / ADC_RAW_MAX));
default:
Fatal("Unknown Pressure id %d", id);
//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);
++}
extern bool Pressure_Init(const char * name, int id);
extern bool Pressure_Cleanup(int id);
extern bool Pressure_Read(int id, double * value);
++extern bool Pressure_Sanity(int id, double value);
#endif //_PRESSURE_H
#include <pthread.h>
#define STRAIN_ADC ADC0
-#define STRAIN_GPIO 15
+ // TODO: Choose this
++#define STRAIN_GPIO 45
/**
* Convert Strain gauge id number to a GPIO pin on the Mux
switch (id)
{
case STRAIN0:
-- return GPIO0_30;
++ return 44;
case STRAIN1:
-- return GPIO1_28;
++ return 26;
case STRAIN2:
-- return GPIO0_31;
++ return 46;
case STRAIN3:
-- return GPIO1_16;
++ return 65;
default:
Fatal("Unknown StrainID %d", id);
return -1; // Should never happen