root/juggler/branches/2.2/modules/gadgeteer/test/IBoxTest.cpp

Revision 19729, 3.4 kB (checked in by patrick, 2 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
2  *
3  * VR Juggler is (C) Copyright 1998-2007 by Iowa State University
4  *
5  * Original Authors:
6  *   Allen Bierbaum, Christopher Just,
7  *   Patrick Hartling, Kevin Meinert,
8  *   Carolina Cruz-Neira, Albert Baker
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23  * Boston, MA 02111-1307, USA.
24  *
25  *************** <auto-copyright.pl END do not edit this line> ***************/
26
27 #include <iostream>
28 #include <iomanip>
29 #include <sys/types.h>
30 #include <drivers/Immersion/IBox/IBoxStandalone.h>
31
32 int main ()
33 {
34    std::string port("/dev/ttyS0");
35    //vpr::Uint32 baud(9600);
36    vpr::Uint32 baud(38400);
37
38    // Get configuration information
39    std::cerr << "-------- Immersion Interface Box Test program -------\n"
40       << "First we need some config info:\n"
41       << "NOTE: Sample values are in ()'s\n"
42       << "Enter 0 for defaults." << std::endl;
43    
44    /*
45    std::cout << "Enter serial port(/dev/ttyS0, /dev/ttyd0, com1): " << std::endl;
46    std::cin >> port;
47    std::cout << "Enter baud rate (9600): " << std::endl;
48    std::cin >> baud;
49
50    if ("0" == port)
51    {
52       port = "/dev/ttyS0";
53    }
54    if (0 == baud)
55    {
56       baud = 9600;
57    }
58    */
59
60    IBoxStandalone* ibox = new IBoxStandalone();
61
62    try
63    {
64       ibox->connect(port, baud);
65    }
66    catch (IBoxException& ex)
67    {
68       delete ibox;
69       ibox = NULL;
70       std::cout << ex.what() << std::endl;
71       exit(-1);
72    }
73    
74    vpr::ReturnStatus status(vpr::ReturnStatus::Succeed);
75    while (status.success())
76    {
77       try
78       {
79          ibox->sendCommand(0,4,0);
80          ibox->checkForPacket();
81
82          printf("\nBtns: %2X%2X%2X%2X, ",
83             ibox->getButtonData(3), ibox->getButtonData(2),
84             ibox->getButtonData(1), ibox->getButtonData(0));
85          /*
86          if (timer_flag) printf("Time: %4X, ", ibox.timer);
87          if (num_anlg) printf("A/D: ");
88          if (num_anlg > 4) printf("%3X%3X%3X%3X",
89             ibox->analog[7], ibox->analog[6],
90             ibox->analog[5], ibox->analog[4]);
91          if (num_anlg > 2) printf("%3X%3X",
92             ibox.analog[3], ibox.analog[2]);
93          if (num_anlg) printf("%3X%3X, ",
94             ibox.analog[1], ibox.analog[0]);
95          if (num_encd) printf("Enc: ");
96          if (num_encd > 3) printf("%5X%5X%5X",
97             ibox.encoder[5], ibox.encoder[4],
98             ibox.encoder[3]);
99          if (num_encd > 2) printf("%5X", ibox.encoder[2]);
100          if (num_encd) printf("%5X%5X",
101             ibox.encoder[1], ibox.encoder[0]);
102          */
103          if (ibox->getButtonData(1))
104          {
105             break;
106          }
107       }
108       catch (vpr::TimeoutException& ex)
109       {
110          std::cout << ex.what() << std::endl;
111          continue;
112       }
113
114
115    }
116    ibox->disconnect();
117    delete ibox;
118    ibox = NULL;
119 }
Note: See TracBrowser for help on using the browser.