X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=server%2Fpin_test.c;h=2db079d86ab7392454ca4d292a1e94bdd8c45e44;hb=ab00d4e4fdd18f65ec9a73725b72d16f5bcc28b9;hp=9e3ad23d25913189e4d14c8423c6c5f979b8065d;hpb=10a0d0813cab99327bcb7f7fcb0008c783cfc685;p=matches%2FMCTX3420.git diff --git a/server/pin_test.c b/server/pin_test.c index 9e3ad23..2db079d 100644 --- a/server/pin_test.c +++ b/server/pin_test.c @@ -12,15 +12,16 @@ */ void Pin_Init() { - for (int i = 0; i < GPIO_NUM_PINS; ++i) + //Don't export anything; make the user do it. + /*for (int i = 0; i < GPIO_NUM_PINS; ++i) GPIO_Export(g_index_to_gpio[i]); for (int i = 0; i < ADC_NUM_PINS; ++i) ADC_Export(i); //Only export 'safe' PWM pins that don't interfere with one another - for (int i = 0; i < PWM_NUM_PINS; ++i) - PWM_Export(g_pin_safe_pwm[i]); + for (int i = 0; i < PWM_NUM_SAFE_PINS; ++i) + PWM_Export(g_pin_safe_pwm[i]);*/ } /** @@ -29,7 +30,7 @@ void Pin_Init() void Pin_Close() { for (int i = 0; i < GPIO_NUM_PINS; ++i) - GPIO_Unexport(g_index_to_gpio[i]); + GPIO_Unexport(g_pin_index_to_gpio[i]); for (int i = 0; i < ADC_NUM_PINS; ++i) ADC_Unexport(i); @@ -106,7 +107,11 @@ void Pin_Handler(FCGIContext *context, char * params) } Log(LOGDEBUG, "Reading GPIO%d", num); FCGI_PrintRaw("Content-type: text/plain\r\n\r\n"); - FCGI_PrintRaw("GPIO%d reads %d\n", num, GPIO_Read(num)); + bool ret; + if (!GPIO_Read(num, &ret)) + FCGI_PrintRaw("GPIO%d read failed. Is it exported?", num); + else + FCGI_PrintRaw("GPIO%d reads %d\n", num, ret); } else if (strcmp(type, "adc") == 0) @@ -118,7 +123,15 @@ void Pin_Handler(FCGIContext *context, char * params) } Log(LOGDEBUG, "Reading ADC%d", num, set); FCGI_PrintRaw("Content-type: text/plain\r\n\r\n"); - FCGI_PrintRaw("ADC%d reads %d\n", num, ADC_Read(num)); + int raw_adc; + if (!ADC_Read(num, &raw_adc)) + { + FCGI_PrintRaw("ADC%d read failed. Is it initialised?", num); + } + else + { + FCGI_PrintRaw("ADC%d reads %d\n", num, raw_adc); + } } else if (strcmp(type, "pwm") == 0) { @@ -153,8 +166,4 @@ void Pin_Handler(FCGIContext *context, char * params) FCGI_RejectJSON(context, "Invalid pin type"); } - - -} - -//EOF +} \ No newline at end of file