IHM
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG
main.cpp@0:d0499d2eac3a, 2021-07-07 (annotated)
- Committer:
- Nanaud
- Date:
- Wed Jul 07 20:32:01 2021 +0000
- Revision:
- 0:d0499d2eac3a
IHM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nanaud | 0:d0499d2eac3a | 1 | #include "main.h" |
Nanaud | 0:d0499d2eac3a | 2 | |
Nanaud | 0:d0499d2eac3a | 3 | /* LCD */ |
Nanaud | 0:d0499d2eac3a | 4 | LCD_DISCO_F746NG lcd; |
Nanaud | 0:d0499d2eac3a | 5 | |
Nanaud | 0:d0499d2eac3a | 6 | /* TS */ |
Nanaud | 0:d0499d2eac3a | 7 | TS_DISCO_F746NG ts; |
Nanaud | 0:d0499d2eac3a | 8 | |
Nanaud | 0:d0499d2eac3a | 9 | /* Serial */ |
Nanaud | 0:d0499d2eac3a | 10 | Serial pc(USBTX,USBRX); |
Nanaud | 0:d0499d2eac3a | 11 | Serial robot(PC_6,PC_7,115200); // D1,D0 Serial 6 |
Nanaud | 0:d0499d2eac3a | 12 | |
Nanaud | 0:d0499d2eac3a | 13 | /* Variables */ |
Nanaud | 0:d0499d2eac3a | 14 | uint16_t x = 0, y = 0; |
Nanaud | 0:d0499d2eac3a | 15 | bool port_depart = BLEU; |
Nanaud | 0:d0499d2eac3a | 16 | bool match_started = false; |
Nanaud | 0:d0499d2eac3a | 17 | bool robot_init = true; |
Nanaud | 0:d0499d2eac3a | 18 | uint8_t menu_select = MENU1; |
Nanaud | 0:d0499d2eac3a | 19 | |
Nanaud | 0:d0499d2eac3a | 20 | int main() |
Nanaud | 0:d0499d2eac3a | 21 | { |
Nanaud | 0:d0499d2eac3a | 22 | pc.printf("ARES21_IHM\r\n"); |
Nanaud | 0:d0499d2eac3a | 23 | |
Nanaud | 0:d0499d2eac3a | 24 | TS_StateTypeDef TS_State; |
Nanaud | 0:d0499d2eac3a | 25 | ts.Init(LARGEUR_LCD, HAUTEUR_LCD); |
Nanaud | 0:d0499d2eac3a | 26 | |
Nanaud | 0:d0499d2eac3a | 27 | lcd.Clear(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 28 | lcd.SetBackColor(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 29 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 30 | |
Nanaud | 0:d0499d2eac3a | 31 | lcd.SetFont(&Font24); |
Nanaud | 0:d0499d2eac3a | 32 | lcd.DisplayStringAt(0, 100, (uint8_t *)"Ares ENSEA", CENTER_MODE); |
Nanaud | 0:d0499d2eac3a | 33 | lcd.SetFont(&Font12); |
Nanaud | 0:d0499d2eac3a | 34 | lcd.DisplayStringAt(0, 150, (uint8_t *)"Coupe de France de robotique 2021", CENTER_MODE); |
Nanaud | 0:d0499d2eac3a | 35 | lcd.SetFont(&Font12); |
Nanaud | 0:d0499d2eac3a | 36 | lcd.DisplayStringAt(0, 200, (uint8_t *)"Robot en cours d'initialisation...", CENTER_MODE); |
Nanaud | 0:d0499d2eac3a | 37 | |
Nanaud | 0:d0499d2eac3a | 38 | wait(3); |
Nanaud | 0:d0499d2eac3a | 39 | aff_preparation(port_depart); |
Nanaud | 0:d0499d2eac3a | 40 | |
Nanaud | 0:d0499d2eac3a | 41 | while(1) { |
Nanaud | 0:d0499d2eac3a | 42 | |
Nanaud | 0:d0499d2eac3a | 43 | |
Nanaud | 0:d0499d2eac3a | 44 | ts.GetState(&TS_State); |
Nanaud | 0:d0499d2eac3a | 45 | if (TS_State.touchDetected) { |
Nanaud | 0:d0499d2eac3a | 46 | x = TS_State.touchX[0]; |
Nanaud | 0:d0499d2eac3a | 47 | y = TS_State.touchY[0]; |
Nanaud | 0:d0499d2eac3a | 48 | pc.printf("touchX = %d, touchY = %d\r\n",x,y); |
Nanaud | 0:d0499d2eac3a | 49 | |
Nanaud | 0:d0499d2eac3a | 50 | switch(menu_select) { |
Nanaud | 0:d0499d2eac3a | 51 | case MENU1 : |
Nanaud | 0:d0499d2eac3a | 52 | if (x >= 25 && x <= 225 && y >= 68 && y <= 194) { |
Nanaud | 0:d0499d2eac3a | 53 | wait_unpressed(TS_State); |
Nanaud | 0:d0499d2eac3a | 54 | port_depart = !port_depart; |
Nanaud | 0:d0499d2eac3a | 55 | if (port_depart == JAUNE) robot.printf("J\n"); |
Nanaud | 0:d0499d2eac3a | 56 | else robot.printf("B\n"); |
Nanaud | 0:d0499d2eac3a | 57 | |
Nanaud | 0:d0499d2eac3a | 58 | aff_preparation(port_depart); |
Nanaud | 0:d0499d2eac3a | 59 | } else if(x >= 255 && x <= 455 && y >= 68 && y <= 194) { |
Nanaud | 0:d0499d2eac3a | 60 | wait_unpressed(TS_State); |
Nanaud | 0:d0499d2eac3a | 61 | menu_select = MENU2; |
Nanaud | 0:d0499d2eac3a | 62 | aff_score(); |
Nanaud | 0:d0499d2eac3a | 63 | } else if(x >= 145 && x <= 345 && y >= 212 && y <= 262) { |
Nanaud | 0:d0499d2eac3a | 64 | if(match_started == 0) { |
Nanaud | 0:d0499d2eac3a | 65 | wait_unpressed(TS_State); |
Nanaud | 0:d0499d2eac3a | 66 | menu_select = MENU1; |
Nanaud | 0:d0499d2eac3a | 67 | robot.printf("M\n"); |
Nanaud | 0:d0499d2eac3a | 68 | match_started = true; |
Nanaud | 0:d0499d2eac3a | 69 | aff_preparation(port_depart); |
Nanaud | 0:d0499d2eac3a | 70 | } |
Nanaud | 0:d0499d2eac3a | 71 | } |
Nanaud | 0:d0499d2eac3a | 72 | break; |
Nanaud | 0:d0499d2eac3a | 73 | |
Nanaud | 0:d0499d2eac3a | 74 | case MENU2 : |
Nanaud | 0:d0499d2eac3a | 75 | if(x >= 420 && x <= 470 && y >= 10 && y <= 60) { |
Nanaud | 0:d0499d2eac3a | 76 | wait_unpressed(TS_State); |
Nanaud | 0:d0499d2eac3a | 77 | menu_select = MENU1; |
Nanaud | 0:d0499d2eac3a | 78 | aff_preparation(port_depart); |
Nanaud | 0:d0499d2eac3a | 79 | } else { |
Nanaud | 0:d0499d2eac3a | 80 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 81 | lcd.FillCircle(x, y, 10); |
Nanaud | 0:d0499d2eac3a | 82 | } |
Nanaud | 0:d0499d2eac3a | 83 | |
Nanaud | 0:d0499d2eac3a | 84 | break; |
Nanaud | 0:d0499d2eac3a | 85 | |
Nanaud | 0:d0499d2eac3a | 86 | case MENU3 : |
Nanaud | 0:d0499d2eac3a | 87 | if(x >= 255 && x <= 455 && y >= 212 && y <= 262) { |
Nanaud | 0:d0499d2eac3a | 88 | wait_unpressed(TS_State); |
Nanaud | 0:d0499d2eac3a | 89 | menu_select = MENU1; |
Nanaud | 0:d0499d2eac3a | 90 | aff_preparation(port_depart); |
Nanaud | 0:d0499d2eac3a | 91 | } |
Nanaud | 0:d0499d2eac3a | 92 | break; |
Nanaud | 0:d0499d2eac3a | 93 | |
Nanaud | 0:d0499d2eac3a | 94 | default : |
Nanaud | 0:d0499d2eac3a | 95 | break; |
Nanaud | 0:d0499d2eac3a | 96 | } |
Nanaud | 0:d0499d2eac3a | 97 | } |
Nanaud | 0:d0499d2eac3a | 98 | } |
Nanaud | 0:d0499d2eac3a | 99 | } |
Nanaud | 0:d0499d2eac3a | 100 | |
Nanaud | 0:d0499d2eac3a | 101 | int decodeMsgRobot(char *buffer) |
Nanaud | 0:d0499d2eac3a | 102 | { |
Nanaud | 0:d0499d2eac3a | 103 | switch(buffer[0]) { |
Nanaud | 0:d0499d2eac3a | 104 | case 'I' : |
Nanaud | 0:d0499d2eac3a | 105 | robot_init = true; |
Nanaud | 0:d0499d2eac3a | 106 | aff_preparation(port_depart); |
Nanaud | 0:d0499d2eac3a | 107 | break; |
Nanaud | 0:d0499d2eac3a | 108 | default : |
Nanaud | 0:d0499d2eac3a | 109 | break; |
Nanaud | 0:d0499d2eac3a | 110 | } |
Nanaud | 0:d0499d2eac3a | 111 | |
Nanaud | 0:d0499d2eac3a | 112 | return 0; |
Nanaud | 0:d0499d2eac3a | 113 | } |
Nanaud | 0:d0499d2eac3a | 114 | |
Nanaud | 0:d0499d2eac3a | 115 | void wait_unpressed(TS_StateTypeDef TS_State) |
Nanaud | 0:d0499d2eac3a | 116 | { |
Nanaud | 0:d0499d2eac3a | 117 | do { |
Nanaud | 0:d0499d2eac3a | 118 | ts.GetState(&TS_State); |
Nanaud | 0:d0499d2eac3a | 119 | } while(TS_State.touchDetected); |
Nanaud | 0:d0499d2eac3a | 120 | } |
Nanaud | 0:d0499d2eac3a | 121 | |
Nanaud | 0:d0499d2eac3a | 122 | void aff_preparation(bool port_depart) |
Nanaud | 0:d0499d2eac3a | 123 | { |
Nanaud | 0:d0499d2eac3a | 124 | lcd.Clear(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 125 | lcd.SetBackColor(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 126 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 127 | lcd.SetFont(&Font24); |
Nanaud | 0:d0499d2eac3a | 128 | lcd.DisplayStringAt(0, 20, (uint8_t *)"Preparation d'avant match", CENTER_MODE); |
Nanaud | 0:d0499d2eac3a | 129 | |
Nanaud | 0:d0499d2eac3a | 130 | if (port_depart == JAUNE) lcd.SetTextColor(LCD_COLOR_YELLOW); |
Nanaud | 0:d0499d2eac3a | 131 | else lcd.SetTextColor(LCD_COLOR_BLUE); |
Nanaud | 0:d0499d2eac3a | 132 | lcd.FillRect(25, 68, 200, 126); |
Nanaud | 0:d0499d2eac3a | 133 | |
Nanaud | 0:d0499d2eac3a | 134 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 135 | lcd.FillRect(255, 68, 200, 126); |
Nanaud | 0:d0499d2eac3a | 136 | lcd.SetBackColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 137 | lcd.SetTextColor(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 138 | lcd.DisplayStringAt(312, 125, (uint8_t *)"Score", LEFT_MODE); |
Nanaud | 0:d0499d2eac3a | 139 | |
Nanaud | 0:d0499d2eac3a | 140 | if (match_started == 0) { |
Nanaud | 0:d0499d2eac3a | 141 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 142 | lcd.FillRect(145, 212, 200, 50); |
Nanaud | 0:d0499d2eac3a | 143 | lcd.SetBackColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 144 | lcd.SetTextColor(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 145 | lcd.DisplayStringAt(170, 229, (uint8_t *)"(Tirette)", LEFT_MODE); |
Nanaud | 0:d0499d2eac3a | 146 | } |
Nanaud | 0:d0499d2eac3a | 147 | } |
Nanaud | 0:d0499d2eac3a | 148 | |
Nanaud | 0:d0499d2eac3a | 149 | void aff_score() |
Nanaud | 0:d0499d2eac3a | 150 | { |
Nanaud | 0:d0499d2eac3a | 151 | lcd.Clear(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 152 | |
Nanaud | 0:d0499d2eac3a | 153 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 154 | lcd.FillCircle(445, 35, 25); |
Nanaud | 0:d0499d2eac3a | 155 | |
Nanaud | 0:d0499d2eac3a | 156 | lcd.SetBackColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 157 | lcd.SetTextColor(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 158 | lcd.SetFont(&Font12); |
Nanaud | 0:d0499d2eac3a | 159 | lcd.DisplayStringAt(425, 30, (uint8_t *)"Retour", LEFT_MODE); |
Nanaud | 0:d0499d2eac3a | 160 | } |
Nanaud | 0:d0499d2eac3a | 161 | |
Nanaud | 0:d0499d2eac3a | 162 | void aff_tests() |
Nanaud | 0:d0499d2eac3a | 163 | { |
Nanaud | 0:d0499d2eac3a | 164 | lcd.Clear(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 165 | |
Nanaud | 0:d0499d2eac3a | 166 | lcd.SetBackColor(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 167 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 168 | lcd.SetFont(&Font24); |
Nanaud | 0:d0499d2eac3a | 169 | lcd.DisplayStringAt(0, 20, (uint8_t *)"Preparation d'avant match", CENTER_MODE); |
Nanaud | 0:d0499d2eac3a | 170 | |
Nanaud | 0:d0499d2eac3a | 171 | lcd.SetBackColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 172 | lcd.SetTextColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 173 | lcd.FillRect(255, 212, 200, 50); |
Nanaud | 0:d0499d2eac3a | 174 | |
Nanaud | 0:d0499d2eac3a | 175 | lcd.SetBackColor(LCD_COLOR_WHITE); |
Nanaud | 0:d0499d2eac3a | 176 | lcd.SetTextColor(LCD_COLOR_BLACK); |
Nanaud | 0:d0499d2eac3a | 177 | lcd.SetFont(&Font24); |
Nanaud | 0:d0499d2eac3a | 178 | lcd.DisplayStringAt(305, 229, (uint8_t *)"Retour", LEFT_MODE); |
Nanaud | 0:d0499d2eac3a | 179 | } |