-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledout_test.c
122 lines (110 loc) · 3.07 KB
/
ledout_test.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* vi: set sw=2 ts=2 tw=80: */
/******************************************************************************
* ledout_test.c
*
* Testprogram for Access Manager MIFARE LEDs, OUTPUTs and RESET button driver
*
* Copyright (C) 2011 KABA AG, CC EAC
*
* Distributed under the terms of the GNU General Public License
* This software may be used without warrany provided and
* copyright statements are left intact.
* Developer: Stefan Wyss - swyss@kbr.kaba.com
*
*****************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "ledout.h"
/*-----------------------------------------------------------------------------
* main program function
*---------------------------------------------------------------------------*/
int main(void)
{
unsigned int data;
int fd, ret, i;
char devname[20] = "/dev/ledout";
DRVMSG drvMsg;
printf("Simple LEDOUT driver test program\r\n");
// *** open the device node ***
fd = open((char *)devname,O_RDWR);
if(fd < 0) {
printf("Error opening %s\n",devname);
return -1;
}
// *** set LED's - disco time! ***
// Attention: Please note that signals out1..out3 are shared among LEDs
// and RELAIS. I.e. setting GREEN is the same as setting REL_ON on out1.
// Setting OFF is the same as setting REL_OFF on out1.
for (i=0; i<20; i++)
{
drvMsg.state =(i+OFF)%4;
drvMsg.out1 = (i+RED)%4;
drvMsg.out2 = (i+GREEN)%4;
drvMsg.out3 = (i+ORANGE)%4;
ret = ioctl(fd, IOCTL_LEDOUT_SET, &drvMsg);
if (ret != 0)
{
printf("ioctl IOCTL_LEDOUT_SET returned error 0x%X\n", ret);
return -1;
}
usleep(200000);
}
// *** get LED's state ***
ret = ioctl(fd, IOCTL_LEDOUT_GET, &drvMsg);
if (ret != 0)
{
printf("ioctl IOCTL_LEDOUT_GET returned error 0x%X\n", ret);
return -1;
}
if ( (drvMsg.state != ORANGE)||(drvMsg.out1 != OFF)||(drvMsg.out2 != RED)||(drvMsg.out3 != GREEN) )
{
printf("error: wrong LED return values:!\n");
printf("state=%d out1=%d out2=%d out3=%d (0=off/1=red/2=green/3=orange)\n",drvMsg.state,drvMsg.out1,drvMsg.out2,drvMsg.out3);
return -1;
}
printf("-> LED state test:\t\t\t[OK]\n");
// *** get reset button state ***
ret = ioctl(fd, IOCTL_LEDOUT_GET, &drvMsg);
if (ret != 0)
{
printf("ioctl IOCTL_LEDOUT_GET returned error 0x%X\n", ret);
return -1;
}
if (drvMsg.reset == RESET_ACTIVE)
{
printf("-> reset button test:\t\t\t[FAIL]\n");
return -1;
}
printf("Please press and hold the reset button!\n");
for (i=0; i<60; i++)
{
ret = ioctl(fd, IOCTL_LEDOUT_GET, &drvMsg);
if (ret != 0)
{
printf("ioctl IOCTL_LEDOUT_GET returned error 0x%X\n", ret);
return -1;
}
if (drvMsg.reset == RESET_ACTIVE)
{
printf("-> reset button test:\t\t\t[OK]\n");
break;
}
sleep(1);
}
// *** set RELAIS on ***
drvMsg.out1 = REL_ON;
drvMsg.out2 = REL_ON;
drvMsg.out3 = REL_ON;
ret = ioctl(fd, IOCTL_LEDOUT_SET, &drvMsg);
if (ret != 0)
{
printf("ioctl IOCTL_LEDOUT_SET returned error 0x%X\n", ret);
return -1;
}
close(fd);
return 0;
}