static void drawBody(void){ // Method for displaying the body of the hangman RIT128x96x4ImageDraw(g_pucBody, 36, 24, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 25, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 26, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 27, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 28, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 29, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 30, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 31, 2, 1); RIT128x96x4ImageDraw(g_pucBody, 36, 32, 2, 1); }
static void clearPointer(int y){ // Method for clearing a pointer int i; for (i=0; i<50; i++){ RIT128x96x4ImageDraw(g_clearPointer, 0, y+i, 4, 15); } }
static void drawLeftLeg(void){ // Method for displaying the left leg of the hangman RIT128x96x4ImageDraw(g_pucLeg2, 36, 33, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 38, 34, 2, 1); RIT128x96x4ImageDraw(g_pucLeg2, 38, 35, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 40, 36, 2, 1); RIT128x96x4ImageDraw(g_pucLeg2, 40, 37, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 42, 38, 2, 1); RIT128x96x4ImageDraw(g_pucLeg2, 42, 39, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 44, 40, 2, 1); }
static void drawRightLeg(void){ // Method for displaying the right leg of the hangman RIT128x96x4ImageDraw(g_pucLeg2, 34, 33, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 34, 34, 2, 1); RIT128x96x4ImageDraw(g_pucLeg2, 32, 35, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 32, 36, 2, 1); RIT128x96x4ImageDraw(g_pucLeg2, 30, 37, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 30, 38, 2, 1); RIT128x96x4ImageDraw(g_pucLeg2, 28, 39, 2, 1); RIT128x96x4ImageDraw(g_pucLeg1, 28, 40, 2, 1); }
static void drawPointer(int y){ // Method for drawing a pointer RIT128x96x4ImageDraw(g_pucPointer1, 0, y, 4, 1); RIT128x96x4ImageDraw(g_pucPointer2, 0, y+1, 4, 1); RIT128x96x4ImageDraw(g_pucPointer3, 0, y+2, 4, 1); RIT128x96x4ImageDraw(g_pucPointer4, 0, y+3, 4, 1); RIT128x96x4ImageDraw(g_pucPointer5, 0, y+4, 4, 1); RIT128x96x4ImageDraw(g_pucPointer6, 0, y+5, 4, 1); RIT128x96x4ImageDraw(g_pucPointer7, 0, y+6, 4, 1); }
//***************************************************************************** // //! Colors a pixel on the oLED display //! //! This function will color a pixel the current color on the oLED display //! //! //! \return None. // //***************************************************************************** void RIT128x96x4DrawDot(unsigned long xpos, unsigned long ypos){ unsigned char *pucRow; const unsigned char dotBufferRight[] = {0x0F}; const unsigned char dotBufferLeft[] = {0x0F}; if((xpos % 2) == 0) { pucRow = (unsigned char *)&dotBufferLeft[0]; } else { pucRow = (unsigned char *)&dotBufferRight[0]; xpos--; } RIT128x96x4ImageDraw(pucRow, xpos, ypos, 2, 1); }
// *************** RIT128x96x4ShowPlot ******************** // Used in all the plots to write buffer to LED // Example 1 Voltage versus time // RIT128x96x4PlotClear(0,1023); // range from 0 to 1023 // RIT128x96x4PlotPoint(data); RIT128x96x4PlotNext(); // called 108 times // RIT128x96x4ShowPlot(); // Example 2 Voltage versus time (N data points/pixel, time scale) // RIT128x96x4PlotClear(0,1023); // range from 0 to 1023 // { // RIT128x96x4PlotPoint(data); // called N times // RIT128x96x4PlotNext(); // } // called 108 times // RIT128x96x4ShowPlot(); // Example 3 Voltage versus frequency (512 points) // perform FFT to get 512 magnitudes // RIT128x96x4PlotClear(0,511); // parameters ignored // { // RIT128x96x4PlotPoint(mag); // called 4 times // RIT128x96x4PlotPoint(mag); // RIT128x96x4PlotPoint(mag); // RIT128x96x4PlotPoint(mag); // RIT128x96x4PlotNext(); // } // called 128 times // RIT128x96x4ShowPlot(); // Inputs: none // Outputs: none void RIT128x96x4ShowPlot(void){ RIT128x96x4ImageDraw(PlotImage, 16, 10, 112, 80); }
void RIT128x96x4ShowPlotFreq(void){ RIT128x96x4ImageDraw(PlotFreqImag, 0, 10, 128, 80); }
static void removeUnderscore(int x, int y){ // Method for removing an underscore from the display RIT128x96x4ImageDraw(g_pucUnderscoreClear, x, y, 128, 1); }
static void drawUnderscore(int x, int y){ // Method for displaying an underline RIT128x96x4ImageDraw(g_pucUnderscore, x, y, 6, 1); }
static void drawRightArm(void){ // Method for displaying the right arm of the handman RIT128x96x4ImageDraw(g_pucRightArm, 28, 27, 8, 1); }
static void drawLeftArm(void){ // Method for displaying the left arm of the hangman RIT128x96x4ImageDraw(g_pucLeftArm, 36, 27, 10, 1); }
// The function to generate and hold the initial start screen //Note, this function does not have a while loop, nor does it set a "vTaskDelay", meaning //it will only execute once. //This is reflected in the way we use it in main; we call it a single time as a part of //our system set up (as a blocking task), and then we enter the task scheduler loop void startScreen(){ /* * The RIT128x96x4** functions are a part of the driver API for the OLED * The details for this API can be found in drivers/rit128x96x4.c * * Create a frame for the OLED display * The ImageDraw function takes an array of unsigned char * each 8-bit char represents 2 pixels (side-by-side) * so, 4 of these bits represent a single pixel's brightness * with valid brightness values ranging (0-15) * and the pixels are represented in pairs. * * Since the pixels are represented in pairs along the horizontal, * and the OLED is 128x96 pixels, * the horizontal frame only needs 64 elements (64 * 2 = 128). * However the vertical frames will require two separate arrays, * each will have 94 elements (the OLED is 96 pixels high * but we have taken care of the two ends with the horizontal lines) * The left frame will set the right column of pixels to zero, * and the right frame will set the left column of pixels to zero. * The blank array elements are initialized to 0 to turn-off pixels later. * It only needs 62 elements because we don't want to erase the frame. */ unsigned char lframe[94], rframe[94], hframe[64], blank[62]; // The loop is used to initialize the arrays unsigned int i; for(i = 0; i < 94; i++){ lframe[i] = 0xF0; // Vertical line for the left edge rframe[i] = 0x0F; // Vertical line for the right edge if(i < 64) hframe[i] = 0xFF; // Horizontal line for top and bottom if(i < 62) blank[i] = 0x00; // The blank line used to clear the screen } // Initialize the OLED display RIT128x96x4Init(1000000); /* * Draw the frame * ImageDraw takes an array of unsigned char as the first argument * the next two arguments are the x and y coordinates (respectively) * of the screen position to start drawing, and the final two arguments * are the width and height (respectively) to which the image is scaled. */ // Draw upper frame starting at (0,0) with width = 128 pixels and height = 1 pixel // (width and height should match the size of array measured in pixels) RIT128x96x4ImageDraw(hframe, 0, 0, 128, 1); // Draws lower frame starting at (0,95) width = 128, height = 1 RIT128x96x4ImageDraw(hframe, 0, 95, 128, 1); // Draws left frame starting at (0,1) width = 2, height = 94 RIT128x96x4ImageDraw(lframe, 0, 1, 2, 94); // Draws right frame starting at (127,1) width = 2, height = 94 RIT128x96x4ImageDraw(rframe, 127, 1, 2, 94); /* * Draw the message * StringDraw takes a string as the first argument * the next two arguments are again the x and y coordinates of the starting position * and the final argument is pixel brightness for the * The first function writes the first part of the message at (32,24) * with a brightness of 15 (full brightness) */ RIT128x96x4StringDraw(" Press the", 32, 24, 15); RIT128x96x4StringDraw("\"Select\" Button", 16, 33, 15); RIT128x96x4StringDraw("To Continue", 32, 42, 15); // Enable the select button, wait for the press, then reset and disable the port // The button is disabled after the splash screen and the port is reset to default for future use. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); GPIOPinTypeGPIOInput(GPIO_PORTG_BASE, GPIO_PIN_7); // Set the select button signal PG7 as input while(GPIOPinRead(GPIO_PORTG_BASE, GPIO_PIN_7)); // Wait until the signal changes (button pressed) SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOG); SysCtlPeripheralDisable(SYSCTL_PERIPH_GPIOG); /* * When the select button is pressed we need to wipe the message leaving the frame on the OLED. * The loop sets the pixels to 0 everywhere except the screen's edges. */ for(i = 24; i < 50; i++) RIT128x96x4ImageDraw(blank, 2, i, 124, 1); }
//*************RIT128x96x4_ShowImage************************************** // Copies the RAM version of the image to the OLED // Inputs: none // Outputs: none void RIT128x96x4_ShowImage(void){ RIT128x96x4ImageDraw(*bitmap, 0, 0, NUM_COLS, NUM_ROWS); }
static void drawHead(void){ // Method for displaying the head of the hangman RIT128x96x4ImageDraw(g_pucHead13, 28, 11, 18, 1); RIT128x96x4ImageDraw(g_pucHead12, 28, 12, 18, 1); RIT128x96x4ImageDraw(g_pucHead11, 28, 13, 18, 1); RIT128x96x4ImageDraw(g_pucHead10, 28, 14, 18, 1); RIT128x96x4ImageDraw(g_pucHead9, 28, 15, 18, 1); RIT128x96x4ImageDraw(g_pucHead8, 28, 16, 18, 1); RIT128x96x4ImageDraw(g_pucHead7, 28, 17, 18, 1); RIT128x96x4ImageDraw(g_pucHead6, 28, 18, 18, 1); RIT128x96x4ImageDraw(g_pucHead5, 28, 19, 18, 1); RIT128x96x4ImageDraw(g_pucHead4, 28, 20, 18, 1); RIT128x96x4ImageDraw(g_pucHead3, 28, 21, 18, 1); RIT128x96x4ImageDraw(g_pucHead2, 28, 22, 18, 1); RIT128x96x4ImageDraw(g_pucHead1, 28, 23, 18, 1); }
static void drawGallow(void){ // method for displaying the gallow RIT128x96x4ImageDraw(g_pucLogo1, 10, 50, 32, 1); RIT128x96x4ImageDraw(g_pucLogo2, 10, 49, 32, 1); RIT128x96x4ImageDraw(g_pucLogo3, 10, 48, 32, 1); RIT128x96x4ImageDraw(g_pucLogo4, 10, 47, 32, 1); RIT128x96x4ImageDraw(g_pucLogo5, 10, 46, 32, 1); RIT128x96x4ImageDraw(g_pucLogo6, 10, 45, 32, 1); RIT128x96x4ImageDraw(g_pucLogo7, 10, 44, 8, 1); RIT128x96x4ImageDraw(g_pucLogo8, 10, 43, 8, 1); RIT128x96x4ImageDraw(g_pucLogo9, 10, 42, 8, 1); RIT128x96x4ImageDraw(g_pucLogo10, 10, 41, 8, 1); RIT128x96x4ImageDraw(g_pucLogo11, 10, 40, 8, 1); RIT128x96x4ImageDraw(g_pucLogo12, 10, 39, 8, 1); RIT128x96x4ImageDraw(g_pucLogo13, 10, 38, 8, 1); RIT128x96x4ImageDraw(g_pucLogo14, 10, 37, 8, 1); RIT128x96x4ImageDraw(g_pucLogo15, 10, 36, 8, 1); RIT128x96x4ImageDraw(g_pucLogo16, 10, 35, 8, 1); RIT128x96x4ImageDraw(g_pucLogo17, 10, 34, 8, 1); RIT128x96x4ImageDraw(g_pucLogo18, 10, 33, 8, 1); RIT128x96x4ImageDraw(g_pucLogo19, 10, 32, 8, 1); RIT128x96x4ImageDraw(g_pucLogo20, 10, 31, 8, 1); RIT128x96x4ImageDraw(g_pucLogo21, 10, 30, 8, 1); RIT128x96x4ImageDraw(g_pucLogo22, 10, 29, 8, 1); RIT128x96x4ImageDraw(g_pucLogo23, 10, 28, 8, 1); RIT128x96x4ImageDraw(g_pucLogo24, 10, 27, 8, 1); RIT128x96x4ImageDraw(g_pucLogo25, 10, 26, 8, 1); RIT128x96x4ImageDraw(g_pucLogo26, 10, 25, 8, 1); RIT128x96x4ImageDraw(g_pucLogo27, 10, 24, 8, 1); RIT128x96x4ImageDraw(g_pucLogo28, 10, 23, 8, 1); RIT128x96x4ImageDraw(g_pucLogo29, 10, 22, 8, 1); RIT128x96x4ImageDraw(g_pucLogo30, 10, 21, 8, 1); RIT128x96x4ImageDraw(g_pucLogo31, 10, 20, 8, 1); RIT128x96x4ImageDraw(g_pucLogo32, 10, 19, 8, 1); RIT128x96x4ImageDraw(g_pucLogo33, 10, 18, 8, 1); RIT128x96x4ImageDraw(g_pucLogo34, 10, 17, 8, 1); RIT128x96x4ImageDraw(g_pucLogo35, 10, 16, 8, 1); RIT128x96x4ImageDraw(g_pucLogo36, 10, 15, 8, 1); RIT128x96x4ImageDraw(g_pucLogo37, 10, 14, 10, 1); RIT128x96x4ImageDraw(g_pucLogo38, 10, 13, 10, 1); RIT128x96x4ImageDraw(g_pucLogo39, 10, 12, 12, 1); RIT128x96x4ImageDraw(g_pucLogo40, 10, 11, 12, 1); RIT128x96x4ImageDraw(g_pucLogo41, 10, 10, 28, 1); RIT128x96x4ImageDraw(g_pucLogo42, 10, 9, 28, 1); RIT128x96x4ImageDraw(g_pucLogo43, 10, 8, 28, 1); RIT128x96x4ImageDraw(g_pucLogo44, 10, 7, 28, 1); RIT128x96x4ImageDraw(g_pucLogo45, 10, 6, 32, 1); RIT128x96x4ImageDraw(g_pucLogo46, 10, 5, 32, 1); RIT128x96x4ImageDraw(g_pucLogo47, 10, 4, 32, 1); RIT128x96x4ImageDraw(g_pucLogo48, 10, 3, 32, 1); }
//***************************************************************************** // // Helper Functions // //***************************************************************************** static void drawLogo(void){ // Method for displaying the Hangman logo int x0 = (128-72)/2; RIT128x96x4ImageDraw(g_pucHangman1, x0, 20, 72, 1); RIT128x96x4ImageDraw(g_pucHangman2, x0, 21, 72, 1); RIT128x96x4ImageDraw(g_pucHangman3, x0, 22, 72, 1); RIT128x96x4ImageDraw(g_pucHangman4, x0, 23, 72, 1); RIT128x96x4ImageDraw(g_pucHangman5, x0, 24, 72, 1); RIT128x96x4ImageDraw(g_pucHangman6, x0, 25, 72, 1); RIT128x96x4ImageDraw(g_pucHangman7, x0, 26, 72, 1); RIT128x96x4ImageDraw(g_pucHangman8, x0, 27, 72, 1); RIT128x96x4ImageDraw(g_pucHangman9, x0, 28, 72, 1); RIT128x96x4ImageDraw(g_pucHangman10, x0, 29, 72, 1); RIT128x96x4ImageDraw(g_pucHangman11, x0, 30, 72, 1); RIT128x96x4ImageDraw(g_pucHangman12, x0, 31, 72, 1); RIT128x96x4ImageDraw(g_pucHangman13, x0, 32, 72, 1); RIT128x96x4ImageDraw(g_pucHangman14, x0, 33, 72, 1); RIT128x96x4ImageDraw(g_pucHangman15, x0, 34, 72, 1); RIT128x96x4ImageDraw(g_pucHangman16, x0, 35, 72, 1); RIT128x96x4ImageDraw(g_pucHangman17, x0, 36, 72, 1); RIT128x96x4ImageDraw(g_pucHangman18, x0, 37, 72, 1); }
//*************RIT128x96x4_ShowImage************************************** // Copies the RAM version of the image to the OLED // Inputs: none // Outputs: none void RIT128x96x4_ShowImage(void){ RIT128x96x4ImageDraw((unsigned char*)buffer, 0, 0, 128, 96); }
//***************************************************************************** // // Displays a logo for a specified amount of time. // //***************************************************************************** static void DisplayLogo(const unsigned char *pucLogo, unsigned long ulWidth, unsigned long ulHeight, unsigned long ulDelay) { unsigned char *pucDest, ucHigh, ucLow; unsigned long ulLoop1, ulLoop2; const unsigned char *pucSrc; long lIdx; // // Loop through thirty two intensity levels to fade the logo in from black. // for(lIdx = 1; lIdx <= 32; lIdx++) { // // Clear the local frame buffer. // for(ulLoop1 = 0; ulLoop1 < sizeof(g_pucFrame); ulLoop1 += 4) { *(unsigned long *)(g_pucFrame + ulLoop1) = 0; } // // Get a pointer to the beginning of the logo. // pucSrc = pucLogo; // // Get a point to the upper left corner of the frame buffer where the // logo will be placed. // pucDest = (g_pucFrame + (((96 - ulHeight) / 2) * 64) + ((128 - ulWidth) / 4)); // // Copy the logo into the frame buffer, scaling the intensity. Loop // over the rows. // for(ulLoop1 = 0; ulLoop1 < ulHeight; ulLoop1++) { // // Loop over the columns. // for(ulLoop2 = 0; ulLoop2 < (ulWidth / 2); ulLoop2++) { // // Get the two nibbles of the next byte from the source. // ucHigh = pucSrc[ulLoop2] >> 4; ucLow = pucSrc[ulLoop2] & 15; // // Scale the intensity of the two nibbles. // ucHigh = ((unsigned long)ucHigh * lIdx) / 32; ucLow = ((unsigned long)ucLow * lIdx) / 32; // // Write the two nibbles to the frame buffer. // pucDest[ulLoop2] = (ucHigh << 4) | ucLow; } // // Increment to the next row of the source and destination. // pucSrc += (ulWidth / 2); pucDest += 64; } // // Wait until an update has been requested. // while(HWREGBITW(&g_ulFlags, FLAG_UPDATE) == 0) { } // // Clear the update request flag. // HWREGBITW(&g_ulFlags, FLAG_UPDATE) = 0; // // Display the local frame buffer on the display. // RIT128x96x4ImageDraw(g_pucFrame, 0, 0, 128, 96); } // // Delay for the specified time while the logo is displayed. // Delay(ulDelay); // // Loop through the thirty two intensity levels to face the logo back to // black. // for(lIdx = 31; lIdx >= 0; lIdx--) { // // Clear the local frame buffer. // for(ulLoop1 = 0; ulLoop1 < sizeof(g_pucFrame); ulLoop1 += 4) { *(unsigned long *)(g_pucFrame + ulLoop1) = 0; } // // Get a pointer to the beginning of the logo. // pucSrc = pucLogo; // // Get a point to the upper left corner of the frame buffer where the // logo will be placed. // pucDest = (g_pucFrame + (((96 - ulHeight) / 2) * 64) + ((128 - ulWidth) / 4)); // // Copy the logo into the frame buffer, scaling the intensity. Loop // over the rows. // for(ulLoop1 = 0; ulLoop1 < ulHeight; ulLoop1++) { // // Loop over the columns. // for(ulLoop2 = 0; ulLoop2 < (ulWidth / 2); ulLoop2++) { // // Get the two nibbles of the next byte from the source. // ucHigh = pucSrc[ulLoop2] >> 4; ucLow = pucSrc[ulLoop2] & 15; // // Scale the intensity of the two nibbles. // ucHigh = ((unsigned long)ucHigh * lIdx) / 32; ucLow = ((unsigned long)ucLow * lIdx) / 32; // // Write the two nibbles to the frame buffer. // pucDest[ulLoop2] = (ucHigh << 4) | ucLow; } // // Increment to the next row of the source and destination. // pucSrc += (ulWidth / 2); pucDest += 64; } // // Wait until an update has been requested. // while(HWREGBITW(&g_ulFlags, FLAG_UPDATE) == 0) { } // // Clear the update request flag. // HWREGBITW(&g_ulFlags, FLAG_UPDATE) = 0; // // Display the local frame buffer on the display. // RIT128x96x4ImageDraw(g_pucFrame, 0, 0, 128, 96); } }