PTimer demo and explanation

Stefan

Legend
Joined
May 7, 2006
Messages
7,286
WCA ID
2003POCH01
YouTube
Visit Channel
Made a new timer, combination of physical equipment and program.

[youtubewide]tZCo-33o2Pw[/youtubewide]

Executable: http://stefan-pochmann.info/ptimer/PTimer.jar
Source code: http://stefan-pochmann.info/ptimer/PTimer.java
Zip with everything: http://stefan-pochmann.info/ptimer/PTimer.zip

You should be able to just run the PTimer.jar file, unless you don't have Java which you can get from java.com.

Works similar to the Speedstacks Stackmat, see above video. Keys for left hand are qwerasdfzxc and ALT, keys for right hand are iop[kl;',./ and CTRL. Quit the program simply with ALT-F4 (standard in Windows, not sure about other systems).
 
Last edited:
Cool, thanks for the source, I'll take a look through it.
I like your button, pretty awesome. :D
I'll try this out next time I do an average.
 
Yes, after stopping you just need to release (left or right hand), then it's in the same state as in the beginning and you can start again. There's no extra reset button.

And I forgot to say: The current keys are 'x' and '/' (also ALT and CTRL, though I have problems with those). And I might include more keys tomorrow. Just saying, in case the current keys are a poor choice for someone who can't modify the program himself - you might want to wait before building a sub-optimal overlay.
 
Made a new timer, combination of physical equipment and program.

[youtubehd]tZCo-33o2Pw[/youtubehd]

Here's the source code:
Code:
/*************************************************************************
 * 
 * PTimer 
 * 
 * Author:  Stefan Pochmann
 * Date:    Nov 18, 2009
 * Version: 1.0
 * 
 * The "P" of "PTimer" is in a quantum superposition - until I decide,
 * it stands for both "Pochmann" and "Puzzle".
 * 
 * It's a simple timer very similar to the Speedstacks Stackmat. Keys
 * 'x' and '/' (or Alt and CTRL) play the role of the stackmat sensors.
 * 
 * Demo video:   [url]http://www.youtube.com/watch?v=tZCo-33o2Pw&fmt=22[/url]
 * Forum thread: [url]http://www.speedsolving.com/forum/showthread.php?t=16952[/url]
 * 
 * I hope the code is self-explanatory cause I don't feel like explaining it.
 *   
 *************************************************************************/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PTimer extends JFrame {
  
  public static void main ( String[] args ) throws Exception {
    new PTimer();
  }

  //--- The side lights and time display
  Canvas left = new Canvas(), right = new Canvas();
  JLabel middle = new JLabel();
  
  PTimer () throws Exception {
  
    //--- Full screen
    setUndecorated( true );
    int width = Toolkit.getDefaultToolkit().getScreenSize().width;
    int height = Toolkit.getDefaultToolkit().getScreenSize().height;
    setBounds( 0, 0, width, height );

    //--- Left and right lights
    left.setSize( width/20, 1 );
    left.setBackground( Color.BLACK );
    right.setSize( width/20, 1 );
    right.setBackground( Color.BLACK );

    //--- Middle display
    middle.setOpaque( true );
    middle.setForeground( Color.RED );
    middle.setBackground( Color.BLACK );
    middle.setHorizontalAlignment( SwingConstants.CENTER );
    middle.setFont( new Font( "Serif", 0, width/4 ) );
    middle.setText( "PTimer" );

    //--- Show everything    
    getContentPane().add( left, BorderLayout.WEST );
    getContentPane().add( middle );
    getContentPane().add( right, BorderLayout.EAST );
    setVisible( true );

    //--- Dance!
    phase = WAIT_FOR_HANDS;
    while ( true ) {
    
      //--- Wait 0.01 seconds, then determine passed time in hundreds of seconds
      Thread.sleep( 10 );
      long hs = ( System.currentTimeMillis() - startTime ) / 10;

      //--- Go from WAIT_FOR_GREEN to WAIT_FOR_START after 0.6 seconds
      if ( phase == WAIT_FOR_GREEN && hs > 60 ) {
        phase = WAIT_FOR_START;
        showLight( left, true );
        showLight( right, true );
      }

      // While running, display the passed time
      if ( phase == WAIT_FOR_STOP  )
        middle.setText( String.format( "%d:%02d.%02d", hs/6000, hs/100%60, hs%100 ));
    }
  }

  //--- The phase we're in
  int phase;
  int WAIT_FOR_HANDS   = 1;
  int WAIT_FOR_GREEN   = 2;
  int WAIT_FOR_START   = 3;
  int WAIT_FOR_STOP    = 4;
  int WAIT_FOR_RELEASE = 5;
  
  //--- Start time, status of buttons
  long startTime;
  boolean leftPressed, rightPressed;

  //--- Show a light (black or red or green)
  void showLight ( Canvas light, boolean pressed ) {
    light.setBackground( pressed ? ( phase == WAIT_FOR_START ? Color.GREEN : Color.RED ) : Color.BLACK );
  }

  //--- Handle key events
  protected void processKeyEvent ( KeyEvent e ) {

    //--- Determine button status
    if( e.getKeyChar() == 'x' || e.getKeyCode() == e.VK_ALT )
      leftPressed = e.getID() != e.KEY_RELEASED;
    if( e.getKeyChar() == '/' || e.getKeyCode() == e.VK_CONTROL )
      rightPressed = e.getID() != e.KEY_RELEASED;
    boolean bothPressed = leftPressed && rightPressed;

    //--- Handle phase transitions
    if ( phase == WAIT_FOR_HANDS && bothPressed ) {
      startTime = System.currentTimeMillis();
      phase = WAIT_FOR_GREEN;
    }

    if ( phase == WAIT_FOR_GREEN && ! bothPressed ) {
      phase = WAIT_FOR_HANDS;
      middle.setText( "PTimer" );
    }
    
    if ( phase == WAIT_FOR_START && ! bothPressed ) {
      startTime = System.currentTimeMillis();
      phase = WAIT_FOR_STOP;
    }
    
    if ( phase == WAIT_FOR_STOP && bothPressed )
      phase = WAIT_FOR_RELEASE;

    if ( phase == WAIT_FOR_RELEASE && ! bothPressed )
      phase = WAIT_FOR_HANDS;

    //--- Show the lights
    showLight( left, leftPressed );
    showLight( right, rightPressed );
  }
}
The attachment contains the sources and the executable PTimer.jar file. You should be able to run it by double-clicking that. Unless you don't have Java yet, which you can get from java.com.

Use keys 'x' and '/' (also ALT and CTRL, though I have problems with them) for left and right hand. Though I intend to cover more keys soon, so you might want to wait for that if the current keys aren't good for you. Quit the program simply with ALT-F4 (standard in Windows, not sure about other systems).

does it work on mac
 
CCT has "Emulate a stackmat with the keyboard" under Options (cont.).
You can even choose which keys to use.

Ok alright I guess I officially suck. Though, like I commented on the video already, I've been wanting to do this anyway and it was a good exercise, so I'm happy to have done it nonetheless.

Gotta try CCT again...
 
CCT has "Emulate a stackmat with the keyboard" under Options (cont.).
You can even choose which keys to use.

Ok alright I guess I officially suck. Though, like I commented on the video already, I've been wanting to do this anyway and it was a good exercise, so I'm happy to have done it nonetheless.

Gotta try CCT again...
By the way, in case anyone wants to try this for CCT, I forgot to mention: In the same options panel, you can set the timer font to be red on black, or whatever you want, which will hold in full screen.
 
Stefan this is so cool. I got tired of scratches on my keyboard from cube landings so we share something in common, keyboards getting all messed up. I'll make one of the cardboard timers timer.

Nicely done!
 
Back
Top