comparison g23m/condat/ms/src/mfw/mfw_mmi.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /*
2 +--------------------------------------------------------------------+
3 | PROJECT: MMI-Framework (8417) $Workfile:: mfw_mmi.c $|
4 | $Author:: Es $ CONDAT GmbH $Revision:: 8 $|
5 | CREATED: 21.09.98 $Modtime:: 1.07.99 10:03 $|
6 | STATE : code |
7 +--------------------------------------------------------------------+
8
9 MODULE : MFW_MMI
10
11 PURPOSE : MFW test application
12
13 EXPORT :
14
15 TO DO :
16
17 $History:: mfw_mmi.c $
18 *
19 * ***************** Version 8 *****************
20 * User: Es Date: 6.07.99 Time: 12:21
21 * Updated in $/GSM/DEV/MS/SRC/MFW
22 */
23
24 #define ENTITY_MFW
25
26 #include <string.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #if defined (NEW_FRAME)
31
32 #include "typedefs.h"
33 #include "vsi.h"
34 #include "pei.h"
35 #include "custom.h"
36 #include "gsm.h"
37
38 #else
39
40 #include "STDDEFS.H"
41 #include "custom.h"
42 #include "gsm.h"
43 #include "vsi.h"
44
45 #endif
46
47 #include "mfw_mfw.h"
48 #include "mfw_sys.h"
49 #include "mfw_win.h"
50 #include "mfw_edt.h"
51 #include "mfw_icn.h"
52 #include "mfw_mnu.h"
53 #include "mfw_kbd.h"
54 #include "mfw_tim.h"
55 #include "dspl.h"
56 #include "drv_key.h"
57 #include "drv_tmr.h"
58
59 #include "prim.h"
60 #ifndef PCM_2_FFS
61 #include "pcm.h"
62 #endif
63
64
65 #include "mfw_nm.h"
66 #include "mfw_sim.h"
67 #include "mfw_cm.h"
68
69 #include "mfw_mmi.h"
70
71
72
73 static U16 scrX, scrY; /* sreen size */
74 static U8 mfwMem [2048]; /* mfw memory pool */
75 //Default colour
76 #define MFW_COLOUR 0x00000000,0x00FFFFFF
77 #define MFW_ICN_COLOUR 0x00000000,0x00FFFFFF
78
79 static int initialized = 0;
80
81 static void volInit (void);
82 static void volExit (void);
83 static void editInit (MfwHnd e);
84 static void editExit (void);
85 static void phoneInit (void);
86 static void phoneExit (void);
87 static void mainInit (void);
88 static void mainExit (void);
89
90
91
92
93 /*
94 +--------------------------------------------------------------------+
95 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
96 | STATE : code ROUTINE : mmi_main |
97 +--------------------------------------------------------------------+
98
99 PURPOSE : start MMI
100
101 */
102
103 void mmi_main (void)
104 {
105 mmiInit();
106 }
107
108
109 /*
110 +--------------------------------------------------------------------+
111 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
112 | STATE : code ROUTINE : mmiInit |
113 +--------------------------------------------------------------------+
114
115 PURPOSE : initialize application
116
117 */
118
119 void mmiInit (void)
120 {
121 if (initialized)
122 mmiExit();
123
124 initialized = 1;
125
126 mfwInit(mfwMem,sizeof(mfwMem)); /* MFW INITIALIZATION */
127 winInit(&scrX,&scrY); /* init window handler */
128 edtInit(); /* init editor handler */
129 icnInit(); /* init icon handler */
130 mnuInit(); /* init menu handler */
131 kbdInit(); /* init keyboard handler */
132 timInit(); /* init timer handler */
133
134 /* MMI MODULES SETUP */
135 volInit(); /* init volume control */
136 mainInit(); /* init main control */
137 }
138
139
140 /*
141 +--------------------------------------------------------------------+
142 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
143 | STATE : code ROUTINE : mmiExit |
144 +--------------------------------------------------------------------+
145
146 PURPOSE : exit application
147
148 */
149
150 void mmiExit (void)
151 {
152 if (!initialized)
153 return;
154
155 mainExit();
156 volExit();
157
158 timExit(); /* finit timer handler */
159 kbdExit(); /* finit keyboard handler */
160 mnuExit(); /* finit menu handler */
161 icnExit(); /* finit icon handler */
162 edtExit(); /* finit edit handler */
163 winExit(); /* finit window handler */
164 mfwExit(); /* exit mfw */
165
166 initialized = 0;
167 }
168
169
170 /*
171 +--------------------------------------------------------------------+
172 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
173 | STATE : code ROUTINE : volControl |
174 +--------------------------------------------------------------------+
175
176 PURPOSE : setup volume control
177
178 */
179
180 #define MAX_VOLUME 10
181
182 static MfwHnd volWin; /* the volume window */
183 static MfwHnd volKbd; /* the volume keyboard */
184 static MfwHnd volTim; /* the volume timer */
185 static int curVolume; /* current volume */
186 static U32 curKey; /* current key */
187
188 static void volShow (void)
189 {
190 timStop(volTim);
191 dspl_ClearAll();
192 dspl_TextOut(20,12,DSPL_TXTATTR_NORMAL,"VOLUME");
193 dspl_DrawRect(20,22,20+curVolume*6,22+5);
194 }
195
196 static int volEventWin (MfwEvt e, MfwWin *w)
197 {
198 switch (e)
199 {
200 case MfwWinVisible:
201 if (w->flags & MfwWinVisible)
202 volShow();
203 break;
204 default:
205 return 0;
206 }
207
208 return 1;
209 }
210
211 static int volEventKbd (MfwEvt e, MfwKbd *kc)
212 {
213 curKey = e;
214 volShow();
215 if (curKey & KEY_MAKE)
216 ((MfwTim *) mfwControl(volTim))->time = 500;
217 else
218 ((MfwTim *) mfwControl(volTim))->time = 2000;
219 timStart(volTim);
220
221 return 1;
222 }
223
224 static int volEventTim (MfwEvt e, MfwTim *tc)
225 {
226 if (!(curKey & KEY_MAKE))
227 {
228 winHide(volWin);
229 return 1;
230 }
231
232 if (curKey & KEY_VOLUP)
233 {
234 if (curVolume < MAX_VOLUME)
235 curVolume++;
236 }
237 else
238 {
239 if (curVolume > 0)
240 curVolume--;
241 }
242 volShow();
243 timStart(volTim);
244
245 return 1;
246 }
247
248 static void volInit (void)
249 {
250 U32 events;
251
252 events = KEY_VOLUP + KEY_VOLDOWN + KEY_MAKE;
253 curVolume = 3;
254 volWin = winCreate(0,0,MfwWinVisible,(MfwCb) volEventWin);
255 volKbd = kbdCreate(0,events,(MfwCb) volEventKbd);
256 volTim = timCreate(0,2000,(MfwCb) volEventTim);
257 }
258
259 static void volExit (void)
260 {
261 timDelete(volTim);
262 kbdDelete(volKbd);
263 winDelete(volWin);
264 }
265
266
267 /*
268 +--------------------------------------------------------------------+
269 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
270 | STATE : code ROUTINE : editControl |
271 +--------------------------------------------------------------------+
272
273 PURPOSE : general editor control
274
275 */
276
277 static MfwHnd myHandle = 0; /* editors handle */
278 static MfwHnd editTim; /* the editor timer */
279
280 static U8 editControls [KCD_MAX] = /* edit control keys: */
281 {
282 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
283 ecBack, ecDel, ecNone, ecNone, ecUp, ecDown, ecLeft, ecRight,
284 ecNone, ecNone, ecEnter, ecNone, ecNone, ecNone,
285 ecNone, ecNone, ecEnter, ecNone, ecNone, ecNone, ecNone
286 };
287
288 static char editHeader [128]; /* editor information */
289 static U8 editAlphaMode; /* alpha mode flag */
290 static U8 editAlphaLevel; /* alpha level selected */
291 static U8 editAlphaKey; /* alpha mode current key */
292 static U8 editAlpha [10][4] = /* alpha mode characters */
293 {
294 {'-','!','?',','},
295 {'a','b','c','1'}, {'d','e','f','2'}, {'g','h','i','3'},
296 {'j','k','l','4'}, {'m','n','o','5'}, {'p','q','r','6'},
297 {'s','t','u','7'}, {'v','w','x','8'}, {'y','z',' ','9'}
298 };
299
300
301 static void editShowHeader (void)
302 {
303 sprintf(editHeader,"%c [%c]",
304 (editAlphaMode)?'A':'N',
305 (editAlphaMode && editAlphaKey != KCD_MAX)?
306 editAlpha[editAlphaKey][editAlphaLevel]:' ');
307 dspl_TextOut(2,0,DSPL_TXTATTR_NORMAL,editHeader);
308 dspl_DrawRect(1,8,98,30);
309 }
310
311 static int editEventTim (MfwEvt e, MfwTim *t)
312 {
313 if (!editAlphaMode)
314 return 1;
315
316 edtChar(myHandle,editAlpha[editAlphaKey][editAlphaLevel]);
317 editAlphaLevel = 3;
318 editAlphaKey = KCD_MAX;
319
320 return 1;
321 }
322
323 static int editEventKbd (MfwEvt e, MfwKbd *k)
324 {
325 if (editAlphaMode)
326 {
327 if (editAlphaKey != KCD_MAX && editAlphaKey != k->code)
328 {
329 timStop(editTim);
330 edtChar(myHandle,editAlpha[editAlphaKey][editAlphaLevel]);
331 editAlphaLevel = 3;
332 editAlphaKey = KCD_MAX;
333 }
334 if (k->code <= KCD_9)
335 {
336 editAlphaKey = k->code;
337 editAlphaLevel++;
338 if (editAlphaLevel > 3)
339 editAlphaLevel = 0;
340 editShowHeader();
341 timStart(editTim);
342 return 1;
343 }
344 }
345 switch (k->code)
346 {
347 case KCD_CLEAR:
348 return 0;
349 case KCD_ABC:
350 editAlphaMode = (U8) !editAlphaMode;
351 if (editAlphaMode)
352 {
353 editAlphaLevel = 3;
354 editAlphaKey = KCD_MAX;
355 }
356 editShowHeader();
357 return 1;
358 default:
359 break;
360 }
361 edtChar(myHandle,editControls[k->code]);
362
363 return 1;
364 }
365
366 static void editInit (MfwHnd e)
367 {
368 myHandle = e;
369 editTim = timCreate(0,1000,(MfwCb) editEventTim);
370
371 editAlphaLevel = 3;
372 editAlphaKey = KCD_MAX;
373 }
374
375 static void editExit (void)
376 {
377 myHandle = 0;
378 timDelete(editTim);
379 }
380
381
382 /*
383 +--------------------------------------------------------------------+
384 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
385 | STATE : code ROUTINE : PhonebookControl |
386 +--------------------------------------------------------------------+
387
388 PURPOSE : setup main window control
389
390 */
391
392 static MfwHnd phoneWin; /* the phonebook window */
393 static MfwHnd phoneKbd; /* the phone keyboard */
394 static MfwHnd phoneEdt; /* the phone editor */
395 static MfwHnd phoneOldFocus; /* previous focus */
396
397 #define PhoneNumSize 32
398 #define PhoneAlphaSize 224
399
400 static struct phoneBookTag
401 {
402 char number [32];
403 char alpha [224];
404 } phoneADN [100] =
405 {
406 {"03039094231","Jie Volckarts"},
407 {"03039094267","Karsten Klawon"},
408 {"03039094108","Erwin Schmid"},
409 {"",""}
410 };
411
412 static int phoneIndex;
413 static int phoneEditing = 0;
414 static int phoneFailure = 0;
415
416 static MfwEdtAttr phoneEditAttr =
417 { /* edit attributes: */
418 {3,10,95,20}, /* edit area */
419 0,0,0, /* fg color, font, mode */
420 editControls, /* control key array */
421 0,0 /* edit buffer, size */
422 };
423
424
425 static void phoneSetEdit (void)
426 {
427 if (editAlphaMode)
428 {
429 phoneEditAttr.text = phoneADN[phoneIndex].alpha;
430 phoneEditAttr.size = PhoneAlphaSize;
431 }
432 else
433 {
434 phoneEditAttr.text = phoneADN[phoneIndex].number;
435 phoneEditAttr.size = PhoneNumSize;
436 }
437 edtReset(phoneEdt);
438 }
439
440 static void phoneShowHeader (void)
441 {
442 char hdr [8];
443
444 editShowHeader();
445 sprintf(hdr," %s%3d",editAlphaMode?" Name ":"Number",phoneIndex);
446 dspl_TextOut(39,0,DSPL_TXTATTR_INVERS,hdr);
447 }
448
449 static void phoneShow (void)
450 {
451 dspl_ClearAll();
452 phoneShowHeader();
453 edtShow(phoneEdt);
454 }
455
456 static int phoneEventWin (MfwEvt e, MfwWin *w)
457 {
458 switch (e)
459 {
460 case MfwWinVisible:
461 if (w->flags & MfwWinVisible)
462 phoneShow();
463 break;
464 default:
465 return 0;
466 }
467
468 return 1;
469 }
470
471 static int phoneEventKbd (MfwEvt e, MfwKbd *kc)
472 {
473 if (phoneFailure)
474 {
475 phoneFailure = 0;
476 e = KEY_CLEAR;
477 }
478 if (phoneEditing)
479 phoneEditing = editEventKbd(e,kc);
480 if (phoneEditing)
481 return 1;
482
483 switch (e & ~KEY_MAKE)
484 {
485 case KEY_MNUUP:
486 if (phoneIndex > 0)
487 phoneIndex--;
488 break;
489 case KEY_MNUDOWN:
490 if (phoneIndex < 99)
491 phoneIndex++;
492 break;
493 case KEY_ABC:
494 editAlphaMode = (U8) !editAlphaMode;
495 break;
496 case KEY_OK:
497 phoneEditAttr.mode = edtCurBar1;
498 phoneEditing = 1;
499 break;
500 case KEY_CLEAR:
501 phoneEditAttr.mode = 0;
502 phoneEditing = 0;
503 winFocus(phoneOldFocus);
504 phoneExit();
505 return 1;
506 default:
507 return 1; /* superflous !? */
508 // return editEventKbd(e,kc);
509 }
510 phoneSetEdit();
511 winShow(phoneWin);
512
513 return 1;
514 }
515
516 static void phoneInit (void)
517 {
518 U32 keys = 0x7fffffff & ~KEY_VOLUP & ~KEY_VOLDOWN;
519
520 phoneWin = winCreate(0,0,MfwWinVisible,(MfwCb) phoneEventWin);
521 phoneKbd = kbdCreate(phoneWin,keys,(MfwCb) phoneEventKbd);
522 phoneEdt = edtCreate(phoneWin,&phoneEditAttr,0,0);
523 editInit(phoneEdt);
524 phoneEditing = 0;
525 phoneFailure = 0;
526 phoneIndex = 0; /* start with index 0 */
527 }
528
529 static void phoneExit (void)
530 {
531 editExit();
532 edtDelete(phoneEdt);
533 kbdDelete(phoneKbd);
534 winDelete(phoneWin);
535 }
536
537 static int viewPhonebook (void)
538 {
539 phoneInit();
540 editAlphaMode = 1; /* start alphanumeric */
541 phoneSetEdit();
542 phoneOldFocus = winFocus(phoneWin); /* make me the first one */
543 winShow(phoneWin);
544
545 return 0;
546 }
547
548 static int searchPhonebook (void)
549 {
550 phoneInit();
551 phoneOldFocus = winFocus(phoneWin); /* make me the first one */
552 phoneFailure = 1;
553 dspl_ClearAll();
554 dspl_TextOut(5,12,DSPL_TXTATTR_NORMAL,"not implemented");
555 return 0;
556 }
557
558 static int newPhonebook (void)
559 {
560 phoneInit();
561 while (phoneIndex < 99 && (strlen(phoneADN[phoneIndex].alpha)
562 || strlen(phoneADN[phoneIndex].number)))
563 phoneIndex++;
564 editAlphaMode = 1; /* start alphanumeric */
565 phoneSetEdit();
566 phoneOldFocus = winFocus(phoneWin); /* make me the first one */
567 winShow(phoneWin);
568
569 return 0;
570 }
571
572
573 /*
574 +--------------------------------------------------------------------+
575 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
576 | STATE : code ROUTINE : MessagesControl |
577 +--------------------------------------------------------------------+
578
579 PURPOSE : setup main window control
580
581 */
582
583 static int doMessages (void)
584 {
585 dspl_ClearAll();
586 dspl_TextOut(30,12,DSPL_TXTATTR_NORMAL,"Sorry..");
587 return 0;
588 }
589
590
591 /*
592 +--------------------------------------------------------------------+
593 | PROJECT : MMI-Framework (8417) MODULE : MFW_MMI |
594 | STATE : code ROUTINE : mainControl |
595 +--------------------------------------------------------------------+
596
597 PURPOSE : setup main window control
598
599 */
600
601 static MfwHnd mainWin; /* the main window */
602 static MfwHnd mainKbd; /* the main keyboard */
603 static MfwHnd mainTim; /* the main timer */
604 static MfwHnd mainMnu; /* the main menu */
605
606
607
608 static char phoneMenuIcons [] =
609 {
610 0x00,0x00, 0x7E,0x7E, 0x41,0x82, 0x59,0x9C, /* VIEW */
611 0x41,0xA2, 0x5D,0xA2, 0x41,0xA2, 0x5D,0x9C,
612 0x41,0x82, 0x41,0x82, 0x7F,0xFE, 0x00,0x00,
613
614 0x00,0x00, 0x7E,0x7E, 0x41,0x82, 0x59,0xBA, /* SEARCH */
615 0x41,0x8A, 0x5D,0x92, 0x41,0x92, 0x5D,0x82,
616 0x41,0x92, 0x41,0x82, 0x7F,0xFE, 0x00,0x00,
617
618 0x00,0x00, 0x7E,0x7E, 0x41,0x81, 0x59,0xBB, /* NEW */
619 0x41,0x87, 0x5D,0x8E, 0x41,0x8C, 0x5D,0xB2,
620 0x41,0x82, 0x41,0x82, 0x7F,0xFE, 0x00,0x00,
621 };
622
623 static MfwIcnAttr phoneMenuIconAttr =
624 {
625 {80,18,16,12}, /* icon area */
626 3, /* number of icons */
627 phoneMenuIcons, /* icon array */
628 MFW_ICN_COLOUR
629 };
630
631 static MfwMnuItem phoneMenuItems [] =
632 {
633 {&phoneMenuIconAttr,0,"VIEW",0,viewPhonebook},
634 {&phoneMenuIconAttr,0,"SEARCH",0,searchPhonebook},
635 {&phoneMenuIconAttr,0,"NEW",0,newPhonebook}
636 };
637
638 static MfwMnuAttr phoneMenuAttr =
639 {
640 {20,5,80,10}, /* one menu line */
641 MNU_LEFT,
642 phoneMenuItems,
643 3,
644 MENUCOLOUR_LISTDEF
645 };
646
647
648 static char mainMenuIcons [] =
649 {
650 0x00,0x00, 0x7E,0x7E, 0x41,0x82, 0x59,0xBA, /* PHONEBOOK */
651 0x41,0x82, 0x5D,0xB2, 0x41,0x82, 0x5D,0x82,
652 0x41,0x82, 0x41,0x82, 0x7F,0xFE, 0x00,0x00,
653
654 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, /* MESSAGES */
655 0x7F,0xFE, 0x50,0x0A, 0x48,0x12, 0x4C,0x32,
656 0x52,0x4A, 0x61,0x86, 0x7F,0xFE, 0x00,0x00
657 };
658
659 static MfwIcnAttr mainMenuIconAttr =
660 {
661 {80,18,16,12}, /* icon area */
662 2, /* number of icons */
663 mainMenuIcons. /* icon array */
664 MFW_ICN_COLOUR
665 };
666
667 static MfwMnuItem mainMenuItems [] =
668 {
669 {&mainMenuIconAttr,0," PHONEBOOK",&phoneMenuAttr,0},
670 {&mainMenuIconAttr,0," MESSAGES",0,doMessages}
671 };
672
673 static MfwMnuAttr mainMenuAttr =
674 {
675 {20,5,80,18}, /* two menu lines */
676 MNU_LEFT | MNU_CUR_STAR,
677 mainMenuItems,
678 2,
679 MENUCOLOUR_LISTDEF
680 };
681
682
683 static void mainShow (void)
684 {
685 timStop(mainTim);
686 dspl_ClearAll();
687 mnuShow(mainMnu);
688 }
689
690 static int mainEventWin (MfwEvt e, MfwWin *w)
691 {
692 switch (e)
693 {
694 case MfwWinVisible:
695 if (w->flags & MfwWinVisible)
696 mainShow();
697 break;
698 default:
699 return 0;
700 }
701
702 return 1;
703 }
704
705 static int mainEventTim (MfwEvt e, MfwTim *t)
706 {
707 winShow(mainWin);
708 winFocus(mainWin);
709
710 return 1;
711 }
712
713 static int mainEventKbd (MfwEvt e, MfwKbd *kc)
714 {
715 switch (e & ~KEY_MAKE)
716 {
717 case KEY_MNUUP:
718 mnuUp(mainMnu);
719 break;
720 case KEY_MNUDOWN:
721 mnuDown(mainMnu);
722 break;
723 case KEY_OK:
724 mnuSelect(mainMnu);
725 break;
726 case KEY_CLEAR:
727 mnuEscape(mainMnu);
728 break;
729 }
730
731 return 1;
732 }
733
734 static void mainInit (void)
735 {
736 U32 keys = KEY_MNUUP + KEY_MNUDOWN + KEY_OK + KEY_CLEAR;
737
738 mainWin = winCreate(0,0,MfwWinVisible,(MfwCb) mainEventWin);
739 mainTim = timCreate(0,1000,(MfwCb) mainEventTim);
740 mainKbd = kbdCreate(0,keys,(MfwCb) mainEventKbd);
741 mainMnu = mnuCreate(mainWin,&mainMenuAttr,0,0,0,0);
742
743 timStart(mainTim);
744 }
745
746 static void mainExit (void)
747 {
748 mnuDelete(mainMnu);
749 kbdDelete(mainKbd);
750 timDelete(mainTim);
751 winDelete(mainWin);
752 }
753