-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathioControl.cpp
More file actions
78 lines (65 loc) · 1.53 KB
/
ioControl.cpp
File metadata and controls
78 lines (65 loc) · 1.53 KB
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
#include "37e12reqs.h"
#include "ioControl.h"
//Optical ISO Outs
void optoIsoControl::setOutput(isodata data)
{
int fd;
OPENDEV(fd,robotConstants::devPath);
ioctl(fd, ISO_DIG_OUT, &data);
close(fd);
}
void optoIsoControl::readInput(isodata * data)
{
int fd;
OPENDEV(fd,robotConstants::devPath);
ioctl(fd, ISO_DIG_IN, data);
close(fd);
}
//For the 8-bit mask: 1 = output, 0 = input
void gpioControl::configIO(int port, unsigned char mask)
{
int fd;
OPENDEV(fd, robotConstants::devPath);
if((port > 1) || (port < 0))
{
printf("invalid port");
}
E12_Digital_Cfg(fd, mask, port);
close(fd);
}
void gpioControl::writePort(int port, unsigned char data)
{
int fd;
OPENDEV(fd, robotConstants::devPath);
if((port > 1) || (port < 0))
{
printf("invalid port");
}
E12_Digitalout(fd, data, port);
close(fd);
}
void gpioControl::readPort(int port, unsigned char data)
{
int fd = 0, rxnum;
E12_Digital_Req(fd);
__u8 buffer[100];
__u32 typemask = 0;
Cop_Data *Cop = CopDeviceCreate(0);
while(!(typemask&DIGRESPONSE))
{
rxnum = read(fd, buffer, sizeof(buffer));
typemask = E12_Packet_Route(Cop, buffer, rxnum);
}
data = Cop->Digital[port];
CopDeviceDestroy(Cop);
}
//PWM
void pwmControl::setPWM(int lineNumber, int dutyCycle)
{
int fd;
Cop_Data *Cop = CopDeviceCreate(0);
OPENDEV(fd,robotConstants::devPath);
E12_PWMControl(fd, lineNumber, gpioConstants::FREQUENCY, dutyCycle, Cop);
close(fd);
CopDeviceDestroy(Cop);
}