#include "options.h"
// Files containing GPIO and PWM definitions
#include "gpio.h"
-#include "pwm.h"
+
/** Array of Actuators (global to this file) initialised by Actuator_Init **/
static Actuator g_actuators[NUMACTUATORS];
{
// Quick actuator function for testing pins
// GPIOPin can be passed as argument, but is just defined here for testing purposes
- int GPIOPin = 13;
// Modify this to only export on first run, only unexport on shutdown
- pinExport(setValue, GPIOString);
- pinDirection(GPIODirection, setValue);
- pinSet(value, GPIOValue, setValue);
- pinUnexport(setValue, GPIOString);
+ pinExport(60);
+ pinDirection(60, 1);
+ pinSet(value, 60);
+ pinUnexport(60);
}
break;
case ACTUATOR_TEST2:
// PWM analogue actuator (currently generates one PWM signal with first PWM module)
+ /*
{
if (pwminit == 0) { // If inactive, start the pwm module
pwm_init();
pwm_set_duty((int)duty); // Set duty percentage for actuator (0-100%)
}
}
+ */
break;
}
#include "gpio.h"
void pinExport(int GPIOPin) {
- FILE *myOutputHandle = NULL;
+
char GPIOString[4];
char setValue[4];
sprintf(GPIOString, "%d", GPIOPin);
- if ((myOutputHandle = fopen(exportPath, "ab")) == NULL){
+
+ FILE * myOutputHandle = fopen(exportPath, "ab");
+ if (myOutputHandle == NULL)
+ {
Log(LOGERR, "Unable to export GPIO pin %f\n", GPIOPin);
}
strcpy(setValue, GPIOString);
if ((myOutputHandle = fopen(GPIODirection, "rb+")) == NULL){
Log(LOGERR, "Unable to open direction handle for pin %f\n", GPIOPin);
}
- if (io == 1) {
+ if (io == 1)
+ {
strcpy(setValue,"out");
fwrite(&setValue, sizeof(char), 3, myOutputHandle);
- else if (io == 0) {
+ }
+ else if (io == 0)
+ {
strcpy(setValue,"in");
fwrite(&setValue, sizeof(char), 2, myOutputHandle);
+ }
else Log(LOGERR, "GPIO direction must be 1 or 0\n");
fclose(myOutputHandle);
}
snprintf(adc_path, sizeof(adc_path), "%s%d", ADCPath, adc_num); // Construct ADC path
int sensor = open(adc_path, O_RDONLY);
char buffer[64]; // I think ADCs are only 12 bits (0-4096), buffer can probably be smaller
- int read = read(sensor, buffer, sizeof(buffer);
- if (read != -1) {
- buffer[read] = NULL;
+ int r = read(sensor, buffer, sizeof(buffer));
+ if (r != -1) {
+ buffer[r] = '\0';
int value = atoi(buffer);
double convert = (value/4096) * 1000; // Random conversion factor, will be different for each sensor (get from datasheets)
// lseek(sensor, 0, 0); (I think this is uneeded as we are reopening the file on each sensor read; if sensor is read continously we'll need this
snprintf(GPIOValue, sizeof(GPIOValue), "%s%d%s", valuePath, GPIOPin, "/value"); //construct pin path
int pin = open(GPIOValue, O_RDONLY);
char ch;
- lseek(fd, 0, SEEK_SET);
- int read = read(pin, &ch, sizeof(ch);
- if (read != -1) {
+ lseek(pin, 0, SEEK_SET);
+ int r = read(pin, &ch, sizeof(ch));
+ if (r != -1)
+ {
if (ch != '0') {
close(pin);
return 1;
close(pin);
return 0;
}
- else {
+ }
+ else
+ {
Log(LOGERR, "Failed to get value from pin %f\n", GPIOPin);
close(pin);
return -1;
strcpy(setValue, GPIOString);
fwrite(&setValue, sizeof(char), 2, myOutputHandle);
fclose(myOutputHandle);
-}
\ No newline at end of file
+}
#include <sched.h>
#include <stdint.h>
-#define exportPath "/sys/class/gpio/export";
-#define unexportPath "/sys/class/gpio/unexport";
-#define valuePath "/sys/class/gpio/gpio";
-#define directionPath "/sys/class/gpio/gpio";
-#define ADCPath "/sys/devices/platform/tsc/ain";
+#include "common.h"
+
+#define exportPath "/sys/class/gpio/export"
+#define unexportPath "/sys/class/gpio/unexport"
+#define valuePath "/sys/class/gpio/gpio"
+#define directionPath "/sys/class/gpio/gpio"
+#define ADCPath "/sys/devices/platform/tsc/ain"
void pinExport(int GPIOPin);
void pinDirection(int GPIOPin, int io);
void pinSet(double value, int GPIOPin);
void pinUnexport(int GPIOPin);
int pinRead(int GPIOPin);
-int ADCRead(int adc_num);
\ No newline at end of file
+int ADCRead(int adc_num);
}
case ANALOG_REALTEST:
{
- d->value = ADCRead(0); //ADC #0 on the Beaglebone
+ //d->value = ADCRead(0); //ADC #0 on the Beaglebone
break;
}
case ANALOG_FAIL0:
- d->value = (double)(rand() % 6) * -( rand() % 2) / ( rand() % 100 + 1);
+ d->value = 250;
+ //d->value = (double)(rand() % 6) * -( rand() % 2) / ( rand() % 100 + 1);
//Gives a value between -5 and 5
break;
case DIGITAL_TEST0:
{
// Can pass pin as argument, just using 20 as an example here
// Although since pins will be fixed, can just define it here if we need to
- d->value = pinRead(20); //Pin 20 on the Beaglebone
+ //d->value = pinRead(20); //Pin 20 on the Beaglebone
break;
}
case DIGITAL_FAIL0: