h file

[CODE]
///////////////////////////////////////////////////////////////////////////////
//CalibrateForm.h
///////////////////////////////////////////////////////////////////////////////

#ifndef CALIBRATE_FORM_H_
#define CALIBRATE_FORM_H_

#include "common.h"

/*
form with calibration
*/

class CCalibrateForm : public CModalForm
{
 public:
  CCalibrateForm();
  
 private:
  Boolean OnOpen( EventType* _pEvent, Boolean& _bHandled );
  Boolean OnDigitizer( EventType* _pEvent, Boolean& _bHandled );
  
  BEGIN_EVENT_MAP( CModalForm )
   EVENT_MAP_ENTRY( frmOpenEvent, OnOpen )
  END_EVENT_MAP()
  
  void DrawCrosshair( Coord _xpos, Coord _ypos );
  void NextState();

  Boolean PreSystemEventHook( EventType* _pEvent );
  
  enum EState
  {
   eInitial,
   eTopleft,
   eBottomright,
   eCheck,
   eFinal
  }m_eState;
  
  Coord m_Extentx;
  Coord m_Extenty;
  Coord m_PenX;
  Coord m_PenY;
  PointType m_Expected_topleft;
  PointType m_Expected_bottomright;
  PointType m_Actual_topleft;
  PointType m_Actual_bottomright;
};

#endif // CALIBRATE_FORM_H_
[/CODE]


cpp file

[CODE]
///////////////////////////////////////////////////////////////////////////////
//CalibrateForm.cpp
///////////////////////////////////////////////////////////////////////////////

#include "CalibrateForm.h"

#define OFFSET 10
#define ACCURACY 3

//-----------------------------------------------------------------------------
// Name        : CCalibrateForm
// Parameters  :
// Return      :
// Description :
//-----------------------------------------------------------------------------
CCalibrateForm::CCalibrateForm() : CModalForm( frmCalibrate )
{
 //m_OffscreenHnd = NULL;
 m_Extentx = 0;
 m_Extenty = 0;
 
 MemSet( &m_Expected_topleft, sizeof( PointType ), 0 );
 MemSet( &m_Expected_bottomright, sizeof( PointType ), 0 );
 MemSet( &m_Actual_topleft, sizeof( PointType ), 0 );
 MemSet( &m_Actual_bottomright, sizeof( PointType ), 0 );
}


//-----------------------------------------------------------------------------
// Name        : OnOpen
// Parameters  :
// Return      :
// Description :
//-----------------------------------------------------------------------------
Boolean CCalibrateForm::OnOpen( EventType* _pEvent, Boolean& _bHandled )
{
 UInt16 err = errNone;
 
 WinGetDisplayExtent( &m_Extentx, &m_Extenty );

 m_eState = eInitial;
 if( err != errNone )
  m_eState = eFinal;
  
 NextState();
 
 _bHandled = false;
 
 return true;
}


//----------------------------------------------------------------------------- 
// Name        : OnPenUp
// Parameters  :
// Return      :
// Description :
//-----------------------------------------------------------------------------
Boolean CCalibrateForm::OnDigitizer( EventType* _pEvent, Boolean& _bHandled )
{
 Boolean tapvalid;
   
 m_PenX = _pEvent->screenX;
 m_PenY = _pEvent->screenY;

 NextState();
    
 _bHandled = false;
 
 return true;
}

//----------------------------------------------------------------------------- 
// Name        : DrawCrosshair
// Parameters  :
// Return      :
// Description :
//-----------------------------------------------------------------------------
void CCalibrateForm::DrawCrosshair( Coord _xpos, Coord _ypos )
{
 UInt16 wIndex = FrmGetObjectIndex( GetFormPtr(), btnDigitizer );
 FrmSetObjectPosition( GetFormPtr(), wIndex, _xpos, _ypos );

 FrmShowObject( GetFormPtr(), wIndex );
 UpdateForm();
}


//----------------------------------------------------------------------------- 
// Name        : NextState
// Parameters  :
// Return      :
// Description :
//-----------------------------------------------------------------------------
void CCalibrateForm::NextState()
{

 Boolean done;
  done = true;
  
  switch( m_eState )
  {
   case eInitial:
    {
     PenResetCalibration();
     DrawCrosshair( /*OFFSET*/1, /*OFFSET*/15 );
     m_Expected_topleft.x = OFFSET + 1;
     m_Expected_topleft.y = OFFSET + 15;
     m_eState = eTopleft;
    }; break;
   case eTopleft:
    {
     // Got top-left tap. Draw 2nd crosshair.
     m_Actual_topleft.x = m_PenX;
     m_Actual_topleft.y = m_PenY;
     SysTaskDelay( SysTicksPerSecond() / 4 );
     DrawCrosshair( m_Extentx - /*OFFSET*/21, m_Extenty - /*OFFSET*/21 );
     m_Expected_bottomright.x = m_Extentx - OFFSET/*21*/;
     m_Expected_bottomright.y = m_Extenty - OFFSET/*21*/;
     m_eState = eBottomright;
    }; break;
   case eBottomright:
    {
     // Got bottom-right tap. Draw 3rd crosshair.
     m_Actual_bottomright.x = m_PenX;
     m_Actual_bottomright.y = m_PenY;
     PenCalibrate( &m_Actual_topleft, &m_Actual_bottomright, 
&m_Expected_topleft,
                   &m_Expected_bottomright );
     SysTaskDelay( SysTicksPerSecond() / 4 );
     DrawCrosshair( m_Extentx * 3 / 4, m_Extenty * 3 / 4 );
     m_eState = eCheck;
    }; break;
   case eCheck:
    {
     // Got final tap. Check it for accuracy and restart or exit accordingly.
     m_PenX -= 10;
     m_PenY -= 10;
     if( ( m_PenX > ( ( m_Extentx * 3 / 4 ) + ACCURACY ) )
         || ( m_PenX < ( ( m_Extentx * 3 / 4 ) - ACCURACY ) )
         || ( m_PenY > ( ( m_Extenty * 3 / 4 ) + ACCURACY ) )
         || ( m_PenY < ( ( m_Extenty * 3 / 4 ) - ACCURACY ) ) )
      {
       m_eState = eInitial;
       done = false;
       break;
      }
      
      m_eState = eFinal;
      done = false;
      CloseForm();
    }; break;
   case eFinal:
    {
     CloseForm();
    }break;
   default:
    {
     ErrNonFatalDisplayIf( 1, "Invalid State" );
     m_eState = eFinal;
     done = false;
    }; break;
   }

}


//----------------------------------------------------------------------------- 
// Name        : PreSystemEventHook
// Parameters  :
// Return      :
// Description :
//-----------------------------------------------------------------------------
Boolean CCalibrateForm::PreSystemEventHook( EventType* _pEvent )
{
 Boolean _bHandled = false;
 switch( _pEvent->eType )
 {
  case penDownEvent:
  {
   OnDigitizer( _pEvent, _bHandled );
   return true;
  }; break;
 };

 return false;
}
[/CODE]


resoures

[CODE]
FORM ID frmCalibrate  AT ( 0 0 160 160 )
NOFRAME  MODAL
BEGIN
        TITLE "Calibrating..."
                
                BUTTON "" ID btnDigitizer  AT (1 15 20 20) BITMAPID 
bmpDigitizer GRAPHICAL
END
[/CODE]


bmpDigitizer is bitmap with cross 20x20








H> Hi all!

H> from time to time I need to recalibrate the digitizer from within my app. 
Unfortunately I cannot determine how to make the functions
H> PenResetCalibration()  and
H> PenCalibrate()
H> work properly.

H> In principle, I take three pen-taps at top left, middle and bottom-right 
locations just like the built in welcome app. and then call PenCalibrate() -- 
so much for the theory.

H> BUT: If I call PenResetCalibration() before that on a SONY Clie, the entire 
device hangs or makes the digitizer just plain dead -- the device does not 
accept any pen input.

H> If I just call PenCalibrate() without a previous PenResetCalibration() it 
works fine on SONY clies and Palm Tungstens -- but only for the moment. If I 
quit the app or soft-reset the device, the
H> entire calibration is skrewed up with screen and digitizer coordinates 
deviating wildly. As if the previous calibration were not stored properly.


H> Does anybody know how those functions have to be applied, or how the logic 
of the built-in calibrator app. works? Maybe our esteemed insider  Ben?

H> Thank a lot!




-- 
Best regards,
 Vladimir                            mailto:[EMAIL PROTECTED]


-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to