X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fsensors%2Fstrain.c;h=7c78b565649e32efc97e6dada93e47114598acd8;hb=0654fb285c91da103314610cd4f27295e3da38f3;hp=4278d6c27cdaf2848606f3a1e581f76051adb9fa;hpb=edb6df04611c10dca29799a1e08096bd4ca28303;p=matches%2FMCTX3420.git diff --git a/server/sensors/strain.c b/server/sensors/strain.c index 4278d6c..7c78b56 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 45 /** * Convert Strain gauge id number to a GPIO pin on the Mux @@ -23,13 +25,13 @@ 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,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;