📄 template.c
字号:
// Template.c
//用途: 提供可套用的模板
#include"..\ucos-ii\includes.h" /* uC/OS interface */
#include "..\ucos-ii\add\osaddition.h"
#include"..\inc\osfile.h"
#include"..\inc\drv\rtc.h"
#include "..\inc\drv.h"
#include <string.h>
#include "..\ucos-ii\add\list.h"
#include "..\inc\drv\figure.h"
#include "..\inc\drv\display.h"
#include "..\inc\maro.h"
#include "..\template.h"
//////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// 基本API函数 //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void strChar2U8(U8 ch2[], const char ch1[])
{
while(*ch1){
*ch2=*ch1;
ch2++;
ch1++;
}
*ch2=0;
}
void U82strChar(char ch2[], const U8 ch1[] )
{
while(*ch1){
*ch2=*ch1;
ch2++;
ch1++;
}
*ch2=0;
}
void Int2strChar(char ch[], const int number)
{
u16 str[256];
Int2Unicode( number, str);
Unicode2strChar(ch, str);
}
int strChar2Int(char ch[])
{
u16 str[256];
int i;
strChar2Unicode(str, ch);
i=Unicode2Int( str );
return i;
}
//strChar2Unicode(U16 ch2 [ ], const char ch1 [ ]);
void Unicode2strChar(char ch2[], const u16 ch1[])
{
while(*ch1){
*ch2=*ch1;
ch2++;
ch1++; //问题1:该函数在c++中通不过
}
*ch2=0;
}
int CntUstrNum(u16 *ustr) // 计算Unicode 串的字数
{
int UstrNum=0;
while(*ustr!=0){
UstrNum++;
ustr++; ////问题1:该函数在c++中通不过
}
return UstrNum;
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// 简单图形API函数 (new) /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void UniformLine(PDC pdc, int Point1x, int Point1y, int Point2x, int Point2y, int PenWidth)
{
int i;
for(i=0;i<PenWidth;i++){
SetPenColor( pdc, RGB(127,127,127));
MoveTo( pdc, Point1x, Point1y+i);
LineTo( pdc, Point2x, Point2y+i);
}
}
void VerticalLine(PDC pdc, int Point1x, int Point1y, int Point2x, int Point2y)
{
int i=0;
SetPenColor( pdc, RGB(192,192,192));
MoveTo( pdc, Point1x+i, Point1y);
LineTo( pdc, Point2x+i, Point2y);
i++;
SetPenColor( pdc, RGB(192,192,192));
MoveTo( pdc, Point1x+i, Point1y);
LineTo( pdc, Point2x+i, Point2y);
i++;
SetPenColor( pdc, RGB(255,255,255));
MoveTo( pdc, Point1x+i, Point1y);
LineTo( pdc, Point2x+i, Point2y);
i++;
SetPenColor( pdc, RGB(0,0,0));
MoveTo( pdc, Point1x+i, Point1y);
LineTo( pdc, Point2x+i, Point2y);
i++;
SetPenColor( pdc, RGB(0,0,0));
MoveTo( pdc, Point1x+i, Point1y);
LineTo( pdc, Point2x+i, Point2y);
}
void HorizonLine(PDC pdc, int Point1x, int Point1y, int Point2x, int Point2y)
{
int i=0;
SetPenColor( pdc, RGB(192,192,192));
MoveTo( pdc, Point1x, Point1y+i);
LineTo( pdc, Point2x, Point2y+i);
i++;
SetPenColor( pdc, RGB(192,192,192));
MoveTo( pdc, Point1x, Point1y+i);
LineTo( pdc, Point2x, Point2y+i);
i++;
SetPenColor( pdc, RGB(128,128,128));
MoveTo( pdc, Point1x, Point1y+i);
LineTo( pdc, Point2x, Point2y+i);
i++;
SetPenColor( pdc, RGB(255,255,255));
MoveTo( pdc, Point1x, Point1y+i);
LineTo( pdc, Point2x, Point2y+i);
i++;
SetPenColor( pdc, RGB(128,128,128));
MoveTo( pdc, Point1x, Point1y+i);
LineTo( pdc, Point2x, Point2y+i);
i++;
SetPenColor( pdc, RGB(0,0,0));
MoveTo( pdc, Point1x, Point1y+i);
LineTo( pdc, Point2x, Point2y+i);
}
void Draw3DUpRect(PDC pdc, int Textx,int Texty,int TextNum, u8 fnt) //画3D 凹矩形,用于模拟量数字的显示
{
structRECT TextRect;
SetRect(&TextRect, Textx, Texty, Textx+OSFontSize[fnt]*TextNum, Texty+OSFontSize[fnt]);
InflateRect(&TextRect, 3,3);
Draw3DRect2(pdc, &TextRect, RGB(192,192,192), RGB(0,0,0));
InflateRect(&TextRect, -1,-1);
Draw3DRect2(pdc, &TextRect, RGB(192,192,192), RGB(0,0,0));
InflateRect(&TextRect, -1,-1);
Draw3DRect2(pdc, &TextRect, RGB(128,128,128), RGB(0,0,0));
}
void Draw3DUpRect2(PDC pdc, structRECT * prect) ////画3D 凸矩形,用于开关量显示
{
Draw3DRect2(pdc, prect, RGB(192,192,192), RGB(0,0,0));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(192,192,192), RGB(0,0,0));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(128,128,128), RGB(0,0,0));
}
void Draw3DDownRect(PDC pdc, int Textx,int Texty,int TextNum, u8 fnt) //画3D 凹矩形,用于模拟量数字的显示
{
structRECT TextRect;
SetRect(&TextRect, Textx, Texty, Textx+OSFontSize[fnt]*TextNum, Texty+OSFontSize[fnt]);
TextRect.left-=3; TextRect.top-=2; TextRect.right+=2; TextRect.bottom+=1;
Draw3DRect2(pdc, &TextRect, RGB(255,255,255), RGB(255,255,255));
InflateRect(&TextRect, -1,-1);
Draw3DRect2(pdc, &TextRect, RGB(128,128,128), RGB(192,192,192));
InflateRect(&TextRect, -1,-1);
Draw3DRect2(pdc, &TextRect, RGB(0,0,0), RGB(192,192,192));
}
void Draw3DDownRect2(PDC pdc, structRECT * prect) //画3D 凹矩形,用于模拟量数字的显示
{
Draw3DRect2(pdc, prect, RGB(255,255,255), RGB(255,255,255));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(128,128,128), RGB(192,192,192));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(0,0,0), RGB(192,192,192));
}
void DrawDBFrameRect(PDC pdc, int Textx,int Texty,int TextNum, u8 fnt) //画3D 凹矩形,用于模拟量数字的显示
{
structRECT rect;
SetRect(&rect, Textx, Texty, Textx+OSFontSize[fnt]*TextNum, Texty+OSFontSize[fnt]);
Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));
InflateRect(&rect, -1,-1);
Draw3DRect2(pdc, &rect, RGB(192,192,192), RGB(0,0,0));
InflateRect(&rect, -1,-1);
Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(0,0,0));
InflateRect(&rect, -1,-1);
Draw3DRect2(pdc, &rect, RGB(255,255,255), RGB(255,255,255));
InflateRect(&rect, -1,-1);
Draw3DRect2(pdc, &rect, RGB(128,128,128), RGB(192,192,192));
InflateRect(&rect, -1,-1);
Draw3DRect2(pdc, &rect, RGB(0,0,0), RGB(192,192,192));
}
void DrawDBFrameRect2(PDC pdc, structRECT * prect) //画3D 凹矩形,用于模拟量数字的显示
{
Draw3DRect2(pdc,prect, RGB(192,192,192), RGB(0,0,0));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(192,192,192), RGB(0,0,0));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(128,128,128), RGB(0,0,0));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(255,255,255), RGB(255,255,255));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(128,128,128), RGB(192,192,192));
InflateRect(prect, -1,-1);
Draw3DRect2(pdc, prect, RGB(0,0,0), RGB(192,192,192));
}
//////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// 状态量显示函数:模拟量+开关量 //////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// 多行字符串显示函数 ////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
// 在矩形框内显示多行字符串,-------------------------可自动换行,可返回错误信息
void TextOutRect2(PDC pdc, structRECT * prect, U16 * ch, U8 bunicode, U8 fnt)
{
int i,j; //计算位置使用
int x,y;
int word_pos=0;
for(i=0,j=0;ch[word_pos]!=0;i++){
if(((i+1)*OSFontSize[fnt]+prect->left)>prect->right){
i=0;
j++;
if(((j+1)*OSFontSize[fnt]+prect->top)>prect->bottom){
Uart_Printf("Error: No enough space to textout!");
return;
}
}
x=(i*OSFontSize[fnt]+prect->left);
y=(j*OSFontSize[fnt]+prect->top);
CharactorOut(pdc, &x, &y, ch[word_pos], bunicode, fnt);
word_pos++;
}
}
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////// 控件函数 //////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
//*/
//以下的一组函数用于实现 ListCtrl2 控件的创建 绘制和消息响应.
//创建: 使用 CreateListCtrl() + CreateListCtrl2Patch()
void CreateListCtrl2Patch(PListCtrl2 pListCtrl, int Max_Word_Num, u8 IsDraw3DRect)
{
pListCtrl->Max_Word_Num=Max_Word_Num;
pListCtrl->IsDraw3DRect=IsDraw3DRect;
}
void DrawListCtrl2(PListCtrl2 pListCtrl)
{
structPOINT Start_Point;
structRECT textRect;
PDC pdc;
int i;
Start_Point.x=pListCtrl->ListCtrlRect.left;
Start_Point.y=pListCtrl->ListCtrlRect.top;
pdc=GetCtrlParentDC((POS_Ctrl) pListCtrl);
if(!pdc)
return;
for(i=0;i<pListCtrl->ListMaxNum;i++){
SetRect(&textRect,
Start_Point.x,
Start_Point.y+i*(OSFontSize[FONTSIZE_SMALL]+CLEARANCEy), // word_num
Start_Point.x+OSFontSize[FONTSIZE_SMALL]*5,
Start_Point.y+(i+1)*(OSFontSize[FONTSIZE_SMALL]+CLEARANCEy));
FillRect2( pdc, &textRect, GRAPH_MODE_NORMAL, COLOR_WHITE);
if((i+pListCtrl->CurrentHead)>=pListCtrl->ListMaxNum)
break;
if((i+pListCtrl->CurrentHead)==pListCtrl->CurrentSel){
TextOut( pdc,textRect.left, textRect.top, pListCtrl->pListText[i], TRUE, FONTSIZE_SMALL|FONT_BLACKBK);
if(pListCtrl->IsDraw3DRect){
Draw3DUpRect( pdc, textRect.left, textRect.top,pListCtrl->Max_Word_Num, FONTSIZE_SMALL);
}
}
else{
TextOut( pdc,textRect.left, textRect.top, pListCtrl->pListText[i], TRUE, FONTSIZE_SMALL);
if(pListCtrl->IsDraw3DRect){
Draw3DUpRect( pdc, textRect.left, textRect.top,pListCtrl->Max_Word_Num, FONTSIZE_SMALL);
}
}
}
ReleaseCtrlParentDC((POS_Ctrl) pListCtrl);
}
void ListCtrl2SelMove(PListCtrl2 pListCtrl, int moveNum, U8 Redraw) //列表框高亮度条移,正数下移,负数上移
{
POSMSG pMsg;
int oldsel=pListCtrl->CurrentSel;
if(moveNum<0){ //向上滚动
if(pListCtrl->CurrentSel+moveNum>=pListCtrl->CurrentHead)
pListCtrl->CurrentSel+=moveNum;
else{
pListCtrl->CurrentSel=MAX(pListCtrl->CurrentSel+moveNum,0);
pListCtrl->CurrentHead=pListCtrl->CurrentSel;
}
}
else{ //向下滚动
if(pListCtrl->CurrentSel+moveNum<pListCtrl->CurrentHead+pListCtrl->ListMaxNum)
pListCtrl->CurrentSel+=moveNum;
else{
pListCtrl->CurrentSel=MIN(pListCtrl->CurrentSel+moveNum,pListCtrl->ListMaxNum-1);
pListCtrl->CurrentHead=MAX(pListCtrl->CurrentSel-pListCtrl->ListMaxNum+1,0);
}
}
if(oldsel==pListCtrl->CurrentSel)
return;
if(Redraw)
DrawListCtrl2(pListCtrl);
//发送列表框选择改变消息
//pMsg=OSCreateMessage((POS_Ctrl)pListCtrl->parentWnd,OSM_LISTCTRL2_SELCHANGE, pListCtrl->CtrlID, pListCtrl->CurrentSel);
//SendMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -