vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fsPinchGlove.h
Go to the documentation of this file.
1 /***************************************************************************
2  fspinchglove.h - description
3  -------------------
4  begin : Mon Jun 3 2002
5  copyright : (C) 2002 by Jan Flasar
6  email : flasar@fi.muni.cz
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef FSPINCHGLOVE_H
19 #define FSPINCHGLOVE_H
20 
21 #include <map>
22 #include <iostream>
23 
24 #if defined(WIN32)
25 #include <windows.h>
26 #endif
27 
28 #include <vrecko/Device.h>
29 #include <vrecko/IOPins.h>
30 
31 namespace vreckoDP_base {
32 
33 
34 #define STARTBYTE (char)0x80 /* Start - hand data only */
35 #define STARTTBYTE (char)0x81 /* Start - hand data & Time stamps */
36 #define STARTXBYTE (char)0x82 /* Start - text or ACK */
37 #define ENDBYTE (char)0x8F /* End of a message */
38 
39 #define CONNECTBYTE (char)0x87 /* Opent the connection */
40 #define CLOSEBYTE (char)0x88 /* Close the connection */
41 #define DEF_PGI_PORT 6666 /* Default TCP port */
42 #define DEF_PGI_SERIAL "/dev/ttyS1" /* Default serial port */
43 
44 #define PGI_MAX_PACKET_LEN 14
45 
46 /* gesture masks */
47 /*#define L_THUMB (int)0x1000
48 #define L_INDEX (int)0x0800
49 #define L_MIDDLE (int)0x0400
50 #define L_RING (int)0x0200
51 #define L_PINKIE (int)0x0100*/
52 
53 #define L_THUMB (int)0x0010
54 #define L_INDEX (int)0x0008
55 #define L_MIDDLE (int)0x0004
56 #define L_RING (int)0x0002
57 #define L_PINKIE (int)0x0001
58 
59 #define R_THUMB (int)0x0010
60 #define R_INDEX (int)0x0008
61 #define R_MIDDLE (int)0x0004
62 #define R_RING (int)0x0002
63 #define R_PINKIE (int)0x0001
64 
65 #define OK 1
66 #define ERR -1
67 #define YES 1
68 #define NO 0
69 
70 #define if_ok( param ) if( ( param ) == OK )
71 #define if_notok( param) if( ( param ) != OK )
72 #define if_err( param ) if( ( param ) < 0 )
73 #define if_null( param ) if( ( param ) == NULL )
74 #define if_nonull( param ) if( ( param ) != NULL )
75 
76 typedef struct {
77  int (*callback) (void*);
78  void *data;
79 } dataT;
80 
81 
82 class DP_EXPORT fsPinchGlove : public vrecko::Device {
83  public:
84  fsPinchGlove();
85  fsPinchGlove(const char *port_name);
86  ~fsPinchGlove();
87 
88  virtual int openDevice(void);
89  int closeDevice(void);
90 
91  void update(void);
92 
93  int initPort(char *port);
94  int *getGesture(void);
95  void setGestureFunc(int (*func) (void*), void *g_object, int t1,
96  int t2 = 0, int t3 = 0, int t4 = 0, int t5 = 0);
97  int activateGesture(int t1, int t2 = 0, int t3 = 0, int t4 = 0, int t5 = 0);
98  int deactivateGesture(int t1, int t2 = 0, int t3 = 0, int t4 = 0, int t5 = 0);
99  int checkGesture(void);
100 
101  int disableTS(void);
102  int enableTS(void);
103  void setReleaseFunc(int (*func) (void*), void *data);
104  void printConf(void);
105  void printGests(void);
106 
107  protected:
108  int port_fd;
109  bool gestureOn;
110  std::map<std::string, dataT*> callbacks;
111  std::map<std::string, int> _signal_transf_table;
112  std::map<std::string, int> _signal_type_table;
113  int _current_type, _signal_backup;
115  char bufx[2*PGI_MAX_PACKET_LEN];
116  char bufxe[5][3];
117  std::map<std::string, int> _active_contact;
119  float ticks;
120  int (*relFunc) (void);
121 
122  int _signal[10], _signal_count;
123 
124  int checkBox(void);
125  void pgd_close(void);
126  int getByte(char *buf);
127  int getPacket(char *buf);
128  int pgdRead(char *buf, int n);
129  int pgdComm(const char buf[2], char *reply);
130 
131 
132  int getData( char *buf, int len, int *time_st );
133  int checkConnection(void);
134  void printBuf( const char *buf, int length );
135  void delay(int msec);
136 
137  private:
138  void invNulls(char *buf, int length);
139  void swapBytes( int &num );
140  int getTicks();
141  int setToVersion1();
142 
143 #if defined(WIN32)
144  HANDLE hCom; // handle for COM port
145 #endif
146 
148 };
149 
150 }
151 
152 #endif