// ezLCD.c // Runs on LM3S811 // Use UART to implement bidirectional data transfer to and from an // ezLCD-301. Provide functions to display a plot and graph data // over time or distance. Functions also send the proper strings to // the ezLCD-301 to implement simple functions such as clearing the // screen, moving the cursor, or drawing simple shapes. // Daniel Valvano // November 17, 2011 /* This is part of the Recorder2 for Admittance2012. Copyright 2012 by Jonathan W. Valvano, valvano@mail.utexas.edu You may use, edit, run or distribute this file as long as the above copyright notice remains THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. For more information about my classes, my research, and my books, see http://users.ece.utexas.edu/~valvano/ */ // either (see #define UART in UART2.c) // U1Rx/PD2 serial from ezLCD-301 Rx Pin 7 // U1Tx/PD3 serial to ezLCD-301 Tx Pin 8 // 3.3V to ezLCD-301 Vcc Pin 16 // Ground between ezLCD-301 Gnd Pins 3,15 // or // U0Rx/PA0 serial from ezLCD-301 Rx Pin 7 // U0Tx/PA1 serial to ezLCD-301 Tx Pin 8 // 3.3V to ezLCD-301 Vcc Pin 16 // Ground between ezLCD-301 Gnd Pins 3,15 #include "UART2.h" #include "ezLCD.h" // store the background and axis colors for the graph, since // other functions may change the current color unsigned long GraphBackgroundColorID = GRAY; // initially gray unsigned long GraphAxisColorID = BLUE; // initially blue // X-position of the next data point to be graphed unsigned short GraphXPos = 50; // 50 to 389 // largest possible value of MAXBUTTONS is 99 (handles 99 buttons) #define MAXBUTTONS 12 // handles at most MAXBUTTONS buttons ezLCD_Button_Obj Buttons[MAXBUTTONS]; // Sometimes the ezLCD-301 transmits an unnecessary reply, // particularly if "verbose" mode is on. Flush the receive // FIFO either periodically or before meaningful data is // expected. void static flushRxFifo(void){ while(UART_InCharNonBlocking()){}; } // Disable all buttons, such as after the ezLCD-301 is // cleared or reset. void static clearAllButtons(void){ int i; for(i=0; i 389) || (GraphXPos < 50)){ GraphXPos = 50; } // graph the data point in the proper location and color UART_OutString("6 "); // set drawing color to ID value of point UART_OutUDec((unsigned long) pointColor); UART_OutCommand("\r", reply, 40);// CR character completes command UART_OutString("17 "); // plot pixel at x=GraphXPos y=graphYPos UART_OutUDec((unsigned long) GraphXPos); UART_OutString(" "); // space character separates X- and Y-coordinates UART_OutUDec((unsigned long) graphYPos); UART_OutCommand("\r", reply, 40);// CR character completes command } //------------ezLCD_GraphPointNoIncNoColor------------ // Graphs a point without incrementing the X-position of the // next point to be plotted. Assume that ezLCD_GraphInit() // has already been called. Once the cursor exceeds the end // of the X-axis, the next point is graphed starting on the // leftmost position in the graph area. In this case, the // drawing color is assumed to be correct for the point(s) // to be plotted. This function is intended for more // efficient plotting of many pre-calculated values. // Structure your program like this: // ezLCD_SetColor(equation1Color); // for(i=0; i<340; i=i+1){ // ezLCD_GraphPointNoIncNoColor(equation1Values[i]); // ezLCD_GraphIncrement(); // } // ezLCD_SetColor(equation2Color); // for(i=0; i<340; i=i+1){ // ezLCD_GraphPointNoIncNoColor(equation2Values[i]); // ezLCD_GraphIncrement(); // } // Input: data 10-bit data point to be plotted // Output: none // Assumes: "verbose" mode off // NOTE: takes about 8 ms at 19,200 baud rate and "verbose" off. void ezLCD_GraphPointNoIncNoColor(unsigned short data){ char reply[40]; // temporary string holds LCD response // Y-position of the next data point to be graphed unsigned long graphYPos; // 14 to 174 // calculate Y-position with following equation: // y = -mx + b + r // m = 160 pixels tall in the Y-direction // slope is negative: as x increases, y decreases // b = 174 pixels from the top of the screen // r = 0.5 to round integer up // x = data/1023 // y = -160*data/1023 + 174 + 0.5 // = -160*data/1023 + 174.5 // = (-160*data + 174.5*1023)/1023 // = (-160*data + 174.5*1024)/1024 (small accuracy loss, efficiency gain) // = (178688 - 160*data)/1024 graphYPos = (178688 - 160*data)/1024; // verify correct X-position if((GraphXPos > 389) || (GraphXPos < 50)){ GraphXPos = 50; } // graph the data point in the proper location UART_OutString("17 "); // plot pixel at x=GraphXPos y=graphYPos UART_OutUDec((unsigned long) GraphXPos); UART_OutString(" "); // space character separates X- and Y-coordinates UART_OutUDec((unsigned long) graphYPos); UART_OutCommand("\r", reply, 40);// CR character completes command } //------------ezLCD_GraphIncrement------------ // Increment the X-position of the next point to be plotted. // Previously plotted data is not removed. If you want to // "sweep" across the plot from left to right and then // automatically start over from the left, structure your // program like this: // ezLCD_GraphPointNoInc(data1, color1); // ezLCD_GraphPointNoInc(data2, color2); // ezLCD_GraphPointNoInc(data3, color3); // ezLCD_GraphPoint(dataLast, colorLast); // If you want to display all recorded data points without // ever removing any, structure your program like this: // ezLCD_GraphPointNoInc(data1, color1); // ezLCD_GraphPointNoInc(data2, color2); // ezLCD_GraphPointNoInc(data3, color3); // ezLCD_GraphPointNoInc(dataLast, colorLast); // ezLCD_GraphIncrement(); // Input: none // Output: none void ezLCD_GraphIncrement(void){ GraphXPos = GraphXPos + 1; } //------------ezLCD_Reset------------ // Send "RESET" command to ezLCD-301. On startup, the macro // "startup.ezm" should be run from the Flash. // Input: none // Output: none // Modifies: ezLCD reset void ezLCD_Reset(void){ UART_OutString("RESET\r"); // reset ezLCD-301 as if just turned on flushRxFifo(); // flush any old LCD responses clearAllButtons(); // clear all buttons } //------------ezLCD_ClearScreen------------ // Send "CLS" command to ezLCD-301. The screen will be // solidly filled with the specified color. Any buttons // will be disabled. // Input: clearColor color ID to use to fill the screen (0 to 199) // Output: none // Assumes: "verbose" mode off void ezLCD_ClearScreen(unsigned short clearColor){ char reply[40]; // temporary string holds LCD response clearAllButtons(); // clear all buttons UART_OutString("CLS "); // clear screen to desired ID value UART_OutUDec((unsigned long) clearColor); UART_OutCommand("\r", reply, 40);// CR character completes command } //------------ezLCD_Ping------------ // Test the ezLCD-301 using the "PING" command. // In "verbose" mode, the response is "Pong". // Otherwise, the response is "0\r". // Input: none // Output: 0 if no error; 1 otherwise // Assumes: "verbose" mode off int ezLCD_Ping(void){ char reply[20]; // temporary strings hold LCD response ezLCD_Verbose(1); // put LCD in "verbose" mode // send "PING" command UART_OutCommandV("PING\r", reply, 20); ezLCD_Verbose(0); // take LCD out of "verbose" mode if(reply[0] == 'P'){ // expect "Pong\r" in reply; simple string compare if(reply[1] == 'o'){ if(reply[2] == 'n'){ if(reply[3] == 'g'){ return 0; // no error } } } } return 1; } //------------ezLCD_Verbose------------ // Send "VERBOSE" command to ezLCD-301. When in verbose // mode, the ezLCD-301 replies to the microcontroller // through the UART with a greater volume of text after // each successful command. Although this can be useful // for debugging, the text is generally meaningless for // stand-alone applications. Verbose mode also greatly // slows down the speed at which commands are executed, // since the biggest bottleneck is usually the baud rate // of the UART. Verbose mode affects synchronization. // Most of the functions in this file are written using // UART_OutCommand(), which assumes that the ezLCD-301 // is not in verbose mode. UART_OutCommandV() should be // used when certain that verbose mode is enabled. // Input: enable new verbose setting to change to // (0=disable verbose or 1=enable verbose) // Output: none void ezLCD_Verbose(unsigned short enable){ char reply[20]; // temporary string holds LCD response // determine which mode the ezLCD-301 is currently in flushRxFifo(); UART_OutString("XY\r"); UART_InString(reply, 20); // In "verbose" mode, the response is // "\rGet XY: X=XXX Y=YYY\r", causing "reply" to be empty // Otherwise, the response is "XXX YYY\r". flushRxFifo(); if(reply[0] == 0){ // already in "verbose" mode if(enable){ return; // no need to do anything } // take LCD out of "verbose" mode UART_OutCommandV("VERBOSE 0\r", reply, 20); } else{ // not in "verbose" mode if(enable == 0){ return; // no need to do anything } // put LCD in "verbose" mode UART_OutCommand("VERBOSE 1\r", reply, 20); } } //------------ezLCD_SetLight------------ // Send "LIGHT X" command to ezLCD-301. The LED back- // light is set to X% of maximum brightness. The // default is 75%. // Input: newLight new LED brighness (0 to 100) percent // Output: none // Assumes: "verbose" mode off void ezLCD_SetLight(unsigned short newLight){ char reply[20]; // temporary string holds LCD response if(newLight <= 100){ // verify valid parameter UART_OutString("LIGHT "); // set backlight brightness level UART_OutUDec((unsigned long) newLight); // CR character completes command UART_OutCommand("\r", reply, 20); } } //------------ezLCD_GetLight------------ // Send "LIGHT" command to ezLCD-301. Return the // current LED backlight value as X% of maximum // brightness. The default is 75%. // In "verbose" mode, the response is "Get Light: XXX\r". // Otherwise, the response is "XXX\r". // Results will be unpredictable if response is not // in this format. // Input: none // Output: current LED brighness (0 to 100) percent // Assumes: "verbose" mode off unsigned short ezLCD_GetLight(void){ int i=0; unsigned short light=0; char string[20]; // temporary string holds LCD response, assumes printable ASCII from $20 to $7F flushRxFifo(); // flush any earlier LCD responses UART_OutCommand("LIGHT\r", string, 20); // the ones digit of the "light" value is one character before the NULL while((string[i] != 0) && (i < 20)){ i = i + 1; // step through response string until string[i] == NULL } if(i == 0){ return 0; // empty string; return 0 in this error case } // back up one character and store its number as the ones digit of "light" light = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number and part of the string? if((string[i-2] >= '0') && (string[i-2] <= '9') && (i >= 2)){ // if so, store its number as the tens digit of "light" light = light + 10*(unsigned short)(string[i-2] - '0'); } // back up three characters, is this a number and part of the string? if((string[i-3] >= '0') && (string[i-3] <= '9') && (i >= 3)){ // if so, store its number as the hundreds digit of "light" light = light + 100*(unsigned short)(string[i-3] - '0'); } return light; } //------------ezLCD_SetColor------------ // Send "COLOR X" command to ezLCD-301. The next thing // that is drawn will be the color of the specified // color ID. An uninitialized color ID may be black. // Input: newColor new color ID of drawing color (0 to 199) // Output: none // Assumes: "verbose" mode off void ezLCD_SetColor(unsigned short newColor){ char reply[20]; // temporary string holds LCD response UART_OutString("COLOR "); // set drawing color to desired ID value UART_OutUDec((unsigned long) newColor); UART_OutCommand("\r", reply, 20);// CR character completes command } //------------ezLCD_GetColor------------ // Send "COLOR" command to ezLCD-301. Return the // current drawing color values. // In "verbose" mode, the response is // "Get Color: R=XX G=XX B=XX\r". // Otherwise, the response is "XX XX XX\r". // Results will be unpredictable if response is not // in this format. // Input: none // Output: red, green, and blue values of the drawing color // Assumes: "verbose" mode off void ezLCD_GetColor(unsigned short *red, unsigned short *green, unsigned short *blue){ int i=0; char string[40]; // temporary string holds LCD response, assumes printable ASCII from $20 to $7F flushRxFifo(); // flush any earlier LCD responses // get drawing color and max of 40 characters from LCD UART_OutCommand("COLOR\r", string, 40); // if the ezLCD-301 was left in "verbose" mode, there will be substring "Get Color: R=" to skip over while((string[i] != '=') && (i < 40)){ i = i + 1; // step through response string until string[i] == '=' } if(i >= 40){ // if not left in "verbose" mode, no "Get Color: R=" will be present i = 0; // start back over at the beginning and continue in the same way } // get the "red" value, which is before the first ' ' // the ones digit of the "red" value is one character before the first ' ' while((string[i] != ' ') && (i < 40)){ i = i + 1; // step through response string until string[i] == ' ' } // back up one character and store its number as the ones digit of "red" *red = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number and part of the string? if((string[i-2] >= '0') && (string[i-2] <= '9') && (i >= 2)){ // if so, store its number as the tens digit of "red" *red = *red + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number and part of the string? if((string[i-3] >= '0') && (string[i-3] <= '9') && (i >= 3)){ // if so, store its number as the hundreds digit of "red" *red = *red + 100*(unsigned short)(string[i-3] - '0'); } } // get the "green" value, which is between the first ' ' and the next ' ' i = i + 1; // the ones digit of the "green" value is one character before the next ' ' while((string[i] != ' ') && (i < 40)){ i = i + 1; // step through response string until string[i] == ' ' } // back up one character and store its number as the ones digit of "green" *green = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number? if((string[i-2] >= '0') && (string[i-2] <= '9')){ // if so, store its number as the tens digit of "green" *green = *green + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number? if((string[i-3] >= '0') && (string[i-3] <= '9')){ // if so, store its number as the hundreds digit of "green" *green = *green + 100*(unsigned short)(string[i-3] - '0'); } } // get the "blue" value, which is between the second ' ' and the NULL i = i + 1; // the ones digit of the "blue" value is one character before the NULL while((string[i] != 0) && (i < 40)){ i = i + 1; // step through response string until string[i] == NULL } // back up one character and store its number as the ones digit of "blue" *blue = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number? if((string[i-2] >= '0') && (string[i-2] <= '9')){ // if so, store its number as the tens digit of "blue" *blue = *blue + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number? if((string[i-3] >= '0') && (string[i-3] <= '9')){ // if so, store its number as the hundreds digit of "blue" *blue = *blue + 100*(unsigned short)(string[i-3] - '0'); } } } //------------ezLCD_SetColorID------------ // Send "COLORID index R G B" command to ezLCD-301. The // specified red, green, and blue values will be stored // in the specified color ID. To see this color, use // "ezLCD_ClearScreen(colorID);". If the ezLCD-301 loses // power, all custom colors may return to default. // Input: colorID destination color ID (16 to 199) (recommend 169 to 199) // red new red value, // green, new green value, // blue new blue value // Output: none // Assumes: "verbose" mode off void ezLCD_SetColorID(unsigned short colorID, unsigned short red, unsigned short green, unsigned short blue){ char reply[20]; // temporary string holds LCD response UART_OutString("COLORID "); // set desired ID to desired red, green, blue values UART_OutUDec((unsigned long) colorID); UART_OutString(" "); UART_OutUDec((unsigned long) red); UART_OutString(" "); UART_OutUDec((unsigned long) green); UART_OutString(" "); UART_OutUDec((unsigned long) blue); UART_OutCommand("\r", reply, 20);// CR character completes command } //------------ezLCD_GetColorID------------ // Send "COLORID index" command to ezLCD-301. Return // the specified color ID's red, green, and blue values. // In "verbose" mode, the response to "COLORID 5" is // "Get Color ID 5: R=16 G=0 B=0\r". // Otherwise, the response is "16 0 0\r". // Results will be unpredictable if response is not // in this format. // Input: colorID color index number to look at (0 to 199) // Output: red, green, and blue values of specified color ID // Assumes: "verbose" mode off // WARNING: this command may not work // Specifically, "COLORID 180 83 120 179" sets color 180 // to "IBM blue". However, "COLORID 180" does not // return R=83, G=120, B=179. It returns // R=10, G=30, B=22, which is a totally different color. void ezLCD_GetColorID(unsigned short colorID, unsigned short *red, unsigned short *green, unsigned short *blue){ int i=0; char string[40]; // temporary string holds LCD response flushRxFifo(); // flush any earlier LCD responses UART_OutString("COLORID "); // get RGB value for desired color ID UART_OutUDec((unsigned long) colorID); // CR character completes command and get max of 40 characters from LCD UART_OutCommand("\r", string, 40); // if the ezLCD-301 was left in "verbose" mode, there will be substring "Get Color ID X: R=" to skip over while((string[i] != '=') && (i < 40)){ i = i + 1; // step through response string until string[i] == '=' } if(i >= 40){ // if not left in "verbose" mode, no "Get Color ID X: R=" will be present i = 0; // start back over at the beginning and continue in the same way } // get the "red" value, which is before the first ' ' // the ones digit of the "red" value is one character before the first ' ' while((string[i] != ' ') && (i < 40)){ i = i + 1; // step through response string until string[i] == ' ' } // back up one character and store its number as the ones digit of "red" *red = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number and part of the string? if((string[i-2] >= '0') && (string[i-2] <= '9') && (i >= 2)){ // if so, store its number as the tens digit of "red" *red = *red + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number and part of the string? if((string[i-3] >= '0') && (string[i-3] <= '9') && (i >= 3)){ // if so, store its number as the hundreds digit of "red" *red = *red + 100*(unsigned short)(string[i-3] - '0'); } } // get the "green" value, which is between the first ' ' and the next ' ' i = i + 1; // the ones digit of the "green" value is one character before the next ' ' while((string[i] != ' ') && (i < 40)){ i = i + 1; // step through response string until string[i] == ' ' } // back up one character and store its number as the ones digit of "green" *green = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number? if((string[i-2] >= '0') && (string[i-2] <= '9')){ // if so, store its number as the tens digit of "green" *green = *green + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number? if((string[i-3] >= '0') && (string[i-3] <= '9')){ // if so, store its number as the hundreds digit of "green" *green = *green + 100*(unsigned short)(string[i-3] - '0'); } } // get the "blue" value, which is between the second ' ' and the NULL i = i + 1; // the ones digit of the "blue" value is one character before the NULL while((string[i] != 0) && (i < 40)){ i = i + 1; // step through response string until string[i] == NULL } // back up one character and store its number as the ones digit of "blue" *blue = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number? if((string[i-2] >= '0') && (string[i-2] <= '9')){ // if so, store its number as the tens digit of "blue" *blue = *blue + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number? if((string[i-3] >= '0') && (string[i-3] <= '9')){ // if so, store its number as the hundreds digit of "blue" *blue = *blue + 100*(unsigned short)(string[i-3] - '0'); } } } //------------ezLCD_SetFontStr------------ // Send "FONT \"font\"" command to ezLCD-301. This sets // the active font to the specified font name. To send a // font index number instead, use ezLCD_SetFontID(). // Input: newFont NULL terminated string name of new font // Output: none // Assumes: "verbose" mode off void ezLCD_SetFontStr(char *newFont){ char reply[40]; // temporary string holds LCD response UART_OutString("FONT \""); // set font to desired font name UART_OutString(newFont); // CR character completes command and get max of 40 characters from LCD UART_OutCommand("\"\r", reply, 40); } //------------ezLCD_SetFontID------------ // Send "FONT index" command to ezLCD-301. This sets the // active font to the specified index number. To send a // font string name instead, use ezLCD_SetFontStr(). // Input: fontID new font index number // Output: none // Assumes: "verbose" mode off void ezLCD_SetFontID(unsigned short fontID){ char reply[40]; // temporary string holds LCD response UART_OutString("FONT "); // set font to desired font index UART_OutUDec((unsigned long) fontID); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_SetFontW------------ // Send "FONTW widget \"font\"" command to ezLCD-301. // This sets the font to be used with the specified // widget. Widgets are used to draw button objects, // and this function must be called to attach a font // to any widgets that will be used. // Widgets seem to return to default when the ezLCD // loses power, although this function still must be // called. // Input: widgetIndex font widget ID, // newWidgetFont NULL terminated string name of font // Output: none // Assumes: "verbose" mode off void ezLCD_SetFontW(unsigned short widgetIndex, char *newWidgetFont){ char reply[40]; // temporary string holds LCD response UART_OutString("FONTW "); // set widget font of desired widget index UART_OutUDec((unsigned long) widgetIndex); UART_OutString(" \""); // set widget font to desired font name UART_OutString(newWidgetFont); // CR character completes command and get max of 40 characters from LCD UART_OutCommand("\"\r", reply, 40); } //------------ezLCD_SetFontO------------ // Send "FONTO value" command to ezLCD-301. This // sets the font orientation to 0 (horizontal) or // 1 (vertical). Sending other values may have // unpredictable results. // Input: newFontO new font orientation value // (0=horizontal or 1=vertical) // Output: none // Assumes: "verbose" mode off void ezLCD_SetFontO(unsigned short newFontO){ char reply[50]; // temporary string holds LCD response if(newFontO <= 1){ // verify valid parameter UART_OutString("FONTO "); // set font orientation UART_OutUDec((unsigned long) newFontO); // CR character completes command and get max of 50 characters from LCD UART_OutCommand("\r", reply, 50); } } //------------ezLCD_GetFontO------------ // Send "FONTO" command to ezLCD-301. This gets // the current font orientation as 0 (horizontal) // or 1 (vertical). // In "verbose" mode, the response is // "Font Orient: Vertical\r" or // "Font Orient: Horizontal\r". // Otherwise, the response is "1\r" or "0\r". // Return 2 if response is not in this format. // Input: none // Output: current font orientation value // Assumes: "verbose" mode off unsigned short ezLCD_GetFontO(void){ int i=0; char string[30]; // temporary string holds LCD response, assumes printable ASCII from $20 to $7F flushRxFifo(); // flush any earlier LCD responses // get font orientation and max of 30 characters from LCD UART_OutCommand("FONTO\r", string, 30); // look for '0', '1', 'V', or 'H' for(i=0; i<30; i=i+1){ switch(string[i]){ case '0': case 'H': return 0; case '1': case 'V': return 1; } } return 2; // an error occurred, return 2 } //------------ezLCD_SetLinewidth------------ // Send "LINEWIDTH value" command to ezLCD-301. // This sets the line width to 1 or 3 pixels wide. // Line width applies to regular lines, the box, // and the circle. // Sending other values may have unpredictable // results. // Input: newLineWidth new line width (pixels) (1 or 3) // Output: none // Assumes: "verbose" mode off void ezLCD_SetLinewidth(unsigned short newLinewidth){ char reply[45]; // temporary string holds LCD response // verify valid parameter if((newLinewidth == 1) || (newLinewidth == 3)){ UART_OutString("LINEWIDTH "); // set line width UART_OutUDec((unsigned long) newLinewidth); // CR character completes command and get max of 45 characters from LCD UART_OutCommand("\r", reply, 45); } } //------------ezLCD_GetLinewidth------------ // Send "LINEWIDTH" command to ezLCD-301. This // gets the current line width as 1 or 3 pixels // wide. // In "verbose" mode, the response is // "Get Line Width: 3\r". // Otherwise, the response is "3\r". // Results will be unpredictable if response is not // in this format. // Input: none // Output: current line width (pixels) // Assumes: "verbose" mode off unsigned short ezLCD_GetLinewidth(void){ int i=0; char string[30]; // temporary string holds LCD response, assumes printable ASCII from $20 to $7F flushRxFifo(); // flush any earlier LCD responses // get line width and max of 30 characters from LCD UART_OutCommand("LINEWIDTH\r", string, 30); // look for a single-digit number of pixels while(((string[i] < '0') || (string[i] > '9')) && (i < 30)){ i = i + 1; // step through response string until string[i] is a number } return (unsigned short)(string[i] - '0'); } //------------ezLCD_SetLinetype------------ // Send "LINETYPE value" command to ezLCD-301. // This sets the line type by inserting the // specified number of pixels between line // segments, creating a dotted or dashed line. // For a solid line, specify 0 pixel gap. // Line type applies to regular lines, the box, // and the circle. // Input: newLineType new number of pixels between line segments // Output: none // Assumes: "verbose" mode off void ezLCD_SetLinetype(unsigned short newLinetype){ char reply[40]; // temporary string holds LCD response UART_OutString("LINETYPE "); // set line type to desired number of pixel spacing UART_OutUDec((unsigned long) newLinetype); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_GetLinetype------------ // Send "LINETYPE" command to ezLCD-301. This // gets the current line type as the number of // pixels between line segments. // In "verbose" mode, the response is // "Get Line Type: 5\r". // Otherwise, the response is "5\r". // Results will be unpredictable if response is not // in this format. // Input: none // Output: current number of pixels between line segments // Assumes: "verbose" mode off unsigned short ezLCD_GetLinetype(void){ int i=0; unsigned short spaces=0; char string[30]; // temporary string holds LCD response, assumes printable ASCII from $20 to $7F flushRxFifo(); // flush any earlier LCD responses // get line type and max of 30 characters from LCD UART_OutCommand("LINETYPE\r", string, 30); // the ones digit of the "spaces" value is one character before the NULL while((string[i] != 0) && (i < 30)){ i = i + 1; // step through response string until string[i] == NULL } if((i == 0) || (i >= 30)){ return 0; // empty string or no NULL found; return 0 in this error case } // back up one character and store its number as the ones digit of "spaces" spaces = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number and part of the string? if((string[i-2] >= '0') && (string[i-2] <= '9') && (i >= 2)){ // if so, store its number as the tens digit of "spaces" spaces = spaces + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number and part of the string? if((string[i-3] >= '0') && (string[i-3] <= '9') && (i >= 3)){ // if so, store its number as the hundreds digit of "spaces" spaces = spaces + 100*(unsigned short)(string[i-3] - '0'); } } return spaces; } //------------ezLCD_SetCursor------------ // Send "XY x y" command to ezLCD-301. This sets // the drawing cursor to the specified X and Y // values if they are legal. // Input: newX new X value of the cursor (0 to 399), // newY new Y value of the cursor (0 to 239) // Output: none // Assumes: "verbose" mode off void ezLCD_SetCursor(unsigned short newX, unsigned short newY){ char reply[40]; // temporary string holds LCD response UART_OutString("XY "); // set cursor to desired X and Y values UART_OutUDec((unsigned long) newX); UART_OutString(" "); UART_OutUDec((unsigned long) newY); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_GetCursor------------ // Send "XY" command to ezLCD-301. This gets the // drawing cursor's X and Y values. // In "verbose" mode, the response is // "Get XY: X=50 Y=50\r". // Otherwise, the response is "50 50\r". // Results will be unpredictable if response is not // in this format. // Input: none // Output: x current X value of the cursor, // y current Y value of the cursor // Assumes: "verbose" mode off void ezLCD_GetCursor(unsigned short *x, unsigned short *y){ int i=0; char string[40]; // temporary string holds LCD response, assumes printable ASCII from $20 to $7F flushRxFifo(); // flush any earlier LCD responses // get cursor values and max of 40 characters from LCD UART_OutCommand("XY\r", string, 40); // if the ezLCD-301 was left in "verbose" mode, look for '=' while((string[i] != '=') && (i < 40)){ i = i + 1; // step through response string until string[i] == '=' } if(i >= 40){ // no '=' anywhere in string, treat as not "verbose" mode i = 0; // start back at the beginning of the string // get the "x" value, which is before the ' ' // the ones digit of the "x" value is one character before the ' ' while((string[i] != ' ') && (i < 40)){ i = i + 1; // step through response string until string[i] == ' ' } // back up one character and store its number as the ones digit of "x" *x = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number and part of the string? if((string[i-2] >= '0') && (string[i-2] <= '9') && (i >= 2)){ // if so, store its number as the tens digit of "x" *x = *x + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number and part of the string? if((string[i-3] >= '0') && (string[i-3] <= '9') && (i >= 3)){ // if so, store its number as the hundreds digit of "x" *x = *x + 100*(unsigned short)(string[i-3] - '0'); } } // get the "y" value, which is between the ' ' and the NULL i = i + 1; // the ones digit of the "y" value is one character before the NULL while((string[i] != 0) && (i < 40)){ i = i + 1; // step through response string until string[i] == NULL } // back up one character and store its number as the ones digit of "y" *y = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number? if((string[i-2] >= '0') && (string[i-2] <= '9')){ // if so, store its number as the tens digit of "y" *y = *y + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number? if((string[i-3] >= '0') && (string[i-3] <= '9')){ // if so, store its number as the hundreds digit of "blue" *y = *y + 100*(unsigned short)(string[i-3] - '0'); } } } else{ // string[i] == '=', treat as "verbose" mode // get the "x" value, which is between the "X=" and the next ' ' // the ones digit of the "x" value is one character before the next ' ' while((string[i] != ' ') && (i < 40)){ i = i + 1; // step through response string until string[i] == ' ' } // back up one character and store its number as the ones digit of "x" *x = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number? if((string[i-2] >= '0') && (string[i-2] <= '9')){ // if so, store its number as the tens digit of "x" *x = *x + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number? if((string[i-3] >= '0') && (string[i-3] <= '9')){ // if so, store its number as the hundreds digit of "x" *x = *x + 100*(unsigned short)(string[i-3] - '0'); } } // get the "y" value, which is between the "Y=" and the '\n' i = i + 1; // the ones digit of the "y" value is one character before the '\n' while((string[i] != '\n') && (i < 40)){ i = i + 1; // step through response string until string[i] == '\n' } // back up one character and store its number as the ones digit of "y" *y = (unsigned short)(string[i-1] - '0'); // back up two characters, is this a number? if((string[i-2] >= '0') && (string[i-2] <= '9')){ // if so, store its number as the tens digit of "y" *y = *y + 10*(unsigned short)(string[i-2] - '0'); // back up three characters, is this a number? if((string[i-3] >= '0') && (string[i-3] <= '9')){ // if so, store its number as the hundreds digit of "y" *y = *y + 100*(unsigned short)(string[i-3] - '0'); } } } } //------------ezLCD_Plot------------ // Send "PLOT" command to ezLCD-301. This plots a // pixel at the drawing cursor's X and Y values in // the current color. // Input: none // Output: none // Assumes: "verbose" mode off void ezLCD_Plot(void){ char reply[40]; // temporary string holds LCD response // plot pixel and get max of 40 characters from LCD UART_OutCommand("PLOT\r", reply, 40); } //------------ezLCD_PlotXY------------ // Send "PLOT x y" command to ezLCD-301. This // plots a pixel at the specified X and Y values // in the current color. // Input: ptX pixel X value (0 to 399), // ptY pixel Y value (0 to 239) // Output: none // Assumes: "verbose" mode off void ezLCD_PlotXY(unsigned short ptX, unsigned short ptY){ char reply[40]; // temporary string holds LCD response UART_OutString("PLOT "); // plot pixel at desired X and Y values UART_OutUDec((unsigned long) ptX); UART_OutString(" "); UART_OutUDec((unsigned long) ptY); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_Line------------ // Send "LINE x y" command to ezLCD-301. This // draws a line from the drawing cursor's X and // Y values to the specified X and Y values. // Input: lineX X value of line endpoint (0 to 399), // lineY Y value of line endpoint (0 to 239) // Output: none // Assumes: "verbose" mode off void ezLCD_Line(unsigned short lineX, unsigned short lineY){ char reply[40]; // temporary string holds LCD response UART_OutString("LINE "); // draw line to desired X and Y values UART_OutUDec((unsigned long) lineX); UART_OutString(" "); UART_OutUDec((unsigned long) lineY); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_Box------------ // Send "BOX w h fill" command to ezLCD-301. // This draws a box with its top left corner at // the drawing cursor's X and Y values with the // specified width and height (in pixels). A // non-zero value of "fill" fills the box. // If the line type (number of pixels between line // segments) is not zero and the box is not filled, // the box's perimeter will be dotted. // Input: width box width (pixels) (1 to 400), // height box height (pixels) (1 to 240), // fill non-zero for filled box // Output: none // Assumes: "verbose" mode off void ezLCD_Box(unsigned short width, unsigned short height, unsigned short fill){ char reply[50]; // temporary string holds LCD response UART_OutString("BOX "); // draw box with desired width, height, and fill UART_OutUDec((unsigned long) width); UART_OutString(" "); UART_OutUDec((unsigned long) height); if(fill){ // send "1" to fill // CR character completes command and get max of 50 characters from LCD UART_OutCommand(" 1\r", reply, 50); } else{ // send "0" for empty box // CR character completes command and get max of 50 characters from LCD UART_OutCommand(" 0\r", reply, 50); } } //------------ezLCD_Circle------------ // Send "CIRCLE radius fill" command to ezLCD-301. // This draws a circle centered at the drawing // cursor's X and Y values with the specified // radius (in pixels). A non-zero value of "fill" // fills the circle. // If the line type (number of pixels between line // segments) is not zero and the circle is not filled, // the circle's perimeter will be dotted. // Input: radius circle radius (pixels), // fill non-zero for filled circle // Output: none // Assumes: "verbose" mode off void ezLCD_Circle(unsigned short radius, unsigned short fill){ char reply[80]; // temporary string holds LCD response UART_OutString("CIRCLE "); // draw circle with desired radius and fill UART_OutUDec((unsigned long) radius); if(fill){ // send "1" to fill // CR character completes command and get max of 80 characters from LCD UART_OutCommand(" 1\r", reply, 80); } else{ // send "0" for empty circle // CR character completes command and get max of 80 characters from LCD UART_OutCommand(" 0\r", reply, 80); } } //------------ezLCD_Arc------------ // Send "ARC radius start end" command to ezLCD-301. // This draws an arc centered at the drawing // cursor's X and Y values with the specified // radius (in pixels) and the specified start and // end angles (in degrees). An angle of 0 degrees // is in the 3:00 position. An angle of 90 degrees // is in the 6:00 position. // Input: radius arc radius (pixels), // start arc starting angle (0 to end), // end arc ending angle (start to 359) // Output: none // Assumes: "verbose" mode off // WARNING: In firmware versions 1.11 and earlier, // this command sometimes changes the drawing cursor's // X and Y values when the line width is set to 3. // The line width is always set to 1. void ezLCD_Arc(unsigned short radius, unsigned short start, unsigned short end){ unsigned short swapTemp; char reply[95]; // temporary string holds LCD response // for proper operation, start angle must be less than end angle if(start > end){ // otherwise, swap them and continue swapTemp = end; end = start; start = swapTemp; } UART_OutString("ARC "); // draw arc with desired radius, starting angle, and ending angle UART_OutUDec((unsigned long) radius); UART_OutString(" "); UART_OutUDec((unsigned long) start); UART_OutString(" "); UART_OutUDec((unsigned long) end); UART_OutCommand("\r", reply, 95);// CR character completes command and get max of 95 characters from LCD } //------------ezLCD_Pie------------ // Send "PIE radius start end" command to ezLCD-301. // This draws a pie slice centered at the drawing // cursor's X and Y values with the specified // radius (in pixels) and the specified start and // end angles (in degrees). An angle of 0 degrees // is in the 3:00 position. An angle of 90 degrees // is in the 6:00 position. // If the line type (number of pixels between line // segments) is not zero, the pie slice will look // like a slice of a target. // Input: radius pie slice radius (pixels), // start slice starting angle (0 to end), // end slice ending angle (start to 359) // Output: none // Assumes: "verbose" mode off void ezLCD_Pie(unsigned short radius, unsigned short start, unsigned short end){ unsigned short swapTemp; char reply[80]; // temporary string holds LCD response // for proper operation, start angle must be less than end angle if(start > end){ // otherwise, swap them and continue swapTemp = end; end = start; start = swapTemp; } UART_OutString("PIE "); // draw pie slice with desired radius, starting angle, and ending angle UART_OutUDec((unsigned long) radius); UART_OutString(" "); UART_OutUDec((unsigned long) start); UART_OutString(" "); UART_OutUDec((unsigned long) end); UART_OutCommand("\r", reply, 80);// CR character completes command and get max of 80 characters from LCD } //------------ezLCD_PrintStr------------ // Send "PRINT string" command to ezLCD-301. This // prints the NULL-terminated string at the drawing // cursor's X and Y values with the pre-configured // font, color, and text orientation. The drawing // cursor is located at the top left corner of the // first character to be printed. The drawing cursor // is then moved to the end of the printed string. // If you wish to continue printing more text on the // same line, simply call ezLCD_PrintStr() again // without needing to move the drawing cursor. // Input: text NULL terminated string to print // Output: none // Assumes: "verbose" mode off // Modifies: ezLCD drawing cursor void ezLCD_PrintStr(char *text){ char reply[40]; // temporary string holds LCD response UART_OutString("PRINT \""); // print desired text string UART_OutString(text); UART_OutCommand("\"\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_PrintStrJustified------------ // Send "PRINT string justification" command to // ezLCD-301. This prints the NULL-terminated string // at the drawing cursor's X and Y values with the // pre-configured font, color, and text orientation // at the specified justification. The drawing cursor // is then moved to the end of the printed string. // If you wish to continue printing more text on the // same line, simply call ezLCD_PrintStrJustified() // again with the same justification code without // needing to move the drawing cursor. // justification is according to the following: // **************************** // * LT CT RT * // * * // * LC CC RC * // * * // * LB CB RB * // **************************** // Input: text NULL terminated string to print, // jcode justification code // (LT, CT, RT, LC, CC, RC, LB, CB, or RB) // Output: none // Assumes: "verbose" mode off // Modifies: ezLCD drawing cursor void ezLCD_PrintStrJustified(char *text, enum justification jcode){ char reply[40]; // temporary string holds LCD response UART_OutString("PRINT \""); // print desired text string UART_OutString(text); switch(jcode){ case LT: UART_OutString("\" LT"); break; case CT: UART_OutString("\" CT"); break; case RT: UART_OutString("\" RT"); break; case LC: UART_OutString("\" LC"); break; case CC: UART_OutString("\" CC"); break; case RC: UART_OutString("\" RC"); break; case LB: UART_OutString("\" LB"); break; case CB: UART_OutString("\" CB"); break; case RB: UART_OutString("\" RB"); break; }; UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_PrintUDec------------ // Send "PRINT string" command to ezLCD-301. This // prints the 16-bit number at the drawing cursor's // X and Y values with the pre-configured font, color, // and text orientation. The drawing cursor is // located at the top left corner of the first // character to be printed. The drawing cursor is // then moved to the end of the printed string. If // you wish to continue printing more text on the same // line, simply call ezLCD_PrintUDec() again without // needing to move the drawing cursor. // Input: n 16-bit number to print // Output: none // Assumes: "verbose" mode off // Modifies: ezLCD drawing cursor void ezLCD_PrintUDec(unsigned short n){ char reply[40]; // temporary string holds LCD response UART_OutString("PRINT \""); // print desired number UART_OutUDec((unsigned long) n); UART_OutCommand("\"\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_PrintUDecJustified------------ // Send "PRINT string justification" command to // ezLCD-301. This prints the 16-bit number at the // drawing cursor's X and Y values with the // pre-configured font, color, and text orientation // at the specified justification. The drawing cursor // is then moved to the end of the printed string. // If you wish to continue printing more text on the // same line, simply call ezLCD_PrintUDecJustified() // again with the same justification code without // needing to move the drawing cursor. // justification is according to the following: // **************************** // * LT CT RT * // * * // * LC CC RC * // * * // * LB CB RB * // **************************** // Input: n 32-bit number to print, // jcode justification code // (LT, CT, RT, LC, CC, RC, LB, CB, or RB) // Output: none // Assumes: "verbose" mode off // Modifies: ezLCD drawing cursor void ezLCD_PrintUDecJustified(unsigned short n, enum justification jcode){ char reply[40]; // temporary string holds LCD response UART_OutString("PRINT \""); // print desired number UART_OutUDec((unsigned long) n); switch(jcode){ case LT: UART_OutString("\" LT"); break; case CT: UART_OutString("\" CT"); break; case RT: UART_OutString("\" RT"); break; case LC: UART_OutString("\" LC"); break; case CC: UART_OutString("\" CC"); break; case RC: UART_OutString("\" RC"); break; case LB: UART_OutString("\" LB"); break; case CB: UART_OutString("\" CB"); break; case RB: UART_OutString("\" RB"); break; }; UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_SetThemeID------------ // Send "THEME " command to ezLCD-301. This // sets the specified theme to the specified parameters. // Themes are used to draw buttons. Themes may return to // default values if the ezLCD-301 loses power. Default // values as of firmware version 1.01 are the following: // THEME 0 1 2 0 0 0 3 3 3 3 '(white/black) // THEME 1 155 152 3 3 3 0 0 0 0 '(black/white) // THEME 2 5 20 3 3 3 4 4 4 4 '(red/white) // THEME 3 9 3 0 0 0 8 8 8 8 '(green/black) // THEME 4 7 3 0 0 0 6 6 6 6 '(yellow/black) // THEME 5 126 118 3 3 3 35 35 35 35 '(orange/white) // THEME 6 111 106 3 3 3 12 12 12 12 '(blue/white) // THEME 7 58 48 3 3 3 14 14 14 14 '(pink/white) // Input: themeID theme ID number (0 to 15), // embossDkColor color ID of button shadow (lower right edge), // embossLtColor color ID of button highlight (upper left edge), // textColorRest color ID of button text at rest, // textColorTouched color ID of button text when touched, // textColorDisabled color ID of button text when disabled, // buttonColorRest color ID of button face at rest, // buttonColorTouched color ID of button face when touched, // buttonColorDisabled color ID of button face when disabled, // commonBGColor color ID of common background color (possibly used when button set to "remove") // widgetIndex font widget ID of button text (not supported before firmware V1.06) // Output: none // Assumes: "verbose" mode off void ezLCD_SetThemeID(unsigned short themeID, unsigned short embossDkColor, unsigned short embossLtColor, unsigned short textColorRest, unsigned short textColorTouched, unsigned short textColorDisabled, unsigned short buttonColorRest, unsigned short buttonColorTouched, unsigned short buttonColorDisabled, unsigned short commonBGColor, unsigned short widgetIndex){ char reply[40]; // temporary string holds LCD response if(themeID > 15){ // verify valid parameter return; // error: cannot have theme ID greater than 15 } UART_OutString("THEME "); // initialize desired theme // send the theme index number UART_OutUDec((unsigned long)themeID); UART_OutString(" "); // send the color ID of button shadow UART_OutUDec((unsigned long)embossDkColor); UART_OutString(" "); // send the color ID of button highlight UART_OutUDec((unsigned long)embossLtColor); UART_OutString(" "); // send the color ID of button text at rest UART_OutUDec((unsigned long)textColorRest); UART_OutString(" "); // send the color ID of button text when touched UART_OutUDec((unsigned long)textColorTouched); UART_OutString(" "); // send the color ID of button text when disabled UART_OutUDec((unsigned long)textColorDisabled); UART_OutString(" "); // send the color ID of button face at rest UART_OutUDec((unsigned long)buttonColorRest); UART_OutString(" "); // send the color ID of button face when touched UART_OutUDec((unsigned long)buttonColorTouched); UART_OutString(" "); // send the color ID of button face when disabled UART_OutUDec((unsigned long)buttonColorDisabled); UART_OutString(" "); // send the color ID of background color UART_OutUDec((unsigned long)commonBGColor); UART_OutString(" "); // send the font widget index number UART_OutUDec((unsigned long)widgetIndex); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_Button------------ // Send "BUTTON id X Y w h option align radius theme text" // command to ezLCD-301. This creates a button with its // top left corner at the specified X and Y values with // the specified width and height (in pixels). The option // is one of the following: // buttonDraw, buttonDisable, buttonPress, buttonToggle // The label text alignment is one of the following: // buttonTxtCenter, buttonTxtRight, buttonTxtLeft, // buttonTxtBottom, buttonTxtTop // The radius is the amount of roundness in the button's // corners (in pixels). A radius of 0 creates a square // button. A radius of half the width or height creates // a round or hotdog shaped button. The theme index sets // the appearance of the button to the specified theme. // See ezLCD_SetThemeID(). The text is the text label on // the button. Finally, the pressFunc and releaseFunc are // pointers to functions which are called when the button // is pressed or released. Try to keep these functions // short, since they will be called from the UART // interrupt, and delays may cause the UART to miss data // from the ezLCD-301. Buttons still work if they are // covered by other graphics, but when the button is // pressed, it is automatically re-drawn, so the graphics // may need to be re-drawn also. All buttons are lost // when the screen is cleared. // Input: id button ID number (0 to MAXBUTTONS-1), // x top left corner X value (0 to 399), // y top left corner Y value (0 to 239), // width button width (pixels) (1 to 400), // height button height (pixels) (1 to 240), // option button option code // (buttonDraw, buttonDisable, // buttonPress, or buttonToggle), // align button text alignment code // (buttonTxtCenter, buttonTxtRight, // buttonTxtLeft, buttonTxtBottom, // or buttonTxtTop), // radius corner smoothing radius (pixels) // (0 to width/2) or (0 to height/2) // whichever is smaller, // theme button theme index (0 to 15), // textLabel NULL terminated string to label button, // pressFunc function to call when button is pressed, // releaseFunc function to call when button is released // Output: none // Assumes: "verbose" mode off // Modifies: ezLCD string variable void ezLCD_Button(unsigned char id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, enum buttonoption option, enum buttonalign align, unsigned short radius, unsigned short theme, char *textLabel, void (*pressFunc)(void), void (*releaseFunc)(void)){ char reply[40]; // temporary string holds LCD response if(id >= MAXBUTTONS){ // verify valid parameter return; // error: cannot have button ID that large } Buttons[id].label = textLabel; Buttons[id].callPress = pressFunc; Buttons[id].callRel = releaseFunc; // options buttonPress and buttonToggle should not change button status if((option != buttonPress) && (option != buttonToggle)){ Buttons[id].option = option; } UART_OutString("STRING "); // set desired string variable UART_OutUDec((unsigned long)id); // send the string index number UART_OutString(" \""); UART_OutString(textLabel); // send the string text // CR character completes command and get max of 40 characters from LCD UART_OutCommand("\"\r", reply, 40); UART_OutString("BUTTON "); // draw desired button UART_OutUDec((unsigned long)id); // send the button index number UART_OutString(" "); UART_OutUDec((unsigned long)x); // send the button top left corner X value UART_OutString(" "); UART_OutUDec((unsigned long)y); // send the button top left corner Y value UART_OutString(" "); // send the button width UART_OutUDec((unsigned long)width); UART_OutString(" "); // send the button height UART_OutUDec((unsigned long)height); UART_OutString(" "); // send the button option code UART_OutUDec((unsigned long)option); UART_OutString(" "); // send the button text alignment code UART_OutUDec((unsigned long)align); UART_OutString(" "); // send the button corner smoothing radius UART_OutUDec((unsigned long)radius); UART_OutString(" "); // send the button theme index number UART_OutUDec((unsigned long)theme); UART_OutString(" "); // send the button text index number (same as id) UART_OutUDec((unsigned long)id); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD } //------------ezLCD_ButtonDefaultAction------------ // Default action for button responses. Currently does // nothing. // Input: none // Output: none void ezLCD_ButtonDefaultAction(void){ } //------------ezLCD_ButtonPress------------ // Function used by external programs to call a button's // "callPress" function. Before the function is called, // the button is checked that it is active and the function // is checked that it is not NULL. // Input: id button ID number of pressed button (1 to MAXBUTTONS-1) // Output: none void ezLCD_ButtonPress(unsigned char id){ if((Buttons[id].option == buttonDraw) && (Buttons[id].callPress != 0)){ Buttons[id].callPress(); } } //------------ezLCD_ButtonRelease------------ // Function used by external programs to call a button's // "callRel" function. Before the function is called, // the button is checked that it is active and the function // is checked that it is not NULL. // Input: id button ID number of pressed button (1 to MAXBUTTONS-1) // Output: none void ezLCD_ButtonRelease(unsigned char id){ if((Buttons[id].option == buttonDraw) && (Buttons[id].callRel != 0)){ Buttons[id].callRel(); } } //------------ezLCD_Picture------------ // Send "PICTURE 0 0 3 name" command to ezLCD-301. This // loads the .JPG, .GIF, or .BMP image and displays it // in the center of the screen. Plug the ezLCD-301 into // the USB port of a computer, load it like a removeable // drive, and copy the image into the ezLCD-301's 4 MB // flash memory in the directory "EZUSER\IMAGES". // Input: file NULL-terminated image file name // Output: none // Assumes: "verbose" mode off void ezLCD_Picture(char *file){ char reply[40]; // temporary string holds LCD response UART_OutString("PICTURE 0 0 3 ");// display desired picture UART_OutString(file); UART_OutCommand("\r", reply, 40);// CR character completes command and get max of 40 characters from LCD }