// just store one converted report at a time StringBuffer report2json(const ConstBuf& in) { char *keys, *vals; unsigned short ir[16], ik[32], iv[32], i; StringBuffer reportJson(100, 8); // copy cuz we edit it char *report = (char*)malloc(in.length()); memcpy(report, in, in.length()); // parse this and humanize js0n((unsigned char*)report, strlen(report), ir, 16); if (!*ir) { free(report); } // TODO: Proper JSON escaping in this function reportJson.appendSprintf("{\"type\":\"%s\"", keyGet(atoi(j0g_safe(0, report, ir)))); keys = report + ir[2]; js0n((unsigned char*)keys, ir[3], ik, 32); if (!*ik) { free(report); reportJson = (char*)NULL; return reportJson; } vals = report+ir[4]; js0n((unsigned char*)vals, ir[5], iv, 32); if (!*iv) { free(report); reportJson = (char*)NULL; return reportJson; } for (i=0; ik[i]; i+=2) { reportJson.appendSprintf(",\"%s\":", keyGet(atoi(j0g_safe(i, keys, ik)))); if (vals[iv[i]-1] == '"') { iv[i]--; iv[i+1]+=2; } *(vals+iv[i]+iv[i+1]) = 0; reportJson.appendSprintf("%s", vals + iv[i]); } reportJson += "}"; free(report); return reportJson; }
//------------------------------------------------------------------------ // 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; } } } } }
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 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 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); }
UINT32 CheckCurBookmark(void) { UINT32 key; UINT32 ui32SelectIdx = 0; if (sPara.ui8BookmarkFlag == 0xaa) { if (!memcmp(xdcfFileAttr.name, sPara.ui8BookName, 13)) { key = UI_KEY_MODE_EBOOK; while ((uiState & UI_MODE_MASK) == UI_MODE_EBOOK) { switch (key) { case UI_KEY_DIR_LEFT: case UI_KEY_DIR_RIGHT: ui32SelectIdx = ui32SelectIdx ? 0 : 1; osdStrDisp(BOOK_DLG_OFF_X+40, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_NSEL : COLOR_BOOK_DLG_SEL, GetBookString(Book_yes_s)); osdStrDisp(BOOK_DLG_OFF_X+140, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_SEL : COLOR_BOOK_DLG_NSEL, GetBookString(Book_no_s)); break; case UI_KEY_FUNC_OK: if (ui32SelectIdx == 0) { g_ui8LoadBookmark = 1; } sPara.ui8BookmarkFlag = 0xff; nandWriteParameters(); LoadingBookmark(); return; case UI_KEY_MODE_EBOOK: osdBarDraw(BOOK_DLG_OFF_X, BOOK_DLG_OFF_Y, BOOK_DLG_WIDTH, BOOK_DLG_HEIGHT, COLOR_BOOK_DLG_BK); osdStrDisp(BOOK_DLG_OFF_X+10, BOOK_DLG_OFF_Y+20, UserFont10x20, 0xd2, GetBookString(IsLoadmark_s)); osdStrDisp(BOOK_DLG_OFF_X+40, BOOK_DLG_OFF_Y+44, UserFont10x20, 0xd2, GetBookString(IsLoadmark_s1)); osdStrDisp(BOOK_DLG_OFF_X+40, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_NSEL : COLOR_BOOK_DLG_SEL, GetBookString(Book_yes_s)); osdStrDisp(BOOK_DLG_OFF_X+140, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_SEL : COLOR_BOOK_DLG_NSEL, GetBookString(Book_no_s)); break; default: break; } if (ui32NextState != UI_MODE_EBOOK) { break; } keyGet(&key); } } } return 1; }
//------------------------------------------------------------------------ // 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); }
char *report2json(char *in) { char *keys, *vals, report[100]; unsigned short ir[16], ik[32], iv[32], i; // copy cuz we edit it memcpy(report, in, 100); // parse this and humanize js0n((unsigned char*)report, strlen(report), ir, 16); if (!*ir) { return NULL; } sprintf(reportJson, "{\"type\":\"%s\"", keyGet(atoi(j0g_safe(0, report, ir)))); keys = report + ir[2]; js0n((unsigned char*)keys, ir[3], ik, 32); if (!*ik) { return NULL; } vals = report+ir[4]; js0n((unsigned char*)vals, ir[5], iv, 32); if (!*iv) { return NULL; } for (i=0; ik[i]; i+=2) { sprintf(reportJson + strlen(reportJson), ",\"%s\":", keyGet(atoi(j0g_safe(i, keys, ik)))); if (vals[iv[i]-1] == '"') { iv[i]--; iv[i+1]+=2; } *(vals+iv[i]+iv[i+1]) = 0; sprintf(reportJson + strlen(reportJson), "%s", vals + iv[i]); } sprintf(reportJson + strlen(reportJson), "}"); return reportJson; }
//------------------------------------------------------------------------ // 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 IsSaveBookmark() { UINT32 key = UI_KEY_MODE_EBOOK; UINT32 ui32SelectIdx = 0; while ((uiState & UI_MODE_MASK) == UI_MODE_EBOOK) { switch (key) { case UI_KEY_DIR_LEFT: case UI_KEY_DIR_RIGHT: ui32SelectIdx = ui32SelectIdx ? 0 : 1; osdStrDisp(BOOK_DLG_OFF_X+40, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_NSEL : COLOR_BOOK_DLG_SEL, GetBookString(Book_yes_s)); osdStrDisp(BOOK_DLG_OFF_X+140, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_SEL : COLOR_BOOK_DLG_NSEL, GetBookString(Book_no_s)); break; case UI_KEY_FUNC_OK: if (ui32SelectIdx == 0) { sPara.ui8BookmarkFlag = 0xaa; memcpy(sPara.ui8BookName, xdcfFileAttr.name, 13); sPara.ui32BookCurPage = ui32CurPageFlag; nandWriteParameters(); } return; case UI_KEY_MODE_EBOOK: osdBarDraw(BOOK_DLG_OFF_X, BOOK_DLG_OFF_Y, BOOK_DLG_WIDTH, BOOK_DLG_HEIGHT, COLOR_BOOK_DLG_BK); osdStrDisp(BOOK_DLG_OFF_X+10, BOOK_DLG_OFF_Y+20, UserFont10x20, 0xd2, GetBookString(IsSavemark_s)); osdStrDisp(BOOK_DLG_OFF_X+40, BOOK_DLG_OFF_Y+44, UserFont10x20, 0xd2, GetBookString(IsSavemark_s1)); osdStrDisp(BOOK_DLG_OFF_X+40, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_NSEL : COLOR_BOOK_DLG_SEL, GetBookString(Book_yes_s)); osdStrDisp(BOOK_DLG_OFF_X+140, BOOK_DLG_OFF_Y+70, UserFont10x20, ui32SelectIdx ? COLOR_BOOK_DLG_SEL : COLOR_BOOK_DLG_NSEL, GetBookString(Book_no_s)); break; default: break; } if (ui32NextState != UI_MODE_EBOOK) { break; } keyGet(&key); } }
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 }
//------------------------------------------------------------------------ // Display the Date and Time on the LCD display //------------------------------------------------------------------------ int dispDate( void ) { static int status; auto int wKey; costate { // Get current Date/Time 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); }
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)); } } }
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; } } }
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 } }
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; } } } } }
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); } } }
/*=================================================================== ===================================================================*/ 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 }
//*************************************************************************** // 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); } }
void paEBookMenuFunc() { UINT32 key = UI_KEY_MODE_ACCESSORIES; UINT32 err; UINT8 item=0, subitem = 1 ; osdClearScreen(0x00); UINT8 flag; EBookRefreshItem[item](); while(1) { switch(key) { case UI_KEY_DIR_UP: if(subitem>1) subitem -- ; EBookRefreshSubitem[item](subitem) ; break ; case UI_KEY_DIR_DOWN: if(subitem< eBookSubMax[ item ] ) subitem++ ; EBookRefreshSubitem[item](subitem ); break ; case UI_KEY_DIR_LEFT: if(item ) { item -- ; } else { item = EBOOK_ITEM_MAX - 1; } EBookRefreshItem[item](); break ; case UI_KEY_DIR_RIGHT: if(item < EBOOK_ITEM_MAX-1) { item++ ; } else { item = 0 ; } EBookRefreshItem[item]( ); break ; case UI_KEY_FUNC_OK: flag = EBookRefreshFunc[item*2 + subitem - 1 ](); if(flag) { MessageShow (MenuSuccess); } osdClearScreen(0);//fqdao pbEBookShow(EBOOK_DRAW_BG ,0 ); pbEBookRefresh(); return; break ; case UI_KEY_ACCIDENT: pbEBookRefresh(); osQuePost(uiKeyMsgQ, &keyButton[UI_KEY_ACCIDENT]); return; break; case UI_KEY_FUNC_B: case UI_KEY_FUNC_MENU: osdClearScreen(0); //fqdao_add 06.5.19 pbEBookShow(EBOOK_DRAW_BG ,0 ); pbEBookRefresh(); return ; break ; } keyGet(&key) ; } }
//------------------------------------------------------------------------ // Get and process the users MENU option //------------------------------------------------------------------------ int GetKeypadOption(int *offset, int *highlight, int num_options ) { static int wKey; if((wKey = keyGet()) != 0) { switch(wKey) { case '-': // Page down if(*offset < (num_options - 1)) { if((*offset + MAXDISPLAYROWS) < (num_options - 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) < (num_options - 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); }
//------------------------------------------------------------------------ // 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; } } }
/* ############################################################################# * * Description encrypt the given buffer and return the encrypted data with * an updated size information * Author Harry Brueckner * Date 2005-03-31 * Arguments char* buffer - buffer to encrypt * int size - size of the buffer * char** newbuffer - pointer to the new buffer which holds the * encrypted data * int* newsize - size of the returned buffer * PASSPHRASE_FN password_cb - callback function pointer used * to get the current passphrase * SHOWERROR_FN showerror_cb - callback function pointer used * to display errors * Return 0 if ok, otherwise 1 */ int gpgEncrypt(char* buffer, int size, char** newbuffer, int* newsize, PASSPHRASE_FN password_cb, SHOWERROR_FN showerror_cb) { gpgme_ctx_t context; gpgme_data_t input, output; gpgme_encrypt_result_t result; gpgme_error_t error; gpgme_key_t* key = NULL; gpgme_key_t tkey = NULL; gpgme_sign_result_t sign_result; int i, keys = 0, showerror = 1; char* agent; char* fpr; char* tmpbuffer = NULL; TRACE(99, "gpgEncrypt()", NULL); /* we set our passphrase callback function */ passphrase_callback = password_cb; /* we initialize the external size data */ newsize[0] = 0; error = gpgme_new(&context); if (!error) { gpgme_set_textmode(context, 1); gpgme_set_armor(context, 1); /* Flawfinder: ignore */ agent = getenv("GPG_AGENT_INFO"); if (!(agent && strchr(agent, ':'))) { retries = 0; gpgme_set_passphrase_cb(context, gpgRequestPassphrase, NULL); } } if (!error) { error = gpgme_data_new_from_mem(&input, buffer, size, 0); } if (!error) { error = gpgme_data_new(&output); } if (!error) { gpgme_signers_clear(context); } if (!error) { /* allocate the keys */ keys = keyCount(); key = memAlloc(__FILE__, __LINE__, sizeof(gpgme_key_t) * (keys + 1)); key[keys] = NULL; signers = 0; for (i = 0; i < keys && !error; i++) { /* add all keys */ fpr = gpgGetFingerprint(keyGet(i), LIST_SECRET); if (fpr) { error = gpgme_get_key(context, fpr, &tkey, LIST_SECRET); if (tkey -> secret); { error = gpgme_signers_add(context, tkey); signers++; } memFreeString(__FILE__, __LINE__, fpr); } fpr = gpgGetFingerprint(keyGet(i), LIST_ALL); if (fpr) { error = gpgme_get_key(context, fpr, &key[i], LIST_ALL); memFreeString(__FILE__, __LINE__, fpr); } } } if (signers > 1) { /* as soon as we get two signers, we must no longer cache anything */ config -> keeppassphrase = 0; clearPassphrase(1); } /* encrypt and sign the data */ if (!error) { error = gpgme_op_encrypt_sign(context, key, GPGME_ENCRYPT_ALWAYS_TRUST, input, output); } /* we don't need the passphrase any longer */ clearPassphrase(0); if (!error) { result = gpgme_op_encrypt_result(context); } if (!error && result -> invalid_recipients) { tmpbuffer = memAlloc(__FILE__, __LINE__, STDBUFFERLENGTH); snprintf(tmpbuffer, STDBUFFERLENGTH, _("Invalid recipient encountered: %s"), result -> invalid_recipients -> fpr); (showerror_cb)(_("GpgMe error"), tmpbuffer); memFree(__FILE__, __LINE__, tmpbuffer, STDBUFFERLENGTH); showerror = 0; error = 1; } if (!error) { sign_result = gpgme_op_sign_result(context); error = gpgCheckSignResult(showerror_cb, sign_result, GPGME_SIG_MODE_NORMAL); showerror = !error; } if (!error) { tmpbuffer = gpgData2Char(output, newsize); } /* free the keys again */ i = 0; while (key && keys && key[i]) { gpgme_key_unref(key[i++]); } memFree(__FILE__, __LINE__, key, sizeof(gpgme_key_t) * (keys + 1)); gpgme_data_release(input); gpgme_data_release(output); gpgme_release(context); *newbuffer = tmpbuffer; if (error) { if (showerror) { (showerror_cb)(_("GpgMe encrypt error"), gpgme_strerror(error)); } return 1; } else return 0; }
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 ); } } }
/* -------------------------------------------------------------------------------------- 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); }