📄 keymenu.c
字号:
status = 0;
ulTime = read_rtc (); // get the RTC value
mktm( &CurTime, ulTime ); // convert seconds to date values
FormatDateTime(); // convert to text
waitfor(DelayMs(5));
// Display Date and Time
glBuffLock();
TextGotoXY(&textWindow, 0, 0);
TextPrintf(&textWindow, "%s\n", szTime);
waitfor(DelayMs(5));
// Display user exit message
TextGotoXY(&textWindow, 0, 3);
TextPrintf(&textWindow, "Press Key to EXIT");
waitfor(DelayMs(5));
glBuffUnlock();
// Wait for key to be pressed to exit
waitfor(((wKey = keyGet()) != 0) || DelayMs(100));
if(wKey != 0)
{
glBlankScreen();
status = 1;
}
}
return(status);
}
//------------------------------------------------------------------------
// LED control function
//------------------------------------------------------------------------
void leds( int mode )
{
static int toggle, increment;
auto int led, mask;
#GLOBAL_INIT {toggle=0;}
#GLOBAL_INIT {increment=0;}
if(mode != OPERATE)
{
ledCntrl = mode;
toggle = 0;
increment = 0;
return;
}
if(ledCntrl == TOGGLE)
{
toggle = (~toggle) & 0x01;
for(led = 0; led <= 6; led++)
{
//Toggle the LED's
dispLedOut(led, toggle);
}
}
else if(ledCntrl == INCREMENT)
{
mask = 0x01;
increment++;
for(led = 0; led <= 6; led++)
{
if(increment & mask)
dispLedOut(led, 1);
else
dispLedOut(led, 0);
mask = mask << 1;
}
}
else
{ //Turn all LED'S OFF
for(led = 0; led <= 6; led++)
dispLedOut(led, 0);
}
}
//------------------------------------------------------------------------
// Date and Time prompt message routine
//------------------------------------------------------------------------
void date_prompt(char *ptr, int *col, int *row)
{
glBlankScreen();
TextGotoXY(&textWindow, 0, 0);
TextPrintf(&textWindow, "%s", ptr);
TextCursorLocation(&textWindow, col, row);
TextGotoXY(&textWindow, 0, 3);
TextPrintf(&textWindow, "ENTER to Continue...");
}
//------------------------------------------------------------------------
// Set Date and Time
// For some reason the starting date is always midnight Jan 1, 2001.
//------------------------------------------------------------------------
void SetDateTime( void )
{
int wKey;
int col, row;
char buffer[256];
fieldupdate dateTime;
// Setup for FAST key repeat after holding down key for 12 ticks
keyConfig ( 6,'E',0, 12, 1, 1, 1 );
keyConfig ( 2,'D',0, 12, 1, 1, 1 );
keyConfig ( 5,'+',0, 12, 1, 1, 1 );
keyConfig ( 1,'U',0, 12, 1, 1, 1 );
keyConfig ( 4,'-',0, 12, 1, 1, 1 );
date_prompt("Select \n4 digit year: ", &col, &row);
dateTime.data = 2001;
while(1)
{
sprintf(buffer, "%04d", dateTime.data);
TextGotoXY(&textWindow, col, row);
TextPrintf(&textWindow, "%s", buffer);
while((wKey = ProcessKeyField(NUMBER, &dateTime)) == 0);
if(dateTime.data < 1900 || dateTime.data > 2047)
{
dateTime.data = 2001;
}
if(wKey == 'E')
{
if( dateTime.data >= 1900 && dateTime.data < 2048) {
CurTime.tm_year = dateTime.data - 1900; // offset from 1900
break;
}
}
}
date_prompt("Enter month: ", &col, &row);
dateTime.data = 1;
while(1)
{
sprintf(buffer, "%02d", dateTime.data);
TextGotoXY(&textWindow, col, row);
TextPrintf(&textWindow, "%s", buffer);
while((wKey = ProcessKeyField(NUMBER, &dateTime)) == 0);
if(wKey == 'E')
{
if( dateTime.data >= 1 && dateTime.data < 13 )
{
CurTime.tm_mon = dateTime.data;
break;
}
}
if(dateTime.data < 1 || dateTime.data > 12)
{
dateTime.data = (dateTime.data < 1) ? 12 : 1;
}
}
date_prompt("Enter \nday of month: ", &col, &row);
dateTime.data = 1;
while(1)
{
sprintf(buffer, "%02d", dateTime.data);
TextGotoXY(&textWindow, col, row);
TextPrintf(&textWindow, "%s", buffer);
while((wKey = ProcessKeyField(NUMBER, &dateTime))== 0);
if(wKey == 'E')
{
if( dateTime.data >= 1 && dateTime.data < 32) {
CurTime.tm_mday = dateTime.data;
break;
}
}
if(dateTime.data < 1 || dateTime.data > 31)
{
dateTime.data = (dateTime.data < 1) ? 31 : 1;
}
}
date_prompt("Enter \nhour (24hr): ", &col, &row);
dateTime.data = 0;
while(1)
{
sprintf(buffer, "%02d", dateTime.data);
TextGotoXY(&textWindow, col, row);
TextPrintf(&textWindow, "%s", buffer);
while((wKey = ProcessKeyField(NUMBER, &dateTime)) == 0);
if(wKey == 'E')
{
if(dateTime.data >= 0 && dateTime.data < 24) {
CurTime.tm_hour = dateTime.data;
break;
}
}
if(dateTime.data < 0 || dateTime.data > 23)
{
dateTime.data = (dateTime.data < 0) ? 23 : 0;
}
}
date_prompt("Enter minute: ", &col, &row);
dateTime.data = 0;
while(1)
{
sprintf(buffer, "%02d", dateTime.data);
TextGotoXY(&textWindow, col, row);
TextPrintf(&textWindow, "%s", buffer);
while((wKey = ProcessKeyField(NUMBER, &dateTime)) == 0);
if(wKey == 'E')
{
if( dateTime.data >= 0 && dateTime.data < 60) {
CurTime.tm_min = dateTime.data;
break;
}
if(wKey == 'E')
{
break;
}
}
if(dateTime.data < 0 || dateTime.data > 59)
{
dateTime.data = (dateTime.data < 0) ? 59 : 0;
}
}
CurTime.tm_sec = 0;
ulTime = mktime ( &CurTime ); // get seconds from 1/1/1980
write_rtc ( ulTime ); // set the real time clock
keypadDef();
glBlankScreen();
while(1)
{
// Get current Date/Time
FormatDateTime(); // convert to text
// Display Date and Time
glBuffLock();
TextGotoXY(&textWindow, 0, 0);
TextPrintf(&textWindow, "%s\n", szTime);
// Display user exit message
TextGotoXY(&textWindow, 0, 3);
TextPrintf(&textWindow, "Press Key to EXIT ");
glBuffUnlock();
keyProcess ();
if((wKey = keyGet()) != 0)
{
glBlankScreen();
break;
}
}
}
//------------------------------------------------------------------------
// Display Sign-on message
//------------------------------------------------------------------------
void SignOnMessage(void)
{
auto int signMesgDone, i, loop;
auto char buffer[256];
// Display Sign-on Message then wait for any key to continue
glXPutBitmap (0,0,53,29,Zwbw5_bmp);
msDelay(500);
signMesgDone = FALSE;
while(!signMesgDone)
{
i=0;
sprintf(buffer, "Hello from Zworld!!!");
strcat(buffer, " Press any KEY to Continue... ");
while(buffer[i] != '\0' && !signMesgDone)
{
glHScroll(50, 0, LCD_XS, 16, -6);
glPrintf (116, 4, &fi6x8, "%c", buffer[i++]);
for(loop=0; loop < 165; loop++)
{
msDelay(1);
keyProcess ();
if(keyGet() != 0)
{
signMesgDone = TRUE;
}
}
}
}
}
//------------------------------------------------------------------------
// Sample program to demonstrate the LCD and keypad
//------------------------------------------------------------------------
void main ( void )
{
auto int option, initialize;
//------------------------------------------------------------------------
// Initialize the controller
//------------------------------------------------------------------------
brdInit(); //Initialize the controller
devPowerSet(DISPDEV, 1); //enable display/keypad buffer
dispInit(); //initialize module
keypadDef(); // Use the default keypad ASCII return values
//glBackLight(1); // Turn-on the backlight
glXFontInit(&fi6x8, 6, 8, 32, 127, Font6x8); // Initialize 6x8 font
glXFontInit(&fi8x10, 8, 10, 32, 127, Font8x10); // Initialize 10x16 font
glXFontInit(&fi12x16, 12, 16, 32, 127, Font12x16); // Initialize 12x16 font
// Setup and center text window to be the entire display
TextWindowFrame(&textWindow, &fi6x8, 1, 0, 121, 32);
// Set variables to known states
initialize = TRUE; // Set flag for MENU options to be displayed
ledCntrl = LEDOFF; // Initially disable the LED's
//------------------------------------------------------------------------
// Display Sign-on message and wait for keypress
//------------------------------------------------------------------------
SignOnMessage();
//------------------------------------------------------------------------
// Main program loop for the MENU system
//------------------------------------------------------------------------
for (;;)
{
costate
{
keyProcess ();
waitfor(DelayMs(10));
}
costate
{
leds(OPERATE);
waitfor(DelayMs(50));
}
costate
{
// Display the MAIN MENU
waitfor((option = display_menu(main_menu, initialize)) > 0);
// Get menu option from the user
switch(option)
{
// Change Date/Time
case 1: glBlankScreen();
SetDateTime();
initialize = TRUE;
break;
// Display current Date/Time
case 2: glBlankScreen();
waitfor(dispDate());
initialize = TRUE;
break;
// Turn Backlight OFF
case 3: glBackLight(0);
initialize = FALSE;
break;
// Turn Backlight ON
case 4: glBackLight(1);
initialize = FALSE;
break;
// Enable Toggle leds option
case 5: leds(TOGGLE);
initialize = FALSE;
break;
// Enable Increment leds option
case 6: leds(INCREMENT);
initialize = FALSE;
break;
// Disable LED's
case 7: leds(LEDOFF);
initialize = FALSE;
break;
// User made invalid selection
default:
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -