📄 keymenu.c
字号:
/***************************************************************************
keymenu.c
Z-World, 2002
This sample program is for the LCD MSCG12232 Display Module and
LP3500 series controllers.
Description
===========
This program demonstrates how to implement a menu system using a
highlight bar on a graphic LCD display. It uses functions from
LCD122KEY7.LIB and devPowerSet() to enable the module.
The menu options for this sample are as follows:
1. Set Date & Time
2. Display Date/Time
3. Turn backlight OFF
4. Turn backlight ON
5. Toggle LEDS
6. Increment LEDS
7. Disable LEDS
To select a option use the scroll keys(Scroll and/or Page UP/DOWN keys)
to highlight the option that you want to select and then press the ENTER
key.
Once the option is selected the operation will be completed or you
will be prompted to do additional steps to complete the option
selected.
Development Note:
-----------------
Menu options can be added/deleted and the highlight bar will automatically
adjust to the new menu list. This will also require that you add/delete case
statements in main() to match your menu list.
**************************************************************************/
#class auto
#memmap xmem
//---------------------------------------------------------
// Bitmaps
//---------------------------------------------------------
// Bitmap : Zwbw5_bmp
// Buffer Size : 203
// Monochrome : White Foreground, Black Background
// Mode : Landscape
// Height : 29 pixels.
// Width : 53 pixels.
// Init : glXPutBitmap (leftedge,topedge,53,29,Zwbw5_bmp);
xdata Zwbw5_bmp {
'\x00','\x00','\x1F','\xF8','\x00','\x00','\x07',
'\x00','\x00','\xFF','\xFF','\x80','\x00','\x07',
'\x00','\x03','\xF3','\xF0','\xE0','\x00','\x07',
'\x00','\x0F','\xFF','\xE0','\x38','\x00','\x07',
'\x00','\x3F','\x0F','\xFC','\x0E','\x00','\x07',
'\x00','\x7E','\x1E','\x07','\x83','\x00','\x07',
'\x00','\xFC','\x38','\x01','\xE1','\x80','\x07',
'\x01','\xB8','\x30','\x00','\x38','\xC0','\x07',
'\x03','\x30','\x70','\x00','\x0C','\x60','\x07',
'\x06','\x60','\xE0','\x00','\x03','\x70','\x07',
'\x0E','\x60','\xC0','\x00','\x01','\xF0','\x07',
'\x0C','\xC1','\x80','\x00','\x00','\xE8','\x07',
'\x1F','\xFF','\xE0','\x00','\x00','\x2C','\x37',
'\x3F','\x83','\x7F','\x00','\x00','\x34','\x1F',
'\x31','\x03','\x01','\xE0','\x00','\x2A','\x3F',
'\x31','\x02','\x00','\x1C','\x00','\x26','\x67',
'\x62','\x06','\x00','\x07','\x00','\x27','\xC7',
'\x62','\x04','\x00','\x01','\x80','\x27','\x07',
'\x00','\x00','\x00','\x00','\x00','\x70','\x07',
'\x00','\x00','\x00','\x00','\x03','\x80','\x07',
'\x7C','\x21','\x0D','\xF9','\xF8','\x7C','\x07',
'\x08','\x31','\x8B','\x0F','\x84','\x63','\x07',
'\x18','\x11','\x8F','\xE1','\x14','\x61','\x07',
'\x11','\x93','\xF0','\x05','\x34','\x61','\x07',
'\x31','\xC0','\x54','\x07','\xE4','\x61','\x07',
'\x20','\x0A','\x56','\x05','\x44','\x61','\x07',
'\x40','\x0C','\x62','\x05','\x24','\x63','\x07',
'\x40','\x04','\x21','\x99','\x34','\x6E','\x07',
'\xFC','\x04','\x20','\xF1','\x17','\xF8','\x07'
};
//---------------------------------------------------------
// Macro's
//---------------------------------------------------------
#define MAXDISPLAYROWS 4
#define LEDOFF 0
#define TOGGLE 1
#define INCREMENT 2
#define OPERATE 3
#define ASCII 0
#define NUMBER 1
//----------------------------------------------------------
// Main_Menu options
//----------------------------------------------------------
// Can insert/delete menu options. The highlight bar is setup
// to start with the first MENU option and stop at the last
// menu option in the MENU.
//
// When adding/deleting menu options you must match up the
// case statements to the menu option number.
//
const char *main_menu [] =
{ " <<<<Main Menu>>>>",
"1.Set Date & Time",
"2.Display Date/Time",
"3.Turn Backlight OFF",
"4.Turn Backlight ON",
"5.Toggle LED's",
"6.Increment LED's",
"7.Disable LED's",
NULL
};
//----------------------------------------------------------
// Structures, arrays, variables
//----------------------------------------------------------
fontInfo fi6x8, fi8x10, fi12x16;
windowFrame textWindow;
typedef struct {
int data;
char *ptr;
} fieldupdate;
struct tm CurTime;
char szTime[40];
char szString[20];
const char Days[] = {"SunMonTueWedThuFriSat"};
const char Months[] = {"JanFebMarAprMayJunJulAugSepOctNovDec"};
int ledCntrl;
int beeperTick, timerTick ;
int max_menu_options;
int max_cmds_options;
unsigned long ulTime;
char *keybuffer;
//------------------------------------------------------------------------
// Milli-sec delay function
//------------------------------------------------------------------------
nodebug
void msDelay(unsigned int delay)
{
auto unsigned long done_time;
done_time = MS_TIMER + delay;
while( (long) (MS_TIMER - done_time) < 0 );
}
//------------------------------------------------------------------------
// Process key to do number and ASCII field changes
//------------------------------------------------------------------------
int ProcessKeyField(int mode, fieldupdate *field)
{
static int wKey;
keyProcess();
msDelay(100);
if((wKey = keyGet()) != 0)
{
switch(wKey)
{
// Decrement number by 10 or pointer by 3
case '-':
if(mode == NUMBER)
field->data -= 10;
else
field->ptr -= 3;
break;
// Increment number by 10 or pointer by 3
case '+':
if(mode == NUMBER)
field->data += 10;
else
field->ptr += 3;
break;
// Increment number or pointer by 1
case 'U':
if(mode == NUMBER)
field->data++;
else
field->ptr++;
break;
// Decrement number or pointer by 1
case 'D': // Decrement X1
if(mode == NUMBER)
field->data--;
else
field->ptr--;
break;
// Done Editing field
case 'E':
wKey = 'E';
break;
default:
wKey = -1;
break;
}
}
return(wKey);
}
//------------------------------------------------------------------------
// Get and process the users MENU option
//------------------------------------------------------------------------
int GetKeypadOption( int *offset, int *highlight )
{
static int wKey;
if((wKey = keyGet()) != 0)
{
switch(wKey)
{
case '-': // Page down
if(*offset < ((sizeof(main_menu)/sizeof(int)) - 1))
{
if((*offset + MAXDISPLAYROWS) < ((sizeof(main_menu)/sizeof(int)) - 1))
*offset += 4;
}
if(*offset == 0)
*highlight = 1;
else
*highlight = 0;
wKey = -1;
break;
case '+': // Page up
if(*offset > 3)
*offset -=4;
else
*offset = 0;
if(*offset == 0)
*highlight = 1;
else
*highlight = 0;
wKey = -1;
break;
case 'U': // Scroll-up by one line
*highlight -= 1;
if(*highlight < 0)
{
*offset -= 1;
*highlight = 0;
}
if(*offset == 0 && *highlight == 0)
*highlight = 1;
wKey = -1;
break;
case 'D': // Scroll-down by one line
if((*offset + (*highlight) + 1) < ((sizeof(main_menu)/sizeof(int)) - 1))
{
*highlight += 1;
if(*highlight > 3)
{
*offset += 1;
*highlight = 3;
}
}
wKey = -1;
break;
case 'E': // Select option
wKey = *offset + *highlight;
break;
default:
wKey = -1;
break;
}
}
return(wKey);
}
//------------------------------------------------------------------------
// Display a MENU on the LCD display and get the menu option from the user
//------------------------------------------------------------------------
int display_menu ( char **line, int initialize)
{
static int offset, tmpoffset, i;
static int menu_option;
static int lasthighlight;
static int scrolling;
static int highlight;
costate
{
if(initialize)
{
offset = 0; // Initialize menu line index
highlight = 1; // Assumes all menus have a heading
tmpoffset = ~offset;
}
menu_option = 0; // Initially set to no option selected
scrolling = FALSE;
// Wait until you get a valid user option
while(menu_option == 0)
{
// Display menu option
if(tmpoffset != offset)
{
glBlankScreen();
for(i=0; i < 4; i++)
{ // Display up to 4 lines of menu options
TextGotoXY(&textWindow, 0, i);
TextPrintf(&textWindow, "%s", line[offset]);
if(line[offset + 1] == NULL) {
break;
}
offset++;
}
// Reset the offset back to the first option displayed
offset = offset-i;
tmpoffset = offset;
}
glSetBrushType(PIXXOR);
glBlock (0, highlight*8, 122, 8);
glSetBrushType(PIXBLACK);
lasthighlight = highlight;
// Get the user's option
waitfor((menu_option = GetKeypadOption(&offset, &highlight)));
// Check if user selected the scrolling option
glSetBrushType(PIXXOR);
glBlock (0, lasthighlight*8, 122, 8);
glSetBrushType(PIXBLACK);
if(menu_option == -1)
{
// Set menu option to zero due to scrolling operation
menu_option = 0;
scrolling = TRUE;
}
}
}
tmpoffset = offset;
return(menu_option);
}
//------------------------------------------------------------------------
// Format the Date and Time for the LCD display
//------------------------------------------------------------------------
void FormatDateTime ( void )
{
char Day[4], Mon[4];
ulTime = read_rtc (); // get the RTC value
mktm( &CurTime, ulTime ); // convert seconds to date values
strncpy ( Day, &Days[CurTime.tm_wday*3], 3 );
strncpy ( Mon, &Months[(CurTime.tm_mon-1)*3], 3 );
Day[3] = 0;
Mon[3] = 0;
sprintf ( szTime, "%s %s %d, %d \n%02d:%02d:%02d",
Day, Mon, CurTime.tm_mday, CurTime.tm_year+1900,
CurTime.tm_hour, CurTime.tm_min, CurTime.tm_sec );
}
//------------------------------------------------------------------------
// Display the Date and Time on the LCD display
//------------------------------------------------------------------------
int dispDate( void )
{
static int status;
auto int wKey;
costate
{
// Get current Date/Time
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -