X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fpin_test.c;h=8640a60df6c69999cbc49ea9c4ecf09649568872;hb=27ff700c938e48bd88ca63575d65575150d9e842;hp=90ae6261be2d49ddaf902de88f9cf6f568203595;hpb=b53d860c11d5a56b1fe929581f5c5a537b4cba91;p=matches%2FMCTX3420.git diff --git a/server/pin_test.c b/server/pin_test.c index 90ae626..8640a60 100644 --- a/server/pin_test.c +++ b/server/pin_test.c @@ -1,6 +1,6 @@ /** * @file pin_test.c - * @purpose Implementations to allow direct control over pins through FastCGI + * @brief Implementations to allow direct control over pins through FastCGI */ #include "pin_test.h" @@ -27,18 +27,23 @@ void Pin_Close() ADC_Unexport(i); for (int i = 0; i < PWM_NUM_PINS; ++i) - PWM_Unexport(g_pin_safe_pwm[i]); + PWM_Unexport(i); } +/** + * Configures a pin (Export/Unexport business) + * @param type The pin type (GPIO/PWM/ADC) + * @param pin_export Whether to export/unexport/leave-as-is the pin + * @param num The pin number + */ bool Pin_Configure(const char *type, int pin_export, int num) { bool ret = true; if (strcmp(type, "gpo") == 0 || strcmp(type, "gpi") == 0) { - if (pin_export < 0) - GPIO_Unexport(num); - else + //Don't allow unexport of gpio + if (pin_export > 0) ret = GPIO_Export(num); } else if (strcmp(type, "pwm") == 0) @@ -50,9 +55,8 @@ bool Pin_Configure(const char *type, int pin_export, int num) } else if (strcmp(type, "adc") == 0) { - if (pin_export < 0) - ADC_Unexport(num); - else + //Don't allow unexport of adc + if (pin_export > 0) ret = ADC_Export(num); } return ret; @@ -120,7 +124,7 @@ void Pin_Handler(FCGIContext *context, char * params) if (strcmp(type, "gpo") == 0) { - if (num <= 0 || num > GPIO_NUM_PINS) + if (num <= 0 || num > GPIO_MAX_NUMBER) { FCGI_RejectJSON(context, "Invalid GPIO pin"); return; @@ -139,7 +143,7 @@ void Pin_Handler(FCGIContext *context, char * params) } else if (strcmp(type, "gpi") == 0) { - if (num < 0 || num >= GPIO_NUM_PINS) + if (num < 0 || num > GPIO_MAX_NUMBER) { FCGI_RejectJSON(context, "Invalid GPIO pin"); return; @@ -172,12 +176,12 @@ void Pin_Handler(FCGIContext *context, char * params) else { FCGI_PrintRaw("Content-type: text/plain\r\n\r\n"); - FCGI_PrintRaw("ADC%d reads %d\n", num, raw_adc); + FCGI_PrintRaw("%d\n", raw_adc); } } else if (strcmp(type, "pwm") == 0) { - if (num < 0 || num >= PWM_NUM_SAFE_PINS) + if (num < 0 || num >= PWM_NUM_PINS) { FCGI_RejectJSON(context, "Invalid PWM pin"); return; @@ -203,7 +207,7 @@ void Pin_Handler(FCGIContext *context, char * params) else { Log(LOGDEBUG, "Stopping PWM%d",num); - PWM_Stop(g_pin_safe_pwm[num]); + PWM_Stop(num); FCGI_PrintRaw("Content-type: text/plain\r\n\r\n"); FCGI_PrintRaw("PWM%d stopped",num); } @@ -214,4 +218,4 @@ void Pin_Handler(FCGIContext *context, char * params) FCGI_RejectJSON(context, "Invalid pin type"); } -} \ No newline at end of file +}