//------------------------------------------------------------------------ // 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; } } } } }
// Displays and Controls the Analog Channel Selection Menu int bgMenuAna1 (void) { static int state, done; auto int options; state = MENU_INIT; done = 0; while ( !done ) { keyProcess(); costate { waitfor ( (options = glMenu(&MenuAnaSetup, &state, 15, 15))!= 0); switch (options) { case 9: done = 1; break; default: waitfor ( bgMenuAna2 ( &AnaSetting[ options - 1 ] ) ); state = MENU_REFRESH; break; } } } glBuffLock(); glMenuClear( &MenuAnaSetup ); // Clear this menu glRefreshMenu( &MenuStart ); // Refresh the Start Menu glBuffUnlock(); return 1; }
/*=================================================================== ===================================================================*/ void adjCursor() { static const char *const stra = " [4] "; static const char *const strb = "[8] Press keys [0]"; static const char *const strc = " [9] "; static const char *const stre = " Press Enter to end "; auto char inkey; auto int xdir, ydir; dispClear(); dispGoto(0,0); dispPrintf("%s", stra); dispGoto(0,1); dispPrintf("%s", strb); dispGoto(0,2); dispPrintf("%s", strc); dispGoto(0,3); dispPrintf("%s", stre); xdir=9; ydir=1; dispGoto(xdir,ydir); dispCursor(DISP_CURBLINK); do { costate { // Process Keypad Press/Hold/Release keyProcess (); waitfor ( DelayMs(10) ); } costate { waitfor ( inkey = keyGet() ); // Wait for Keypress switch (inkey) { case '4': ydir--; if (ydir < 0) ydir=3; break; case '8': xdir--; if (xdir < 0) xdir=19; break; case '9': ydir++; if (ydir > 3) ydir=0; break; case '0': xdir++; if (xdir > 19) xdir=0; break; default: break; } dispGoto(xdir,ydir); } } while (inkey != EXITKEY); dispClear(); dispCursor(DISP_CUROFF); }
void adjBacklight() { static const char *const stra = " Light on "; static const char *const strb = " Light off "; static const char *const strd = " Press [2] again "; static const char *const stre = " Press Enter to end "; auto char inkey; auto unsigned int slite; dispClear(); dispGoto(0,2); dispPrintf("%s", strd); dispGoto(0,3); dispPrintf("%s", stre); do { do { keyProcess (); } while (!(inkey = keyGet())); if (inkey== '2') { dispBacklight(slite = slite ? 0:1); //turn on/off LCD backlight } if (slite) { dispGoto(0,0); dispPrintf("%s", stra); } else { dispGoto(0,0); dispPrintf("%s", strb); } } while (inkey != EXITKEY); dispClear(); }
//*************************************************************************** // Function to display the user instruction for creating a message from // the keypad. //*************************************************************************** void display_help(void) { auto int i, loop; auto int wKey, helpMenuDone; // Copy help messages to a single array buffer[0] = '\0'; for(i = 0; i<(sizeof(help)/2); i++) { strcat(buffer, help[i]); } // Display help message until the user presses a key helpMenuDone = FALSE; while(!helpMenuDone) { i=0; while(buffer[i] != '\0' && !helpMenuDone) { glHScroll(0, 16, LCD_XS, 16, -6); glPrintf(116, 20, &fi6x8, "%c", buffer[i++]); // 250ms delay loop, checking for key press every msec for(loop=0; loop < 250; loop++) { msDelay(1); keyProcess (); if(keyGet() != 0) { helpMenuDone = TRUE; } } } } }
/*=================================================================== ===================================================================*/ void adjContrast() { static const char *const stra = " Press [1] "; static const char *const strb = " for more contrast "; static const char *const strc = " Press [6] "; static const char *const strd = " for less contrast "; static const char *const stre = " Press Enter to end "; auto char inkey; auto unsigned int scontrast; scontrast=BCONTRAST; dispClear(); dispGoto(0,3); dispPrintf("%s", stre); do { costate { // Process Keypad Press/Hold/Release keyProcess (); waitfor ( DelayMs(10) ); } costate { dispGoto(0,0); dispPrintf("%s", stra); dispGoto(0,1); dispPrintf("%s", strb); waitfor (DelaySec(2)); yield; dispGoto(0,0); dispPrintf("%s", strc); dispGoto(0,1); dispPrintf("%s", strd); waitfor (DelaySec(2)); yield; } costate { waitfor ( inkey = keyGet() ); // Wait for Keypress switch (inkey) { case '1': if (scontrast > HICONTRAST) scontrast-=8; break; case '6': if (scontrast <= LOCONTRAST) scontrast+=8; break; default: break; } dispContrast (scontrast); } } while (inkey != EXITKEY); dispClear(); dispContrast (BCONTRAST); }
//------------------------------------------------------------------------ // 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); }
// The Analog Channel Setup Menu int bgMenuAna2 ( _AnaSetting *Input ) { static int state, done; auto int options; state = MENU_INIT; done = 0; while ( !done ) { keyProcess(); costate { waitfor(DelayMs(1)); glBuffLock(); glSetBrushType(PIXWHITE); glBlock(0,180,320,60); glSetBrushType(PIXBLACK); glPrintf(0,180,&fi10x16,"Input -> %d",Input->In ); glPrintf(0,200,&fi10x16,"Status -> %s",statusMsg[Input->Enable]); glPrintf(0,220,&fi10x16,"Mode -> %s",modeMsg[Input->GainMode]); statusMsg[Input->Enable], glBuffUnlock(); waitfor ((options =glMenu( &MenuAnaSet2, &state, 30, 30 ) )!= 0); switch (options) { case 1: Input ->Enable = 1; done = 1; break; case 2: Input ->Enable = 0; done = 1; break; case 3: waitfor ( bgMenuRSel ( Input ) ); break; case 4: done = 1; break; } } } glBuffLock(); glSetBrushType(PIXWHITE); glBlock(0,180,320,60); glSetBrushType(PIXBLACK); glMenuClear( &MenuAnaSet2 ); glRefreshMenu( &MenuAnaSetup ); glBuffUnlock(); return 1; }
//------------------------------------------------------------------------ // Milli-sec delay function that also monitors the keypad //------------------------------------------------------------------------ nodebug int key_msDelay(int delay) { auto int loop; for(loop=0; loop < delay; loop++) { msDelay(1); keyProcess (); if(keyGet() != 0) { return(TRUE); } } }
void rundemo() { char inkey; int i,j,k,m; brdInit(); //initialize controller keypadDef(); dispContrast (BCONTRAST); dispBacklight(1); //turn on LCD backlight dointro(); while (1) { dispClear (); //dispContrast(wC); dispGoto(0,0); dispPrintf("%s", "Press [1] Contrast "); dispGoto(0,1); dispPrintf("%s", "Press [2] Backlight"); dispGoto(0,2); dispPrintf("%s", "Press [3] Speaker "); dispGoto(0,3); dispPrintf("%s", "Press [4] Cursor "); do { keyProcess(); } while (!(inkey = keyGet())); switch (inkey) { case '1': adjContrast(); break; case '2': adjBacklight(); break; case '3': adjSpeaker(); break; case '4': adjCursor(); break; default: break; } //end switch } //end forever while }
// The Range Selection Menu int bgMenuRSel ( _AnaSetting *Input ) { static int state, done; auto int options; state = MENU_INIT; done = 0; while (!done) { keyProcess(); costate { waitfor ((options = glMenu( &MenuRangeSel,&state,45,45 ))!= 0); Input ->GainMode = options - 1; done = 1; } } glBuffLock(); glMenuClear( &MenuRangeSel ); // Clear this menu glRefreshMenu( &MenuAnaSet2 ); // Refresh the Start Menu glBuffUnlock(); return 1; }
// Displays and Controls the System System Menu int bgMenuSys (void) { static int state, done; auto int options; state = MENU_INIT; done = 0; while (!done) { keyProcess(); costate { waitfor (( options = glMenu(&MenuSysSetup, &state, 15, 15))!= 0); switch (options) { case 1: glBackLight(1); state = MENU_REFRESH; break; case 2: glBackLight(0); state = MENU_REFRESH; break; case 3: waitfor( bgMenuAdjC() ); state = MENU_REFRESH; break; case 4: done = 1; break; } } } glBuffLock(); glMenuClear(&MenuSysSetup); // Clear this menu glRefreshMenu(&MenuStart); // Refresh the Start Menu glBuffUnlock(); return 1; }
// Displays the Start Menu int bgMenuStart (void) { static int state, done; auto int options; state = MENU_INIT; done = 0; glBuffLock(); glBlankScreen(); glBuffUnlock(); while (!done) { keyProcess(); costate { waitfor (( options = glMenu(&MenuStart, &state, 0, 0 )) != 0 ); switch (options) { case 1: waitfor ( bgMenuSys() ); state = MENU_REFRESH; break; case 2: waitfor ( bgMenuAna1() ); state = MENU_REFRESH; break; case 3: done = 1; break; } } } glBuffLock(); glMenuClear(&MenuStart); // Clear this menu glBuffUnlock(); return 1; }
// The Contrast Adjustment Menu int bgMenuAdjC (void) { static int state, done; auto int options; state = MENU_INIT; done = 0; while (!done) { keyProcess(); costate { waitfor ((options= glMenu(&MenuAdjContrast,&state, 30, 30 ))!= 0); switch (options) { case 1: if (LastContrast < 255 ) LastContrast++; glSetContrast(LastContrast); state = MENU_REFRESH; break; case 2: if (LastContrast > 0 ) LastContrast--; glSetContrast(LastContrast); state = MENU_REFRESH; break; case 3: done = 1; break; } } } glBuffLock(); glMenuClear( &MenuAdjContrast ); // Clear this menu glRefreshMenu( &MenuSysSetup ); // Refresh the Start Menu glBuffUnlock(); return 1; }
void main() { auto int nIn; auto char cOut; auto char inkey; brdInit(); keypadDef(); serCopen(_232BAUD); serMode(0); serCwrFlush(); serCrdFlush(); while (1) { costate { // Process Keypad Press/Hold/Release keyProcess(); waitfor(DelayMs(10)); } costate { if ((inkey = keyGet()) != 0) { // Wait for Keypress dispPrintf ("%c", inkey); // Display Byte serCputc(inkey); // Transmit byte } waitfor(DelayMs(10)); } costate { if ((nIn=serCgetc()) != -1) // Wait for receive byte dispPrintf ("%c", nIn); // Display Byte waitfor(DelayMs(10)); } } }
/* -------------------------------------------------------------------------------------- SYNTAX: int display_menu(char **line, int *state, int menu_num, int num_options) DESCRIPTION: Display a MENU on the LCD display and get the menu option from the user PARAMETER1: Pointer to list of menu options PARAMETER2: Pointer to Menu control parameter, control parameters macro's are as follows: MENU_INIT..........Initialize and Display Menu MENU_NO_CHANGE.....Select option, No menu/highlight bar changes occur. MENU_REFRESH.......Display last image of menu of where it was. PARAMETER3: Unique menu number, starting with 0 and on up. PARAMETER4: The number of options for a given menu. RETURN VALUE: 0 if no option is selected, otherwise it be the option selected -----------------------------------------------------------------------------------------*/ int display_menu ( char **line, int *state, int level, int num_options) { auto int menu_option; auto int i; auto struct menu_infor *ptr; ptr = &menu[level]; menu_option = 0; // Initially set to no option selected switch(*state) { case 0: // Set menu parameters in menu structure array ptr->current_offset = 0; // Initialize menu line index ptr->highlight = 1; // Assumes all menus have a heading ptr->new_offset = !ptr->current_offset; keyProcess (); // Make sure no key is being pressed initially if(keyGet() == 0) { *state = 4; break; } break; case 1: // Get the user's option menu_option = GetKeypadOption(&ptr->current_offset, &ptr->highlight, num_options); if(menu_option == -1) { // Check if user selected the scrolling option glSetBrushType(PIXXOR); glBlock (0, ptr->lasthighlight*8, 122, 8); glSetBrushType(PIXBLACK); // Set menu option to zero due to scrolling operation menu_option = 0; *state = 4; } break; case 2: // Refresh menu options glBuffLock(); glBlankScreen(); for(i=0; i < 4; i++) { // Display up to 4 lines of menu options TextGotoXY(&textWindow, 0, i); TextPrintf(&textWindow, "%s", line[ptr->current_offset]); if(*line[ptr->current_offset + 1] == '\0') { break; } ptr->current_offset++; } // Reset the offset back to the first option displayed ptr->current_offset = ptr->current_offset-i; ptr->new_offset = ptr->current_offset; glSetBrushType(PIXXOR); glBlock (0, ptr->highlight*8, 122, 8); glSetBrushType(PIXBLACK); glBuffUnlock(); ptr->lasthighlight = ptr->highlight; *state = 1; break; case 4: // Display menu option if(ptr->current_offset != ptr->new_offset) { glBuffLock(); glBlankScreen(); for(i=0; i < 4; i++) { // Display up to 4 lines of menu options TextGotoXY(&textWindow, 0, i); TextPrintf(&textWindow, "%s", line[ptr->current_offset]); if(*line[ptr->current_offset + 1] == '\0') { break; } ptr->current_offset++; } glBuffUnlock(); // Reset the offset back to the first option displayed ptr->current_offset = ptr->current_offset-i; ptr->new_offset = ptr->current_offset; } glSetBrushType(PIXXOR); glBlock (0, ptr->highlight*8, 122, 8); glSetBrushType(PIXBLACK); ptr->lasthighlight = ptr->highlight; *state = 1; break; default: *state = 0; break; } return(menu_option); }
main() { auto unsigned wKey; auto int i; /* init FORM searchable names - must init ALL FORMSpec structs! */ FORMSpec[0].name = "email_from"; FORMSpec[0].value = emailTemp.from; FORMSpec[0].len = MAX_FROM_LEN; FORMSpec[1].name = "email_subject"; FORMSpec[1].value = emailTemp.subject; FORMSpec[1].len = MAX_SUBJECT_LEN; FORMSpec[2].name = "email_body"; FORMSpec[2].value = emailTemp.body; FORMSpec[2].len = MAX_BODY_LEN; initsystem(); sock_init(); http_init(); tcp_reserveport(80); FlagInit(); CreateEmailList(); LogInit(); DispBufferInit(); DispNoEmail(); while (1) { http_handler(); costate { keyProcess(); //scans for keypress waitfor (DelayMs(10)); } costate { waitfor (wKey = keyGet()); //get key from buffer switch (wKey) { case DELETE: if (emailList.ptr != -1) { LogAddEmailEntry("deleted", email.from, email.subject); DeleteEmail(); } DispEmail(); break; case READ: if ((emailList.ptr != -1) && (emailIndex[emailList.ptr].read != 1)) { LogAddEmailEntry("read", email.from, email.subject); emailIndex[emailList.ptr].read = 1; FlagCheck(); } break; case EMAIL_UP: if (emailList.ptr != -1) { if (emailIndex[emailList.ptr].prev != -1) { emailList.ptr = emailIndex[emailList.ptr].prev; } DispEmail(); } break; case EMAIL_DOWN: if (emailList.ptr != -1) { if (emailIndex[emailList.ptr].next != -1) { emailList.ptr = emailIndex[emailList.ptr].next; } DispEmail(); } break; case SCROLL_UP: if ((emailList.ptr != -1) && (emailDispLine > 0)) { emailDispLine--; DispUpdateWindow(); } break; case SCROLL_DOWN: if ((emailList.ptr != -1) && ((emailDispLine + 4) < emailLastLine)) { emailDispLine++; DispUpdateWindow(); } break; default: // Do nothing break; } //end switch } //end costate } }
void main(void) { auto int wKey; char buffer[20]; auto int i,j; brdInit(); initLcdKeypad(); // Initialize the #web-registered variables strcpy(passwords[0].entrypw, "12340"); strcpy(passwords[0].entryname, "JGunchy"); strcpy(passwords[0].entrytime, "no activity"); strcpy(passwords[0].exittime, "no activity"); for (i=1; i<MAX_ENTRIES; i++) { strcpy(passwords[i].entrypw, "Unused"); strcpy(passwords[i].entryname, "Unused"); strcpy(passwords[i].entrytime, "no activity"); strcpy(passwords[i].exittime, "no activity"); } updateentry(); //initialize temporary variables j= 10; i = 0; // Initialize the TCP/IP stack, HTTP server sock_init(); http_init(); while (1) { // Drive the HTTP server http_handler(); costate { keyProcess(); wKey = keyGet(); } costate { switch (wKey) { case 0: break; case '+': //entry case '-': //exit buffer[i]='\0'; TextGotoXY(&wholewindow, 0, 1); if (confirmentry(buffer, wKey)) { TextPrintf(&wholewindow, "Accepted"); TextGotoXY(&wholewindow, 0, 3); TextPrintf(&wholewindow, "Thank you %s", buffer); } else { TextPrintf(&wholewindow, "Incorrect password"); } i=0; j=10; waitfor(DelaySec(3)); glBlankScreen(); TextGotoXY(&wholewindow, 0, 0); TextPrintf(&wholewindow, "Password"); break; default: if (i<7) { buffer[i] = wKey; TextGotoXY(&wholewindow, j, 0); //TextPrintf(&wholewindow, "%c", wKey); TextPrintf(&wholewindow, "%c", '*'); j++; i++; } break; }//end switch }//end costate switch } }
void main(void) { tcp_Socket tcpSock; char *messages[12]; unsigned int key; int i, send_response, test; // Initialize flag to indicate not ready to send response send_response = FALSE; // Initialize the message array with NULL pointers for (i = 0; i < (sizeof(messages)/sizeof(char*)); i++) { messages[i] = NULL; } // Define messages here--note that you only need define the messages // you will actually use. messages[0] = "I hear ya..."; messages[1] = "Hello, there..."; messages[2] = "It's a \"Rabbit\" Kind of place..."; initsystem(); sock_init(); // Configure the upper row of keys on the keypad, in order // from left to right. for (i = 0; i < 7; i++) { // Only enable a key if there is a corresponding message if (messages[i] != NULL) { keyConfig ( i, ('0'+ i), 0, 0, 0, 0, 0 ); } else { keyConfig ( i, IGNORE, 0, 0, 0, 0, 0 ); } } while (1) { // Process Keypad Press/Hold/Release costate { keyProcess (); waitfor ( DelayMs(10) ); } costate { // Wait for a message from another device if (send_response == FALSE) { glBlankScreen(); TextGotoXY(&wholewindow, 0, 0 ); TextPrintf(&wholewindow, "Waiting for a \nmessage to be sent!"); // Function is blocking until a message is received RecvMessage(&tcpSock); // Received message, prompt user to continue TextGotoXY(&wholewindow, 0, 3 ); TextPrintf(&wholewindow, "Press key to proceed"); // Allow the keyProcess function(above costate) to execute before // checking for keypress. waitfor(DelayMs(10)); // Check if a key has been pressed waitfor ( key = keyGet() ); // Wait for Keypress // Set flag to send respond back to controller that // sent the message. send_response = TRUE; } } costate { if(send_response) { glBlankScreen(); TextGotoXY(&wholewindow, 0, 0 ); TextPrintf(&wholewindow, "Press the key that \nis setup to send \nyour response..."); waitfor ( key = keyGet() ); // Wait for Keypress // Flash Leds to indicate that a key has been pressed flashled(key - '0'); // Only handle the keypress if it corresponds to a message and if // a response is currently needed if (key != IGNORE) { SendMessage(&tcpSock, (key - '0'), messages); send_response = FALSE; } } } } }
void main(void) { char* messages[12]; int i; unsigned key; // User keypress tcp_Socket tcpSock; int respond; respond = 0; // Initialize the message array for (i = 0; i < 12; i++) { messages[i] = ""; } // Define messages here--note that you only need define the messages // you will actually use. messages[0] = "I hear ya"; messages[1] = "Hello, there"; messages[2] = "I'm here"; messages[3] = "This Rabbit is fast!"; messages[6] = "That's right, Charlie!"; messages[7] = "Daisy, Daisy, Give me your answer, do."; brdInit(); sock_init(); // Configure the upper row of keys on the keypad, in order from left // to right for (i = 0; i < 6; i++) { // Only enable a key if there is a corresponding message if (strcmp(messages[i], "") != 0) { keyConfig ( 5-i, i+1, 0, 0, 0, 0, 0 ); } else { keyConfig ( 5-i, IGNORE, 0, 0, 0, 0, 0 ); } } // Configure the lower row of keys on the keypad, in order from left // to right for (i = 6; i < 12; i++) { // Only enable a key if there is a corresponding message if (strcmp(messages[i], "") != 0) { keyConfig ( 19-i, i+1, 0, 0, 0, 0, 0 ); } else { keyConfig ( 19-i, IGNORE, 0, 0, 0, 0, 0 ); } } while (1) { costate { // Process Keypad Press/Hold/Release keyProcess (); waitfor ( DelayMs(10) ); } costate { // Process Keypad Press/Hold/Release waitfor ( key = keyGet() ); // Wait for Keypress // Only handle the keypress if it corresponds to a message and if // a response is currently needed if ((key != IGNORE) && (respond == 1)) { SendMessage(&tcpSock, key, messages); respond = 0; } } // Receive a message. RecvMessage() will block until something comes in. if (respond == 0) { RecvMessage(&tcpSock, &respond); } } }
main () { static int enable,stopUpdate,updatecomplete; auto int loop,keyPress; static byte init,input; static CoData BarGraph; //Set all the Channels Structures to a default state // Enabled, 0 to 10Vdc range. for (loop = 0 ; loop < 8 ; loop++) { AnaSetting[loop].In = loop; AnaSetting[loop].GainMode = 1; AnaSetting[loop].Enable = 1; } updatecomplete = 0; stopUpdate = 1; brdInit(); // Initialize the Controller glInit(); // Initialize the LCD keyInit(); // Initialize the Keypad keypadDef(); // Setup the Keypad Default Values LastContrast = 24; // Setup the Inital Contrast Setting // Turn on the Backlight glBackLight(1); // Set the Contrast glSetContrast(LastContrast); // Setup the Fonts used in this sample glXFontInit(&fi6x8, 6, 8, 32, 255, Font6x8); glXFontInit(&fi8x10, 8, 10, 32, 127, Font8x10); glXFontInit(&fi10x16, 10, 16, 32, 127, Font10x16); glXFontInit(&fi17x35, 17,35,0x20,0xFF, Font17x35); // Setup the Menus glMenuInit( &MenuStart, &fi10x16, DOUBLE_LINE, SHADOW,startMenu, " START MENU ", -1 ); glMenuInit( &MenuSysSetup, &fi10x16, DOUBLE_LINE, SHADOW,systemSetup, " SYSTEM SETUP ", -1 ); glMenuInit( &MenuAnaSetup, &fi10x16, DOUBLE_LINE, SHADOW,analogSetup, " ANALOG SETUP ", 5 ); glMenuInit( &MenuAdjContrast, &fi10x16, DOUBLE_LINE, SHADOW,adjContrast, " CONSTRAST ADJUST ", -1 ); glMenuInit( &MenuRangeSel, &fi10x16, DOUBLE_LINE, SHADOW,rangeSelect, " RANGE SELECT ", 5 ); glMenuInit( &MenuAnaSet2, &fi10x16, DOUBLE_LINE, SHADOW,analogSet2, " ANALOG SETUP2 ", -1 ); input = 0; init = 1; for (;;) { // Check for any keypresses keyProcess(); // This costate displays the Initial screen, and Starts the // Bargraphing demo costate { waitfor (init); waitfor ( bgMainScreen () ); init = 0; input = 0; waitfor ( bgBarSet(&fi8x10) ); stopUpdate = 0; CoBegin( &BarGraph ); } // This costate checks for the 'S' key to be pressed // (key just below the label 'CONFIG DEMO') costate { waitfor ( ( keyPress = keyGet() )== 'S' ); stopUpdate = 1; waitfor (updatecomplete); CoReset( &BarGraph ); waitfor ( bgMenuStart() ); init = 1; } // This costate displays the Bargraphs costate BarGraph { waitfor(!stopUpdate); waitfor(IntervalMs(350)); updatecomplete = 0; glBuffLock(); input = 0; while (input <= 7) { if ( AnaSetting[input].Enable ) { waitfor ( bgBarGraph ( &AnaSetting[ input ], &fi8x10 ) ); } input++; waitfor (DelayMs(1)); } glBuffUnlock(); updatecomplete = 1; CoBegin( &BarGraph ); } } }
/*=================================================================== ===================================================================*/ void adjSpeaker() { auto unsigned int aFreq, aAmp, wKey, akey, validkey; aFreq = LOSPEAKER; aAmp = 0; wKey=akey='0'; validkey = 1; dispClear(); dispGoto(0,0); dispPrintf("Volume: Press 1-4 "); dispGoto(0,1); dispPrintf("Freq: Press 5 or 0 "); dispGoto(0,2); dispPrintf("Volume level %c ", wKey); dispGoto(0,3); dispPrintf("Freq level %d ", aFreq); do { do { keyProcess (); } while (!(wKey = keyGet())); switch (wKey) { case '1': aAmp = 0; // no volume akey=wKey; break; case '2': aAmp = 2; // level 1 akey=wKey; break; case '3': aAmp = 1; // level 2 akey=wKey; break; case '4': aAmp = 3; // level 3 akey=wKey; break; case '5': if (aFreq < HISPEAKER) aFreq+=100; // increase frequency break; case '0': if (aFreq > LOSPEAKER) aFreq-=100; // decrease frequency break; default: validkey = 0; break; } if (validkey) { dispGoto(13,2); dispPrintf("%c", akey); dispGoto(13,3); dispPrintf("%4d", aFreq); spkrOut (aFreq, aAmp ); // output to speaker } else validkey=1; } while (wKey != EXITKEY); dispClear(); spkrOut (0, 0); // output off to speaker }
void main (void) { unsigned int aFreq, aAmp, wKey, akey, validkey; brdInit(); // initialize board, keypad, display keypadDef(); // set keypad to default layout dispContrast(BCONTRAST); // adjust contrast dispBacklight(1); // turn on backlight dispGoto(0,0); dispPrintf ("1-4 for volume" ); dispGoto(0,1); dispPrintf ("'5' inc, '0' dec" ); aFreq = LOFREQ; aAmp = 0; wKey=akey='0'; validkey = 1; dispGoto(0,2); dispPrintf("Vol level %c", wKey); dispGoto(0,3); dispPrintf("Frequency %d", aFreq); for (;;) { costate { // Process Keypad Press/Hold/Release keyProcess (); waitfor ( DelayMs(10) ); } costate { // Process Keypad Press/Hold/Release waitfor ( wKey = keyGet() ); // Wait for Keypress switch ( wKey) { case '1': aAmp = 0; // no volume akey=wKey; break; case '2': aAmp = 2; // level 1 akey=wKey; break; case '3': aAmp = 1; // level 2 akey=wKey; break; case '4': aAmp = 3; // level 3 akey=wKey; break; case '5': if (aFreq < HIFREQ) aFreq+=STEP; // increase frequency break; case '0': if (aFreq > LOFREQ) aFreq-=STEP; // decrease frequency break; default: validkey = 0; break; } if (validkey) { dispGoto(10,2); dispPrintf("%c ", akey); dispGoto(10,3); dispPrintf("%d ", aFreq); spkrOut (aFreq, aAmp ); // output to speaker } else validkey=1; } } }
/** * @method CGame::UpdateFrame() * @desc called every frame, calls the update methods of all other game managers */ void CGame::UpdateFrame(DWORD milliseconds) { keyProcess(); InputManagerC::GetInstance()->update(milliseconds); AngryBirdsMouse::getInstance()->update(); if (CGame::mGameState == LEVEL) { PhysicsWorld::getInstance()->update(milliseconds); level->update(milliseconds); if (GetBirdCount() != 0) PlayerManager::getInstance()->update(milliseconds); BlockManager::getInstance()->update(); PigManager::getInstance()->update(milliseconds); nextButton->update(); previousButton->update(); resetButton->update(); if (nextButton->isButtonPressed()) { levelNumber++; loadNextLevel(); } if (previousButton->isButtonPressed()) { levelNumber--; if (levelNumber < 0) { levelNumber = 0; } loadNextLevel(); } if (resetButton->isButtonPressed()) { loadNextLevel(); } } if (CGame::mGameState == START_MENU) { playButton->update(); if (playButton->isButtonPressed()) { CGame::mGameState = LEVEL; Background::getInstance()->loadBackground(levelBackgroundSrc); level = new Level(); level->init(); TiXmlHandle docHandle(doc); PlayerManager::createInstance()->init(docHandle.FirstChildElement().ChildElement("birds", 0).Element(), docHandle.FirstChildElement().ChildElement("catapult", 0).Element(), docHandle.FirstChildElement().ChildElement("birdpoof", 0).Element()); BlockManager::createInstance()->init(docHandle.FirstChildElement().ChildElement("blocks", 0).Element()); PigManager::createInstance()->init(docHandle.FirstChildElement().ChildElement("pigs", 0).Element(), docHandle.FirstChildElement().ChildElement("poof", 0).Element()); PlayerManager::getInstance()->loadLevel(docHandle.FirstChildElement().ChildElement("level", levelNumber).ChildElement("birds", 0).Element()); BlockManager::getInstance()->loadLevel(docHandle.FirstChildElement().ChildElement("level", levelNumber).ChildElement("blocks", 0).Element()); PigManager::getInstance()->loadLevel(docHandle.FirstChildElement().ChildElement("level", levelNumber).ChildElement("pigs", 0).Element()); } } }
//------------------------------------------------------------------------ // Sample program to demonstrate the LCD and keypad //------------------------------------------------------------------------ void main ( void ) { auto int option; static int state; //------------------------------------------------------------------------ // Initialize the controller //------------------------------------------------------------------------ brdInit(); // Initialize the controller dispInit(); // Start-up the keypad driver, Initialize the graphic driver 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 ledCntrl = LEDOFF; // Initially disable the LED's state = MENU_INIT; //------------------------------------------------------------------------ // 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, &state, LVL_MAINMENU, NUM_MAINMENU_OPTS)) > 0); // Get menu option from the user switch(option) { // Change Date/Time case 1: glBlankScreen(); SetDateTime(); state = MENU_INIT; break; // Display current Date/Time case 2: glBlankScreen(); waitfor(dispDate()); state = MENU_INIT; break; // Display backlight memu options case 3: waitfor(backlight_menu()); state = MENU_REFRESH; break; // Enable Toggle leds option case 4: leds(TOGGLE); state = MENU_NO_CHANGE; break; // Enable Increment leds option case 5: leds(INCREMENT); state = MENU_NO_CHANGE; break; // Disable LED's case 6: leds(LEDOFF); state = MENU_NO_CHANGE; break; // User made invalid selection default: break; } } } }
main() { static int led, channel, wKey, keypad_active, prompt_displayed; static int new_keypress_message, release_value, i; //------------------------------------------------------------------------ // Initialize the controller //------------------------------------------------------------------------ brdInit(); // Initialize the controller for this demo // Start-up the keypad driver and // Initialize the graphic driver dispInit(); // Use default key values along with a key release code keyConfig ( 3,'R', '1', 0, 0, 0, 0 ); keyConfig ( 6,'E', '2', 0, 0, 0, 0 ); keyConfig ( 2,'D', '3', 0, 0, 0, 0 ); keyConfig ( 5,'+', '4', 0, 0, 0, 0 ); keyConfig ( 1,'U', '5', 0, 0, 0, 0 ); keyConfig ( 4,'-', '6', 0, 0, 0, 0 ); keyConfig ( 0,'L', '7', 0, 0, 0, 0 ); // Initialize 6x8 font glXFontInit(&fi6x8, 6, 8, 32, 127, Font6x8); // Initialize 6x8 font glXFontInit(&fi8x10, 8, 10, 32, 127, Font8x10); // initialize 8x10 font glBlankScreen(); // Initialize control flags keypad_active = FALSE; prompt_displayed = FALSE; new_keypress_message = FALSE; for(;;) { costate { keyProcess (); waitfor ( DelayMs(10) ); } costate { // Wait for any key to be pressed waitfor((wKey = keyGet()) != 0); release_value = -1; switch(wKey) { case 'L': release_value = '7'; break; case '-': release_value = '6'; break; case 'U': release_value = '5'; break; case '+': release_value = '4'; break; case 'D': release_value = '3'; break; case 'E': release_value = '2'; break; case 'R': release_value = '1'; break; } if(release_value != -1) { keypad_active = TRUE; // Wait for the key to be released waitfor(keyGet() == release_value); keypad_active = FALSE; } } costate { if(!keypad_active) { if(!prompt_displayed) { glBlankScreen(); glPrintf (0, 0, &fi6x8, "Waiting for a Key to"); glPrintf (0, 8, &fi6x8, "be pressed on the "); glPrintf (0, 16, &fi6x8, "LCD Keypad...."); glFillPolygon(4, 115, 26, 121,26, 121,31, 115, 31); prompt_displayed = TRUE; new_keypress_message = FALSE; // Turn-Off leds on the Demo board pbLedOut(DS1, OFF); //DS1 off pbLedOut(DS2, OFF); //DS2 off } for(channel = 0; channel <= 6; channel++) { for(led = 0; led <=6; led++) { if(led != channel) dispLedOut(led, 0); } dispLedOut(channel, 1); waitfor(DelayMs(100)); if(keypad_active) { break; } } } } costate { if(keypad_active && !new_keypress_message) { glBlankScreen(); glFillPolygon(4, 113, 26, 121,26, 121,31, 113, 31); switch(wKey) { case 'L': glPrintf (0, 0, &fi8x10, "Scroll-Left key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(0, 1); channel = 0; break; case '-': glPrintf (0, 0, &fi8x10, "Page-Down key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(1, 1); channel = 1; pbLedOut(DS1, ON); //DS1 on break; case 'U': glPrintf (0, 0, &fi8x10, "Scroll-Up key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(2, 1); channel = 2; break; case '+': glPrintf (0, 0, &fi8x10, "Page-Up key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(3, 1); channel = 3; pbLedOut(DS2, ON); //DS2 on break; case 'D': glPrintf (0, 0, &fi8x10, "Scroll-Down key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(4, 1); channel = 4; break; case 'E': glPrintf (0, 0, &fi8x10, "Enter key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(5, 1); channel = 5; break; case 'R': glPrintf (0, 0, &fi8x10, "Scroll-Right"); glPrintf (0, 16, &fi8x10, "key is Active."); dispLedOut(6, 1); channel = 6; break; } for(led=0; led <=6; led++) { if(led != channel) { dispLedOut(led, 0); } } prompt_displayed = FALSE; new_keypress_message = TRUE; } } costate { if(keypad_active) { for(i=0; i<(LCD_XS-8); i+=4) { glHScroll(0, 26, LCD_XS, 6, -4); waitfor(DelayMs(5)); if(!keypad_active) abort; } for(i=0; i<(LCD_XS-8); i+=4) { glHScroll(0, 26, LCD_XS, 6, 4); waitfor(DelayMs(5)); if(!keypad_active) abort; } } } } }
//------------------------------------------------------------------------ // Set Date and Time //------------------------------------------------------------------------ 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 = month2tm_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; } } }
//*************************************************************************** // Message Menu used to create ASCII strings from the keypad //*************************************************************************** void enter_chars(char *p) { int i, column, len, disp_col, disp_row; int wKey; char *orig_ptr; // Initialize function parameters orig_ptr = p; i = 0; column = 0; len = 0; // Display the initial charater set for the user to choose from glBlankScreen(); TextGotoXY(&textWindow1, 0, 1); TextPrintf(&textWindow1, "-"); TextGotoXY(&textWindow1, 0, 0); TextPrintf(&textWindow1, "%s", s[i]); // Display user instructions display_help(); // 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 ); keyConfig ( 0,'L',0, 12, 1, 1, 1 ); keyConfig ( 3,'R',0, 12, 1, 1, 1 ); // Clear only the bottom half of the display glSetBrushType(PIXWHITE); glBlock(0,16,122,16); glSetBrushType(PIXBLACK); // Set window2 to start at column 0 TextGotoXY(&textWindow2, 0, 0); TextPrintf(&textWindow2, "_"); TextGotoXY(&textWindow2, 0, 0); do { // Wait for a key to be pressed do { keyProcess(); msDelay(50); wKey = keyGet(); } while(wKey == 0); switch(wKey) { // Scroll-Down to select new character group case 'D': i = i < (sizeof(s)/2)-1 ? ++i : 0; clrline(1, len); TextGotoXY(&textWindow1, 0, 1); TextPrintf(&textWindow1, "-"); column = 0; clrline(0, strlen(*s)); TextGotoXY(&textWindow1, 0, 0); TextPrintf(&textWindow1, "%s", s[i]); break; // Scroll-Up to select new character group case 'U': i = i > 0 ? --i : 0; clrline(1, len); TextGotoXY(&textWindow1, 0, 1); TextPrintf(&textWindow1, "-"); column = 0; clrline(0, strlen(*s)); TextGotoXY(&textWindow1, 0, 0); TextPrintf(&textWindow1, "%s", s[i]); break; // Scroll-Right for character set case 'R': column = column < strlen(*(&s[i]))-1 ? ++column : 0; clrline(1, len = strlen(*(&s[i]))); TextGotoXY(&textWindow1, column, 1); TextPrintf(&textWindow1, "-"); break; // Scroll-Left for character set case 'L': column = column > 0 ? --column : 0; clrline(1, len = strlen(*(&s[i]))); TextGotoXY(&textWindow1, column, 1); TextPrintf(&textWindow1, "-"); break; // Add the selected character to the message case '+': // select char *p = s[i][column]; if(*p == '_' && column == strlen(*(&s[i]))-1 ) { // Change to a space *p = ' '; } TextCursorLocation(&textWindow2, &disp_col, &disp_row); TextPrintf(&textWindow2, "%c", *p++); TextPrintf(&textWindow2, "_"); TextGotoXY(&textWindow2, disp_col+1, 0); break; // Do a Backspace in the message case '-': TextGotoXY(&textWindow2, disp_col, disp_row); TextPrintf(&textWindow2, " "); TextGotoXY(&textWindow2, disp_col, disp_row); TextPrintf(&textWindow2, "_ "); if(disp_col > 0) { p--; } TextGotoXY(&textWindow2, disp_col--, disp_row); if(disp_col < 0) { disp_col = 0; p = orig_ptr; } break; } }while(wKey != 'E'); // NULL the terminate the user message *p = '\0'; // Set the keypad back to the default driver configuration keypadDef(); }
//*************************************************************************** // Mainline //*************************************************************************** void main ( void ) { auto char entry[256]; auto int wKey, i, loop; auto int helpMenuDone; //------------------------------------------------------------------------ // Board and drivers initialization //------------------------------------------------------------------------ brdInit(); // Required for all controllers dispInit(); // Graphic driver initialization, Start-up the keypad driver keypadDef(); // Set keys to the default driver configuration //------------------------------------------------------------------------ // Font initialization //------------------------------------------------------------------------ // Initialize structures with FONT bitmap information glXFontInit(&fi6x8, 6, 8, 32, 127, Font6x8); // initialize basic font //------------------------------------------------------------------------ // Text window initialization //------------------------------------------------------------------------ // Setup the widow frame to be the entire LCD to display information TextWindowFrame(&textWindow1, &fi6x8, 0, 0, 122, 32); TextWindowFrame(&textWindow2, &fi6x8, 0, 24, 122, 8); //------------------------------------------------------------------------ // Main loop for the user to create messages from the keypad //------------------------------------------------------------------------ while(1) { // Display user prompt for the message menu glBlankScreen(); TextGotoXY(&textWindow1, 0, 0); TextPrintf(&textWindow1, "Press + to create a message...\n"); // Wait for ENTER key to be pressed do { keyProcess(); wKey = keyGet(); } while(wKey != '+'); // Go to the message menu glBlankScreen(); memset(entry,0,sizeof(entry)); enter_chars(entry); // Display the message the user typed glBlankScreen(); TextGotoXY(&textWindow1, 0, 0); TextPrintf(&textWindow1, "Typed...%s", entry); // Wait for user to press any key to startover TextGotoXY(&textWindow1, 0, 3); TextPrintf(&textWindow1, "ENTER to Continue"); do { keyProcess(); wKey = keyGet(); } while(wKey == 0); } }