-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui_menu.tbs
722 lines (661 loc) · 26 KB
/
ui_menu.tbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
'*************************************************************************************************************************
' ON SCREEN MENU CONTROL
' This is a menu libaray, by reading from a TAB delimited description file, a 4 buttons operated menu will show on a LCD
' The description file is consisted of following fields
' Acc lvl: Access level for this tem (byte value), counting from 0
' Men lvl: Menu level for this item (byte value), counting from 0
' Item type:Type of this item (one character):'N' - normal item; 'F' - folder item
' Item String: A string that will appear for this item on the screen
' Item Data: A comma-delimited field that contains all necessary information for normal items. This field is not necessary for the folder items.
'
'*************************************************************************************************************************
include "global.tbh"
'------------------------ internal -----------------------------
declare sub ui_menu_addr_fill(start_addr as word)
declare sub ui_menu_display(clear_menu as no_yes)
declare sub ui_menu_string_parse(start_index as byte, d as menu_key_actions)
declare sub ui_menu_cursor_display(color as word, force_print as no_yes)
declare sub ui_menu_out()
declare sub ui_menu_in()
declare sub ui_back_current_lcd()
declare sub ui_menu_scroll(refresh as no_yes)
declare sub menu_fade()
declare function ui_menu_call_ib(byref item_data as string(60),reprint as no_yes) as ui_input_box_results
declare function ui_menu_call_lb(byref item_data as string(60)) as ui_list_box_results
declare sub ui_menu_key_proc(key_event as pl_kp_event_codes, key_code as byte)
declare sub ui_menu_timer_proc()
'------------------------ external -----------------------------
declare sub device_ui_menu_command(s as string)
'---------------------------------------------------------------
dim ui_menu_string as string(DISPLAY_STR_LEN) 'string displayed on the LCD
dim ui_menu_desc_file as string(20) 'file name of the menu item description
dim ui_menu_lvl_path as string(MENU_MAX_LVL*2) 'address(in description file) of all previously accessed menu item(folder) which leads to current folder
dim ui_menu_index_path as string(MENU_MAX_LVL) 'actual index of all previously accessed menu item(folder) which leads to current folder
dim ui_menu_display_index_path as string(MENU_MAX_LVL) 'display index of all previously accessed menu item(folder) which leads to current folder
dim menu_pos_x, menu_pos_y, menu_width, menu_height as word
dim menu_item_index, menu_display_index, menu_start_index as byte '3 byte-size variable are used to keep track of the items in this module,
'menu_item_index: the actual index of all the menu items that is accessible to the user(according to access lvl)
'menu_display_index: the actually position of the cursor on the LCD
'menu_start_index: the menu_item_index of the 1st item displayed on LCD
dim menu_timeout_ctr, menu_timeout, menu_access_level, menu_current_lvl as byte
dim menu_item_count as byte
dim menu_result as ui_menu_results
dim flag_last_lvl as no_yes 'is the current lvl the last lvl
dim cached_ib_str as string(IB_MAX_LEN)
dim ui_menu_exit_flag as no_yes
dim menu_addr_array(MENU_MAX_ITEM_PER_LVL) as menu_display_item
#if MENU_CURSOR_STYLE > 0
dim previous_display_index as byte
#endif
'=============================================================
public function ui_menu(
x_coord as word, 'x coordination
y_coord as word, 'y coordination
width as word, 'width of the menu in pixel
height as word, 'height of the menu in pixel
byref menu_states as string(MENU_MAX_LVL), 'allows user to start up the menu inside of selected sub-folders instead of root. example: if menu_state="23" then the menu will started at 2nd folder of menu lvl 1, 3rd folder of menu lvl 2. if menu_state="" then menu started at root.
byref menu_descriptor_file as string(20), 'the descriptor file
access_level as byte, 'access level of the user, only the menu item that is small or equal to access_level will show.
timeout as byte 'if no respond from the keypad within the time defined by "timeout", exit the menu and return to the previous screen. If timeout=0, no time out applies
) as ui_menu_results
dim kp_event as pl_kp_event_codes
dim kp_code as byte
dim t as word
menu_current_lvl=0
menu_item_count=0
menu_access_level=access_level
ui_menu_lvl_path=""
menu_pos_x=x_coord
menu_pos_y=y_coord
menu_width=width
menu_height=height-lcd.fontheight-5
ui_menu_desc_file=menu_descriptor_file
ui_menu_string=""
ui_menu_index_path=""
ui_menu_display_index_path=""
menu_timeout_ctr=timeout
menu_timeout=timeout
menu_item_index=0
menu_display_index=0
menu_result=MENU_RESULT_TIMEOUT
flag_last_lvl=NO
cached_ib_str=""
ui_menu_exit_flag=NO
ui_menu_addr_fill(1)
ui_menu_string_parse(0,MENU_KEY_IN)
menu_start_index=0
LCD_LOCK
'------------------- Print menu on LCD --------------------
device_menu_pre(x_coord,y_coord,width,height,menu_states,menu_descriptor_file,access_level,timeout)
ui_menu_display(yes)
ui_menu_cursor_display(LCD_CURSORCOLOR, yes)
ui_menu_scroll(yes)
LCD_UNLOCK
if kp.enabled=NO or kp.genkpevent<>NO then
kp.enabled=NO
kp.genkpevent=NO
kp.enabled=YES
else
kp.clearbuffer
end if
wait:
device_menu_interrupt()
if ui_menu_exit_flag=YES then goto key_pressed
if kp.enabled=NO then kp.enabled=YES
if kp.getkey(kp_event,kp_code)=OK then
if kp_event=PL_KP_EVENT_LOCKEDUP then
reset_keypad()
goto wait
end if
ui_menu_key_proc(kp_event,kp_code)
end if
if menu_result<>MENU_RESULT_TIMEOUT then
ui_menu=menu_result
goto key_pressed
end if
if t<> sys.timercount then
t=sys.timercount
ui_menu_timer_proc
end if
if timeout=0 then
goto wait
else
if menu_timeout_ctr=0 then
ui_menu=MENU_RESULT_TIMEOUT
key_pressed:
if menu_result=MENU_RESULT_OK then
end if
exit function
end if
goto wait
end if
end function
'----------------------------------------------------------------------------
sub menu_fade()
lcd.forecolor=LCD_DISABLE_FORECOLOR
LCD_LOCK
ui_menu_display(no)
ui_menu_scroll(yes)
ui_menu_cursor_display(LCD_DISABLE_FORECOLOR, yes)
LCD_UNLOCK
lcd.forecolor=LCD_FORECOLOR
end sub
'----------------------------------------------------------------------------
sub menu_path_store(addr as word)
'backup the address(in description file) of all previously accessed menu item(folder) which leads to current folder
dim msb, lsb as byte
msb=addr/256
lsb=addr - msb*256
ui_menu_lvl_path=ui_menu_lvl_path + chr(msb) + chr(lsb)
end sub
'----------------------------------------------------------------------------
function menu_covert_addr(s_addr as string(2)) as word
'convert a 2-bytes string to a word value
dim msb, lsb as byte
msb=asc(left(s_addr,1))
lsb=asc(right(s_addr,1))
menu_covert_addr=msb*256+lsb
end function
'----------------------------------------------------------------------------
sub ui_menu_addr_fill(start_addr as word)
'Filled up the menu_addr_array according to the current menu_lvl, and access_lvl
dim s as string
dim i, item_end as word
dim access_lvl, menu_lvl as byte
dim addr1, addr2 as word
dim str_len1,str_len2 as byte
dim index, j as byte
dim menu_type as string(1)
romfile.open(ui_menu_desc_file) 'this file is a setting descriptor table
romfile.pointer=start_addr
i=romfile.find(romfile.pointer,">>",1)
index=0
menu_item_count=0
while i <> 0 and index < MENU_MAX_ITEM_PER_LVL
addr1=0
addr2=0
str_len1=0
str_len2=0
romfile.pointer=i+2
item_end=romfile.find(romfile.pointer,chr(CR),1)
for j=0 to 3
do
i=romfile.find(romfile.pointer,chr(TAB),1)
if i=0 then exit sub
if j=3 then addr1=romfile.pointer
s=romfile.getdata(i-romfile.pointer)
romfile.pointer=i+1
loop while s=""
select case j
case 0: 'extract access lvl
access_lvl=val(s)
case 1: 'extract menu lvl
menu_lvl=val(s)
case 2: 'extract item type
menu_type=s
case 3:
str_len1=len(s)
end select
next j
if menu_type="N" then
do
addr2=romfile.pointer
s=romfile.getdata(1)
loop while s=chr(TAB)
str_len2=item_end-addr2
end if
if menu_lvl=menu_current_lvl and not(access_lvl>menu_access_level) then
menu_addr_array(index).display_string_addr=addr1
menu_addr_array(index).display_string_len=str_len1
menu_addr_array(index).display_item_type=menu_type
menu_addr_array(index).display_item_data_addr=addr2
menu_addr_array(index).display_item_data_len=str_len2
menu_item_count=menu_item_count + 1
index=index + 1
end if
if menu_current_lvl <> 0 and menu_lvl < menu_current_lvl then exit while
i=romfile.find(romfile.pointer,">>",1)
wend
end sub
'----------------------------------------------------------------------------
sub ui_menu_string_parse(start_index as byte, d as menu_key_actions)
'read address of the menu item from menu_addr_string(item stack), and parse them into real menu item, accessing the item information from the menu description file, using the address.
dim s as string(24)
dim i as word
dim index, item_num as byte
romfile.open(ui_menu_desc_file) 'this file is a setting descriptor table
if MENU_DISPLAY_ITEM_PER_LVL > menu_item_count then
item_num=menu_item_count
else
item_num=MENU_DISPLAY_ITEM_PER_LVL
end if
select case d
case MENU_KEY_IN,MENU_KEY_OUT
ui_menu_string=""
for index=start_index to start_index+item_num-1
romfile.pointer=menu_addr_array(index).display_string_addr
s=romfile.getdata(menu_addr_array(index).display_string_len)
ui_menu_string=ui_menu_string+s+"`"
next i
case MENU_KEY_UP:
index=start_index
romfile.pointer=menu_addr_array(index).display_string_addr
s=romfile.getdata(menu_addr_array(index).display_string_len)
i=instr(1,ui_menu_string,"`",item_num-1)
ui_menu_string=s+"`"+left(ui_menu_string,i)
case MENU_KEY_DOWN:
index=start_index+item_num-1
romfile.pointer=menu_addr_array(index).display_string_addr
s=romfile.getdata(menu_addr_array(index).display_string_len)
i=instr(1,ui_menu_string,"`",1)
i=len(ui_menu_string)-i
ui_menu_string=right(ui_menu_string,i)+s+"`"
end select
end sub
'----------------------------------------------------------------------------
sub ui_menu_cursor_display(color as word, force_print as no_yes)
'print the cursor at correct posistion (according to menu_display_index) on the LCD
dim x, y as word
#if MENU_CURSOR_STYLE=0
romfile.open(SMALL_ICON_FILE)
lcd_clear(menu_pos_x, menu_pos_y, SCROLL_CURSOR_WIDTH, menu_height)
x=menu_pos_x+ 1
y=menu_pos_y+menu_display_index * (lcd.fontheight + UM_VER_SPACING)+(lcd.fontheight/2)-3
lcd.bmp(romfile.offset,x,y,19,0,5,8)
#else
x=menu_pos_x+ 1
lcd.linewidth=SCROLL_BORDER
if menu_display_index <> previous_display_index and force_print=NO then
lcd.forecolor=LCD_BACKCOLOR
y=menu_pos_y+(previous_display_index)*(lcd.fontheight+UM_VER_SPACING)-UM_VER_SPACING/2-3
lcd.rectangle(x,y,x+menu_width-SCROLL_CURSOR_WIDTH-SCROLL_BAR_WIDTH-SCROLL_BORDER-CURSOR_BAR_LEN_OFFSET,y+lcd.fontheight+UM_VER_SPACING)
end if
if menu_display_index <> previous_display_index or force_print=YES then
lcd.forecolor=color
y=menu_pos_y+menu_display_index*(lcd.fontheight + UM_VER_SPACING)-UM_VER_SPACING/2-3
lcd.rectangle(x,y,x+menu_width-SCROLL_CURSOR_WIDTH-SCROLL_BAR_WIDTH-SCROLL_BORDER-CURSOR_BAR_LEN_OFFSET,y+lcd.fontheight+UM_VER_SPACING)
lcd.forecolor=LCD_FORECOLOR
end if
#endif
end sub
'----------------------------------------------------------------------------
sub ui_menu_display(clear_menu as no_yes)
'print the ui_menu_string, which contains the menu items.
#if MENU_CURSOR_STYLE=0
if clear_menu=YES then lcd_clear(menu_pos_x + SCROLL_CURSOR_WIDTH, menu_pos_y, menu_width - SCROLL_CURSOR_WIDTH*2-SCROLL_BAR_WIDTH-SCROLL_BORDER*2, menu_height)
#elif MENU_CURSOR_STYLE > 0
' if clear_menu=YES then lcd_clear(menu_pos_x, menu_pos_y-UM_VER_SPACING/2-SCROLL_BORDER-1, menu_width -SCROLL_BAR_WIDTH-SCROLL_BORDER*2, menu_height+UM_VER_SPACING+SCROLL_BORDER)
#endif
lcd.textalignment=PL_LCD_TEXT_ALIGNMENT_TOP_LEFT
romfile.open(LCD_STD_FONT)
lcd.setfont(romfile.offset)
lcd.textverticalspacing=UM_VER_SPACING
lcd.texthorizontalspacing=UM_HOR_SPACING
lcd.forecolor=LCD_FORECOLOR
lcd.backcolor=LCD_BACKCOLOR
lcd.printaligned(ui_menu_string, menu_pos_x + SCROLL_CURSOR_WIDTH, menu_pos_y, menu_width-SCROLL_CURSOR_WIDTH*2-SCROLL_BAR_WIDTH-SCROLL_BORDER-CURSOR_BAR_LEN_OFFSET, menu_height)
end sub
'----------------------------------------------------------------------------
sub ui_menu_up()
'when cursor on the menu is moving up, if the cursor is already at the first item on current page, LCD refreshes and display the last page, and cursor is pointing the last item on the previous page.
dim menu_prev_start as byte
menu_prev_start=menu_start_index
if menu_item_index > 0 then
menu_item_index=menu_item_index - 1
device_move_cursor(menu_addr_array(menu_item_index),ui_menu_desc_file)
else
exit sub
end if
if menu_display_index=0 and menu_start_index > 0 then
menu_start_index=menu_start_index - 1
ui_menu_string_parse(menu_start_index,MENU_KEY_UP)
LCD_LOCK
ui_menu_display(yes)
LCD_UNLOCK
else
#if MENU_CURSOR_STYLE > 0
previous_display_index=menu_display_index
#endif
menu_display_index=menu_display_index - 1
end if
if menu_prev_start=menu_start_index then exit sub
if menu_start_index=menu_item_count-MENU_DISPLAY_ITEM_PER_LVL-1 or menu_start_index=0 then
ui_menu_scroll(yes)
end if
end sub
'----------------------------------------------------------------------------
sub ui_menu_down()
'when cursor on the menu is moving down, if the cursor is already at the last item on current page, LCD refreshes and display the next page, and cursor is pointing the first item on the next page.
dim menu_prev_start as byte
menu_prev_start=menu_start_index
menu_item_index=menu_item_index + 1
if menu_item_index > menu_item_count-1 then
menu_item_index=menu_item_index - 1
exit sub
end if
previous_display_index=menu_display_index
menu_display_index=menu_display_index + 1
device_move_cursor(menu_addr_array(menu_item_index),ui_menu_desc_file)
if menu_display_index > MENU_DISPLAY_ITEM_PER_LVL-1 then
menu_display_index=menu_display_index - 1
menu_start_index=menu_item_index - menu_display_index
ui_menu_string_parse(menu_start_index,MENU_KEY_DOWN)
LCD_LOCK
ui_menu_display(yes)
LCD_UNLOCK
end if
if menu_prev_start=menu_start_index then exit sub
if menu_start_index=menu_item_count-MENU_DISPLAY_ITEM_PER_LVL or menu_start_index=1 then
ui_menu_scroll(yes)
end if
end sub
'----------------------------------------------------------------------------
function ui_menu_call_lb(byref item_data as string(60)) as ui_list_box_results
'This function prepares all necessary variables for the List box, and invoke ui_list_box() function.
dim listbox_state as string(10)
dim timeout as byte
dim pos1, pos2 as byte
dim listbox_data as string
dim setting_name as string(5)
dim i as word
dim lb_result as ui_list_box_results
dim b as byte
'dim s as string
pos1=instr(1,item_data,chr(COMMA),2)
pos2=instr(1,item_data,chr(COMMA),3)
setting_name=mid(item_data,pos1+1,pos2-pos1-1)
b=0
if device_settings_sg(setting_name,b,listbox_state,"",DEVICE_GET)=EN_STG_STATUS_OK then
romfile.open(ui_menu_desc_file)
'i=menu_covert_addr(mid(menu_addr_string,menu_item_index*2+1,2))
romfile.pointer=i+3
pos1=instr(1,item_data,",",3)
listbox_data=mid(item_data,pos1+1,len(item_data)-pos1-1)
timeout=20
'adjust list box position
lb_result=ui_list_box(LIST_BOX_X, LIST_BOX_Y, LIST_BOX_W, LIST_BOX_H, listbox_data, listbox_state,NO, timeout)
if lb_result=LIST_BOX_RESULT_OK then
if device_settings_sg(setting_name,b,listbox_state,"",DEVICE_SET)=EN_STG_STATUS_OK then set_stg_modified()
end if
ui_menu_call_lb=lb_result
else
ui_msg_box(COMMAND_SETTING_FAILURE,MSG_BOX_X,MSG_BOX_Y,MSG_BOX_W,MSG_BOX_H,PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER,device_mb_get_key(MBK_OK),no,0)
end if
end function
'----------------------------------------------------------------------------
function ui_menu_call_ib(byref item_data as string(60),reprint as no_yes) as ui_input_box_results
'This function prepares all necessary variables for the input box, and invoke ui_list_box() function.
dim setting_name as string(5)
dim edit_str, mask_str, temp as string(IB_MAX_LEN)
dim char_range as input_box_char_ranges
dim pos1, pos2, initial_pos, timeout, input_length as byte
dim secret_mode, insert_mode as no_yes
dim ib_result as ui_input_box_results
dim b as byte
'get setting value from EEPROM
pos1=instr(1,item_data,chr(COMMA),2)
pos2=instr(1,item_data,chr(COMMA),3)
setting_name=mid(item_data,pos1+1,pos2-pos1-1)
b=0
if device_settings_sg(setting_name,b,edit_str,"",DEVICE_GET)=EN_STG_STATUS_OK then
pos1=instr(1,item_data,chr(COMMA),3)
pos2=instr(1,item_data,chr(COMMA),4)
mask_str=mid(item_data,pos1+1,pos2-pos1-1)
pos1=instr(1,item_data,chr(COMMA),5)
temp=mid(item_data,pos2+1,pos1-pos2-1)
select case temp
case "D": char_range=INPUT_BOX_CHAR_RANGE_09
case "A": char_range=INPUT_BOX_CHAR_RANGE_AZ
case "B": char_range=INPUT_BOX_CHAR_RANGE_09AZ
end select
pos2=instr(1,item_data,chr(COMMA),6)
temp=mid(item_data,pos1+1,pos2-pos1-1)
input_length=val(temp)
temp=right(item_data,1)
if temp="N" then secret_mode=NO
if temp="Y" then secret_mode=YES
insert_mode=MENU_IB_INSERT
timeout=20
if reprint=YES then
edit_str=cached_ib_str
end if
if INPUT_BOX_INIT_POS=0 then
initial_pos=1
else
initial_pos=len(edit_str)
end if
lcd_clear(INPUT_BOX_X, INPUT_BOX_Y, INPUT_BOX_W, INPUT_BOX_H)
ib_result=ui_input_box(mask_str,edit_str,char_range,secret_mode,insert_mode,initial_pos,timeout,input_length)
'special cases for settings
if ib_result=INPUT_BOX_RESULT_OK then
if device_settings_sg(setting_name,b,edit_str,"",DEVICE_SET)<>EN_STG_STATUS_OK then
ib_result=INPUT_BOX_RESULT_FAIL
else
set_stg_modified()
end if
end if
ui_menu_call_ib=ib_result
cached_ib_str=edit_str
else
ui_msg_box(COMMAND_SETTING_FAILURE,MSG_BOX_X,MSG_BOX_Y,MSG_BOX_W,MSG_BOX_H,PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER,device_mb_get_key(MBK_OK),no,0)
end if
end function
'----------------------------------------------------------------------------
sub ui_menu_out()
'this sub is called when user want to go out one level (folder) in the menu.
dim addr as word
dim confirm_key, cancel_key as string(3)
dim return_key as byte
dim mb_popped as no_yes
flag_last_lvl=NO
mb_popped=NO
if menu_current_lvl > 0 then
menu_current_lvl=menu_current_lvl - 1
else
mb_popped=YES
confirm_key=device_mb_get_key(MBK_YES)
cancel_key=device_mb_get_key(MBK_NO)
return_key=ui_msg_box(EXIT_MENU,MSG_BOX_X,MSG_BOX_Y,MSG_BOX_W,MSG_BOX_H,PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER,confirm_key+cancel_key,no,0)
if instr(1,confirm_key,chr(return_key),1)> 0 then
ui_menu_exit_flag=yes
exit sub
end if
end if
ui_menu_lvl_path=left(ui_menu_lvl_path, len(ui_menu_lvl_path)-2)
addr=menu_covert_addr(right(ui_menu_lvl_path,2))
ui_menu_addr_fill(addr)
previous_display_index=menu_display_index
if ui_menu_index_path<>"" then
menu_item_index=asc(right(ui_menu_index_path,1))
ui_menu_index_path=left(ui_menu_index_path,len(ui_menu_index_path)-1)
menu_display_index=asc(right(ui_menu_display_index_path,1))
ui_menu_display_index_path=left(ui_menu_display_index_path, len(ui_menu_display_index_path)-1)
end if
menu_start_index=menu_item_index - menu_display_index
ui_menu_string_parse(menu_start_index,MENU_KEY_OUT)
LCD_LOCK
if mb_popped=yes then
lcd_clear(MSG_BOX_X-SCROLL_BORDER,MSG_BOX_Y-SCROLL_BORDER,MSG_BOX_W+SCROLL_BORDER*2,MSG_BOX_H+SCROLL_BORDER*2)
device_menu_pre("","","","","","","","")
end if
lcd_clear(menu_pos_x, menu_pos_y-UM_VER_SPACING/2-SCROLL_BORDER-1, menu_width -SCROLL_BAR_WIDTH-SCROLL_BORDER*2, menu_height+UM_VER_SPACING+SCROLL_BORDER-10)
ui_menu_display(yes)
ui_menu_cursor_display(LCD_CURSORCOLOR, yes)
ui_menu_scroll(yes)
device_move_cursor(menu_addr_array(menu_item_index),ui_menu_desc_file)
LCD_UNLOCK
if kp.enabled=NO then kp.enabled=YES
end sub
'----------------------------------------------------------------------------
sub ui_menu_in()
'this sub is called when user want to go out one level (folder) in the menu
'or select the menu item that is currently pointed by the cursor.
dim i as word
dim s as string(60)
dim ib_result as ui_input_box_results
dim lb_result as ui_list_box_results
dim item_data as string
dim reprint as no_yes
#if UI_TABLE_CONTROL
dim tb_result as ui_tbl_box_results
#endif
if flag_last_lvl=YES then exit sub
i=menu_addr_array(menu_item_index).display_string_addr
ui_back_current_lcd
menu_path_store(i)
if menu_addr_array(menu_item_index).display_item_type="F" then
ui_menu_addr_fill(i)
ui_menu_string_parse(0,MENU_KEY_IN)
if ui_menu_string="" then
ui_msg_box(EMPTY_FOLDER,MSG_BOX_X,MSG_BOX_Y,MSG_BOX_W,MSG_BOX_H,PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER,"",no,STD_INPUT_WAIT_TIME)
device_menu_pre("","","","","","","","")
ui_menu_out
else
previous_display_index=menu_display_index
menu_display_index=0
menu_start_index=0
menu_item_index=0
LCD_LOCK
lcd_clear(menu_pos_x, menu_pos_y-UM_VER_SPACING/2-SCROLL_BORDER-1, menu_width -SCROLL_BAR_WIDTH-SCROLL_BORDER*2, menu_height+UM_VER_SPACING+SCROLL_BORDER-4)
ui_menu_display(yes)
ui_menu_cursor_display(LCD_CURSORCOLOR, yes)
ui_menu_scroll(yes)
LCD_UNLOCK
device_move_cursor(menu_addr_array(menu_item_index),ui_menu_desc_file)
end if
exit sub
end if
'extract item_data
romfile.open(ui_menu_desc_file)
romfile.pointer=menu_addr_array(menu_item_index).display_item_data_addr
item_data=romfile.getdata(menu_addr_array(menu_item_index).display_item_data_len)
if left(item_data,1)="S" then goto setting
if left(item_data,1)="C" then goto command
setting:
flag_last_lvl=YES
i=instr(1,item_data,chr(COMMA),1)
if i > 0 then
s=mid(item_data,i+1,1)
else
s=""
end if
select case s
case "I":
reprint=NO
print_ib:
menu_fade
ib_result=ui_menu_call_ib(item_data,reprint)
if ib_result=INPUT_BOX_RESULT_FAIL then
ui_msg_box(SYS_SETTING_VALUE_INVALID,MSG_BOX_X,MSG_BOX_Y,MSG_BOX_W,MSG_BOX_H,PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER,"",no,0)
reprint=YES
goto print_ib
end if
device_menu_pre("","","","","","","","")
ui_menu_out
case "L":
menu_fade
lb_result=ui_menu_call_lb(item_data)
device_menu_pre("","","","","","","","")
ui_menu_out
#if UI_TABLE_CONTROL
case "T"
tb_result=ui_tbl_box(menu_pos_x, menu_pos_y, menu_width,menu_height,item_data)
device_menu_pre("","","","","","","","")
ui_menu_out
#endif
case else
ui_msg_box(INVALID_INPUT,MSG_BOX_X,MSG_BOX_Y,MSG_BOX_W,MSG_BOX_H,PL_LCD_TEXT_ALIGNMENT_MIDDLE_CENTER,"",no,STD_INPUT_WAIT_TIME)
device_menu_pre("","","","","","","","")
ui_menu_out
end select
exit sub
command:
flag_last_lvl=YES
i=instr(1,item_data,chr(COMMA),1)
if i > 0 then
s=right(item_data,len(item_data)-i)
'For the commands that need to confirm before excuting, add them into select case below
'proper information need to be provided before calling the msg_box
device_ui_menu_command(s)
device_menu_pre("","","","","","","","")
end if
ui_menu_out
end sub
'----------------------------------------------------------------------------
sub ui_menu_scroll(refresh as no_yes)
'The subroutin takes care of all the necessary changes on the LCD when the cursor is moving.
dim scroll_cursor as byte
dim x, y, h, h1 as word
x=menu_pos_x + menu_width - SCROLL_BAR_WIDTH-SCROLL_BORDER
y=menu_pos_y
h=menu_height-SCROLL_ARROW_HEIGHT*2
if menu_item_count > 0 then h1=(h-SCROLL_BORDER)/menu_item_count
if h1 < SCROLL_MIN_HEIGHT then h1=SCROLL_MIN_HEIGHT
if menu_item_count > 0 and menu_item_count > menu_item_index then
if menu_item_index=0 then
scroll_cursor=y+SCROLL_ARROW_HEIGHT+SCROLL_BORDER/2
else
if menu_item_index=menu_item_count-1 then
scroll_cursor=y+h+SCROLL_ARROW_HEIGHT+SCROLL_BORDER-h1
else
scroll_cursor =y+SCROLL_ARROW_HEIGHT+SCROLL_BORDER/2-1 + (h-SCROLL_BORDER)*menu_item_index/(menu_item_count)
end if
end if
else
exit sub
end if
lcd.linewidth=SCROLL_BORDER
lcd.filledrectangle(x,y+SCROLL_ARROW_HEIGHT,x+SCROLL_BAR_WIDTH,y+h+SCROLL_ARROW_HEIGHT)
lcd.fill(x+SCROLL_BORDER/2,scroll_cursor,SCROLL_BAR_WIDTH-SCROLL_BORDER+1,h1)
if refresh=NO then exit sub
romfile.open(SMALL_ICON_FILE)
if menu_start_index=0 then
lcd.bmp(romfile.offset,x+SCROLL_ARROW_X_POS_OFFSET,y+SCROLL_ARROW_Y_POS_OFFSET,39,3,19,10)
else
lcd.bmp(romfile.offset,x+SCROLL_ARROW_X_POS_OFFSET,y+SCROLL_ARROW_Y_POS_OFFSET,1,2,19,11)
end if
if menu_start_index=menu_item_count-MENU_DISPLAY_ITEM_PER_LVL or menu_item_count < MENU_DISPLAY_ITEM_PER_LVL then
lcd.bmp(romfile.offset,x+SCROLL_ARROW_X_POS_OFFSET,y+h+SCROLL_ARROW_Y_POS_OFFSET+SCROLL_ARROW_HEIGHT,39,6,19,11)
else
lcd.bmp(romfile.offset,x+SCROLL_ARROW_X_POS_OFFSET,y+h+SCROLL_ARROW_Y_POS_OFFSET+SCROLL_ARROW_HEIGHT,20,2,19,11)
end if
end sub
'----------------------------------------------------------------------------
sub ui_menu_key_proc(key_event as pl_kp_event_codes, key_code as byte)
'This is the subroutin excutes the proper action when on_kp event is triggered and redirect to the ui_menu module
dim ks as menu_key_actions
menu_timeout_ctr=menu_timeout
device_menu_key_proc(key_event, key_code, ks)
select case key_event
case PL_KP_EVENT_PRESSED:
select case ks
case MENU_KEY_UP:
ui_menu_up
ui_menu_cursor_display(LCD_CURSORCOLOR, no)
ui_menu_scroll(no)
case MENU_KEY_DOWN:
ui_menu_down
ui_menu_cursor_display(LCD_CURSORCOLOR, no)
ui_menu_scroll(no)
case MENU_KEY_OUT:
ui_menu_out
case MENU_KEY_IN:
ui_menu_in
end select
end select
end sub
'----------------------------------------------------------------------------
sub ui_back_current_lcd()
'backup the necessary data for menu, so it can be restored later.
ui_menu_index_path=ui_menu_index_path + chr(menu_item_index)
ui_menu_display_index_path=ui_menu_display_index_path + chr(menu_display_index)
menu_current_lvl=menu_current_lvl + 1
end sub
'----------------------------------------------------------------------------
sub ui_menu_timer_proc()
'This is the subroutin counts down to time out when on_sys_timer event is triggered
'and redirect to the ui_menu module
if menu_timeout_ctr>0 then
menu_timeout_ctr=menu_timeout_ctr-1
end if
end sub