-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpiotest.c
84 lines (79 loc) · 1.72 KB
/
gpiotest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <signal.h>
#include "gpiodev.h"
volatile sig_atomic_t done = 0;
void sig_handler(int sig)
{
done = 1;
}
int main()
{
signal(SIGINT, &sig_handler); // set up signal handler
char c = '\0';
int _idx = 1, idx = 976;
if (gpiodev_pinout == PINOUT_RPI)
{
idx = 13;
_idx = 13;
}
else if (gpiodev_pinout == PINOUT_AD9361)
{
idx = 976;
_idx = 1;
}
else if (gpiodev_pinout == PINOUT_AD9364)
{
idx = 960;
_idx = 0;
}
gpioSetMode(_idx, GPIO_OUT);
while (!done)
{
switch (c)
{
case 's':
case 'S':
printf("Enter GPIO pin number: ");
while (scanf(" %d", &idx) < 0);
if (gpiodev_pinout == PINOUT_RPI)
{
_idx = idx;
}
else if (gpiodev_pinout == PINOUT_AD9361)
{
_idx = idx - 976;
}
else if (gpiodev_pinout == PINOUT_AD9364)
{
_idx = idx - 960;
}
gpioSetMode(_idx, GPIO_OUT);
c = '\0';
break;
case 'h':
case 'H':
gpioWrite(_idx, GPIO_HIGH);
c = '\0';
break;
case 'l':
case 'L':
gpioWrite(_idx, GPIO_LOW);
c = '\0';
break;
case 'q':
case 'Q':
done = 1;
continue;
break;
case '\n':
c = '\0';
continue;
break;
default:
printf("GPIO: %d, [s]elect GPIO, toggle [h]igh, toggle [l]ow, [q]uit: ", idx);
break;
}
c = getchar();
}
return 0;
}