📄 8069238504d0001d1a2799d0dc5dea19
字号:
/* Scheduler include files. */
#include "FreeRTOS.h"
#include "task.h"
//#include "mkd.h"
#include "type.h"
#include "../gui/font5_7.h"
#include "uart.h"
#include "stdio.h"
#include "package.h"
#include "keyscan.h"
#include "../app/kbd.h"
#include "../gui/GUI_StockC.h"
#include "../lcd/lcddrive.h"
/* ---------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------- */
//extern uint8 const DCB2HEX_TAB[8];
uint8 curCmdStat=0x00; //用来标志系统是否忙
extern struct TURNPAGE m_TurnPage;
extern struct CmdRcv CmdRcvIrq;
/*-----------------------------------------------------------
* function : responseErrorReport
* parameter:errcode
* specification : if Cmd received from the upper is uncorrect ,
* return the errcode to the upper
*
* -----------------------------------------------------------*/
void responseErrorReport(unsigned char errcode)
{
uint8 buf;
buf=(uint8)errcode;
responseReport('A',&buf,1);
}
/*-------------------------------------------------------------
* function: responseReport
* specification:construct datas for responsing
* parameters:flag A or I;pStr is the pointer of returning datas
* len=sizeof(pStr)+1
*-------------------------------------------------------------*/
void responseReport(unsigned char flag,uint8 *pStr,uint8 len)
{
int oLen,offset;
unsigned char buf[200];
unsigned char BccChr;
offset=0;
BccChr=0;
buf[offset]=0x02; BccChr=BccChr^0x02; offset++;
buf[offset]=0x2c; BccChr=BccChr^0x2c; offset++;
buf[offset]=len+1; BccChr=BccChr^buf[offset]; offset++;
buf[offset]=flag; BccChr=BccChr^buf[offset]; offset++;
for(oLen=0;oLen<len;oLen++)
{
buf[offset]=*(pStr+oLen); BccChr=BccChr^buf[offset]; offset++;
}
buf[offset]=0x03; BccChr=BccChr^buf[offset]; offset++;
buf[offset]=BccChr; offset++;
xUARTSend(buf,offset);
}
/*-----------------------------------------------------------------------
* function : vStartPCKTasts
* specification : start a tast for receive Cmd from the upper
* parameter : uxPriority is the priority of task
*
*
* ----------------------------------------------------------------------*/
void vStartPCKTasks( unsigned portBASE_TYPE uxPriority )
{
/* Create the task. */
xTaskCreate( vPCKTask,(signed portCHAR *)"PCK", pckSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
}
/*------------------------------------------------------------------------
*
* function : vPCKTask
* specification : Crearte a task named vPCKTask
* parameter : pvParameters
*
* ------------------------------------------------------------------------*/
uint8 t_len;
static portTASK_FUNCTION( vPCKTask, pvParameters )
{
//uint8 tmpstring[10]={0x30,0x00,0xff,0x02,0x04,0x05};
portTickType xPCKRate, xLastPCKTime;
int retCode,i;
uint8 tmpChar[20];
//char * pStr;
/* The parameters are not used. */
( void ) pvParameters;
xUARTStartReceive(); //notice uart communication irq , may start receiving
m_TurnPage.len=0;
m_TurnPage.ptr=0;
xPCKRate = pck_RATE_BASE ;
xPCKRate /= portTICK_RATE_MS; //delay xPCKRate ms
/* We need to initialise xLastPCKTime prior to the first call to vTaskDelayUntil(). */
xLastPCKTime = xTaskGetTickCount();
for(;;)
{
/* Delay for half the flash period then turn the LED on. */
vTaskDelayUntil( &xLastPCKTime, xPCKRate );
retCode=xUARTRead((unsigned char*)recvBuff,(DWORD*)&cmdBuff_Len); //从串口缓冲中取数据
if(retCode==0x0f) continue; //no data ,continue waiting
if(retCode>0&&retCode<5) //如果接收错误,返回接收错误帧
{
/*package error */
responseErrorReport(retCode);
continue;
}
switch(recvBuff[0])
{
case 'S':
responseErrorReport(0);
//初始化系统
break;
case 'I':
//SendByte(0x55);
retCode=DoCommand(cmdBuff);
if(retCode==0x02)
responseErrorReport(0x02); //device busy
break;
case 'C':
//retCode=2; //返回一个确认帧
tmpChar[0]=0x00;
tmpChar[1]=0x00;
cmd_Len=CmdRcvIrq.len;
for(i=0;i<3;i++)
SendByte(*(recvBuff+i));
memcpy(cmdBuff,recvBuff,CmdRcvIrq.len);
responseReport('A',tmpChar,2);
break;
default:
responseErrorReport(0x03); //error command
break;
}
}
}
/*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
/*----------------------------------------------------------------------------------
*
* function : DoCommand
* specificaiton : specify the received command and perform the command
* parameters : cmdStr and cmdLen
*
* --------------------------------------------------------------------------------*/
int DoCommand(uint8 * ptr)
{
uint8 tmpData,i;
//uint8 tmp;
//uint8 * ptr;
if(curCmdStat) return 2; //device busy
//ptr=curCmdStat;
for(i=0;i<3;i++)
SendByte(*(ptr+i));
tmpData=*(ptr+1); //获得Cmd
portENTER_CRITICAL();
{
curCmdStat=0x02; //设置忙标志位
switch(tmpData)
{
case 0x30: //开关背景灯
//CurrCmdStatMKD.curCmdNob=0;
SwitchlightMKD(ptr);
break;
case 0x32: //清屏
//CurrCmdStatMKD.curCmdNob=2;
ClearScreenMKD(ptr);
break;
case 0x33: //显示内容
//SendByte(cmdBuff_Len);
DisplayStringMKD(ptr,cmd_Len); //cmdBuff_Len-5是显示内容占的字节
break;
case 0x34: //设置显示模式
//CurrCmdStatMKD.curCmdNob=4;
//SetDisplayMode(ptr+2);
case 0x35: //读取键值
//CurrCmdStatMKD.curCmdNob=5;
//for(tmp=0;tmp<cmd_Len;tmp++)
//SendByte(*(ptr+tmp));
PollingKeyMKD(ptr);
break;
}
curCmdStat=0x00; //清楚忙标志位
}
portEXIT_CRITICAL();
return 0;
}
/*-----------------------------------------------------------------------
*
* 区域清屏
*
*
*
* ----------------------------------------------------------------------*/
int ClearScreenMKD(uint8 *ptr)
{
uint8 x,y,w,h,pm,tmpChar[20];
uint8 fillData=0x00;
ptr+=2; //跳到PM
pm=*ptr;
//SendByte(pm);
if(pm==0x30) //如果是清全屏
{
x=0;y=0;w=120;h=120;
ClearFlag(); //clear turnFlag
}
else if(pm==0x31) //区域清屏
{
ptr+=2; //跳过pm
y=(*ptr)*12; ptr+=2; //计算第Y行顶点的像素坐标
x=(*ptr)*6; ptr+=2; //计算第X列顶点的像素坐标
w=(*ptr)*6; ptr+=2; //计算w列宽的像素值
h=(*ptr)*12; ptr+=2; //计算h行高占的像素值
//SendByte(x);
//SendByte(y);
//SendByte(w);
//SendByte(h);
}
//if(*ptr==0x31)
// fillData=0xff;
if(w==0||h==0) return NORMAL;
LCD_FillDat(x,y,w,h,fillData); //填充指定区域
SendByte(0xaa);
tmpChar[0]=0x00; //返回数据
tmpChar[1]=0x00;
responseReport('R',tmpChar,3);
return NORMAL;
}
/*---------------------------------------------------------------------------
*
* 开或关背景灯
*
*
* --------------------------------------------------------------------------*/
int SwitchlightMKD(uint8 * ptr)
{
uint8 tmpChar[20];
uint8 * tmp;
ptr+=2;
tmp=ptr; //pm
if(*tmp==0x30)
LCD_BackLight(1);
else
LCD_BackLight(0);
tmpChar[0]=0x00;
tmpChar[1]=0x00;
responseReport('R',tmpChar,3);
return NORMAL;
}
/*-------------------------------------------------------------------------------
*
*
* function : display a string on appointing location.
*
* parameter : ptr 从显示坐标开始,len为显示内容所占的长度
*
*
* ------------------------------------------------------------------------------*/
int DisplayStringMKD(uint8 * ptr,uint8 len)
{
//uint8 num;
uint8 tmpChar[20];
uint32 x,y,color;
int tmp;
ptr+=3;
color=*ptr; ptr+=2; //获得显示颜色
//ptr++; /* Skip the PM */
//SendByte(len);
y=(*ptr); ptr+=2; // get the y row
x=(*ptr); ptr++; //get the x column
//SendByte(x);
//SendByte(y);
tmp=200-20*y-x; //是否需要翻页
len-=7; //得到字符的长度
SendByte(tmp);
if(tmp<len)
{
m_TurnPage.ptr=ptr;
m_TurnPage.len=len;
m_TurnPage.x=x;
m_TurnPage.y=y;
m_TurnPage.first_len=tmp;
PutString(m_TurnPage.x,m_TurnPage.y,ptr,m_TurnPage.first_len);
m_TurnPage.TURN_Flag=1;
DisplayFlag(2);
//PollingKeyMKD(ptr);
}
else
{
PutString(x,y,ptr,len);
ClearFlag();
}
tmpChar[0]=0x00;
tmpChar[1]=0x00;
responseReport('R',tmpChar,3);
return NORMAL;
}
/*-------------------------------------------------------------------------------
*
* function : SetDisplayMode
* specification : 设置显示方式,0x00白底黑字;0x01黑底白字
*
* parameter : ptr-- the pointer to the command
*
* ------------------------------------------------------------------------------*/
int SetDisplayMode(uint8 *ptr)
{
uint8 tmp,tmpChar[20];
tmp=*(ptr+1); // skip pm
if(tmp==0x00)
GUI_SetColor(1,0);
else
GUI_SetColor(0,1);
tmpChar[0]=0x00;
tmpChar[1]=0x00;
responseReport('R',tmpChar,3);
return 0;
}
/*-----------------------------------------------------------------------------------
*
* 显示一个字符串
* 在x列,y行 显示一个字符串,宽度len
*
* ---------------------------------------------------------------------------------*/
void PutString(uint8 x,uint8 y,uint8 *ptr,uint8 len)
{
uint32 m_x,m_y;
m_x=(uint32)(x)*6; //计算列像素坐标
m_y=(uint32)(y)*12; //计算行像素坐标
GUI_PutString(m_x,m_y,ptr,len);
}
/*------------------------------------------------------------------------------------
*
*
*
*
*
* ------------------------------------------------------------------------------------*/
void strCopy(uint8 * dest,uint8 * sour,uint8 len)
{
uint8 i;
for(i=0;i<len;i++)
{
*(dest+i)=*(sour);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -