📄 main.c
字号:
/****************************************Copyright (c)**************************************************
** ARM LINUX Development Co.,LTD.
**
**--------------File Info-------------------------------------------------------------------------------
** File name: main.c
** Last modified Date: 2006-12-11
** Last Version: 1.0
** Descriptions: The main() function
**
**------------------------------------------------------------------------------------------------------
** Created by: Jacky Chen
** Created date: 2007-05-7
** Version: 1.0
** Descriptions: The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include "common.h" //公共变量
#include "fonts.h" //字体
#include "main.h"
#include "init.h" //载入位图, 自定义按钮
#include "meter.h" //仪表扫描,注册
//重绘制显示区
/*
组态时候,更新顶端状态栏
显示时候更新显示区
*/
int DoPaintMain(HWND hWnd,int message,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
BOOL onetime=0;
hdc = BeginPaint(hWnd);
FreshTopPage(hdc);
SetBkColor(hdc,PIXEL_darkblue);
SelectFont(hdc,song26font);
if(bLeftShow) ShowLeft( hWnd);
FreshDispZero(hdc);
//f(CurrentPage==RTCURVE_PAGE)
//DrawRTCurve(hdc,0 ,6,0,TOP+TOP2,WIDTH,HEIGHT-TOP-TOP2-BOTTOM2-BOTTOM);
EndPaint(hWnd,hdc);
return 0;
}
//建立并显示进度条
HWND ShowProgressBar(HWND hWnd)
{
HWND hWnd_porgress_bar;//进度条
hWnd_porgress_bar = CreateWindow ("progressbar","",
WS_VISIBLE, IDC_PROGRESSBAR,
100, 80, 160, 50, hWnd, 0);
SendMessage (hWnd_porgress_bar, PBM_SETRANGE, 0, 1000);
SendMessage (hWnd_porgress_bar, PBM_SETSTEP, 10, 0);
return hWnd_porgress_bar;
}
BOOL f_scan_devices=0;
int MainWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
HWND activehwnd;
static RECT top_rect;
static int DeviceCom_counter;
static BOOL bhistory_mode;
static BOOL keydowned;
static short ctrl_conf_id;//组态总页面上焦点位置 :0-7
int id ;
id = LOWORD(wParam);
switch (message)
{
case MSG_CREATE:
{
BITMAP backbmp;
// hdc=GetClientDC(hWnd);
//LoadBitmap(HDC_SCREEN,&backbmp,"res/back.bmp"); //载入背景图片
//FillBoxWithBitmap(hdc,0,0,WIDTH,HEIGHT,&backbmp);
//ReleaseDC(hdc);
printf( "test");
InitFonts(); //初始化字体
LoadBmp ( );
//system("mkdir /mnt/u");
//system("mount /dev/sda1 /mnt/u");
//载入其他图片
//PB=ShowProgressBar(hWnd);
//FRESHPB(PB,1000);
// Init();//开辟仪表扫描中注册用数据空间
//全局变量 历史记录有关
//history record file number per month
//通讯有关初始化
//PortSend(Commfd2,Type1,8); //debug
//设备扫描得到总设备数,通道总数
//Comminit();
//组态信息
//GetConfigureInformation();//从组态保存文件中得到初始值
//组态页面数据初始化
// ConfigInit();
bhistory_mode=0;//历史页面不启动
//SetCoordinate(0,13,0,HEIGHT-TOP); //给总浏览页面设置块坐标
//组态页面显示有关
ctrl_conf_id=0;
//累积有关
//历史记录有关
//DestroyWindow(PB); //销毁进度条
//hdc = GetClientDC(hWnd);
// FillBoxWithBitmap(hdc,520,2,36,36,&save_bmp);
//ReleaseDC(hdc);
hdc=GetClientDC(hWnd);
// SetBrushColor(hdc,PIXEL_darkblue);
// FillBox(hdc,0,0,WIDTH,HEIGHT);
// SetBrushColor(hdc,PIXEL_lightwhite);
// FillBox(hdc,482,2,156 ,36);
ReleaseDC(hdc);
CreateLeft( hWnd);
CreateBottom( hWnd);
HideBottom( hWnd);
HideLeftButton( hWnd);
// RegisterMybutton();//注册按钮
//DeviceDefaultReg();//测试用模拟通道注册
}
break;
case MSG_TIMER:
{
/*第一次进入进行板卡扫描,前10S 注册
设备注册好后,若有注册好的PV卡
PV卡自带4路通道
和流量卡则对其进行通道注册
超时后如果有设备那么注册结束
*/
if(!devices_registed)
{ /*
模拟通道改变时候历史文件的建立
SetupHistoryFile(0);//0通道 AI1
没有扫描到仪表则用默认数值
ReadDefaultValue(gchannum,RealIndex);
*/
printf(" t.");
}
else //注册完毕
{
if(dev_number>0) //则正常通讯
{
printf("c. ");
if(!b_wr_config)ReadPV();// 不是组态信息通讯时候定时读取PV
//SetupHistoryFile(0); 文件的建立
}
else //启用DEMO
{
ReadDefaultValue(13,RealIndex);
}
}
GetTime(hWnd);
//检测报警
DetectAlarm( );
// 写文件累积信息
RealIndex++;//时实 绘图点的 下标
if(RealIndex>RealIndex_max){RealIndex=0;fullscr=1;}
// 历史记录
// Record(1);
//更新显示区
SetFreshZero();
InvalidateRect (hWnd, &top_rect, FALSE);
}break;
case MSG_PAINT:
//绘制上端状态条 :时间,存储,报警,页面说明
//更新显示区
DoPaintMain(hWnd,message,wParam,lParam);
/* if(!f_scan_devices) //只运行1次
{
DeviceScan();f_scan_devices=1;
if(dev_number>0)//注册成功
{
devices_registed=1;
PrintDeviceInfo();
}
else//没有板卡则启用DEMO
{
devices_registed=0;
SetBourate(9600);
DemoRegist( );//模拟通讯注册 信息
}
//对通道上基本进行初始化
AiChanInit( hWnd);//通道显示数据的初始化
MathChanInit(hWnd);
DiInit();
SetTimer(hWnd,_ID_TIMER,100);
} */
break;
case MSG_COM: //通讯处理
printf(" MSG_COM");
//RecvLength=0;//下次接收的起始位置
//得到 PV值后通知minigui更新实时显示的数值
// SaveComData(dev_number); //保存本设备的信息
//SetRect (&top_rect, 80,0,640,40);
//InvalidateRect (hWnd, &top_rect, FALSE);
break;
case MSG_KEYDOWN:
if(!keydowned) //按下,为防止多次响应MSG_KEYDOWN
{
if(id==KEY_PAGE)SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_PAGE),BM_SETSTATE,BST_PUSHED,0);
if(id==KEY_MODE)SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_MODE),BM_SETSTATE , BST_PUSHED,0);
if(id==KEY_HIST)SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_HIST),BM_SETSTATE , BST_PUSHED,0);
if(id==KEY_EVENT)SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_EVEN),BM_SETSTATE,BST_PUSHED,0);
if(id==KEY_STAT)SendMessage (GetDlgItem(hWnd,LEFT_BUTTON_STAT),BM_SETSTATE,BST_PUSHED,0);
if(id==KEY_DOWNLOAD)SendMessage (GetDlgItem(hWnd,BOTTOM_BUTTON_DOWN),BM_SETSTATE,BST_PUSHED,0);
if(id==KEY_CLEAR)SendMessage (GetDlgItem(hWnd,BOTTOM_BUTTON_CLEA),BM_SETSTATE,BST_PUSHED,0);
if(id==KEY_OPERATE)SendMessage (GetDlgItem(hWnd,BOTTOM_BUTTON_OPER),BM_SETSTATE,BST_PUSHED,0);
if(id==KEY_CONF)SendMessage (GetDlgItem(hWnd,BOTTOM_BUTTON_CONF),BM_SETSTATE,BST_PUSHED,0);
if(id==KEY_CUMUL)SendMessage (GetDlgItem(hWnd,BOTTOM_BUTTON_CUMUL),BM_SETSTATE,BST_PUSHED,0);
keydowned=1;
}
break;
case MSG_KEYUP:
keydowned=0;//直到弹起后方可响应MSG_KEYDOWN
if(id==KEY_OPEN)//底侧门
{
if(!bDoorOpen)
{bDoorOpen=1;
//显示底侧按钮
ShowBottom( hWnd);
}
else {bDoorOpen=0;
HideBottom( hWnd);
}
InvalidateRect(hWnd,NULL,TRUE);
}
bFreshtop=1;
//显示的时候允许扫描
if( bLeftShow){ //左侧菜单是否在显示
ScanModeKey(hWnd, id);//总浏览,数字,BAR,实时,页面上 A S W 键处理
}
if( !bLeftShow)
{
if( (id==KEY_PAGE)||(id==KEY_MODE)||
(id==KEY_HIST)||(id==KEY_EVENT)||
(id==KEY_STAT)||(id==KEY_EXIT))
{bLeftShow=1; //等待一定时间后自动为0
oldseconds=nowseconds;//记住当前时间
//显示按钮一次
ShowLeft( hWnd);
InvalidateRect(hWnd,NULL,TRUE);
}
}
if(bDoorOpen)
{ //扫描底端按钮,包括下载,清除,操作,组态
ScanBottomKey( hWnd ,id );
if(id==KEY_CUMUL) //累积按钮响应
{
SendMessage (GetDlgItem(hWnd,BOTTOM_BUTTON_CUMUL),BM_SETSTATE,0,0);
sprintf(topinfo,"累积 " );
DlgDisCumul(hWnd);
}
}
//显示模式下按键处理
if(id==SCANCODE_ESCAPE)SendMessage (hWnd, MSG_CLOSE, 0, 0L);
SetRect (&top_rect, 80,0,640,40);
InvalidateRect (hWnd, &top_rect, FALSE);
break;
case MSG_LBUTTONDOWN:
{
// DoLBUTTONDOWN(hWnd,message,wParam,lParam);
}
break;
case MSG_COMMAND:
{
if(id==BOTTOM_BUTTON_SHUT)
ExitSystem(hWnd,0);
if((id==BOTTOM_BUTTON_CLEA)&&(disp_mode!=4))
{
CleanButtonFonts(hWnd);
SetDlgItemText(hWnd, BOTTOM_BUTTON_CUMUL,"确认" );
SetDlgItemText(hWnd, BOTTOM_BUTTON_SHUT,"取消" );
bLeftShow=0;
DlgClean(hWnd);
//改变当前页面按键字样
ReButtonFonts(hWnd);
oldseconds=nowseconds;
bLeftShow=1;
// system("command df >1.txt");
// MessageBox(hWnd,"数据清除成功!","提示",MB_YESNO|MB_ICONQUESTION);
}
if(id==BOTTOM_BUTTON_DOWN)
bLeftShow=0;
DownLoadToUsb(hWnd);
oldseconds=nowseconds;
bLeftShow=1;
if(id==BOTTOM_BUTTON_OPER)
{
strcpy(topinfo,"操作 ");
SetRect (&top_rect, 80,0,640,40);
InvalidateRect (hWnd, &top_rect, FALSE);
DlgConfOperate(hWnd);
// MessageBox(hWnd,"操作成功","提示",MB_YESNO|MB_ICONQUESTION);
}
}
break;
case MSG_DESTROY:
{
DestroyAllControls(hWnd);
return 0;
}
case MSG_CLOSE:
{
for(id=0;id<gchannum;id++)
{
fclose(channel_hist[id].fd);
}
// system("rm dat.tmp -rf"); //删除查询磁盘空间产生的临时文件
DoDestroyMain(hWnd,message,wParam,lParam);
return 0;
}
break;
}
return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
int DoDestroyMain(HWND hWnd,int message,WPARAM wParam,LPARAM lParam)
{
//pthread_join(CommThread[CurThread],NULL);
// close(Commfd);
KillTimer(hWnd,_ID_TIMER);
DestroyMainWindow(hWnd);
MainWindowCleanup (hWnd);
PostQuitMessage(hWnd);
return 0;
}
extern void DlgDownload (HWND hWnd);
int DownLoadToUsb(HWND hWnd)
{
//DlgDownload(hWnd);
// SendMessage(GetFirstHosted(hWnd),MSG_USER1,0,0) ;
bfresh_conf=1;
gdisp_mode=CONFIG_MODE;
SetRect (&top_rect, 80,0,640,40);
InvalidateRect (hWnd, &top_rect, FALSE);
// RTU_Write( 1,2 , 0x0f);
// MessageBox(hWnd,"请插入U盘","提示",MB_YESNO|MB_ICONQUESTION);
//RTU_Write( 1,100.2, 0x0f);
// RTU_Write( 1,0.1013, 0x0f);
// RTU_Write( 1,-200, 0x0f);
return 1;
}
//鼠标左键
int DoLBUTTONDOWN(HWND hWnd,int message,WPARAM wParam,LPARAM lParam)
{
int code = HIWORD(wParam);
int oldx,oldy;
unsigned char str[20];
oldx = LOWORD (lParam);
oldy = HIWORD (lParam);
sprintf(str,"code= %d x is %d,y is %d",code,oldx,oldy);
MessageBox(hWnd,str,"error",MB_OK);
}
//
CleanButtonFonts(HWND hWnd )
{
SetDlgItemText(hWnd, LEFT_BUTTON_PAGE," " );
SetDlgItemText(hWnd, LEFT_BUTTON_MODE," " );
SetDlgItemText(hWnd, LEFT_BUTTON_HIST," " );
SetDlgItemText(hWnd, LEFT_BUTTON_EVEN," " );
SetDlgItemText(hWnd, LEFT_BUTTON_STAT," " );
SetDlgItemText(hWnd, LEFT_BUTTON_EXIT," " );
SetDlgItemText(hWnd, BOTTOM_BUTTON_DOWN," " );
SetDlgItemText(hWnd, BOTTOM_BUTTON_CLEA," " );
SetDlgItemText(hWnd, BOTTOM_BUTTON_OPER," " );
SetDlgItemText(hWnd, BOTTOM_BUTTON_CONF," " );
}
//
ReButtonFonts(HWND hWnd )
{
SetDlgItemText(hWnd, LEFT_BUTTON_PAGE,BN_PAGE_STR);
SetDlgItemText(hWnd, LEFT_BUTTON_MODE,"\n模式\nS" );
SetDlgItemText(hWnd, LEFT_BUTTON_HIST,"\n历史\nA" );
SetDlgItemText(hWnd, LEFT_BUTTON_EVEN,"\n事件\nD" );
SetDlgItemText(hWnd, LEFT_BUTTON_STAT,"\n状态\nEnter" );
SetDlgItemText(hWnd, LEFT_BUTTON_EXIT,"\n离开\nQ" );
SetDlgItemText(hWnd, BOTTOM_BUTTON_DOWN,"下载\nF3" );
SetDlgItemText(hWnd, BOTTOM_BUTTON_CLEA,"清除\nF4" );
SetDlgItemText(hWnd, BOTTOM_BUTTON_OPER,"操作\nF5" );
SetDlgItemText(hWnd, BOTTOM_BUTTON_CONF,"组态\nF6" );
SetDlgItemText(hWnd, BOTTOM_BUTTON_CUMUL,"累积\nF7" );
SetDlgItemText(hWnd, BOTTOM_BUTTON_SHUT,"关机\nESC" );
}
//下面的按钮扫描,不包括累积按钮
void ScanBottomKey(HWND hWnd ,int id)
{
if(id==KEY_DOWNLOAD)
{
SendMessage(GetDlgItem(hWnd,BOTTOM_BUTTON_DOWN), BM_SETSTATE, 0,0);
DownLoadToUsb(hWnd);
}
else if(id==KEY_CLEAR)
{
SendMessage(GetDlgItem(hWnd,BOTTOM_BUTTON_CLEA), BM_SETSTATE, 0,0);
SendMessage (hWnd, MSG_COMMAND, BOTTOM_BUTTON_CLEA,0); //进入模式按钮响应
}
else if(id==KEY_OPERATE)
{
SendMessage(GetDlgItem(hWnd,BOTTOM_BUTTON_OPER), BM_SETSTATE, 0,0);
SendMessage (hWnd, MSG_COMMAND, BOTTOM_BUTTON_OPER,0); //进入模式按钮响应
}
if(id==KEY_CONF) //显示模式改为组态模式
{
SendMessage (GetDlgItem(hWnd,BOTTOM_BUTTON_CONF),BM_SETSTATE,0,0);
last_mode=gdisp_mode;
gdisp_mode=CONFIG_MODE;
strcpy(topinfo,"组态 ");
bfresh_conf=1;
InvalidateRect(hWnd,NULL,TRUE);
DlgConf(hWnd);
ShowLeft( hWnd);
gdisp_mode=last_mode;
InvalidateRect(hWnd,NULL,TRUE);
}
}
// w:本模式下上翻页
// s: 模式切换
//a: 报警页面
// d:累计页面LEFT_BUTTON_HIST
void ScanModeKey(HWND hWnd ,int id )
{
unsigned char str[20];
if(id==KEY_PAGE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -