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

📄 app_bluescreen_demo.c

📁 LPC2300 MP3 Player code
💻 C
📖 第 1 页 / 共 2 页
字号:
{
	unsigned char i = 0;
	unsigned char j = 0;
	unsigned int res;

	if (showing_flag)
	{
		return;	
	}

	while (current_dir[i]) //search for \0
	{
		showing_path[i] = current_dir[i];
		i++;
	}

	if (i > 1) //file in root don't need '/'
	{
		showing_path[i] = '/';
		i++;
	}
	else
	{
		i = 0;
	}

	while (file_name[j])
	{
		showing_path[i] = file_name[j];
		i++;
		j++;
	}

	showing_path[i] = 0;
	i=0;

	SDSPIInit();
	res = file_fopen(&showing_file, &efs.myFs, showing_path, 'r');
	if (res == 0)
	{
		showing_flag = 1;

		TSLCDOutIns(TS_INS_START_ADX);
		TSLCDOutDat(0);
		TSLCDOutIns(TS_INS_END_ADX);
		TSLCDOutDat(TS_SIZE_X-1);
		TSLCDOutIns(TS_INS_GRAM_ADX);
		TSLCDOutDat(0);

		TSLCDOutIns(TS_INS_START_ADY);
		TSLCDOutDat(0);
		TSLCDOutIns(TS_INS_END_ADY);
		TSLCDOutDat(TS_SIZE_Y-1);
		TSLCDOutIns(TS_INS_GRAM_ADY);
		TSLCDOutDat(TS_SIZE_Y-1); //fix bug from version 4_8_2008
	
		TSLCDOutIns(TS_INS_RW_GRAM);
	}
}

void AppSDShowPicFreeTime(void)
{
	unsigned int k;
	unsigned int res;

	unsigned char buffer[512];

	if (showing_flag)
	{
		SDSPIInit();

		res = file_read(&showing_file,512,buffer);
		if (res)
		{
			for (k=0;k<res;k+=2)
			{
				TSLCDOutDat2(buffer[k],buffer[k+1]);
			}
		}
		else
		{
			showing_flag = 0;
			file_fclose(&showing_file);
			fs_umount(&efs.myFs);
		}
	}
}

void AppSDShowPic(char *file_name)
{
	unsigned char i = 0;
	unsigned char j = 0;
	unsigned int k;
	unsigned int res;

	unsigned char buffer[512];

//	AppSDInit();
	SDSPIInit();
	if (!sd_inited)
	{
		return;	
	}
	
	while (current_dir[i]) //search for \0
	{
		showing_path[i] = current_dir[i];
		i++;
	}

	if (i > 1) //file in root don't need '/'
	{
		showing_path[i] = '/';
		i++;
	}
	else
	{
		i = 0;
	}

	while (file_name[j])
	{
		showing_path[i] = file_name[j];
		i++;
		j++;
	}

	showing_path[i] = 0;
	i=0;

	res = file_fopen(&showing_file, &efs.myFs, showing_path, 'r');
	if (res == 0)
	{

		TSLCDOutIns(TS_INS_START_ADX);
		TSLCDOutDat(0);
		TSLCDOutIns(TS_INS_END_ADX);
		TSLCDOutDat(TS_SIZE_X-1);
		TSLCDOutIns(TS_INS_GRAM_ADX);
		TSLCDOutDat(0);

		TSLCDOutIns(TS_INS_START_ADY);
		TSLCDOutDat(0);
		TSLCDOutIns(TS_INS_END_ADY);
		TSLCDOutDat(TS_SIZE_Y-1);
		TSLCDOutIns(TS_INS_GRAM_ADY);
		TSLCDOutDat(0);
	
		TSLCDOutIns(TS_INS_RW_GRAM);

		res = file_read(&showing_file,512,buffer);
		while (res)
		{
			for (k=0;k<res;k+=2)
			{
				TSLCDOutDat2(buffer[k],buffer[k+1]);
			}
			res = file_read(&showing_file,512,buffer);
		}
	}
	else
	{
		saystr("\r\nFile not found\r\n");
	}

	file_fclose(&showing_file);
	fs_umount(&efs.myFs);
}

long cal_posx(unsigned short x)
{
	long buf;
	buf = x - ccx;
	buf = buf*cm1x;
	buf = buf/cm2x;
	buf = buf + chalfx;
#ifdef TS_ORN_PORTRAIT
	if (filp_horizontal)
		return (TS_SIZE_X - buf);
	else
#endif
		return (buf);
}

long cal_posy(unsigned short y)
{
	long buf;
	buf = y - ccy;
	buf = buf*cm1y;
	buf = buf/cm2y;
	buf = buf + chalfy;
#ifndef TS_ORN_PORTRAIT
	if (filp_horizontal)
		return (TS_SIZE_Y - buf);
	else
#endif
		return (buf);
}

pos_t scan_pen(void)
{
	unsigned short tc_x_buf,tc_y_buf;
	unsigned short tc_x_max,tc_y_max;
	unsigned short tc_x_min,tc_y_min;
	pos_t pos;

	pos.on = 0;
	if (TCIsPenOn())
	{
		TCRead();
		tc_x_buf = TCGetH();
		tc_y_buf = TCGetV();

		tc_x_max = TCGetH();
		tc_y_max = TCGetV();
		tc_x_min = TCGetH();
		tc_y_min = TCGetV();

		TCRead();
		tc_x_buf += TCGetH();
		tc_y_buf += TCGetV();

		if (TCGetH() > tc_x_max)
			tc_x_max = TCGetH();
		if (TCGetH() < tc_x_min)
			tc_x_min = TCGetH();
		if (TCGetV() > tc_y_max)
			tc_y_max = TCGetV();
		if (TCGetV() < tc_y_min)
			tc_y_min = TCGetV();

		TCRead();
		tc_x_buf += TCGetH();
		tc_y_buf += TCGetV();

		if (TCGetH() > tc_x_max)
			tc_x_max = TCGetH();
		if (TCGetH() < tc_x_min)
			tc_x_min = TCGetH();
		if (TCGetV() > tc_y_max)
			tc_y_max = TCGetV();
		if (TCGetV() < tc_y_min)
			tc_y_min = TCGetV();

		TCRead();
		tc_x_buf += TCGetH();
		tc_y_buf += TCGetV();

		if (TCGetH() > tc_x_max)
			tc_x_max = TCGetH();
		if (TCGetH() < tc_x_min)
			tc_x_min = TCGetH();
		if (TCGetV() > tc_y_max)
			tc_y_max = TCGetV();
		if (TCGetV() < tc_y_min)
			tc_y_min = TCGetV();

		tc_x_buf -= tc_x_max;
		tc_x_buf -= tc_x_min;
		tc_y_buf -= tc_y_max;
		tc_y_buf -= tc_y_min;

		tc_x_buf = tc_x_buf >> 1;
		tc_y_buf = tc_y_buf >> 1;

		if (TCIsPenOn())
		{
			pos.x = cal_posx(tc_x_buf);
			pos.y = cal_posy(tc_y_buf);
			pos.on = 1;
		}
	}
	return (pos);
}

void AppScanPen(void)
{
	pos_t pos = scan_pen();
	if (pos.on)
	{
		if (last_pen_check)
		{
			p_stat = PST_HOLD;
		}
		else
		{
			p_stat = PST_DOWN;
		}

		if ((pos.x) && (pos.y) && (pos.x < TS_SIZE_X) && (pos.y < TS_SIZE_Y))
		{
			hpos = pos.x;
			vpos = pos.y;
			ScrObjDo(hpos,vpos,p_stat);
		}

		last_pen_check = 1;
	}
	else
	{
		if (last_pen_check)
		{
			p_stat = PST_UP;
		}
		else
		{
			p_stat = PST_NOTFOUND;		
		}

		ScrObjDo(hpos,vpos,p_stat);

		last_pen_check = 0;
	}
}

void AppTask1ms(void)
{
}

void AppTask10ms(void)
{
	VSAudioTask();//mp3
	AppScanPen();
}

void AppTask100ms(void)
{
	ScrObjTask100ms();
}

void AppTask500ms(void)
{
	if (time_500ms_cnt & 1)
	{	
		Clrb(LED1_PRTC,LED1_PIN);
	}
	else
	{
		Setb(LED1_PRTS,LED1_PIN);
	}
}

void AppCalibrateScreen(unsigned char wait_time)
{
	pos_t pos;
	unsigned char line;
//	char str[32];
	unsigned char i2c_buf[32];
	long dat_buf;
	int buf;

	int x[TC_TP_NUM];
	int y[TC_TP_NUM];

    long sum_xx = 0;
    long sum_yy = 0;
    long sum_fx = 0;
    long sum_fy = 0;
    long sum_fxx = 0;
    long sum_fyy = 0;

	float cx;
	float mx;
	float cy;
	float my;

    float mx_new;
    float my_new;

	float buf_mod1;

	long fx[TC_TP_NUM];
	long fy[TC_TP_NUM];
	long xx[TC_TP_NUM];
	long yy[TC_TP_NUM];
	long fxx[TC_TP_NUM];
	long fyy[TC_TP_NUM];

	unsigned char i,j,k;
	unsigned char good_press;

	EPRead(EP_AD_CFG,25,i2c_buf);

	if ((i2c_buf[EP_FIRST_READ] == CAL_VALID_PORTRAIT) || 
		(i2c_buf[EP_FIRST_READ] == CAL_VALID_LANDSCAPE)) //check for valid touch screen calibration data
	{
		if (wait_time)
		{
#ifdef TS_ORN_PORTRAIT
			line = 8;
#else
			line = 5;
#endif
	/*		TSLCDFillRect(0,TS_SIZE_X-1,0,TS_SIZE_Y-1,TS_COL_BLUE,TS_MODE_NORMAL);
			TSLCDSetOffset((TS_SIZE_X-TSLCDGetStringWidth("Press the screen")) >> 1,0);
			TSLCDPrintStr( line,0,"Press the screen",TS_MODE_FULL);
			line += 2;
			TSLCDSetOffset((TS_SIZE_X-TSLCDGetStringWidth("to recalibrate")) >> 1,0);
			TSLCDPrintStr( line,0,"to recalibrate",TS_MODE_FULL);
			line += 2;
			TSLCDSetOffset((TS_SIZE_X-TSLCDGetStringWidth("within 3 seconds")) >> 1,0);
			k = 0;
	*/
		}

		for (i=0;i<wait_time;i++)
		{
		/*	sprintf(str,"within %d seconds",wait_time-i);
			TSLCDPrintStr( line,0,str,TS_MODE_FULL);

		*/
			for (j=0;j<10;j++)
			{
				if (TCIsPenOn())
				{
					k = 1;
					break;
				}
//				delay_1ms(100);
			}
			if (k)
				break;
		}
		TSLCDSetOffset(0,0);

		if (k == 0) //use old data
		{
			if (i2c_buf[EP_FIRST_READ] != CAL_VALID)
				filp_horizontal = 1;

			ccx = 0;
			for (i=0;i<4;i++) //sizeof long = 4
			{
				dat_buf = i2c_buf[EP_FIRST_READ + EP_AD_CFG_CX + i];
				dat_buf	<<= i*8;
				ccx |= dat_buf;
			}
		
			cm1x = 0;
			for (i=0;i<4;i++) //sizeof long = 4
			{
				dat_buf = i2c_buf[EP_FIRST_READ + EP_AD_CFG_M1X + i];
				dat_buf	<<= i*8;
				cm1x |= dat_buf;
			}
		
			cm2x = 0;
			for (i=0;i<4;i++) //sizeof long = 4
			{
				dat_buf = i2c_buf[EP_FIRST_READ + EP_AD_CFG_M2X + i];
				dat_buf	<<= i*8;
				cm2x |= dat_buf;
			}
		
			ccy = 0;
			for (i=0;i<4;i++) //sizeof long = 4
			{
				dat_buf = i2c_buf[EP_FIRST_READ + EP_AD_CFG_CY + i];
				dat_buf	<<= i*8;
				ccy |= dat_buf;
			}
		
			cm1y = 0;
			for (i=0;i<4;i++) //sizeof long = 4
			{
				dat_buf = i2c_buf[EP_FIRST_READ + EP_AD_CFG_M1Y + i];
				dat_buf	<<= i*8;
				cm1y |= dat_buf;
			}
		
			cm2y = 0;
			for (i=0;i<4;i++) //sizeof long = 4
			{
				dat_buf = i2c_buf[EP_FIRST_READ + EP_AD_CFG_M2Y + i];
				dat_buf	<<= i*8;
				cm2y |= dat_buf;
			}

			return;
		}
	}

	while(TCIsPenOn());

	TSLCDFillRect(0,TS_SIZE_X-1,0,TS_SIZE_Y-1,TS_COL_BLUE,TS_MODE_NORMAL);

	for (i=0; i<TC_TP_NUM; i++)
	{
		TSLCDFillCirc(tc_tpx[i],tc_tpy[i],8,TS_COL_WHITE,TS_MODE_FULL);
		TSLCDFillCirc(tc_tpx[i],tc_tpy[i],6,TS_COL_BLUE,TS_MODE_FULL);
		TSLCDFillRect(tc_tpx[i],tc_tpx[i],tc_tpy[i],tc_tpy[i],TS_COL_WHITE,TS_MODE_NORMAL);

		good_press = 0;
		while (!good_press)
		{
			while (!TCIsPenOn());
			TCRead();
			delay_1ms(50);
			if (TCIsPenOn())
			{
				TCRead();
				//delay_1ms(500);
				while (TCIsPenOn());
				good_press = 1;
			}
		}
		fx[i] = TCGetH();
		fy[i] = TCGetV();

		TSLCDFillCirc(tc_tpx[i],tc_tpy[i],8,TS_COL_BLUE,TS_MODE_FULL);
	}

	for (i=0;i<TC_TP_NUM;i++)
	{
        x[i] = tc_tpx[i] - chalfx;
        y[i] = tc_tpy[i] - chalfy;
        xx[i] = x[i] * x[i];
        yy[i] = y[i] * y[i];
		fxx[i] = fx[i] * x[i];
		fyy[i] = fy[i] * y[i];
	}

	for (i=0;i<TC_TP_NUM;i++)
    {
        sum_xx += xx[i];
        sum_yy += yy[i];
        sum_fx += fx[i];
        sum_fy += fy[i];
        sum_fxx += fxx[i];
        sum_fyy += fyy[i];
    }

    cx = ((float)sum_fx) / ((float)(TC_TP_NUM));
    mx = ((float)sum_fxx) / ((float)sum_xx);
    cy = ((float)sum_fy) / ((float)(TC_TP_NUM));
    my = ((float)sum_fyy) / ((float)sum_yy);

	ccx = (long)cx;
	ccy = (long)cy;

    mx_new = mx;
    my_new = my;

	buf_mod1 = mx_new - (long)mx_new;
	if (buf_mod1 < 0)
		buf_mod1 = -buf_mod1;
	buf = 1;

    while ((buf_mod1 > 0.05) && (buf_mod1 < 0.95))
    {
        buf++;
        mx_new = mx*((float) buf);
		buf_mod1 = mx_new - (long)mx_new;
		if (buf_mod1 < 0)
			buf_mod1 = -buf_mod1;
    }

	cm1x = buf;
    cm2x = (long)(mx * buf);

	buf_mod1 = my_new - (long)my_new;
	if (buf_mod1 < 0)
		buf_mod1 = -buf_mod1;
    buf = 1;

    while ((buf_mod1 > 0.05) && (buf_mod1 < 0.95))
    {
        buf++;
        my_new = my*((float)buf);
		buf_mod1 = my_new - (long)my_new;
		if (buf_mod1 < 0)
			buf_mod1 = -buf_mod1;
    }

    cm1y = buf;
    cm2y = (long)(my * buf);

	i2c_buf[EP_FIRST_WRITE] = CAL_VALID; //EP_AD_CFG_STATUS --> config data valid

	dat_buf = ccx;
	for (i=0;i<4;i++) //sizeof long = 4
	{
		i2c_buf[EP_FIRST_WRITE + EP_AD_CFG_CX + i] = dat_buf;
		dat_buf >>= 8;
	}

	dat_buf = cm1x;
	for (i=0;i<4;i++) //sizeof long = 4
	{
		i2c_buf[EP_FIRST_WRITE + EP_AD_CFG_M1X + i] = dat_buf;
		dat_buf >>= 8;
	}

	dat_buf = cm2x;
	for (i=0;i<4;i++) //sizeof long = 4
	{
		i2c_buf[EP_FIRST_WRITE + EP_AD_CFG_M2X + i] = dat_buf;
		dat_buf >>= 8;
	}

	dat_buf = ccy;
	for (i=0;i<4;i++) //sizeof long = 4
	{
		i2c_buf[EP_FIRST_WRITE + EP_AD_CFG_CY + i] = dat_buf;
		dat_buf >>= 8;
	}

	dat_buf = cm1y;
	for (i=0;i<4;i++) //sizeof long = 4
	{
		i2c_buf[EP_FIRST_WRITE + EP_AD_CFG_M1Y + i] = dat_buf;
		dat_buf >>= 8;
	}

	dat_buf = cm2y;
	for (i=0;i<4;i++) //sizeof long = 4
	{
		i2c_buf[EP_FIRST_WRITE + EP_AD_CFG_M2Y + i] = dat_buf;
		dat_buf >>= 8;
	}

	EPWrite(EP_AD_CFG,25,i2c_buf);
	delay_1ms(100);

	TSLCDFillRect(0,TS_SIZE_X-1,0,TS_SIZE_Y-1,TS_COL_BLUE,TS_MODE_NORMAL);
	line -= 4;
	TSLCDSetOffset((TS_SIZE_X-TSLCDGetStringWidth("Now try pressing")) >> 1,0);
	TSLCDPrintStr( line,0,"Now try pressing",TS_MODE_FULL);
	line += 2;
	TSLCDSetOffset((TS_SIZE_X-TSLCDGetStringWidth("on the screen")) >> 1,0);
	TSLCDPrintStr( line,0,"on the screen",TS_MODE_FULL);
	line += 2;
	TSLCDSetOffset((TS_SIZE_X-TSLCDGetStringWidth("then please reset")) >> 1,0);
	TSLCDPrintStr( line,0,"then please reset",TS_MODE_FULL);

	while (1)
	{
		pos = scan_pen();
		if (pos.on)
		{
			if ((pos.x) && (pos.y) && (pos.x < TS_SIZE_X) && (pos.y < TS_SIZE_Y))
			{
				hpos = pos.x;
				vpos = pos.y;
			//	TSLCDFillCirc(pos.x,pos.y,10,TS_COL_RED,TS_MODE_NORMAL);
				TSLCDFillCirc(pos.x,pos.y,5,TS_COL_RED,TS_MODE_NORMAL);

			}
		}
		delay_1ms(10);
	}
}

void AppEPTest(void)
{
	unsigned char i2c_buf[5];
	unsigned char ep_test_val;

	EPRead(EP_SIZE-8,1,i2c_buf);
	ep_test_val = i2c_buf[EP_FIRST_READ];
	ep_test_val++;

	i2c_buf[EP_FIRST_WRITE] = ep_test_val;
	EPWrite(EP_SIZE-8,1,i2c_buf);
	delay_1ms(100);

	i2c_buf[EP_FIRST_READ] = ~ep_test_val;

	EPRead(EP_SIZE-8,1,i2c_buf);
	if (i2c_buf[EP_FIRST_READ] == ep_test_val)
	{
		saystr("\r\nEEPROM test passed\r\n");
	}
	else
	{
		saystr("\r\nEEPROM test failed\r\n");
	}
}

void AppInit(void)
{
	Clrb(BL_CTL_PRTC,BL_CTL_PIN);

  	SerialInit(CONS_SER,8,0x34);				// 57600 
	SerialInit(XBEE_SER,48,0x34);				// 9600
	
	EPInit(24,24); 								// ~357 kHz

	Orb(VS_CS_DPRT,VS_CS_PIN);
	Setb(VS_CS_PRTS,VS_CS_PIN);
	Orb(VS_DCS_DPRT,VS_DCS_PIN);
	Setb(VS_DCS_PRTS,VS_DCS_PIN);
	Orb(TC_CS_DPRT,TC_CS_PIN);
	Setb(TC_CS_PRTS,TC_CS_PIN);

	AppSDInit();
	TCInit();

	delay_1ms(100);

	AppEPTest();
	VSInit();

	Setb(BL_CTL_PRTS,BL_CTL_PIN);
	TSLCDRst();
	TSLCDInit();

	TSLCDSetFontColor(TS_COL_WHITE);
	TSLCDSetBackColor(TS_COL_BLUE);

	TSLCDCfgFont(font_vrinda11x16,11,2,2);
	TSLCDSetVaryWidth(1);
	TSLCDSetBold(0);
	AppCalibrateScreen(1);
	ShowLogo();

	delay_1ms(1000);

	TSLCDCfgFont(font_vrinda11x16,11,2,2);
	TSLCDSetVaryWidth(1);
	TSLCDSetBold(0);
	
	ScrObjInit(OperateScreenInit);
}


void AppRun(void)
{

	AppSDShowPicFreeTime();
}

⌨️ 快捷键说明

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