Merge branch 'master' of https://github.com/szmoore/MCTX3420
[matches/MCTX3420.git] / server / sensors / strain.c
index 4278d6c..77a11a2 100644 (file)
@@ -6,6 +6,8 @@
 #include <pthread.h>
 
 #define STRAIN_ADC ADC0
+// TODO: Choose this
+#define STRAIN_GPIO 15
 
 /**
  * Convert Strain gauge id number to a GPIO pin on the Mux
@@ -59,10 +61,11 @@ 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;
@@ -70,12 +73,14 @@ bool Strain_Init(const char * name, int id)
 
 bool Strain_Cleanup(int id)
 {
-       static bool kill_adc = false;
-       if (!kill_adc)
+       static int killed = 0;
+       if (++killed == 4)
        {
-               kill_adc = true;
+
+               GPIO_Set(STRAIN_GPIO, false);
                ADC_Unexport(STRAIN_ADC);
        }
+
        int gpio_num = Strain_To_GPIO(id);
        GPIO_Unexport(gpio_num);
        return true;

UCC git Repository :: git.ucc.asn.au