3 char pin_dir = "/sys/class/gpio/gpio"; //move these
5 /** Sets a GPIO pin to the desired value
6 * @param value - the value (1 or 0) to write to the pin
7 * @param pin_num - the number of the pin (refer to electronics team)
10 //also need to export and set pin direction
12 void SetPin(int value, int pin_num) {
16 snprintf(pin_path, sizeof(pin_path), "%s%d%s", pin_dir, pin_num, "/value"); //create pin path
17 pin = open(pin_path, O_WRONLY);
18 if (pin < 0) perror("Failed to open pin");
20 strncpy(buffer, "1", ARRAY_SIZE(buffer) - 1);
23 strncpy(buffer, "0", ARRAY_SIZE(buffer) - 1);
25 int write = write(pin, buffer, strlen(buffer));
26 if (write < 0) perror ("Failed to write to pin");
30 //TODO: Be able to write to multiple PWM modules - easy to change
31 // but current unsure about how many PWM signals we need
34 * Set an Actuator value
35 * @param a - The Actuator
36 * @param value - The value to set
38 void Actuator_SetValue(Actuator * a, double value)
42 gettimeofday(&t, NULL);
44 DataPoint d = {TIMEVAL_DIFF(t, g_options.start_time), value};
47 case ACTUATOR_TEST0: //Pressure regulator example - requires PWM, 0-1000kPa input
49 if (pwm_active == 0) { //if inactive, start the pwm module
52 pwm_set_period(FREQ); //50Hz defined in pwm header file
54 if(value >= 0 && value <= 700) {
55 double duty = value/1000 * 100; //convert pressure to duty percentage
56 pwm_set_duty((int)duty); //set duty percentage for actuator
61 SetPin(value, 1); //Digital switch example - "1" is the pin number, to be specified by electronics team
65 Log(LOGDEBUG, "Actuator %s set to %f", g_actuator_names[a->id], value);
68 Data_Save(&(a->data_file), &d, 1);