📄 clock.c
字号:
/*************************************************************************
*
* Copyright (C) Asic Center. 2001
* All Rights Reserved
*
* Filename : clock.c
* Function : Some tasks for testing system prototype, such as SHELL, TIMER
* TASK, IDLE TASK, TASK A,B,C, and so on.
* Create :
* 2002/07/8 christian-ren Create this file
*
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <asixwin.h>
#include <asixapp.h>
#include <sys\systmr.h>
#include <asixwin\bitmap.h>
// added global var
#define cocx LCD_WIDTH/2 //centre of circle x
#define cocy LCD_HEIGHT/2 //centre of circle y
#define pi 3.1415926
//added by rsh 2002/06/29 17:00
// struct gTimeParam{
// U8 second;
// U8 minute;
// U8 hour;
// }TimeParam ={58,32,15},* timeParamPtr;
ASIX_TIME TimeParam ={15,32,58},* timeParamPtr;
U8 testchar = 0;
//U8 CHANGETIME = 0;
U8 charstr[2];
U8 oldhour=0,oldmin=5,oldsec=5;
U8 firstprint = 0;
//added by rsh 2002/06/19/20:00
void SearchChildWin(U32 hGC)
{
U32 ChildWin;
// U32 OutputText1,OutputText2;
char *TestString = "The Time is :";//added 2002/06/27
MSG msgchild;
U8 childquit = 0;
U32 pGC;
U8 x = cocx,y = cocy;
double r;
U8 tarx =0,tary=0;
double secptr = 0;
double angle = 0;
pGC = hGC;
ChildWin= CreateWindow( WNDCLASS_WIN, //窗口类型(主窗口)
"子菜单", //窗口标题
WS_OVERLAPPEDWINDOW, //窗口风格(主窗口风格的宏定义参见头文件asixwin.h)
0,0, //窗口左上角在逻辑屏幕中的坐标
PHY_LCD_W,PHY_LCD_H, //窗口的宽度和高度
0, //窗口的父窗口(主窗口没有父窗口)
0, //窗口的附加参数(主窗口没有附加参数)
NULL);
///////added by renshh 2002/06/27
//TextOut(childhGc, TestString, 20,100, \
// HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
// childhGc = GetGC();
r = x*(0.8);
secptr =60;
angle = ((secptr*2*pi)/60 - pi/2);
tarx = (x+0.9*r*cos(angle));tary = (y+0.9*r*sin(angle));
DrawLine( pGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawCircle(pGC, GPC_BLACK, x, y, r, GPC_REPLACE_STYLE );
while (! childquit)
{
ASIXGetMessage(&msgchild, NULL, 0, 0);
switch (msgchild.message)
{ case WM_QUIT:
childquit = 1;
break;
default:
break;
}
DefWindowProc(msgchild.message, msgchild.lparam, msgchild.data, msgchild.wparam);
}
DestroyWindow(ChildWin);
}
void PrintCharOut(U32 hGC)
{
//U32 hGC;
char tmpchar ;
// char second = 8,minute =8,hour = 8;
char *ptrchar;
char *ptr1 = "点 分 秒";
//second = TimeParam.second;
//minute = TimeParam.minute;
//hour = TimeParam.hour;
timeParamPtr = &TimeParam;
//second = timeParamPtr->second;
//minute = timeParamPtr->minute;
//hour = timeParamPtr->hour;
tmpchar = '0'+timeParamPtr->hour;
ptrchar = & tmpchar;
*(ptrchar + 1) = '\0';
ClearRec( hGC, GPC_WHITE, 20,80 , 120, 40, GPC_REPLACE_STYLE );
DrawText(hGC, ptr1, 30,90,150,190, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
DrawText(hGC, ptrchar, 20,90,150,190, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
tmpchar = '0'+ timeParamPtr->minute;
ptrchar = & tmpchar;
*(ptrchar + 1) = '\0';
DrawText(hGC, ptrchar, 50,90,150,190, \
HZK_16X16_FONT, GPC_BLACK, GPC_REPLACE_STYLE);
tmpchar = '0'+ timeParamPtr->second;
ptrchar = & tmpchar;
*(ptrchar + 1) = '\0';
DrawText(hGC, ptrchar, 85,90,150,190, \
HZK_16X16_FONT, GPC_BLACK,GPC_REPLACE_STYLE);
}
//added by rsh 2002/06/19 16:00,test childwindow
void TestWinFrame(void)
{
MSG msg;
U32 mainwin;
//U32 vscroll;
U32 hGC;
U8 quit=0;
U32 timerSecond;
U32 bt1,bt2;
// char tmpchar ;
// U8 *ptrchar;
U8 *ptr1 = "点 分 秒";
/* 创建主窗口 */
mainwin = CreateWindow( WNDCLASS_WIN, //窗口类型(主窗口)
"调试TIMER 和子菜单", //窗口标题
WS_OVERLAPPEDWINDOW, //窗口风格(主窗口风格的宏定义参见头文件asixwin.h)
0,0, //窗口左上角在逻辑屏幕中的坐标
PHY_LCD_W,PHY_LCD_H, //窗口的宽度和高度
0, //窗口的父窗口(主窗口没有父窗口)
0, //窗口的附加参数(主窗口没有附加参数)
NULL); //窗口的附加数据(主窗口没有附加数据)
bt1 = CreateWindow( WNDCLASS_BUTTON,
"下个菜单",
WS_CHILD | BS_REGULAR,
20,30,
52,20,
mainwin,
0,
NULL);
bt2 = CreateWindow( WNDCLASS_BUTTON,
"退出",
WS_CHILD | BS_REGULAR,
90,30,
32,20,
mainwin,
0,
NULL);
/* 用户可以在此绘图,但该图形不会被保存 */
hGC = GetGC();
// KVMStarter();
CreateTimer( &timerSecond, 3000, NULL, NULL, CYC_MODE|AUTO_START_MODE );
StartTimer( timerSecond );
// 消息处理
while(!quit)
{
ASIXGetMessage(&msg, NULL, 0, 0);
switch(msg.message)
{
// 在此用户加入自己的消息处理
case WM_COMMAND:
if (msg.lparam == bt1)
{
// SearchChildWin(); //for time count
}else
if (msg.lparam == bt2)
{
quit = 1;
}
break;
case WM_TIMER:
quit =1;
break;
// 关闭窗口的消息,建议用户不要更改该消息的处理
case WM_QUIT:
quit = 1;
break;
}
DefWindowProc(msg.message, msg.lparam, msg.data, msg.wparam);
PrintCharOut(hGC);
}
StopTimer( timerSecond );
FreeTimer( timerSecond );
DestroyWindow( mainwin );
EndofTask();
}
U8 *GetASIIStr(U8 num)
{
U8 Lchar,Hchar;
// U8 charstr[2]; use global var,but suggest use as it little
Hchar = num /10 + '0';
Lchar = num % 10+'0';
charstr[0] = Hchar;
charstr[1] = Lchar;
charstr[2] = '\0';
return charstr;
}
void DrawNewHourhand(U32 hGC,U8 x,U8 y,double handlen)
{
double diffangle = 2*pi*(13.0/360);
double angle;
double tarx,tary,mleftx,mlefty,mrightx,mrighty;
angle = (((timeParamPtr->hour%12)*2*pi)/12 +(timeParamPtr->minute/12)*(2*pi/60)- pi/2);
tarx = (x+handlen*cos(angle));tary = (y+handlen*sin(angle));
// DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
angle = ((timeParamPtr->hour%12)*2*pi)/12 +(timeParamPtr->minute/12)*(2*pi/60)-diffangle - pi/2;
mleftx =(x+0.3*handlen*cos(angle));
mlefty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
angle =((timeParamPtr->hour%12)*2*pi)/12 +(timeParamPtr->minute/12)*(2*pi/60)+diffangle - pi/2;
mrightx =(x+0.3*handlen*cos(angle));
mrighty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
}
void CoverOldHourhand(U32 hGC,U8 x,U8 y,double handlen)
{
double diffangle = 2*pi*(13.0/360);
double angle;
double tarx,tary,mleftx,mlefty,mrightx,mrighty;
angle= (((oldhour%12)*2*pi)/12 - pi/2)+(oldmin/12)*(2*pi/60);
tarx = (x+handlen*cos(angle));tary = (y+handlen*sin(angle));
// DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
// DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
angle = (((oldhour%12)*2*pi)/12 - pi/2)+(oldmin/12)*(2*pi/60)-diffangle;
mleftx =(x+0.3*handlen*cos(angle));
mlefty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_XOR_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
//刷新残余点
// DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
// DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_XOR_STYLE );
angle = (((oldhour%12)*2*pi)/12 - pi/2)+(oldmin/12)*(2*pi/60)+diffangle;
mrightx =(x+0.3*handlen*cos(angle));
mrighty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_XOR_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_XOR_STYLE );
// DrawLine( hGC, GPC_BLACK,mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
// DrawLine( hGC, GPC_BLACK,mrightx, mrighty,tarx,tary,GPC_SOLID_LINE, GPC_XOR_STYLE );
}
void DrawNewMinhand(U32 hGC,U8 x,U8 y,double handlen)
{
double diffangle = 2*pi*(7.0/360);
double angle;
double tarx,tary,mleftx,mlefty,mrightx,mrighty;
angle = ((timeParamPtr->minute*2*pi)/60 - pi/2);
tarx = (x+handlen*cos(angle));tary = (y+handlen*sin(angle));
// DrawLine( hGC, GPC_BLACK,x, y, tarx, tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
angle = ((timeParamPtr->minute*2*pi)/60-diffangle - pi/2);
mleftx =(x+0.3*handlen*cos(angle));
mlefty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mleftx, mlefty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mleftx, mlefty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
angle =((timeParamPtr->minute*2*pi)/60+diffangle - pi/2);
mrightx =(x+0.3*handlen*cos(angle));
mrighty =(y+0.3*handlen*sin(angle));
DrawLine( hGC, GPC_BLACK,x, y, mrightx, mrighty, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
DrawLine( hGC, GPC_BLACK, mrightx, mrighty,tarx,tary, GPC_SOLID_LINE, GPC_REPLACE_STYLE );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -