4 * The entry window implementation
6 * Copyright 2007-2008 @ xianweizeng@gmail.com
11 * File Coding system: gb2312
12 * set-buffer-file-coding-system
15 * 2008-09-24 Change code indent
22 #include <minigui/common.h>
23 #include <minigui/minigui.h>
24 #include <minigui/gdi.h>
25 #include <minigui/window.h>
26 #include <minigui/control.h>
27 #include <minigui/mgext.h>
29 #include "motormain.h"
30 #include "motorregister.h"
31 #include "motorfile.h"
33 #include "bkgndEdit.h"
36 #include "userprogram.h"
37 #include "keyboard.h" /* Keyboard Check */
41 /* define globle variables */
43 int isIMEOpenInMotor
; /* 0: disappear 1: display */
45 /* startup paramters */
46 struct startup_params_t startupParams
;
49 struct motorStatus_t motorStatus
;
52 PLOGFONT systemDefaultFont
,userFont24
,userFont16
;
57 static int animationFlag
= 0; /* Is flash on flag */
59 static BITMAP welcomeBkgnd
;
61 struct welcome_help_t
{
62 unsigned char * msg_welcome
;
65 static struct welcome_help_t welcome_help
[SYSLANG_NO
] =
74 int loadInitConfigFile(struct startup_params_t
*pStartup_params
)
80 fp
= fopen("./user/init.cfg","r");
82 printf("Open init file error!\n");
87 fscanf(fp
,"%d %d %d\n",&isFlashOn
, &isBkgnd
, &lastuser
);
90 pStartup_params
->isFlashOn
= isFlashOn
;
91 pStartup_params
->whichBkgnd
= isBkgnd
;
92 pStartup_params
->lastuser
= lastuser
;
100 int saveInitConfigFile (struct startup_params_t
*pStartup_params
)
104 fp
=fopen("./user/init.cfg","w");
106 printf("Open init file error!\n");
110 fprintf(fp
,"%d %d %d\n",pStartup_params
->isFlashOn
,
111 pStartup_params
->whichBkgnd
,
112 pStartup_params
->lastuser
);
119 static struct comCmdData_t cmdData
;
121 static int sendUserLimits(int flag
)
123 int data
= 0, tmpdata
;
124 int unit
= currentuser
->unit
;
127 memset(cmdSendBuf
,0,12);
131 data
= currentuser
->frontlimit
;
134 data
= currentuser
->middlelimit
;
137 data
= currentuser
->backlimit
;
142 data
= inch_to_mm(tmpdata
);
146 cmdData
.status
= 0x30 + flag
;
148 setCmdFrame(&cmdData
,cmdSendBuf
);
149 sendCommand(cmdSendBuf
);
150 printf("Send Limit %d %d\n",flag
,data
);
154 static void sendUserAllLimits(void)
158 for(flag
=0;flag
<3;flag
++){
160 sendUserLimits(flag
);
165 static void reinitAnimationBkgnd(HWND hWnd
)
169 hdc
= BeginPaint (hWnd
);
170 FillBoxWithBitmap (hdc
, 0, 0, 0, 0, &welcomeBkgnd
);
171 EndPaint (hWnd
, hdc
);
173 SendMessage (GetDlgItem (hWnd
, 800),
174 ANM_STARTPLAY
, 0, 0);
178 static int AnimationWinProc(HWND hWnd
, int message
, WPARAM wParam
, LPARAM lParam
)
181 unsigned char *pWelcomeText
= welcome_help
[*curSysLang
].msg_welcome
;
188 hdc
= BeginPaint (hWnd
);
189 if (LoadBitmap (HDC_SCREEN
, &welcomeBkgnd
, "./res/welcome.jpg"))
191 FillBoxWithBitmap (hdc
, 0, 0, 0, 0, &welcomeBkgnd
);
192 EndPaint (hWnd
, hdc
);
197 hdc
= BeginPaint (hWnd
);
198 TextOut (hdc
, 210, 220, pWelcomeText
);
199 EndPaint (hWnd
, hdc
);
200 ANIMATION
* anim
= CreateAnimationFromGIF89aFile (HDC_SCREEN
, "./res/welcome.gif");
204 SetWindowAdditionalData (hWnd
, (DWORD
) anim
);
205 CreateWindow (CTRL_ANIMATION
,
207 WS_VISIBLE
| ANS_AUTOLOOP
,
209 0, 0, 640, 480, hWnd
, (DWORD
)anim
);
210 SendMessage (GetDlgItem (hWnd
, 800), ANM_STARTPLAY
, 0, 0);
215 case MSG_KEYDOWN
: // anykey press,pause
216 switch(LOWORD(wParam
)){
218 EnterKeyboardCheck(hWnd
);
219 /* Re-init background */
220 reinitAnimationBkgnd(hWnd
);
226 cmdData
.status
= 0x30;
227 cmdData
.data
= 80000;
228 setCmdFrame(&cmdData
,cmdbuf
); // En-frame
229 sendCommand(cmdbuf
); // Sent it out
231 #if defined (CONFIG_DEBUG_ON_PC) || defined (CONFIG_DEBUG_ON_TARGET)
233 SendMessage (GetDlgItem (hWnd
, 800), ANM_STOPPLAY
, 0, 0);
240 #if defined (CONFIG_DEBUG_ON_PC) || defined (CONFIG_DEBUG_ON_TARGET)
241 case MSG_KEYUP
: // anykey press,go out
242 switch(LOWORD(wParam
)){
244 SendMessage(hWnd
,MSG_CLOSE
,0,0);
250 case MSG_RECV
: // Reveive frame from LowerMachine
252 //int ret = isCmdValid(cmdbuf); // Now, there is no Check
254 memset(&cmdData
,0,sizeof(cmdData
));
255 getCmdFrame(&cmdData
,cmdbuf
); // Decode, get data
256 if(cmdData
.flag
== 'R'){
257 motorStatus
.currentCutPos
= cmdData
.data
; // Refresh Data
258 motorStatus
.devStatus
= cmdData
.status
; // Refresh Status
260 SendMessage (GetDlgItem (hWnd
, 800), ANM_STOPPLAY
, 0, 0);
262 SendMessage(hWnd
,MSG_CLOSE
,0,0);
269 DestroyAnimation ((ANIMATION
*)GetWindowAdditionalData (hWnd
), TRUE
);
270 DestroyAllControls (hWnd
);
276 UnloadBitmap (&welcomeBkgnd
);
278 DestroyMainWindow (hWnd
);
279 PostQuitMessage (hWnd
);
283 return DefaultMainWinProc(hWnd
, message
, wParam
, lParam
);
287 int MiniGUIMain (int argc
, const char* argv
[])
291 MAINWINCREATE CreateInfo
;
293 isIMEOpenInMotor
= 0;
294 motorStatus
.currentCutPos
= 0;
295 motorStatus
.newCutPos
= 0;
296 motorStatus
.devStatus
= 0;
297 motorStatus
.flags
= 0;
298 motorStatus
.cutCounter
= 0;
301 myIMEWindow
=GBIMEWindow (HWND_DESKTOP
); // IME window handler
303 MoveWindow(myIMEWindow
,170,110,365,40,0);
304 ShowWindow(myIMEWindow
,SW_HIDE
); // Hide IME window
305 isIMEOpenInMotor
= 0;
310 userFont24
= CreateLogFont (NULL
, "song", "GB2312",
311 FONT_WEIGHT_BOOK
, FONT_SLANT_ROMAN
, FONT_SETWIDTH_NORMAL
,
312 FONT_SPACING_CHARCELL
, FONT_UNDERLINE_NONE
,
313 FONT_STRUCKOUT_NONE
, 24, 0);
314 userFont16
= CreateLogFont (NULL
, "song", "GB2312",
315 FONT_WEIGHT_BOOK
, FONT_SLANT_ROMAN
, FONT_SETWIDTH_NORMAL
,
316 FONT_SPACING_CHARCELL
, FONT_UNDERLINE_NONE
,
317 FONT_STRUCKOUT_NONE
, 16, 0);
318 //systemDefaultFont = GetSystemFont(SYSLOGFONT_DEFAULT);
320 #ifndef CONFIG_DEBUG_ON_PC
321 initSerialCommunication(); /* Init Serial Communication Port */
325 /* update system time by RTC */
328 loadInitConfigFile(&startupParams
);
329 animationFlag
= startupParams
.isFlashOn
;
331 loadUserConfigFile();
332 /* printf("Unit Flag = %d \n",userinformation[0].unit); */
333 curSysLang
= &userinformation
[0].language
;
336 SetDesktopRect(0, 0, 1024, 768);
339 if (!InitMiniGUIExt()) {
343 CreateInfo
.dwStyle
= WS_VISIBLE
;
344 CreateInfo
.dwExStyle
= WS_EX_NONE
;
345 CreateInfo
.spCaption
= "" ;
346 CreateInfo
.hMenu
= 0;
347 CreateInfo
.hCursor
= 0;
348 CreateInfo
.hIcon
= 0;
349 CreateInfo
.MainWindowProc
= AnimationWinProc
;
354 CreateInfo
.iBkColor
= PIXEL_lightwhite
;
355 CreateInfo
.dwAddData
= 0;
356 CreateInfo
.dwReserved
= 0;
357 CreateInfo
.hHosting
= HWND_DESKTOP
;
360 hMainWnd
= CreateMainWindow (&CreateInfo
);
361 if (hMainWnd
== HWND_INVALID
)
364 ShowWindow (hMainWnd
, SW_SHOWNORMAL
);
366 while (GetMessage(&Msg
, hMainWnd
)) {
367 TranslateMessage(&Msg
);
368 DispatchMessage(&Msg
);
371 MainWindowThreadCleanup (hMainWnd
);
375 /* Enter user window directly */
376 /* before entering user window, at least these data structure should
378 * - userinformation[] and the currentuser pointer is set correctly
379 * - the user limits should be send to machine
380 * - programCreate should be filled and parsed to user window
382 loadUserConfigFile(); /* fill userinformation[] */
383 currentid
= startupParams
.lastuser
; /* get lastuser id */
384 currentuser
= &userinformation
[currentid
];
386 sendUserAllLimits(); /* send user limits to machine */
388 PRINTF("current user %d current program %d \n",currentid
,
389 currentuser
->recent_programe
);
391 /* load program file */
392 loadProgramFile(currentuser
->recent_programe
, &programCreate
);
399 #ifndef _LITE_VERSION
400 #include <minigui/dti.c>