⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 touch.c

📁 一款车载DVD的车机源程序(正在生成中的哦)
💻 C
字号:
/***************************************************************************
Project  :  Car two ting dvd System
Compiler :  ST7 HiCross C (HiWARE)
Module   :  autos.c 
Version  :  V 1.0
Created  :  24 11, 2005
Author   :  tomi / SA
Description
         -  Touch panel use the ADS7846  
Modified
		 - tomi
***************************************************************************/
#include "Touch.h"
#include "Inter.h"
#include "Libr.h"
#include "St72321.h"
#include "IOport.h"
#include "Sys_config.h" 
#include "System_operation.h"
#include "Menu.h"
#include "OSD.h"


unsigned char highlight_item;
static unsigned char Keep_touch_key_code;
static unsigned char Temp_touch_key_code;
unsigned int Touch_data_process(unsigned char touch_command);
void Send_command_to_touch_panel(void);
void Detect_touch_panel(void);
static void Enable_touch_key(void);
/*******************************************************************
Function:Send the command to the touch panel and getparms the X and Y volume
*******************************************************************/
unsigned int Touch_data_process(unsigned char touch_command)
{
	unsigned char i;
	unsigned int j=0;
	
	CLEAR_TOUCH_CLK;
	for( i = 0; i < 8; i++)
 		{
   		delay_us(2);
       	CLEAR_TOUCH_CLK;
        if (touch_command & 0x80)  
            SET_TOUCH_DIN;
        else  
            CLEAR_TOUCH_DIN;
         
		SET_TOUCH_CLK;			
		touch_command <<= 1;
   		}
    CLEAR_TOUCH_DIN;
	delay_us(2);
   	CLEAR_TOUCH_CLK;
   	delay_us(2);

    for( i = 0; i < 16; i++)
   		{
      	delay_us(2); 
		SET_TOUCH_CLK;
	
        if (TOUCH_DOUT_HIGH) 
			j |= 1;
   		CLEAR_TOUCH_CLK;
		j <<= 1;
	  	}
	return(j >> 4 );
}
/**********************************************************
Function:Power on send the command to the touch panel to init it
**********************************************************/
void Send_command_to_touch_panel(void)
{
	Touch_data_process(X_POSITION_COMMAND);
	Touch_data_process(Y_POSITION_COMMAND);
}
/****************************************************************
Function:Program in the main prigram to detect the touch signal by the IRQ
****************************************************************/
void Detect_touch_panel(void)
{
	unsigned char i = 0;
	unsigned int datax,datay,datax1,datay1;
	unsigned int **Menu_name;
	unsigned int *Touch_key_name;
	unsigned char Touch_key_code;
	unsigned char j;
	if(!ValBit(PB_DR,TOU_IRQ))
		{
		datax = Touch_data_process(X_POSITION_COMMAND);
		datay = Touch_data_process(Y_POSITION_COMMAND);

		WAIT_20ms();
		
		datax1 = Touch_data_process(X_POSITION_COMMAND);
		datay1 = Touch_data_process(Y_POSITION_COMMAND);
		if(datax1>datax)
			datax1=datax1-datax;
		else 
			datax1=datax-datax1;

		if(datay1>datay)
			datay1=datay1-datay;
		else 
			datay1=datay-datay1;

		if(datax1<100 && datay1<100)
			{
			if(!ValBit(System_flag1,OSD_on_flag))	//OSD from off to on
				{//Restart displaythe osd all picture
				Set_bell_sound_time(10);
				Clear_osd();
				OSDPosition(1);
				Display_one_mode_all_osd_item();
				return;
				}
			if(!ValBit(System_flag2,Display_on_flag))
//Display from off to on
				{
				Set_bell_sound_time(10);
				SetBit(System_flag2,Display_on_flag);
				Open_TFT_high_power;
				WAIT_100ms();
				WAIT_100ms();
				WAIT_100ms();
				return;
				}
			while( ((MENU_LIST *)Total_menu_list[System_mode])[i].item)
				{
				 if((datax < ((MENU_LIST *)Total_menu_list[System_mode])[i].xy.x1)
					&& (datax > ((MENU_LIST *)Total_menu_list[System_mode])[i].xy.x2)
					&& (datay > ((MENU_LIST *)Total_menu_list[System_mode])[i].xy.y1)
					&& (datay < ((MENU_LIST *)Total_menu_list[System_mode])[i].xy.y2))
				 	{
				 	if(Keep_touch_key_code != i)
				 		{
				 		highlight_item = i;
				 		SetBit(System_flag,Touch_key_flag);
				 		Keep_touch_key_code = i;
						Clear_OSD_delay = 500;
				 		return;
				 		}
				 	else		//Find out the volume up/volume down key item
				 		{
				 		Temp_touch_key_code = i;
				 		switch(System_mode)
				 			{
				 			case AV_mode:
				 				if(i == (ITEM_AV_DEC-1) || i == (ITEM_AV_ADDING-1) || i == (ITEM_AV_LEFT_CLOSE_PANEL-1) || i == (ITEM_AV_RIGHT_CLOSE_PANEL-1) || i == (ITEM_AV_LEFT_OPEN_PANEL-1) || i == (ITEM_AV_RIGHT_OPEN_PANEL-1))
				 					Enable_touch_key();
				 				break;
				 			case CDC_mode:
				 				if(i == (ITEM_CDC_DEC-1) || i == (ITEM_CDC_ADDING-1) || i == (ITEM_CDC_LEFT_CLOSE_PANEL-1) || i == (ITEM_CDC_RIGHT_CLOSE_PANEL-1) || i == (ITEM_CDC_LEFT_OPEN_PANEL-1) || i == (ITEM_CDC_RIGHT_OPEN_PANEL-1))
				 					Enable_touch_key();
				 				break;
				 			case Csp_setting_mode:
				 				if(i == (ITEM_CSP_FRONT_SP_BALANCE_DEC-1) || i == (ITEM_CSP_FRONT_SP_BALANCE_ADDING-1) || i == (ITEM_CSP_TOTAL_VOLUME_DEC-1) ||i == (ITEM_CSP_TOTAL_VOLUME_ADDING-1) || i == (ITEM_CSP_BACK_SP_BALANCE_DEC-1) || i == (ITEM_CSP_BACK_SP_BALANCE_ADDING-1)  )
				 					Enable_touch_key();
				 				break;
				 			case DVD_mode:
				 				if(i == (ITEM_DVD_DEC-1) || i == (ITEM_DVD_ADDING-1) ||i ==(ITEM_DVD_LEFT_CLOSE_PANEL-1) || i == (ITEM_DVD_RIGHT_CLOSE_PANEL-1) || i == (ITEM_DVD_LEFT_OPEN_PANEL-1) || i == (ITEM_DVD_RIGHT_OPEN_PANEL-1) )
				 					Enable_touch_key();
				 				break;
				 			case Radio_mode:
				 				if(i == (ITEM_RADIO_DEC-1) || i == (ITEM_RADIO_ADDING-1))
				 					Enable_touch_key();
				 				break;
				 			case Time_setting_mode:
				 				if(i == (ITEM_TIME_DEC-1) || i == (ITEM_TIME_ADDING-1))
				 					Enable_touch_key();
				 				break;
				 			case TV_mode:
				 				if(i == (ITEM_TV_DEC-1) || i == (ITEM_TV_ADDING-1) || i == (ITEM_TV_LEFT_CLOSE_PANEL-1) || i == (ITEM_TV_RIGHT_CLOSE_PANEL-1) || i == (ITEM_TV_LEFT_OPEN_PANEL-1) || i == (ITEM_TV_RIGHT_OPEN_PANEL-1))
				 					Enable_touch_key();
				 				break;
				 			case Video_setting_mode:
				 				if(i == (ITEM_VIDEO_DEC-1) || i == (ITEM_VIDEO_ADDING-1))
				 					Enable_touch_key();
				 				break;
				 			}
				 		}
				 	}
				i++;
				}
			}
			
		}
	else
		{
		Keep_touch_key_code = 0xff;
		}
}


static void Enable_touch_key(void)
{
	highlight_item = Temp_touch_key_code;
	SetBit(System_flag,Touch_key_flag);
	Keep_touch_key_code = Temp_touch_key_code;
	Clear_OSD_delay = 500;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -