コード例 #1
0
ファイル: touchscreen.c プロジェクト: fabienroyer/NetduinoGo
void tsCalibrate(void)
{
  tsTouchData_t data;

  /* --------------- Welcome Screen --------------- */
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);

  /* ----------------- First Dot ------------------ */
  // 10% over and 10% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 10, lcdGetHeight() / 10, 5);
  _tsLCDPoints[0].x = lcdGetWidth() / 10;
  _tsLCDPoints[0].y = lcdGetHeight() / 10;
  _tsTSPoints[0].x = data.xraw;
  _tsTSPoints[0].y = data.yraw;

  /* ---------------- Second Dot ------------------ */
  // 50% over and 90% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() - lcdGetHeight() / 10, 5);
  _tsLCDPoints[1].x = lcdGetWidth() / 2;
  _tsLCDPoints[1].y = lcdGetHeight() - lcdGetHeight() / 10;
  _tsTSPoints[1].x = data.xraw;
  _tsTSPoints[1].y = data.yraw;

  /* ---------------- Third Dot ------------------- */
  // 90% over and 50% down
  data = tsRenderCalibrationScreen(lcdGetWidth() - lcdGetWidth() / 10, lcdGetHeight() / 2, 5);
  _tsLCDPoints[2].x = lcdGetWidth() - lcdGetWidth() / 10;
  _tsLCDPoints[2].y = lcdGetHeight() / 2;
  _tsTSPoints[2].x = data.xraw;
  _tsTSPoints[2].y = data.yraw;

  // Do matrix calculations for calibration and store to EEPROM
  setCalibrationMatrix(&_tsLCDPoints[0], &_tsTSPoints[0], &_tsMatrix);
}
コード例 #2
0
/******************************************************************************
 *
 * Description:
 *    Store calibration data for the touch panel
 *
 * Params:
 *   [in] 
 *
 * Returns:
 *   None
 *
 *****************************************************************************/
void touch_calibrate(tTouchPoint ref1, tTouchPoint ref2, tTouchPoint ref3, 
  tTouchPoint scr1, tTouchPoint scr2, tTouchPoint scr3)
{
  POINT disp[3];
  POINT scr[3];
  
  disp[0].x = ref1.x;
  disp[0].y = ref1.y;
  disp[1].x = ref2.x;
  disp[1].y = ref2.y;
  disp[2].x = ref3.x;
  disp[2].y = ref3.y;
  
  scr[0].x = scr1.x;
  scr[0].y = scr1.y;                  
  scr[1].x = scr2.x;
  scr[1].y = scr2.y;
  scr[2].x = scr3.x;
  scr[2].y = scr3.y;  
  
  setCalibrationMatrix(disp, scr,
                       &storedCalData.storedMatrix);

  calibrated = TRUE;
  
}
コード例 #3
0
ファイル: touch.c プロジェクト: Blone/my-project-hihack
/***************************************************************************//**
 * @brief Set calibration table
 *
 * @param[in] displayPtr
 *	Table of display points
 *
 * @param[in] screenPtr
 *	Table of adc values reflecting display points
 *
 * @return
 *	Returns OK if calibration table is set.
 ******************************************************************************/
int TOUCH_CalibrationTable(POINT * displayPtr, POINT * screenPtr)
{
  int result;
  result = setCalibrationMatrix(displayPtr, screenPtr, &calibrationMatrix);
#ifndef TOUCH_WITHOUT_STORE
  if (result == OK)
    touch_StoreCalibration();
#endif
  return(result);
}
コード例 #4
0
ファイル: MrsvrMessageServer.cpp プロジェクト: tokjun/MTest
int MrsvrMessageServer::onRcvMsgMaster(igtl::Socket::Pointer& socket, igtl::MessageHeader::Pointer& header)
{

#ifdef DEBUG_MRSVR_MESSAGE_SERVER
  fprintf(stderr, "MrsvrMessageServer::onRcvMsgMaster():Receiving TRANSFORM data type.\n");
#endif
  
  // Create a message buffer to receive transform data
  igtl::TransformMessage::Pointer transMsg;
  transMsg = igtl::TransformMessage::New();
  transMsg->SetMessageHeader(header);
  transMsg->AllocatePack();
  
  // Receive transform data from the socket
  socket->Receive(transMsg->GetPackBodyPointer(), transMsg->GetPackBodySize());
  
  // Deserialize the transform data
  // If you want to skip CRC check, call Unpack() without argument.
  int c = transMsg->Unpack(1);
  
  if (c & igtl::MessageHeader::UNPACK_BODY) { // if CRC check is OK
    // Retrive the transform data
    igtl::Matrix4x4 matrix;
    transMsg->GetMatrix(matrix);
    // Check the device name in the OpenIGTLink header
    if (strcmp(transMsg->GetDeviceName(), "TARGET") == 0 ||
        strcmp(transMsg->GetDeviceName(), "ProstateNavRobotTarg") == 0){

      setTargetMatrix(matrix);      
      printTargetMatrix(matrix);
      
      //if (result == TARGET_ACCEPTED) {
      //} else if (result == TARGET_OUT_OF_RANGE) {
      //}

    } else if (strcmp(transMsg->GetDeviceName(), "ZFrameTransform") == 0){
      
      setCalibrationMatrix(matrix);
      //-------------------------------------------------- july6,ez
      fZFrameTransform = true;
      //-------------------------------------------------- end july6,ez
    }
    
    return 1;
  }
  
  return 0;
}
コード例 #5
0
void tsCalibrate(void)
{
  tsTouchData_t data;

  /* --------------- Welcome Screen --------------- */
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() / 2, 5);
  systickDelay(250);

  /* ----------------- First Dot ------------------ */
  // 10% over and 10% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 10, lcdGetHeight() / 10, 5);
  _tsLCDPoints[0].x = lcdGetWidth() / 10;
  _tsLCDPoints[0].y = lcdGetHeight() / 10;
  _tsTSPoints[0].x = data.xraw;
  _tsTSPoints[0].y = data.yraw;
  printf("Point 1 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
        (int)_tsLCDPoints[0].x, (int)_tsLCDPoints[0].y, (int)_tsTSPoints[0].x, (int)_tsTSPoints[0].y);
  systickDelay(250);

  /* ---------------- Second Dot ------------------ */
  // 50% over and 90% down
  data = tsRenderCalibrationScreen(lcdGetWidth() / 2, lcdGetHeight() - lcdGetHeight() / 10, 5);
  _tsLCDPoints[1].x = lcdGetWidth() / 2;
  _tsLCDPoints[1].y = lcdGetHeight() - lcdGetHeight() / 10;
  _tsTSPoints[1].x = data.xraw;
  _tsTSPoints[1].y = data.yraw;
  printf("Point 2 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
       (int)_tsLCDPoints[1].x, (int)_tsLCDPoints[1].y, (int)_tsTSPoints[1].x, (int)_tsTSPoints[1].y);
  systickDelay(250);

  /* ---------------- Third Dot ------------------- */
  // 90% over and 50% down
  data = tsRenderCalibrationScreen(lcdGetWidth() - lcdGetWidth() / 10, lcdGetHeight() / 2, 5);
  _tsLCDPoints[2].x = lcdGetWidth() - lcdGetWidth() / 10;
  _tsLCDPoints[2].y = lcdGetHeight() / 2;
  _tsTSPoints[2].x = data.xraw;
  _tsTSPoints[2].y = data.yraw;
  printf("Point 3 - LCD X:%04d Y:%04d TS X:%04d Y:%04d \r\n", 
        (int)_tsLCDPoints[2].x, (int)_tsLCDPoints[2].y, (int)_tsTSPoints[2].x, (int)_tsTSPoints[2].y);
  systickDelay(250);

  // Do matrix calculations for calibration and store to EEPROM
  setCalibrationMatrix(&_tsLCDPoints[0], &_tsTSPoints[0], &_tsMatrix);
}
コード例 #6
0
ファイル: tscCalibrate.c プロジェクト: OS-Project/Divers
static void TouchCalibrate(void)
{
    unsigned char i;
 
    POINT stDisplayPoint[3] = {{0, 0},{LCD_WIDTH, 0}, {0, LCD_HEIGHT}};
    POINT stTouchScreenPoint[3];

    UARTPuts("Touch at Right bottom", -1);

    while(!IsTSPress);

    IsTSPress = 1; 

    for(i = 0; i < 3; i++)
    {
         while(DMTimerCounterGet(SOC_DMTIMER_2_REGS) < 0xffffff);

         DMTimerDisable(SOC_DMTIMER_2_REGS);

         DMTimerCounterSet(SOC_DMTIMER_2_REGS, 0);

	 stTouchScreenPoint[i].x = x_val[0];
	 stTouchScreenPoint[i].y = y_val[0];

         if(i == 0)
         {
              UARTPuts("\r\n", -1);
              UARTPuts("Touch at Left bottom", -1);

         }
         else if(i == 1)
         {
              UARTPuts("\r\n", -1);
              UARTPuts("Touch at Right Top", -1);
         }
         else
         {
              UARTPuts("\r\n", -1);
         }
    }

    setCalibrationMatrix( stDisplayPoint, stTouchScreenPoint, &stMatrix);
}
コード例 #7
0
ファイル: TouchPanel.c プロジェクト: Seok-Jung/STM32F207
/*******************************************************************************
* Function Name  : TouchPanel_Calibrate
* Description    : 
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void TouchPanel_Calibrate(void)
{
  uint8_t i;
  Coordinate * Ptr;

  for(i=0;i<3;i++)
  {
   LCD_Clear(Black);
   GUI_Text(44,10,"Touch crosshair to calibrate",0xffff,Black);
   delay_ms(300);
   DrawCross(DisplaySample[i].x,DisplaySample[i].y);
   do
   {
     Ptr=Read_Ads7846();
   }
   while( Ptr == (void*)0 );
   ScreenSample[i].x= Ptr->x; ScreenSample[i].y= Ptr->y;
  }
  setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix );
  LCD_Clear(Black);
} 
コード例 #8
0
ファイル: XPT2046.c プロジェクト: alepnm/lcd
void TouchPanel_Calibrate(void)
{
  unsigned char i;
  Coordinate * Ptr;

  for(i=0;i<3;i++)
  {
   SSD1289_Clear(Black);
   SSD1289_CleanText(44,10,"Touch crosshair to calibrate",Red);
   Delay(250);
   SSD1289_DrawCross(DisplaySample[i].x,DisplaySample[i].y, Red, RGB565CONVERT(184,158,131));
   do
   {
     Ptr = Read_XPT2046();
   }
   while( Ptr == (void*)0 );
   ScreenSample[i].x= Ptr->x; ScreenSample[i].y= Ptr->y;
  }
  setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix );
  SSD1289_Clear(Black);
} 
コード例 #9
0
ファイル: TouchPanel.c プロジェクト: Separius/CortexM3-Paint
/*******************************************************************************
* Function Name  : TouchPanel_Calibrate
* Description    : 校准触摸屏
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void TouchPanel_Calibrate(void)
{
  uint8_t i;
  Coordinate * Ptr;

  for(i=0;i<3;i++)
  {
   LCD_Clear(White);
   GUI_Text(10,10,"Touch crosshair to calibrate",Black,White);   
   DelayUS(1000 * 500);
   DrawCross(DisplaySample[i].x,DisplaySample[i].y);
   do
   {
   Ptr = Read_Ads7846();
   }
   while( Ptr == (void*)0 );
   ScreenSample[i].x = Ptr->x; ScreenSample[i].y = Ptr->y;
  }
  setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix ) ;  /* 送入值得到参数 */	   
  LCD_Clear(White);
} 
コード例 #10
0
ファイル: TouchPanel.c プロジェクト: MenglongWu/TS100_VEx
/*******************************************************************************
* Function Name  : TouchPanel_Calibrate
* Description    : 校准触摸屏
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void TouchPanel_Calibrate(void)
{
  /* */ uint8_t i;
  //Coordinate * Ptr;

  for(i=0;i<3;i++)
  {
  
 /*取消开机触摸屏校准2011.11.23yujignxiong 	   
   LCD_Clear(Black);
   //GUI_Text(44,10,"Touch crosshair to calibrate",0xffff,Black);
   delay_ms(500);
   DrawCross(DisplaySample[i].x,DisplaySample[i].y);
   do
   {
     Ptr=Read_Ads7846();   
   }
   while( Ptr == (void*)0 );  //得到AD的XY 坐标,即触摸按点的坐标值,返回值为0
   X[i] = ScreenSample[i].x= Ptr->x; 
   Y[i] = ScreenSample[i].y= Ptr->y;	 */

  /* */  
     ScreenSample[i].x = X[i] ;
     ScreenSample[i].y = Y[i]  ;   
 
  }	

							 //根据显示屏的十字坐标,与触摸屏的获取坐标计算得出参数,【 K A B C D E F】
  setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix ) ;  /* 送入值得到参数 */	   

/*
  LCD_Clear(Yellow);
  GUI_Chinese(100,104,"聚联科技",White,Red);
  GUI_Text(90,140,"I LIKE G-LINK",White,Red);
  delay_ms(10000);
  LCD_Clear(Black);
*/

} 
コード例 #11
0
/*******************************************************************************
* Function Name  : TouchPanel_Calibrate
* Description    : У׼´¥ÃþÆÁ
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
void TouchPanel_Calibrate(void)
{
  uint8_t i;
  Coordinate * Ptr;
  for(i=0;i<3;i++)
  {
   LCD_Clear(BLACK);
   //LCD_SetTextColor(BLUE);
   //LCD_SetBackColor(BLACK);
   //LCD_StringLine(10,10,"Touch crosshair to calibrate");
   GUI_Text(10, 10, "Touch crosshair to calibrate",BLUE,BLACK);
   Delay(0xFFFFFF);
   DrawCross(DisplaySample[i].x,DisplaySample[i].y);
   do
   {
   Ptr=Read_Ads7846();
   }
   while( Ptr == (void*)0 );
   ScreenSample[i].x= Ptr->x; ScreenSample[i].y= Ptr->y;
  }
  setCalibrationMatrix( &DisplaySample[0],&ScreenSample[0],&matrix ) ;  /* ËÍÈëÖµµÃµ½²ÎÊý */	
  LCD_Clear(BLACK);
}
コード例 #12
0
ファイル: main.c プロジェクト: dudeofea/Capstone-2014
//* Function: Perform DSP
//* Description: Performs a number of operations on the camera input
//such as thresholding/centroid calc. Then draw squares on the screen
//or switch color or brush size, or even clear the screen. Depending
//on the number of centroids and their size, a different gesture is
//detected and the corresponding action is performed. See below for
//more details
//* Input: nothing
//* Returns: nothing
void *perform_DSP(void *args){
	static int calibrate = 1;
	struct Centroid *centroids;
	static int touch = 0;
	static int fingerup = 0;
	struct Centroid last_centroid;
	POINT point1, point2;

	while(dsp_running){
		//calculate centroids
		centroids = get_fingers();
		
	    //if fingers are touching
		if (centroids[0].size > 0)
		{
			touch = 1;
			last_centroid = get_biggest_finger(centroids);
		}else{
			//if finger just came off
			if (touch == 1)
				fingerup = 1;
			touch = 0;
		}
	    //if calibrating
	    if (calibrate)
	    {
	    	//black out screen if calbrating
	    	struct pixel back_color = COLOR_DARK_GREY;	//background color
			for (int i = 0; i < DATA_LEN; ++i)
		    {
				//dark grey
				pixels2[i*RGBA_LEN+RGBA_R] = back_color.r;	//set red value
				pixels2[i*RGBA_LEN+RGBA_G] = back_color.g;	//set green value
				pixels2[i*RGBA_LEN+RGBA_B] = back_color.b;	//set blue value
				pixels2[i*RGBA_LEN+RGBA_A] = SHORT_MAX;	//set alpha
				pixels2[i*4+3] = SHORT_MAX;
		    }
	    	//draw calibration point
			calib_color.x = perfectPoints[calibrate-1].x;
			calib_color.y = perfectPoints[calibrate-1].y;
			draw_square(pixels2, DATA_WIDTH, DATA_HEIGHT, calib_color);
			if (fingerup)
			{
				//set actual calibration points to the last finger that touched the display
				actualPoints[calibrate-1].x = last_centroid.x;
				actualPoints[calibrate-1].y = last_centroid.y;
				calibrate++;			//increment up to number of calibration points
				//if done calibration
				if (calibrate > 3)
				{
					//create calibration matrix
					setCalibrationMatrix(&perfectPoints[0], &actualPoints[0], &calibMatrix);
					//clear pixels
					for (int i = 0; i < DATA_LEN * 4; ++i)
					{
						pixels2[i] = 0;
					}
					//done calibration
					calibrate = 0;
				}
				fingerup = 0;
			}
	    }else{
		    if (centroids != NULL)
		    {
		    	for (int i = 0; i < 10; ++i)
				{
					//if decently sized, draw as a red pixel
					if (centroids[i].size > 10)
					{
						point2.x = centroids[i].x;
						point2.y = centroids[i].y;
						getDisplayPoint(&point1, &point2, &calibMatrix);
						finger_colors[0].x = point1.x;
						finger_colors[0].y = point1.y;
						draw_square(pixels2, DATA_WIDTH, DATA_HEIGHT, finger_colors[0]);
					}
				}
		    }
		}
	}
	return NULL;
}
コード例 #13
0
ファイル: sample.c プロジェクト: SiliconLabs/Gecko_SDK
/**********************************************************************
 *
 *     Function: main()
 *
 *  Description: Entry point into console version of sample
 *                program that exercises the calibration 
 *                functions.
 * 
 *  Argument(s): argCount - the number of arguments provided
 *               argValue - pointer to the list of char strings 
 *                           representing the command line arguments.
 * 
 *       Return: void
 *
 */
int main( int argCount, char ** argValue )
{

    int retValue = OK ;

    MATRIX  matrix ;
    POINT   display ;
    
    
    int     n ;


      
    greeting() ;


        /* The following call calculates the translation matrix that   */
        /*  results when the three consecutive points in the sample    */
        /*  set are used.  Such points are assumed to be properly      */
        /*  spaced within the screen surface.                          */
        /* Note that we call the function twice as we would normally   */
        /*  do within a calibration routine.  The first time we call   */
        /*  it using a perfect set of display and screen arguments.    */
        /* Such a call is made to obtain a calibration matrix that is  */
        /*  just good enough to collect samples to do the real         */
        /*  calibration.                                               */
        /*                                                             */
        /*                                                             */
        /*                                                             */
        /*                 NOTE!    NOTE!    NOTE!                     */
        /*                                                             */
        /*  setCalibrationMatrix() and getDisplayPoint() will do fine  */
        /*  for you as they are, provided that your digitizer          */
        /*  resolution does not exceed 10 bits (1024 values).  Higher  */
        /*  resolutions may cause the integer operations to overflow   */
        /*  and return incorrect values.  If you wish to use these     */
        /*  functions with digitizer resolutions of 12 bits (4096      */
        /*  values) you will either have to a) use 64-bit signed       */
        /*  integer variables and math, or b) judiciously modify the   */
        /*  operations to scale results by a factor of 2 or even 4.    */
        /*                                                             */


    setCalibrationMatrix( &perfectDisplaySample[0], 
						  &perfectScreenSample[0], 
						  &matrix ) ;

        /* Look at the matrix values when we use a perfect sample set. */
        /* The result is a unity matrix.                               */
    printf("\n\nLook at the unity matrix:\n\n"
           "matrix.An = % 8ld  matrix.Bn = % 8ld  matrix.Cn = % 8ld\n"
           "matrix.Dn = % 8ld  matrix.En = % 8ld  matrix.Fn = % 8ld\n"
           "matrix.Divider = % 8ld\n",
           matrix.An,matrix.Bn,matrix.Cn,
           matrix.Dn,matrix.En,matrix.Fn,
           matrix.Divider ) ;





        /* Now is when we need to do the work to collect a real set of */
        /*  calibration data.                                          */

        /* Draw three targets on your display. Drawing one at time is  */
        /*  probably a simpler implementation. These targets should be */
        /*  widely separated but also avoid the areas too near the     */
        /*  edges where digitizer output tends to become non-linear.   */
        /*  The recommended set of points is (in display resolution    */
        /*   percentages):                                             */
        /*                                                             */
        /*                  ( 15, 15)                                  */
        /*                  ( 50, 85)                                  */
        /*                  ( 85, 50)                                  */
        /*                                                             */
        /* Each time save the display and screen set (returned by the  */
        /*  digitizer when the user touches each calibration target    */
        /*  into the corresponding array).                             */ 
        /* Since you normalized your calibration matrix above, you     */
        /*  should be able to use touch screen data as it would be     */
        /*  provided by the digitizer driver.  When the matrix equals  */
        /*  unity, getDisplayPoint() returns the same raw input data   */
        /*  as output.                                                 */



    


        /* Call the function once more to obtain the calibration       */
        /*  factors you will use until you calibrate again.            */
    setCalibrationMatrix( &displaySample[0], &screenSample[0], &matrix ) ;

        /* Let's see the matrix values for no particular reason.       */
    printf("\n\nThis is the actual calibration matrix that we will use\n"
           "for all points (until we calibrate again):\n\n"
           "matrix.An = % 8d  matrix.Bn = % 8d  matrix.Cn = % 8d\n"
           "matrix.Dn = % 8d  matrix.En = % 8d  matrix.Fn = % 8d\n"
           "matrix.Divider = % 8d\n",
           matrix.An,matrix.Bn,matrix.Cn,
           matrix.Dn,matrix.En,matrix.Fn,
           matrix.Divider ) ;



        /* Now, lets use the complete set of screen samples to verify  */
        /*  that the calculated calibration matrix does its job as     */
        /*  expected.                                                  */
    printf("\n\nShow the results of our work:\n\n"
           "  Screen Sample    Translated Sample    Display Sample\n\n" ) ;


        /* In a real application, your digitizer driver interrupt      */
        /*  would probably do the following:                           */
        /*      1) collect raw digitizer data,                         */
        /*      2) filter the raw data which would probably contain    */
        /*          position jitter,                                   */
        /*      3) filter out repeated values (a touch screen          */
        /*          controller normally continues causing interrupts   */
        /*          and collecting data as long as the user is         */
        /*          pressing on the screen), and                       */
        /*      4) call the function getDisplayPoint() to obtain       */
        /*          the display coordinates that the user meant to     */
        /*          input as he touched the screen.                    */
        /*                                                             */
        /* This code sample, of course, only uses sample data.  So we  */
        /*  simply run through all the available sample points.        */

    for( n = 0 ; n < MAX_SAMPLES ; ++n )
    {
        getDisplayPoint( &display, &screenSample[n], &matrix ) ;
        printf("  % 6d,%-6d      % 6d,%-6d       % 6d,%-6d\n", 
                screenSample[n].x,  screenSample[n].y,
                display.x,          display.y,
                displaySample[n].x, displaySample[n].y ) ;
    }


    return( retValue ) ;

} // end of main() 
コード例 #14
0
ファイル: main.c プロジェクト: EnergyMicro/EFM32LG_DK3650
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  uint32_t buttons;
  POINT P[ 3 ];
  TOUCH_Config_TypeDef touch_config = TOUCH_INIT_DEFAULT;
  const char readmeText[] = \
    "USB Bitmap transfer using USB drive functionality.\r\n\r\n"\
    "This example demonstrate use several functionalities:\r\n"\
    "1. Creation of virtual drive in system with FAT FS,\r\n"\
    "2. Mounting the drive on PC and file transfer,\r\n"\
    "3. Bitmap file creation based on TFT frame buffer content,\r\n"\
    "4. Resistive touch panel interaction.\r\n\r\n"\
    "On system startup initial drive is created and\r\n"\
    "formatted using FAT FS then simple readme.txt file\r\n"\
    "is put on file system. Every time user press PB4 key\r\n"\
    "new file, containing TFT frame buffer in bitmap format\r\n"\
    "is added. All files could be retrieved after connecting\r\n"\
    "board to PC by means of USB. For this connection use\r\n"\
    "small USB socket located on Leopard Gecko CPU board, not\r\n"\
    "the big one on development kit.\r\n\r\n"\
    "If new files doesn't appear on drive after pressing PB4,\r\n"\
    "try to reconnect the board to PC.\r\n\r\n"\
    "Board:  Energy Micro EFM32LG-DK3650 Development Kit\r\n"\
    "Device: EFM32LG990F256\r\n";


  /* Configure for 48MHz HFXO operation of core clock */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  CMU_ClockEnable(cmuClock_GPIO, true);

  CMU_ClockEnable( cmuClock_ADC0, true);

  /* Set frame buffer start address */
  frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2);

  /* Make sure CYCCNT is running, needed by delay functions. */
  DWT_CTRL |= 1;

  /* Initialize USB subsystem and prepare for taking pictures */
  BITMAP_Init();
  /* Create our first file on disk - simple readme */
  BITMAP_CreateFileAndSaveData("README.TXT", readmeText, sizeof(readmeText));

  /* Indicate we are waiting for AEM button state enabling EFM */
  while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM)
  {
    /* Show a short "strobe light" on DK LEDs, indicating wait */
    BSP_LedsSet(0x8001);
    delayMs(100);
    BSP_LedsSet(0x4002);
    delayMs(100);
  }

  touch_config.frequency = 13000000; /* use max ADC frequency */
  touch_config.ignore = 0;           /* notice every move, even 1 pixel */
  TOUCH_Init(&touch_config);

  /* Initialize touch screen calibration factor matrix with approx. values  */
  setCalibrationMatrix( (POINT*)&lcdCalibPoints,   /* Display coordinates   */
                        (POINT*)&touchCalibPoints, /* Touch coordinates     */
                        &calibFactors );      /* Calibration factor matrix  */
  while (1)
  {
    delayMs(100);
    if ( TFT_DirectInit(&tftInit) )
    {
      delayMs(100);
      displayHelpScreen();
      BSP_LedsSet(0x0000);
      BSP_PeripheralAccess(BSP_TOUCH, true);
      GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0);

      do
      {
        delayMs(25);
        buttons = readButtons();

        /* Draw on screen */
        if ( buttons & BC_UIF_PB1 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */

          do
          { TOUCH_Pos_TypeDef *pos = TOUCH_GetPos();
            if ( pos->pen )
              drawPixel( pos->x, pos->y, COLOR );
              delayMs(1);

            buttons = readButtons() & ~BC_UIF_PB1;
            if(buttons == BC_UIF_PB4)
            {
              getNicePicture();
              buttons &= ~BC_UIF_PB4;
            }
          } while ( buttons == 0 );
        }

        /* Calibrate touch screen */
        else if ( buttons & BC_UIF_PB2 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 0 ].x, lcdCalibPoints[ 0 ].y, COLOR );
          TFT_DrawString(30, 35, "Tap green marker" );
          P[ 0 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 1 ].x, lcdCalibPoints[ 1 ].y, COLOR );
          TFT_DrawString(40, 130, "Tap green marker" );
          P[ 1 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 2 ].x, lcdCalibPoints[ 2 ].y, COLOR );
          TFT_DrawString(20, 180, "Tap green marker" );
          P[ 2 ] = getTouchTapSample10bit();

          TOUCH_CalibrationTable((POINT*)&lcdCalibPoints,/* Display coordinates*/
                                &P[0]);                  /* Touch coordinates  */

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          TFT_DrawString(10, 100, "The touch screen is" );
          TFT_DrawString(30, 130, "now calibrated !" );
        }

        /* Display help screen */
        else if ( buttons & BC_UIF_PB3 )
        {
          displayHelpScreen();
          while ( readButtons() & BC_UIF_PB3 )
             delayMs(50);
        } else if( buttons & BC_UIF_PB4 )
        {
          getNicePicture();
        }
      } while ( ( buttons & EXIT_LOOP ) == 0 );
    }
    else
    {
      BSP_LedsSet(0x8001);
      delayMs(100);
      BSP_LedsSet(0x4002);
    }
  }
}
コード例 #15
0
ファイル: TouchTest.cpp プロジェクト: lstefani006/teensy
void loop() 
{
	if (nn < 3)
	{
		if (ts.touched()) {
			TS_Point p = ts.getPoint();
			touch[nn].x = p.x/4;
			touch[nn].y = p.y/4;
			nn += 1;
			Serial.print(p.x);
			Serial.print("/");
			Serial.println(p.y);
			delay(1*1000);
			Serial.println(nn);
		}
	}
	else if (nn == 3)
	{
		setCalibrationMatrix(display, touch, &matrix);
		Serial.println("Matrix");
		Serial.print("matrix.An = "); Serial.print(matrix.An); Serial.println(";");
		Serial.print("matrix.Bn = "); Serial.print(matrix.Bn); Serial.println(";");
		Serial.print("matrix.Cn = "); Serial.print(matrix.Cn); Serial.println(";");
		Serial.print("matrix.Dn = "); Serial.print(matrix.Dn); Serial.println(";");
		Serial.print("matrix.En = "); Serial.print(matrix.En); Serial.println(";");
		Serial.print("matrix.Fn = "); Serial.print(matrix.Fn); Serial.println(";");
		Serial.print("matrix.Divider = "); Serial.print(matrix.Divider); Serial.println(";");

		nn+=1;
	}
	else
	{
		static int32_t col = ILI9341_RED;

		if (ts.touched()) 
		{
			TS_Point p = ts.getPoint();
			POINT touch;
			touch.x = p.x/4;
			touch.y = p.y/4;
			POINT display;
			getDisplayPoint(&display, &touch, &matrix);


			bool found = false;

			for (int c = 0; c < int(sizeof(colors)/sizeof(colors[0])); c++)
			{
				int16_t d=20;
				int16_t xa = 40+d*c;
				int16_t xb = 40+d*c + d;

				int16_t ya = 0;
				int16_t yb = 0 + d;

				if (display.x >= xa && display.x <= xb && display.y >= ya && display.y <= yb)
				{
					col = colors[c];
					tft.fillRect(0, 0, d, d, col);
					tft.drawRect(0, 0, d, d, ILI9341_WHITE);
					found = true;

					if (col == ILI9341_BLACK) {
						cls();
						col = ILI9341_WHITE;

					}
					break;
				}
			}

			if (found == false)
			tft.drawPixel(display.x, display.y, col);

		}
	}
}
コード例 #16
0
ファイル: main.c プロジェクト: AndreMiras/EFM32-Library
/**************************************************************************//**
 * @brief  Main function
 *****************************************************************************/
int main(void)
{
  uint32_t buttons;
  POINT touchSample, P[ 3 ];
  ADC_Init_TypeDef init = ADC_INIT_DEFAULT;

  /* Configure for 48MHz HFXO operation of core clock */
  CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);

  /* Initialize DK board register access */
  BSP_Init(BSP_INIT_DEFAULT);

  /* If first word of user data page is non-zero, enable eA Profiler trace */
  BSP_TraceProfilerSetup();

  CMU_ClockEnable(cmuClock_GPIO, true);

  CMU_ClockEnable( cmuClock_ADC0, true);
  /* Max ADC clock is 13MHz, use 14MHz/(1+1) or 48MHz/(5+1) */
  init.prescale = 5;
  ADC_Init(ADC0, &init);
  sInit.reference = adcRefVDD;

  /* Set frame buffer start address */
  frameBuffer = (uint16_t *) EBI_BankAddress(EBI_BANK2);

  /* Make sure CYCCNT is running, needed by delay functions. */
  DWT_CTRL |= 1;

  /* Indicate we are waiting for AEM button state enabling EFM */
  BSP_LedsSet(0x8001);
  while (BSP_RegisterRead(&BC_REGISTER->UIF_AEM) != BC_UIF_AEM_EFM)
  {
    /* Show a short "strobe light" on DK LEDs, indicating wait */
    BSP_LedsSet(0x8001);
    delayMs(200);
    BSP_LedsSet(0x4002);
    delayMs(50);
  }

  /* Initialize touch screen calibration factor matrix with approx. values  */
  setCalibrationMatrix( (POINT*)&lcdCalibPoints,   /* Display coordinates   */
                        (POINT*)&touchCalibPoints, /* Touch coordinates     */
                        &calibFactors );      /* Calibration factor matrix  */

  while (1)
  {
    if ( TFT_DirectInit(&tftInit) )
    {
      displayHelpScreen();
      BSP_LedsSet(0x0000);
      BSP_PeripheralAccess(BSP_TOUCH, true);
      GPIO_PinModeSet(LCD_TOUCH_X1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_X2, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y1, gpioModeInput, 0);
      GPIO_PinModeSet(LCD_TOUCH_Y2, gpioModeInput, 0);

      do
      {
        buttons = readButtons();

        /* Draw on screen */
        if ( buttons & BC_UIF_PB1 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */

          do
          {
            if ( touched() )
            {
              touchSample = getTouchSample();
              drawPixel( touchSample.x, touchSample.y, COLOR );
            }
            delayMs( 2 );

            buttons = readButtons() & ~BC_UIF_PB1;
          } while ( buttons == 0 );
        }

        /* Calibrate touch screen */
        else if ( buttons & BC_UIF_PB2 )
        {
          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 0 ].x, lcdCalibPoints[ 0 ].y, COLOR );
          TFT_DrawString(30, 35, "Tap green marker" );
          P[ 0 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 1 ].x, lcdCalibPoints[ 1 ].y, COLOR );
          TFT_DrawString(40, 130, "Tap green marker" );
          P[ 1 ] = getTouchTapSample10bit();

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          drawCross( lcdCalibPoints[ 2 ].x, lcdCalibPoints[ 2 ].y, COLOR );
          TFT_DrawString(20, 180, "Tap green marker" );
          P[ 2 ] = getTouchTapSample10bit();

          setCalibrationMatrix( (POINT*)&lcdCalibPoints,/* Display coordinates*/
                                &P[0],                  /* Touch coordinates  */
                                &calibFactors );  /* Calibration factor matrix*/

          memset( frameBuffer, BLACK, 2 * WIDTH * HEIGHT );   /* Clear screen */
          TFT_DrawString(10, 100, "The touch screen is" );
          TFT_DrawString(30, 130, "now calibrated !" );
        }

        /* Display help screen */
        else if ( buttons & BC_UIF_PB3 )
        {
          displayHelpScreen();
          while ( readButtons() & BC_UIF_PB3 ) {}
        }

      } while ( ( buttons & EXIT_LOOP ) == 0 );
    }
    else
    {
      BSP_LedsSet(0x8001);
      delayMs(200);
    }
  }
}