View Javadoc

1   /*
2    * @(#)$Id: Win32TabletProxy.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author       :   Michele Croci, mcroci@gmail.com
5    *
6    * Purpose      : 	Reads the tablet position.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date             Who         Reason
13   *
14   * Oct 22, 2007     crocimi			Initial Release
15   * 
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.io.wacom;
28  
29  
30  
31  import java.awt.Point;
32  import java.util.logging.Logger;
33  
34  import org.ximtec.igesture.io.wacom.Wintab32.ORIENTATION;
35  import org.ximtec.igesture.io.wacom.Wintab32.PACKET;
36  import org.ximtec.igesture.io.wacom.Wintab32.ROTATION;
37  
38  
39  
40  
41  
42  /**
43   * Reads the mouse position.
44   * 
45   * @version 1.0, Oct 2007
46   * @author Michele Croci
47   *
48   */
49  public class Win32TabletProxy {
50  
51     private static final Logger LOGGER = Logger.getLogger(Win32TabletProxy.class
52           .getName());
53  
54  
55     
56     private WacomUtils tabletUtils =  new WacomUtils();
57     private PACKET lastPacket = null;
58  
59     public Win32TabletProxy(){
60  	  LOGGER.info("Init..."); 
61        tabletUtils.open();
62     }
63     
64     public boolean isExtraDataSupported(){
65  	   return tabletUtils.isDataSupported(14)||tabletUtils.isDataSupported(16)||
66  	   tabletUtils.isDataSupported(17)||tabletUtils.isDataSupported(18);
67     }
68     
69     /**
70      * Get the next packet data from the tablet Pc
71      * 
72      */
73     public void getNextPacket() {
74  		   lastPacket = tabletUtils.getOnePacket();
75     } 
76     
77     /**
78      * Return the last readed packet
79      * 
80      */
81     public PACKET getLastPacket() {
82  
83             return lastPacket;
84     } 
85     
86     /**
87      * Returns the pressure of the pen on the table 
88      * 
89      * @return the timestamp
90      */
91     public long getTimeStamp() {
92  	   if (lastPacket!=null) //just in case
93  		    return lastPacket.pkTime;
94  	   else
95  		   return 0;
96     } 
97     
98  
99  
100    /**
101     * Returns the pressure of the pen on the table 
102     * 
103     * @return the pressure (min =0, max = 1023)
104     */
105    public int getPressure() {
106 	   if (lastPacket!=null)
107 	        return lastPacket.pkNormalPressure;
108 	   else
109 		   return -1;
110    } 
111    
112    /**
113     * Returns the tangent pressure of the pen on the table 
114     * 
115     * @return the tangent pressure 
116     */
117    public int getTangentPressure() {
118 	   if (lastPacket!=null)
119 	      return lastPacket.pkTangentPressure;
120 	   else
121 		   return -1;
122    } 
123    
124    /**
125     * Returns the z-value of the cursor position
126     * 
127     * @return z-value
128     */
129    public int getzval() {
130 	   if (lastPacket!=null)
131 	         return lastPacket.pkZ;
132 	   else
133 		   return -1;
134    } 
135    
136    
137    
138    /**
139     * Returns the orientation of the pen on the table 
140     * 
141     * @return orientation (altitude, azimuth, twist)
142     */
143    public ORIENTATION getOrientation() {
144 	   if (lastPacket!=null)
145 	      return lastPacket.pkOrientation;
146 	    else
147 	         return null;
148    } 
149    
150    
151    /**
152     * Returns the rotation of the pen on the table 
153     * 
154     * @return rotation (pitch, roll, yaw)
155     */
156    public ROTATION getRotation() {
157 	   if (lastPacket!=null){ 
158 		      return lastPacket.pkRotation;
159 		   }else
160 			   return null;
161    } 
162    
163    
164    /**
165     * Returns the location of the tablet cursor on the screen.
166     * 
167     * @return the location of the tablet cursor on the screen.
168     */
169    public Point getLastCursorLocation() {
170 	   if (lastPacket!=null) //just in case
171 		   return new Point(lastPacket.pkX, lastPacket.pkY);
172 	   else
173 		   return null;
174    } 
175    
176    
177    public int buttonPressed(){
178       return lastPacket.pkButtons;
179    }
180 
181 }