char* alphaShowDialogue(void) { char result; /* These need to be instantiated here since the width and height of the lcd is retrieved dynamically depending on screen orientation */ alphaBtnX[0] = ALPHA_COL1_LEFT; alphaBtnX[1] = ALPHA_COL2_LEFT; alphaBtnX[2] = ALPHA_COL3_LEFT; alphaBtnX[3] = ALPHA_COL4_LEFT; alphaBtnX[4] = ALPHA_COL5_LEFT; alphaBtnY[0] = ALPHA_ROW1_TOP; alphaBtnY[1] = ALPHA_ROW2_TOP; alphaBtnY[2] = ALPHA_ROW3_TOP; alphaBtnY[3] = ALPHA_ROW4_TOP; alphaBtnY[4] = ALPHA_ROW5_TOP; alphaBtnY[5] = ALPHA_ROW6_TOP; /* Initialise the string buffer */ memset(&alphaString[0], 0, sizeof(alphaString)); alphaString_ptr = alphaString; alphaPage = 0; /* Draw the background and render the buttons */ drawFill(ALPHA_COLOR_BACKGROUND); alphaRefreshScreen(); /* Capture results until the 'OK' button is pressed */ while(1) { result = alphaHandleTouchEvent(); if (result == '>') return (char *)&alphaString; } }
char* alphaShowDialogue(void) { char result; /* These need to be instantiated here since the width and height of the lcd is retrieved dynamically depending on screen orientation */ alphaBtnX[0] = ALPHA_COL1_LEFT; alphaBtnX[1] = ALPHA_COL2_LEFT; alphaBtnX[2] = ALPHA_COL3_LEFT; alphaBtnX[3] = ALPHA_COL4_LEFT; alphaBtnX[4] = ALPHA_COL5_LEFT; alphaBtnY[0] = ALPHA_ROW1_TOP; alphaBtnY[1] = ALPHA_ROW2_TOP; alphaBtnY[2] = ALPHA_ROW3_TOP; alphaBtnY[3] = ALPHA_ROW4_TOP; alphaBtnY[4] = ALPHA_ROW5_TOP; alphaBtnY[5] = ALPHA_ROW6_TOP; /* Initialise the string buffer */ memset(&alphaString[0], 0, sizeof(alphaString)); alphaString_ptr = alphaString; alphaPage = 0; /* Draw the background and render the buttons */ drawFill(COLOR_WHITE); drawRectangleFilled(0, ALPHA_KEYPAD_TOP - ALPHA_BTN_SPACING, lcdGetWidth() - 1, lcdGetHeight() - 1, COLOR_DARKGRAY); drawLine(0, (ALPHA_KEYPAD_TOP - ALPHA_BTN_SPACING) + 1, lcdGetWidth() - 1, (ALPHA_KEYPAD_TOP - ALPHA_BTN_SPACING) + 1, COLOR_LIGHTGRAY); alphaRefreshScreen(); /* Capture results until the 'OK' button is pressed */ while(1) { result = alphaHandleTouchEvent(); if (result == '>') return (char *)&alphaString; } }
char alphaHandleTouchEvent(void) { tsTouchData_t data; char result = '\0'; uint8_t row, col; int32_t tsError = -1; // Blocking delay until a valie touch event occurs while (tsError) { tsError = tsWaitForEvent(&data, 0); } // Attempt to convert touch data to char if ((data.y < ALPHA_ROW1_TOP) || (data.y > ALPHA_ROW6_TOP + ALPHA_BTN_HEIGHT)) { return result; } // Get column if ((data.x > alphaBtnX[0]) && (data.x < alphaBtnX[0] + ALPHA_BTN_WIDTH)) col = 0; else if ((data.x > alphaBtnX[1]) && (data.x < alphaBtnX[1] + ALPHA_BTN_WIDTH)) col = 1; else if ((data.x > alphaBtnX[2]) && (data.x < alphaBtnX[2] + ALPHA_BTN_WIDTH)) col = 2; else if ((data.x > alphaBtnX[3]) && (data.x < alphaBtnX[3] + ALPHA_BTN_WIDTH)) col = 3; else if ((data.x > ALPHA_COL5_LEFT) && (data.x < ALPHA_COL5_LEFT + ALPHA_BTN_WIDTH)) col = 4; else return result; // Get row if ((data.y > ALPHA_ROW1_TOP) && (data.y < ALPHA_ROW1_TOP + ALPHA_BTN_HEIGHT)) row = 0; else if ((data.y > ALPHA_ROW2_TOP) && (data.y < ALPHA_ROW2_TOP + ALPHA_BTN_HEIGHT)) row = 1; else if ((data.y > ALPHA_ROW3_TOP) && (data.y < ALPHA_ROW3_TOP + ALPHA_BTN_HEIGHT)) row = 2; else if ((data.y > ALPHA_ROW4_TOP) && (data.y < ALPHA_ROW4_TOP + ALPHA_BTN_HEIGHT)) row = 3; else if ((data.y > ALPHA_ROW5_TOP) && (data.y < ALPHA_ROW5_TOP + ALPHA_BTN_HEIGHT)) row = 4; else if ((data.y > ALPHA_ROW6_TOP) && (data.y < ALPHA_ROW6_TOP + ALPHA_BTN_HEIGHT)) row = 5; else return result; // Match found ... update button and process the results alphaRenderButton(alphaPage, col, row, true); result = alphaKeys[alphaPage][row][col]; if (result == '<') { // Trim character if backspace was pressed if (alphaString_ptr > alphaString) { alphaString_ptr--; *alphaString_ptr = '\0'; } } else if (result == '*') { // Switch page if the shift button was pressed alphaPage++; if (alphaPage > 3) { alphaPage = 0; } // Update the UI alphaRefreshScreen(); } else if (result == '>') { // OK button systickDelay(CFG_TFTLCD_TS_KEYPADDELAY); return '>'; } else { // Add text to string buffer *alphaString_ptr++ = result; } // Brief delay systickDelay(CFG_TFTLCD_TS_KEYPADDELAY); // Return button to deselected state alphaRefreshScreen(); return result; }