ViSP  2.8.0
vpRingLight.cpp
1 /****************************************************************************
2  *
3  * $Id: vpRingLight.cpp 4317 2013-07-17 09:40:17Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Ring light management.
36  *
37  * Authors:
38  * Fabien Spindler
39  *
40  *****************************************************************************/
41 
42 
43 # include <visp/vpConfig.h>
44 
45 #ifdef VISP_HAVE_PARPORT
46 
47 # include <sys/types.h>
48 # include <sys/stat.h>
49 # include <fcntl.h>
50 # include <sys/ioctl.h>
51 # include <sys/time.h>
52 # include <unistd.h>
53 
54 # include <visp/vpRingLight.h>
55 # include <visp/vpDebug.h>
56 # include <visp/vpTime.h>
57 
78 {
79  off();
80 }
81 
91 {
92  off();
93 }
94 
103 {
104  // Data set by the parallel port:
105  // - D1: need to send a 500us pulse width
106  // - D2: 0 }
107  // - D3: 0 } To control the light throw the NE555
108  // D2 and D3 are used to select the multiplexer output.
109  // Light must be connected to output 1+,1-
110 
111  // To activates the light we send a pulse
112  int mask_mode_pulse_d2 = 0x00; // D2 is low
113  int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
114  unsigned char data = 0x00;
115  // data = parport.getData(); // actual value of the data bus
116  // vpTRACE("Actual data 0x%x = %d\n", data, data);
117 
118  data = data | mask_pulse_d1 | mask_mode_pulse_d2;
119  //vpTRACE("Send 0x%x = %d\n", data, data);
120  parport.sendData(data); // send a 0-1 pulse
121 
122  // Wait 500 micro seconds
123  struct timeval ti, tc; // Initial and current time
124  struct timeval tempo;
125  tempo.tv_usec = 500;
126  gettimeofday(&ti,0L);
127  do {
128  gettimeofday(&tc,0L);
129  } while (tc.tv_usec < ti.tv_usec + tempo.tv_usec);
130 
131  data = data & (~mask_pulse_d1);
132  //vpTRACE("Send 0x%x = %d\n", data, data);
133  parport.sendData(data); // send a 1-0 pulse
134 }
135 
145 void vpRingLight::pulse(double time)
146 {
147  // Data set by the parallel port:
148  // - D1: a pulse with duration fixed by time
149  // - D2: 0 }
150  // - D3: 1 } To control the light directly throw the pulse comming from D1
151  // D2 and D3 are used to select the multiplexer output.
152  // Light must be connected to output 1+,1-
153 
154  // To activates the light we send a pulse
155  int mask_mode_pulse_d3 = 0x08; // D3 is hight, D2 is low
156  int mask_pulse_d1 = 0x02; // we send a pulse on D1 : L, H, L
157  unsigned char data = 0x00;
158  // data = parport.getData(); // actual value of the data bus
159  // vpTRACE("Actual data 0x%x = %d\n", data, data);
160 
161  data = data | mask_pulse_d1 | mask_mode_pulse_d3;
162  //vpTRACE("Send 0x%x = %d\n", data, data);
163  parport.sendData(data); // send a 0-1 pulse
164 
165  // Wait 500 micro seconds
166  struct timeval ti, tc; // Initial and current time
167  gettimeofday(&ti,0);
168  do {
169  gettimeofday(&tc,0);
170  } while (tc.tv_usec < ti.tv_usec + time*1000);
171 
172  data = data & (~mask_pulse_d1);
173  //vpTRACE("Send 0x%x = %d\n", data, data);
174  parport.sendData(data); // send a 1-0 pulse
175 }
176 
184 {
185  // Data set by the parallel port:
186  // - D1: 0 to turn OFF, 1 to turn ON
187  // - D2: 1 }
188  // - D3: 0 } To control the light throw D1
189  // D2 and D3 are used to select the multiplexer output.
190  // Light must be connected to output 1+,1-
191 
192  // To activates the light we send a pulse
193  int mask_mode_onoff_d2 = 0x04; // D2 is Hight
194  int mask_on_d1 = 0x02; // D1 is Hight to turn the light on
195  unsigned char data = 0x00;
196  //data = parport.getData(); // actual value of the data bus
197 
198  data = data | mask_on_d1 | mask_mode_onoff_d2;
199  //vpTRACE("Send 0x%x = %d\n", data, data);
200  parport.sendData(data);
201 }
202 
210 {
211  // Data set by the parallel port:
212  // - D1: 0 to turn OFF, 1 to turn ON
213  // - D2: 1 }
214  // - D3: 0 } To control the light throw D1
215  // D2 and D3 are used to select the multiplexer output.
216  // Light must be connected to output 1+,1-
217 
218  // To activates the light we send a pulse
219  int mask_mode_onoff_d2 = 0x04; // D2 is Hight
220  int mask_off_d1 = 0x00; // D1 is Low to turn the light off
221  unsigned char data = 0x00;
222  //data = parport.getData(); // actual value of the data bus
223 
224  data = data | mask_off_d1 | mask_mode_onoff_d2;
225  //vpTRACE("Send 0x%x = %d\n", data, data);
226  parport.sendData(data);
227 }
228 
229 #endif
void sendData(unsigned char &data)