4 void Actuator_SetValue(Actuator * a, double value)
8 gettimeofday(&t, NULL);
10 DataPoint d = {TIMEVAL_DIFF(t, g_options.start_time), value};
13 case ACTUATOR_TEST0: //LED actuator test code, should blink onboard LED next to Ethernet port
14 FILE *LEDHandle = NULL; //code reference: http://learnbuildshare.wordpress.com/2013/05/19/beaglebone-black-controlling-user-leds-using-c/
15 char *LEDBrightness = "/sys/class/leds/beaglebone\:green\:usr0/brightness";
17 if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL) {
18 fwrite("1", sizeof(char), 1, LEDHandle);
22 if((LEDHandle = fopen(LEDBrightness, "r+")) != NULL) {
23 fwrite("0", sizeof(char), 1, LEDHandle);
26 else perror("Pin value should be 1 or 0");
29 // Quick actuator function for testing pins
30 // GPIOPin can be either passed as an argument, or defined here (as pins won't change)
31 // First way is better and more generalised
33 // Modify this to only export on first run, unexport on shutdown
34 pinExport(setValue, GPIOString);
35 pinDirection(GPIODirection, setValue);
36 pinSet(value, GPIOValue, setValue);
37 pinUnexport(setValue, GPIOString);
40 if (pwminit == 0) { //if inactive, start the pwm module
45 pwm_set_period(FREQ); //50Hz defined in pwm header file
47 if(value >= 0 && value <= 1000) {
48 double duty = value/1000 * 100; //convert pressure to duty percentage
49 pwm_set_duty((int)duty); //set duty percentage for actuator
52 Log(LOGDEBUG, "Actuator %s set to %f", g_actuator_names[a->id], value);
54 Data_Save(&(a->data_file), &d, 1);