X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fsensors%2Fstrain.c;h=77a11a2a4c0d0a7547f92edfd9f42e64a044e7e8;hb=30ac3b06c92aace69ac4847d93db3dbf7b93df38;hp=3ee1624a867780452eaae8c0365e3c8c5d988503;hpb=c3a1f0d6a3c293a45ab9f24a63b43e3f5aa7bd15;p=matches%2FMCTX3420.git diff --git a/server/sensors/strain.c b/server/sensors/strain.c index 3ee1624..77a11a2 100644 --- a/server/sensors/strain.c +++ b/server/sensors/strain.c @@ -6,6 +6,8 @@ #include #define STRAIN_ADC ADC0 +// TODO: Choose this +#define STRAIN_GPIO 15 /** * Convert Strain gauge id number to a GPIO pin on the Mux @@ -33,7 +35,7 @@ static int Strain_To_GPIO(StrainID id) default: Fatal("Unknown StrainID %d", id); return -1; // Should never happen - } + } } /** @@ -59,15 +61,36 @@ bool Strain_Init(const char * name, int id) if (!GPIO_Set(gpio_num, false)) Fatal("Couldn't set GPIO%d for strain sensor %d to LOW", gpio_num, id); - static bool init_adc = false; - if (!init_adc) + static int init = 0; + if (++init == 1) { - init_adc = true; + GPIO_Export(STRAIN_GPIO); + GPIO_Set(STRAIN_GPIO, true); ADC_Export(STRAIN_ADC); } return true; } +bool Strain_Cleanup(int id) +{ + static int killed = 0; + if (++killed == 4) + { + + GPIO_Set(STRAIN_GPIO, false); + ADC_Unexport(STRAIN_ADC); + } + + int gpio_num = Strain_To_GPIO(id); + GPIO_Unexport(gpio_num); + return true; +} + +bool Strain_Sanity(int id, double value) +{ + return true; +} + /** * Read from a Strain gauge * @param id - The strain gauge to read