1
- // BEWARE, this file is expluded from Linux compilation
2
- // because the of the missing nuttx header file
1
+ /* WARNING: This file is expluded from Linux compilation because the of the missing NuttX header file */
3
2
4
3
#include "gpio_actuator.h"
4
+ #include "actuator.h"
5
5
#include "stdio.h"
6
6
#include <errno.h>
7
7
#include <fcntl.h>
8
8
#include <nuttx/ioexpander/gpio.h>
9
9
#include <sys/ioctl.h>
10
10
#include <unistd.h>
11
11
12
- int gpio_actuator_on (actuator_t * act ) {
13
- // TODO: change the device to be actuator specific
14
- int fd = open ("/dev/gpio12" , O_RDWR );
12
+ /*
13
+ * Turn on a GPIO actuator.
14
+ * @param act The actuator to turn on.
15
+ * @return 0 on success, an error code on failure.
16
+ */
17
+ static int gpio_actuator_on (actuator_t * act ) {
18
+ int fd = open ((char * )act -> priv , O_RDWR );
15
19
if (fd < 0 ) {
16
- fprintf (stderr , "Failed to open gpio with err %d\n" , errno );
20
+ fprintf (stderr , "Failed to open gpio '%s' with err %d\n" , ( char * ) act -> priv , errno );
17
21
return -1 ;
18
22
}
19
23
@@ -32,11 +36,16 @@ int gpio_actuator_on(actuator_t *act) {
32
36
return 0 ;
33
37
}
34
38
35
- int gpio_actuator_off (actuator_t * act ) {
36
- // TODO: change the device to be actuator specific
37
- int fd = open ("/dev/gpio12" , O_RDWR );
39
+ /*
40
+ * Turn off a GPIO actuator.
41
+ * @param act The actuator to turn off.
42
+ * @return 0 on success, an error code on failure.
43
+ */
44
+ static int gpio_actuator_off (actuator_t * act ) {
45
+
46
+ int fd = open ((char * )act -> priv , O_RDWR );
38
47
if (fd < 0 ) {
39
- fprintf (stderr , "Failed to open gpio with err %d\n" , errno );
48
+ fprintf (stderr , "Failed to open gpio '%s' with err %d\n" , ( char * ) act -> priv , errno );
40
49
return -1 ;
41
50
}
42
51
@@ -54,3 +63,13 @@ int gpio_actuator_off(actuator_t *act) {
54
63
fprintf (stdout , "Actuator #%d turned off\n" , act -> id );
55
64
return 0 ;
56
65
}
66
+
67
+ /*
68
+ * Initialize a GPIO actuator.
69
+ * @param act The actuator structure to initialize.
70
+ * @param id The actuator ID
71
+ * @param dev The path to the GPIO character device
72
+ */
73
+ void gpio_actuator_init (actuator_t * act , uint8_t id , const char * dev ) {
74
+ actuator_init (act , id , gpio_actuator_on , gpio_actuator_off , (char * )dev );
75
+ }
0 commit comments