#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <ctype.h>
#include "options.h"
/**
/**
* Unexport a GPIO pin and close its' file descriptors
+ * @param pin The GPIO number to be unexported
*/
void GPIO_Unexport(int pin)
{
return true;
}
- sprintf(g_buffer, "%s/in_voltage%d_raw", g_options.adc_device_path, pin);
+ sprintf(g_buffer, "%s/in_voltage%d_raw", ADC_DEVICE_PATH, pin);
g_adc[pin].fd_value = open(g_buffer, O_RDONLY);
if (g_adc[pin].fd_value <0)
{
}
GPIO_Pin *gpio = &g_gpio[g_pin_gpio_to_index[pin]];
+ if (!gpio->initialised)
+ {
+ AbortBool("GPIO %d is not initialised.", pin);
+ }
if (pwrite(gpio->fd_direction, "in", 2, 0) != 2)
- AbortBool("Couldn't set GPIO %d direction - %s", pin, strerror(errno));
+ {
+ AbortBool("Couldn't set GPIO %d direction - %s", pin, strerror(errno));
+ }
char c = '0';
if (pread(gpio->fd_value, &c, 1, 0) != 1)
+ {
AbortBool("Couldn't read GPIO %d value - %s", pin, strerror(errno));
+ }
*result = (c == '1');
return true;
// Have to stop PWM before changing it
if (pwrite(pwm->fd_run, "0", 1, 0) != 1)
{
- AbortBool("Couldn't stop PWM%d - %s", pin, strerror(errno));
+ AbortBool("Couldn't stop PWM %d - %s", pin, strerror(errno));
}
char c = polarity ? '1' : '0';
if (pwrite(pwm->fd_polarity, &c, 1, 0) != 1)
{
- AbortBool("Couldn't set PWM%d polarity - %s", pin, strerror(errno));
+ AbortBool("Couldn't set PWM %d polarity - %s", pin, strerror(errno));
}
//This must be done first, otherwise period/duty settings can conflict
if (fwrite("0", 1, 1, pwm->file_duty) < 1)
{
- AbortBool("Couldn't zero the duty for PWM%d - %s", pin, strerror(errno));
+ AbortBool("Couldn't zero the duty for PWM %d - %s", pin, strerror(errno));
}
if (fprintf(pwm->file_period, "%lu", period) < 0)
{
- AbortBool("Couldn't set period for PWM%d - %s", pin, strerror(errno));
+ AbortBool("Couldn't set period for PWM %d - %s", pin, strerror(errno));
}
if (fprintf(pwm->file_duty, "%lu", duty) < 0)
{
- AbortBool("Couldn't set duty cycle for PWM%d - %s", pin, strerror(errno));
+ AbortBool("Couldn't set duty cycle for PWM %d - %s", pin, strerror(errno));
}
if (pwrite(pwm->fd_run, "1", 1, 0) != 1)
{
- AbortBool("Couldn't start PWM%d - %s", pin, strerror(errno));
+ AbortBool("Couldn't start PWM %d - %s", pin, strerror(errno));
}
return true;
/**
* Deactivate a PWM pin
* @param pin - The syfs pin number
+ * @return true on success, false otherwise
*/
-void PWM_Stop(int pin)
+bool PWM_Stop(int pin)
{
if (pin < 0 || pin >= PWM_NUM_PINS)
{
- Abort("Invalid PWM pin number %d specified.", pin);
+ AbortBool("Invalid PWM pin number %d specified.", pin);
+ }
+ else if (!g_pwm[pin].initialised)
+ {
+ AbortBool("PWM %d is not initialised.", pin);
}
if (pwrite(g_pwm[pin].fd_run, "0", 1, 0) != 1)
{
- Abort("Couldn't stop PWM %d - %s", pin, strerror(errno));
+ AbortBool("Couldn't stop PWM %d - %s", pin, strerror(errno));
}
+
+ return true;
}
/**
{
AbortBool("ADC %d read failed: %s", id, strerror(errno));
}
+
*value = strtol(adc_str, NULL, 10);
return true;
-}
\ No newline at end of file
+}
+
+#ifndef _BBB
+//For running on systems that are not the BBB
+bool True_Stub(void *arg, ...) { return true; }
+bool ADC_Read_Stub(int *val, ...) { *val = 0; return true; }
+bool GPIO_Read_Stub(bool *val, ...) { *val = false; return true; }
+#endif