new graphics and user input

Dependencies:   BSP_DISCO_F769NI

Committer:
asingh2
Date:
Wed Jul 29 21:58:36 2020 +0000
Revision:
3:3a1eea2b8d4d
Parent:
2:2becc6f12303
New graphics and user input added (touch)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jeromecoutant 0:cc2802bc7c1b 1 #include "mbed.h"
asingh2 3:3a1eea2b8d4d 2 #include "stm32f769i_discovery_lcd.h"
jeromecoutant 0:cc2802bc7c1b 3 #include "stm32f769i_discovery.h"
jeromecoutant 0:cc2802bc7c1b 4 #include "stm32f769i_discovery_ts.h"
jeromecoutant 0:cc2802bc7c1b 5
jeromecoutant 0:cc2802bc7c1b 6 TS_StateTypeDef TS_State = {0};
jeromecoutant 0:cc2802bc7c1b 7
asingh2 3:3a1eea2b8d4d 8 uint32_t Xsize = 0;
asingh2 3:3a1eea2b8d4d 9 uint32_t Ysize = 0;
asingh2 3:3a1eea2b8d4d 10
asingh2 3:3a1eea2b8d4d 11 Serial pc(USBTX, USBRX); // tx, rx
asingh2 3:3a1eea2b8d4d 12
asingh2 3:3a1eea2b8d4d 13 AnalogIn Ain(A0); //Read Analog input
asingh2 3:3a1eea2b8d4d 14 AnalogIn Ain1(A1); //Read Analog input 1
asingh2 3:3a1eea2b8d4d 15 AnalogIn Ain2(A2); //Read Analog input 2
asingh2 3:3a1eea2b8d4d 16 DigitalIn user(USER_BUTTON); //Read user button
asingh2 3:3a1eea2b8d4d 17 DigitalOut myLED(LED1); //Toggle LED on if button is pressed
asingh2 3:3a1eea2b8d4d 18
asingh2 3:3a1eea2b8d4d 19 float ADCdata = 0;
asingh2 3:3a1eea2b8d4d 20 float vibdata = 0;
asingh2 3:3a1eea2b8d4d 21
asingh2 3:3a1eea2b8d4d 22 float datain[10000];
asingh2 3:3a1eea2b8d4d 23 float datain1[10000];
asingh2 3:3a1eea2b8d4d 24 int button_state=0;
asingh2 3:3a1eea2b8d4d 25
asingh2 3:3a1eea2b8d4d 26 /*
asingh2 3:3a1eea2b8d4d 27
asingh2 3:3a1eea2b8d4d 28 BSP_LCD_SetBackColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 29 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 30 BSP_LCD_SetTextColor(LCD_COLOR_BLACK);
asingh2 3:3a1eea2b8d4d 31 BSP_LCD_SetTextColor(LCD_COLOR_GRAY);
asingh2 3:3a1eea2b8d4d 32 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
asingh2 3:3a1eea2b8d4d 33 BSP_LCD_SetTextColor(LCD_COLOR_RED);
asingh2 3:3a1eea2b8d4d 34
asingh2 3:3a1eea2b8d4d 35 */
asingh2 3:3a1eea2b8d4d 36
jeromecoutant 0:cc2802bc7c1b 37 int main()
jeromecoutant 0:cc2802bc7c1b 38 {
jeromecoutant 0:cc2802bc7c1b 39 uint16_t x1, y1;
asingh2 3:3a1eea2b8d4d 40
jeromecoutant 0:cc2802bc7c1b 41 BSP_LCD_Init();
asingh2 3:3a1eea2b8d4d 42 // BSP_LCD_InitEx(LCD_ORIENTATION_PORTRAIT);
jeromecoutant 0:cc2802bc7c1b 43 BSP_LCD_LayerDefaultInit(0, LCD_FB_START_ADDRESS);
Jerome Coutant 2:2becc6f12303 44 BSP_LCD_SelectLayer(0);
jeromecoutant 0:cc2802bc7c1b 45
jeromecoutant 0:cc2802bc7c1b 46 /* Touchscreen initialization */
jeromecoutant 0:cc2802bc7c1b 47 if (BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()) == TS_ERROR) {
jeromecoutant 0:cc2802bc7c1b 48 printf("BSP_TS_Init error\n");
asingh2 3:3a1eea2b8d4d 49 }
asingh2 3:3a1eea2b8d4d 50 Xsize = BSP_LCD_GetXSize();
asingh2 3:3a1eea2b8d4d 51 Ysize = BSP_LCD_GetYSize();
asingh2 3:3a1eea2b8d4d 52 BSP_LCD_Clear(LCD_COLOR_ORANGE);
asingh2 3:3a1eea2b8d4d 53 BSP_LCD_SetTextColor(LCD_COLOR_DARKBLUE);
asingh2 3:3a1eea2b8d4d 54 BSP_LCD_SetBackColor(LCD_COLOR_ORANGE);
asingh2 3:3a1eea2b8d4d 55 BSP_LCD_SetFont(&Font24);
asingh2 3:3a1eea2b8d4d 56
asingh2 3:3a1eea2b8d4d 57 BSP_LCD_DisplayStringAt(40,75 , (uint8_t *)"BD", CENTER_MODE);
jeromecoutant 0:cc2802bc7c1b 58 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 59 BSP_LCD_DisplayStringAt(0, 250, (uint8_t *)"ThrillSeeker Fistula Health Monitor", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 60
asingh2 3:3a1eea2b8d4d 61 HAL_Delay(2000);
asingh2 3:3a1eea2b8d4d 62
asingh2 3:3a1eea2b8d4d 63 BSP_LCD_Clear(LCD_COLOR_DARKBLUE);
asingh2 3:3a1eea2b8d4d 64 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 65 BSP_LCD_SetBackColor(LCD_COLOR_DARKBLUE);
jeromecoutant 0:cc2802bc7c1b 66 BSP_LCD_SetFont(&Font24);
asingh2 3:3a1eea2b8d4d 67 BSP_LCD_DisplayStringAt(0, 150, (uint8_t *)"Detection Ready: Place armband on Fistula Arm", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 68 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
asingh2 3:3a1eea2b8d4d 69 BSP_LCD_DisplayStringAt(0, 250, (uint8_t *)"Press OK when ready", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 70
asingh2 3:3a1eea2b8d4d 71 BSP_LCD_FillRect(437, 375, 75, 75);
asingh2 3:3a1eea2b8d4d 72 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 73 BSP_LCD_DisplayStringAt(72, 400, (uint8_t *)" OK", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 74
asingh2 3:3a1eea2b8d4d 75
jeromecoutant 0:cc2802bc7c1b 76 while (1) {
asingh2 3:3a1eea2b8d4d 77
asingh2 3:3a1eea2b8d4d 78 BSP_TS_GetState(&TS_State);
asingh2 3:3a1eea2b8d4d 79 if (TS_State.touchDetected) {
asingh2 3:3a1eea2b8d4d 80 x1 = TS_State.touchX[0];
jeromecoutant 0:cc2802bc7c1b 81 y1 = TS_State.touchY[0];
asingh2 3:3a1eea2b8d4d 82 pc.printf("Touch Detected x=%d y=%d\n", x1, y1);
asingh2 3:3a1eea2b8d4d 83 BSP_LCD_SetTextColor(LCD_COLOR_ORANGE);
asingh2 3:3a1eea2b8d4d 84 BSP_LCD_FillCircle(x1, y1, 2);
asingh2 3:3a1eea2b8d4d 85
asingh2 3:3a1eea2b8d4d 86 if ((475<x1<525) && (350<y1<400))
asingh2 3:3a1eea2b8d4d 87 button_state=1;
asingh2 3:3a1eea2b8d4d 88 //else button_state=0;
asingh2 3:3a1eea2b8d4d 89 HAL_Delay(100);}
asingh2 3:3a1eea2b8d4d 90 //button_state=user;
asingh2 3:3a1eea2b8d4d 91 if(button_state==1)
asingh2 3:3a1eea2b8d4d 92 {
asingh2 3:3a1eea2b8d4d 93 ADCdata=Ain;
jeromecoutant 0:cc2802bc7c1b 94
asingh2 3:3a1eea2b8d4d 95 vibdata = (Ain1 - Ain2) ;
asingh2 3:3a1eea2b8d4d 96 button_state=0;
asingh2 3:3a1eea2b8d4d 97 x1=0;
asingh2 3:3a1eea2b8d4d 98 y1=0;
asingh2 3:3a1eea2b8d4d 99
asingh2 3:3a1eea2b8d4d 100
asingh2 3:3a1eea2b8d4d 101 for(int count1 = 0; count1 < 10000; count1++)
asingh2 3:3a1eea2b8d4d 102 { datain1[count1]=vibdata;
asingh2 3:3a1eea2b8d4d 103 if (datain1[count1]>vibdata)
asingh2 3:3a1eea2b8d4d 104 vibdata=datain1[count1];
asingh2 3:3a1eea2b8d4d 105 else vibdata=vibdata;
asingh2 3:3a1eea2b8d4d 106
asingh2 3:3a1eea2b8d4d 107 }
asingh2 3:3a1eea2b8d4d 108
asingh2 3:3a1eea2b8d4d 109 for(int count = 0; count < 10000; count++)
asingh2 3:3a1eea2b8d4d 110 { datain[count]=ADCdata;
asingh2 3:3a1eea2b8d4d 111 if (datain[count]>ADCdata)
asingh2 3:3a1eea2b8d4d 112 ADCdata=datain[count];
asingh2 3:3a1eea2b8d4d 113 else ADCdata=ADCdata;
asingh2 3:3a1eea2b8d4d 114 }
asingh2 3:3a1eea2b8d4d 115
asingh2 3:3a1eea2b8d4d 116 /* pc.printf("\n Button State: %d", button_state);
asingh2 3:3a1eea2b8d4d 117 pc.printf("\n Microphone Data: %f ",ADCdata);
asingh2 3:3a1eea2b8d4d 118 pc.printf("\n Vibration Data: %f", vibdata);*/
asingh2 3:3a1eea2b8d4d 119
asingh2 3:3a1eea2b8d4d 120 vibdata=abs(vibdata);
asingh2 3:3a1eea2b8d4d 121 pc.printf("\n Vibration Data: %f", vibdata);
asingh2 3:3a1eea2b8d4d 122
asingh2 3:3a1eea2b8d4d 123 if (vibdata<0.1) {
asingh2 3:3a1eea2b8d4d 124
asingh2 3:3a1eea2b8d4d 125 vibdata=0;
asingh2 3:3a1eea2b8d4d 126 BSP_LCD_Clear(LCD_COLOR_ORANGE);
asingh2 3:3a1eea2b8d4d 127 BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
asingh2 3:3a1eea2b8d4d 128 BSP_LCD_SetBackColor(LCD_COLOR_ORANGE);
asingh2 3:3a1eea2b8d4d 129 BSP_LCD_DisplayStringAt(0, 150, (uint8_t *)"Fistula is Normal", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 130 //HAL_Delay(200);
asingh2 3:3a1eea2b8d4d 131
asingh2 3:3a1eea2b8d4d 132 }
asingh2 3:3a1eea2b8d4d 133
asingh2 3:3a1eea2b8d4d 134 else if ((0.1 <= vibdata) && (vibdata <0.2)) {
asingh2 3:3a1eea2b8d4d 135 vibdata=0;
asingh2 3:3a1eea2b8d4d 136 BSP_LCD_Clear(LCD_COLOR_ORANGE);
asingh2 3:3a1eea2b8d4d 137 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 138 BSP_LCD_SetBackColor(LCD_COLOR_ORANGE);
asingh2 3:3a1eea2b8d4d 139 BSP_LCD_DisplayStringAt(0, 150, (uint8_t *)"Potential Occlusion to occur soon.", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 140 BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)"Fistula health at 75%", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 141 // HAL_Delay(5000);
asingh2 3:3a1eea2b8d4d 142
asingh2 3:3a1eea2b8d4d 143 }
asingh2 3:3a1eea2b8d4d 144
asingh2 3:3a1eea2b8d4d 145 else if (vibdata>= 0.2){
asingh2 3:3a1eea2b8d4d 146 vibdata=0;
asingh2 3:3a1eea2b8d4d 147 BSP_LCD_Clear(LCD_COLOR_RED);
asingh2 3:3a1eea2b8d4d 148 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 149 BSP_LCD_SetBackColor(LCD_COLOR_RED);
asingh2 3:3a1eea2b8d4d 150 BSP_LCD_DisplayStringAt(0, 150, (uint8_t *)"Abnormality detected: Please Consult Physician", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 151 // HAL_Delay(5000);
asingh2 3:3a1eea2b8d4d 152
asingh2 3:3a1eea2b8d4d 153 }
asingh2 3:3a1eea2b8d4d 154 vibdata=0;
asingh2 3:3a1eea2b8d4d 155 /* if (ADCdata<0.202) {
asingh2 3:3a1eea2b8d4d 156
asingh2 3:3a1eea2b8d4d 157 ADCdata=0;
asingh2 3:3a1eea2b8d4d 158 BSP_LCD_Clear(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 159 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 160 BSP_LCD_SetBackColor(LCD_COLOR_GRAY);
asingh2 3:3a1eea2b8d4d 161 BSP_LCD_SetFont(&Font24);
asingh2 3:3a1eea2b8d4d 162 BSP_LCD_DisplayStringAt(0, 150, (uint8_t *)"Fistula is Normal", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 163 HAL_Delay(20000);
asingh2 3:3a1eea2b8d4d 164
asingh2 3:3a1eea2b8d4d 165 }
asingh2 3:3a1eea2b8d4d 166
asingh2 3:3a1eea2b8d4d 167 else if ((0.202 <= ADCdata) && (ADCdata <0.85)) {
asingh2 3:3a1eea2b8d4d 168 ADCdata=0;
asingh2 3:3a1eea2b8d4d 169 BSP_LCD_Clear(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 170 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 171 BSP_LCD_SetBackColor(LCD_COLOR_GRAY);
asingh2 3:3a1eea2b8d4d 172 BSP_LCD_SetFont(&Font24);
asingh2 3:3a1eea2b8d4d 173
asingh2 3:3a1eea2b8d4d 174 BSP_LCD_DisplayStringAt(0, 150, (uint8_t *)"Potential Occlusion to occur soon.", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 175 BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)"Fistula health at xx%", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 176 HAL_Delay(20000);
asingh2 3:3a1eea2b8d4d 177 }
asingh2 3:3a1eea2b8d4d 178
asingh2 3:3a1eea2b8d4d 179 else if (ADCdata>= 0.85){
asingh2 3:3a1eea2b8d4d 180 ADCdata=0;
asingh2 3:3a1eea2b8d4d 181 BSP_LCD_Clear(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 182 BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
asingh2 3:3a1eea2b8d4d 183 BSP_LCD_SetBackColor(LCD_COLOR_GRAY);
asingh2 3:3a1eea2b8d4d 184 BSP_LCD_SetFont(&Font24);
asingh2 3:3a1eea2b8d4d 185
asingh2 3:3a1eea2b8d4d 186 BSP_LCD_DisplayStringAt(0, 150, (uint8_t *)"Abnormality detected: Please Consult Physician", CENTER_MODE);
asingh2 3:3a1eea2b8d4d 187 HAL_Delay(20000);
asingh2 3:3a1eea2b8d4d 188
asingh2 3:3a1eea2b8d4d 189 }*/
asingh2 3:3a1eea2b8d4d 190
asingh2 3:3a1eea2b8d4d 191 }
jeromecoutant 0:cc2802bc7c1b 192 }
asingh2 3:3a1eea2b8d4d 193 }