Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JPanel;
- import javax.swing.Timer;
- /*show the glove-state values on command-line*/
- @SuppressWarnings("serial")
- public class ShowGloveValues extends JPanel{
- public final Glove glove;
- public Timer pollTimer;
- public static final int GLOVE_DELAY = 50;
- /*print glove-values to the command-line*/
- public ShowGloveValues(){
- /*init the glove*/
- glove = new Glove();
- /*start to update the glove states*/
- startPolling();
- }
- /*show the hand position*/
- private void showHandPosition(){
- final float vals[] = glove.getHandPosition();
- System.out.println("x-position: " + vals[0]);
- System.out.println("y-position: " + vals[1]);
- System.out.println("z-position: " + vals[2]);
- System.out.println();
- }
- /*show the hand orientation*/
- private void showHandOrientation(){
- final float vals[] = glove.getHandOrientation();
- System.out.println("pitch:" + vals[0]);
- System.out.println("yaw:" + vals[1]);
- System.out.println("roll:" + vals[2]);
- }
- private void showLedNumber(){
- final byte leds[] = glove.getVisibleLedPos();
- System.out.print("Led number: " + leds[0] + " ");
- }
- private void showTrackedLed(){
- final int ledPos = glove.getTrackedLed();
- System.out.print ("Tracked Led: " + ledPos + " ");
- }
- public String showActiveLedPosX(){
- final float pos[][] = glove.getActiveLedPos();
- return "" + pos[glove.getTrackedLed()][0];
- }
- /*update the glove and show the glove-state values*/
- protected void startPolling(){
- final ActionListener pollPerformer = new ActionListener(){
- public void actionPerformed(final ActionEvent e){
- glove.update();
- showActiveLedPosX();
- /*exit by double-pressed D-button*/
- if (glove.isDpressed()) {
- pollTimer.stop();
- System.exit(0);
- }
- }
- };
- /*next update after GLOVE_DELAY ms*/
- pollTimer = new Timer(GLOVE_DELAY, pollPerformer);
- pollTimer.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement