Merge branch 'master' of github:szmoore/MCTX3420 into report
[matches/MCTX3420.git] / server / sensors / strain.c
index 3ee1624..7c78b56 100644 (file)
@@ -6,6 +6,8 @@
 #include <pthread.h>
 
 #define STRAIN_ADC ADC0
+// TODO: Choose this
+#define STRAIN_GPIO 45
 
 /**
  * Convert Strain gauge id number to a GPIO pin on the Mux
@@ -23,17 +25,17 @@ static int Strain_To_GPIO(StrainID id)
        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
-       }
+  }
 }
 
 /**
@@ -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

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