Personal Test Environment
Dependencies: LCD_DISCO_F746NG TS_DISCO_F746NG mbed
main.cpp@1:c00262e1ef4c, 2018-03-06 (annotated)
- Committer:
- DirtyGray
- Date:
- Tue Mar 06 18:32:34 2018 +0000
- Revision:
- 1:c00262e1ef4c
- Parent:
- 0:bab80a319f0d
Personal test environment
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DirtyGray | 0:bab80a319f0d | 1 | #include "mbed.h" |
DirtyGray | 0:bab80a319f0d | 2 | #include "TS_DISCO_F746NG.h" |
DirtyGray | 0:bab80a319f0d | 3 | #include "LCD_DISCO_F746NG.h" |
DirtyGray | 0:bab80a319f0d | 4 | #include "globals.h" |
DirtyGray | 0:bab80a319f0d | 5 | |
DirtyGray | 0:bab80a319f0d | 6 | #include "drawMe.h" |
DirtyGray | 0:bab80a319f0d | 7 | #include "pixelRun.h" |
DirtyGray | 0:bab80a319f0d | 8 | #include "TempSense.h" |
DirtyGray | 0:bab80a319f0d | 9 | |
DirtyGray | 0:bab80a319f0d | 10 | void showButton(uint32_t, uint32_t, int, uint8_t *); |
DirtyGray | 0:bab80a319f0d | 11 | |
DirtyGray | 0:bab80a319f0d | 12 | uint16_t butHeight = 80; |
DirtyGray | 0:bab80a319f0d | 13 | uint16_t butWidth = 80; |
DirtyGray | 0:bab80a319f0d | 14 | |
DirtyGray | 0:bab80a319f0d | 15 | //LCD_DISCO_F746NG LCDscreen; |
DirtyGray | 0:bab80a319f0d | 16 | //TS_DISCO_F746NG LCDtouchScreen; |
DirtyGray | 0:bab80a319f0d | 17 | |
DirtyGray | 0:bab80a319f0d | 18 | int main() |
DirtyGray | 0:bab80a319f0d | 19 | { |
DirtyGray | 0:bab80a319f0d | 20 | //init LCD screen |
DirtyGray | 0:bab80a319f0d | 21 | TS_StateTypeDef touchStatus; |
DirtyGray | 0:bab80a319f0d | 22 | LCDtouchScreen.Init(LCDscreen.GetXSize(), LCDscreen.GetYSize()); |
DirtyGray | 0:bab80a319f0d | 23 | |
DirtyGray | 0:bab80a319f0d | 24 | //set button text |
DirtyGray | 0:bab80a319f0d | 25 | uint8_t but1Text[30] = " Draw Game"; |
DirtyGray | 0:bab80a319f0d | 26 | uint8_t but2Text[30] = " Pixel Run"; |
DirtyGray | 0:bab80a319f0d | 27 | uint8_t but3Text[30] = "Temperature"; |
DirtyGray | 0:bab80a319f0d | 28 | |
DirtyGray | 0:bab80a319f0d | 29 | //set background to black |
DirtyGray | 0:bab80a319f0d | 30 | LCDscreen.Clear(LCD_COLOR_BLACK); |
DirtyGray | 0:bab80a319f0d | 31 | |
DirtyGray | 0:bab80a319f0d | 32 | //draw buttons |
DirtyGray | 0:bab80a319f0d | 33 | showButton(LCD_COLOR_BLUE, LCD_COLOR_WHITE, 1, but1Text); //draw |
DirtyGray | 0:bab80a319f0d | 34 | showButton(LCD_COLOR_GREEN, LCD_COLOR_WHITE, 2, but2Text); //pixel |
DirtyGray | 0:bab80a319f0d | 35 | showButton(LCD_COLOR_YELLOW, LCD_COLOR_WHITE, 3, but3Text); //temperature |
DirtyGray | 0:bab80a319f0d | 36 | |
DirtyGray | 0:bab80a319f0d | 37 | //loop that checks for button presses |
DirtyGray | 0:bab80a319f0d | 38 | while(1) { |
DirtyGray | 0:bab80a319f0d | 39 | LCDtouchScreen.GetState(&touchStatus); |
DirtyGray | 0:bab80a319f0d | 40 | if (touchStatus.touchDetected) { |
DirtyGray | 0:bab80a319f0d | 41 | if ((touchStatus.touchX[0] <= 80) && (touchStatus.touchY[0] <= 80)) { |
DirtyGray | 0:bab80a319f0d | 42 | drawGame(); |
DirtyGray | 0:bab80a319f0d | 43 | } else if ((touchStatus.touchX[0] <= 80) && (touchStatus.touchY[0] <= 160)) { |
DirtyGray | 0:bab80a319f0d | 44 | pixelScan(); |
DirtyGray | 0:bab80a319f0d | 45 | } else if ((touchStatus.touchX[0] <= 80) && (touchStatus.touchY[0] <= 240)){ |
DirtyGray | 0:bab80a319f0d | 46 | tempDisplay(); |
DirtyGray | 0:bab80a319f0d | 47 | } |
DirtyGray | 0:bab80a319f0d | 48 | } |
DirtyGray | 0:bab80a319f0d | 49 | } |
DirtyGray | 0:bab80a319f0d | 50 | } |
DirtyGray | 0:bab80a319f0d | 51 | |
DirtyGray | 0:bab80a319f0d | 52 | void showButton(uint32_t backColor, uint32_t textColor, int position, uint8_t *text) |
DirtyGray | 0:bab80a319f0d | 53 | { |
DirtyGray | 0:bab80a319f0d | 54 | LCDscreen.SetBackColor(backColor); |
DirtyGray | 0:bab80a319f0d | 55 | LCDscreen.SetTextColor(backColor); |
DirtyGray | 0:bab80a319f0d | 56 | LCDscreen.SetFont(&Font12); |
DirtyGray | 0:bab80a319f0d | 57 | |
DirtyGray | 0:bab80a319f0d | 58 | if (position == 1) { |
DirtyGray | 0:bab80a319f0d | 59 | LCDscreen.FillRect(0, 0, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 60 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 61 | LCDscreen.DisplayStringAt(0, 40, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 62 | } else if (position == 2) { |
DirtyGray | 0:bab80a319f0d | 63 | LCDscreen.FillRect(0, 80, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 64 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 65 | LCDscreen.DisplayStringAt(0, 120, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 66 | } else if (position == 3) { |
DirtyGray | 0:bab80a319f0d | 67 | LCDscreen.FillRect(0, 160, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 68 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 69 | LCDscreen.DisplayStringAt(0, 200, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 70 | } else if (position == 4) { |
DirtyGray | 0:bab80a319f0d | 71 | LCDscreen.FillRect(80, 0, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 72 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 73 | LCDscreen.DisplayStringAt(80, 40, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 74 | } else if (position == 5) { |
DirtyGray | 0:bab80a319f0d | 75 | LCDscreen.FillRect(80, 80, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 76 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 77 | LCDscreen.DisplayStringAt(80, 120, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 78 | } else if (position == 6) { |
DirtyGray | 0:bab80a319f0d | 79 | LCDscreen.FillRect(80, 160, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 80 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 81 | LCDscreen.DisplayStringAt(80, 200, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 82 | } else if (position == 7) { |
DirtyGray | 0:bab80a319f0d | 83 | LCDscreen.FillRect(160, 0, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 84 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 85 | LCDscreen.DisplayStringAt(160, 40, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 86 | } else if (position == 8) { |
DirtyGray | 0:bab80a319f0d | 87 | LCDscreen.FillRect(160, 80, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 88 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 89 | LCDscreen.DisplayStringAt(160, 120, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 90 | } else if (position == 9) { |
DirtyGray | 0:bab80a319f0d | 91 | LCDscreen.FillRect(160, 160, butWidth, butHeight); |
DirtyGray | 0:bab80a319f0d | 92 | LCDscreen.SetTextColor(textColor); |
DirtyGray | 0:bab80a319f0d | 93 | LCDscreen.DisplayStringAt(160, 200, text, LEFT_MODE); |
DirtyGray | 0:bab80a319f0d | 94 | } |
DirtyGray | 0:bab80a319f0d | 95 | } |