forked from andreynech/rtdm-pwm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxeno-pwm-app.c
54 lines (44 loc) · 1.11 KB
/
xeno-pwm-app.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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <rtdm/rtdm.h>
#define DEVICE_NAME "gpio-pwm"
int
main(int argc, char *argv)
{
char buf[64];
int c;
ssize_t bufsize = sizeof(buf);
ssize_t size;
int device;
int ret;
// open the device
device = rt_dev_open(DEVICE_NAME, 0);
if (device < 0)
{
printf("ERROR : can't open device %s (%s)\n",
DEVICE_NAME, strerror(-device));
return 1;
}
for(c = 0; c <= 100; c += 10)
{
size = sprintf(buf, "%u", c);
size = rt_dev_write (device, (const void*)buf, size);
printf("Write to device %s\t: %d bytes - %s\n", DEVICE_NAME, size, buf);
sleep(1);
memset(buf, 0, bufsize);
size = rt_dev_read (device, (void*)&buf, bufsize);
printf("Read from device %s\t: %d bytes - %s\n", DEVICE_NAME, size, buf);
}
size = sprintf(buf, "50");
size = rt_dev_write (device, (const void*)buf, size);
// close the device
ret = rt_dev_close(device);
if (ret < 0)
{
printf("ERROR : can't close device %s (%s)\n",
DEVICE_NAME, strerror(-ret));
return 2;
}
return 0;
}