Nathan Leprevier / Mbed OS Grecordeur

Dependencies:   LCD_DISCO_F746NG GRecorder BSP_DISCO_F746NG

Committer:
nathanld
Date:
Thu Jun 16 10:04:10 2022 +0000
Revision:
7:349cc40eeb9c
Parent:
6:09e7353d7e54
code instrumentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JohnnyK 5:071136c3eefa 1 /**
JohnnyK 5:071136c3eefa 2 * Notebook page https://os.mbed.com/users/JohnnyK/notebook/how-start-with-the-littlevgl/
JohnnyK 5:071136c3eefa 3 */
JohnnyK 5:071136c3eefa 4
JohnnyK 0:10c4b83c458d 5 #include "mbed.h"
nathanld 6:09e7353d7e54 6 #include "MPU6050.h"
nathanld 6:09e7353d7e54 7 #include "LCD_DISCO_F746NG.h"
JohnnyK 0:10c4b83c458d 8 #include "lvgl/lvgl.h"
JohnnyK 3:4f5dc253eb7b 9 #include "hal_stm_lvgl/tft/tft.h"
JohnnyK 3:4f5dc253eb7b 10 #include "hal_stm_lvgl/touchpad/touchpad.h"
JohnnyK 5:071136c3eefa 11 #include "lv_demo.h" /*Comment/uncomment will switch between LVGL demo and Hello word example*/
JohnnyK 0:10c4b83c458d 12
JohnnyK 3:4f5dc253eb7b 13 #define LVGL_TICK 10 //Time tick value for lvgl in ms (1-10msa)
JohnnyK 3:4f5dc253eb7b 14 #define TICKER_TIME 10ms //modified to miliseconds
JohnnyK 0:10c4b83c458d 15
JohnnyK 3:4f5dc253eb7b 16 Ticker ticker; //Ticker for lvgl
JohnnyK 3:4f5dc253eb7b 17
nathanld 6:09e7353d7e54 18
JohnnyK 5:071136c3eefa 19 /*
JohnnyK 5:071136c3eefa 20 * Callback function for lvgl timing.
JohnnyK 5:071136c3eefa 21 * Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10).
JohnnyK 5:071136c3eefa 22 * It is required for the internal timing of LittlevGL.
JohnnyK 5:071136c3eefa 23 */
JohnnyK 0:10c4b83c458d 24 void lv_ticker_func(){
JohnnyK 0:10c4b83c458d 25 lv_tick_inc(LVGL_TICK);
JohnnyK 0:10c4b83c458d 26 }
JohnnyK 0:10c4b83c458d 27
nathanld 6:09e7353d7e54 28 //definition des connexion serie
nathanld 6:09e7353d7e54 29 //Serial pc(USBTX, USBRX);
nathanld 6:09e7353d7e54 30
nathanld 6:09e7353d7e54 31
nathanld 6:09e7353d7e54 32 //I2C test(I2C_SDA, I2C_SCL);
nathanld 6:09e7353d7e54 33 const int addr = 0x68;
nathanld 6:09e7353d7e54 34
nathanld 6:09e7353d7e54 35 //acquisition position angulaire
nathanld 6:09e7353d7e54 36 float accelero[3]= {1};
nathanld 6:09e7353d7e54 37 float gyro[3]= {1};
nathanld 6:09e7353d7e54 38 float temperature =0;
nathanld 6:09e7353d7e54 39 float MAAccelero[3]= {0,0,0};
nathanld 6:09e7353d7e54 40 float MIAccelero[3]= {0,0,0};
nathanld 6:09e7353d7e54 41 int i=0;
nathanld 6:09e7353d7e54 42
nathanld 6:09e7353d7e54 43
nathanld 6:09e7353d7e54 44 MPU6050 module(D14,D15);
nathanld 6:09e7353d7e54 45
nathanld 6:09e7353d7e54 46 static void event_MAX(lv_event_t* e)
nathanld 6:09e7353d7e54 47 {
nathanld 6:09e7353d7e54 48 LV_LOG_USER("btn_max et min was Clicked");
nathanld 6:09e7353d7e54 49
nathanld 6:09e7353d7e54 50
nathanld 6:09e7353d7e54 51
nathanld 6:09e7353d7e54 52 }
nathanld 6:09e7353d7e54 53
nathanld 6:09e7353d7e54 54
JohnnyK 5:071136c3eefa 55 static void event_handler(lv_event_t* event)
JohnnyK 3:4f5dc253eb7b 56 {
JohnnyK 5:071136c3eefa 57 lv_event_code_t code = lv_event_get_code(event);
JohnnyK 5:071136c3eefa 58 if(code == LV_EVENT_CLICKED) {
JohnnyK 3:4f5dc253eb7b 59 printf("Clicked\n");
nathanld 6:09e7353d7e54 60
nathanld 6:09e7353d7e54 61 MAAccelero[0]= 0;
nathanld 6:09e7353d7e54 62 MAAccelero[1]= 0;
nathanld 6:09e7353d7e54 63 MAAccelero[2]= 0;
nathanld 6:09e7353d7e54 64
JohnnyK 3:4f5dc253eb7b 65 }
JohnnyK 5:071136c3eefa 66 else if(code == LV_EVENT_VALUE_CHANGED) {
JohnnyK 3:4f5dc253eb7b 67 printf("Toggled\n");
JohnnyK 0:10c4b83c458d 68 }
JohnnyK 1:627f26953c53 69 }
nathanld 6:09e7353d7e54 70
nathanld 6:09e7353d7e54 71
nathanld 6:09e7353d7e54 72
JohnnyK 3:4f5dc253eb7b 73 // main() runs in its own thread in the OS
JohnnyK 0:10c4b83c458d 74 int main()
JohnnyK 0:10c4b83c458d 75 {
nathanld 6:09e7353d7e54 76
nathanld 6:09e7353d7e54 77 //changement du l'echelle du module
nathanld 6:09e7353d7e54 78 module.setGyroRange(MPU6050_GYRO_RANGE_2000);
nathanld 6:09e7353d7e54 79 module.setAcceleroRange(MPU6050_ACCELERO_RANGE_16G);
nathanld 6:09e7353d7e54 80
nathanld 6:09e7353d7e54 81 //Event lorsqu'appuie sur bouton MIN/MAX
nathanld 6:09e7353d7e54 82
nathanld 6:09e7353d7e54 83
JohnnyK 3:4f5dc253eb7b 84 printf("LVGL-");
JohnnyK 3:4f5dc253eb7b 85 lv_init(); //Initialize the LVGL
JohnnyK 3:4f5dc253eb7b 86 tft_init(); //Initialize diplay
JohnnyK 3:4f5dc253eb7b 87 touchpad_init(); //Initialize touchpad
JohnnyK 3:4f5dc253eb7b 88 ticker.attach(callback(&lv_ticker_func),TICKER_TIME); //Attach callback to ticker
JohnnyK 3:4f5dc253eb7b 89
nathanld 6:09e7353d7e54 90 LV_IMG_DECLARE(Logoiut);
nathanld 6:09e7353d7e54 91
JohnnyK 3:4f5dc253eb7b 92 printf("Hello world\n");
nathanld 6:09e7353d7e54 93
nathanld 6:09e7353d7e54 94 /*lv_obj_t * label1 = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 95 lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); //Break the long lines
nathanld 6:09e7353d7e54 96 lv_label_set_recolor(label1, true); //Enable re-coloring by commands in the text
JohnnyK 3:4f5dc253eb7b 97 lv_label_set_text(label1, "#0000ff Hello# #ff00ff world# #ff0000 - the LVGL and MbedOS#");
JohnnyK 3:4f5dc253eb7b 98 lv_obj_set_width(label1, 150);
nathanld 6:09e7353d7e54 99 lv_obj_align(label1, LV_ALIGN_TOP_MID, 0, 20);*/
nathanld 6:09e7353d7e54 100
nathanld 6:09e7353d7e54 101 //Circular scroll
JohnnyK 5:071136c3eefa 102 lv_obj_t * label2 = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 103 lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR);
nathanld 6:09e7353d7e54 104 lv_obj_set_width(label2, 300);
nathanld 6:09e7353d7e54 105 lv_label_set_text(label2, "IUT CACHAN - Enregistreur de g - Leprevier-Destas Nathan - LP MECSE -");
nathanld 6:09e7353d7e54 106 lv_obj_align(label2, LV_ALIGN_BOTTOM_MID, -30, 0);
JohnnyK 0:10c4b83c458d 107
nathanld 6:09e7353d7e54 108
JohnnyK 0:10c4b83c458d 109 lv_obj_t * label;
nathanld 6:09e7353d7e54 110
nathanld 6:09e7353d7e54 111 //Bouton MAX/MIN
JohnnyK 5:071136c3eefa 112 lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
JohnnyK 5:071136c3eefa 113 lv_obj_add_event_cb(btn2, event_handler,LV_EVENT_ALL, NULL);
nathanld 6:09e7353d7e54 114 lv_obj_align(btn2, LV_ALIGN_TOP_LEFT, 25, 5);
JohnnyK 5:071136c3eefa 115 label = lv_label_create(btn2);
nathanld 6:09e7353d7e54 116 lv_label_set_text(label, "Reset Valeurs Max");
nathanld 6:09e7353d7e54 117
nathanld 6:09e7353d7e54 118 //Logo IUT
nathanld 6:09e7353d7e54 119 lv_obj_t * img = lv_img_create(lv_scr_act());
nathanld 6:09e7353d7e54 120 lv_img_set_src(img, &Logoiut);
nathanld 6:09e7353d7e54 121 lv_obj_set_width(img, 250);
nathanld 6:09e7353d7e54 122 lv_obj_align(img, LV_ALIGN_TOP_RIGHT, -5, 7);
nathanld 6:09e7353d7e54 123
nathanld 6:09e7353d7e54 124 //MAX GX
nathanld 6:09e7353d7e54 125 lv_obj_t * labelMaxX = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 126 lv_label_set_recolor(labelMaxX, true); //Enable re-coloring by commands in the text
nathanld 6:09e7353d7e54 127 lv_label_set_text(labelMaxX, "#0080ff MAX# G sur #0080ff Axe X :#");
nathanld 6:09e7353d7e54 128 lv_obj_set_width(labelMaxX, 200);
nathanld 6:09e7353d7e54 129 lv_obj_align(labelMaxX, LV_ALIGN_TOP_RIGHT, -5, 70);
nathanld 6:09e7353d7e54 130
nathanld 6:09e7353d7e54 131 //MAX GY
nathanld 6:09e7353d7e54 132 lv_obj_t * labelMaxY = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 133 lv_label_set_recolor(labelMaxY, true); //Enable re-coloring by commands in the text
nathanld 6:09e7353d7e54 134 lv_label_set_text(labelMaxY, "#0080ff MAX G# sur #0080ff Axe Y :#");
nathanld 6:09e7353d7e54 135 lv_obj_set_width(labelMaxY, 200);
nathanld 6:09e7353d7e54 136 lv_obj_align(labelMaxY, LV_ALIGN_CENTER, 138, 0);
nathanld 6:09e7353d7e54 137
nathanld 6:09e7353d7e54 138 //MAX GZ
nathanld 6:09e7353d7e54 139 lv_obj_t * labelMaxZ = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 140 lv_label_set_recolor(labelMaxZ, true); //Enable re-coloring by commands in the text
nathanld 6:09e7353d7e54 141 lv_label_set_text(labelMaxZ, "#0080ff MAX G# sur #0080ff Axe Z :#");
nathanld 6:09e7353d7e54 142 lv_obj_set_width(labelMaxZ, 200);
nathanld 6:09e7353d7e54 143 lv_obj_align(labelMaxZ, LV_ALIGN_BOTTOM_RIGHT, -5, -70);
nathanld 6:09e7353d7e54 144
nathanld 6:09e7353d7e54 145 //MIN GX
nathanld 6:09e7353d7e54 146 lv_obj_t * labelMinX = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 147 lv_label_set_recolor(labelMinX, true); //Enable re-coloring by commands in the text
nathanld 6:09e7353d7e54 148 lv_label_set_text(labelMinX, "G sur #ff0000 Axe X :#");
nathanld 6:09e7353d7e54 149 lv_obj_set_width(labelMinX, 200);
nathanld 6:09e7353d7e54 150 lv_obj_align(labelMinX, LV_ALIGN_TOP_LEFT, 10, 70);
nathanld 6:09e7353d7e54 151
nathanld 6:09e7353d7e54 152 //MIN GY
nathanld 6:09e7353d7e54 153 lv_obj_t * labelMinY = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 154 lv_label_set_recolor(labelMinY, true); //Enable re-coloring by commands in the text
nathanld 6:09e7353d7e54 155 lv_label_set_text(labelMinY, "G sur #ff0000 Axe Y :#");
nathanld 6:09e7353d7e54 156 lv_obj_set_width(labelMinY, 200);
nathanld 6:09e7353d7e54 157 lv_obj_align(labelMinY, LV_ALIGN_CENTER, -130, 0);
nathanld 6:09e7353d7e54 158
nathanld 6:09e7353d7e54 159 //MIN GZ
nathanld 6:09e7353d7e54 160 lv_obj_t * labelMinZ = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 161 lv_label_set_recolor(labelMinZ, true); //Enable re-coloring by commands in the text
nathanld 6:09e7353d7e54 162 lv_label_set_text(labelMinZ, "G sur #ff0000 Axe Z :#");
nathanld 6:09e7353d7e54 163 lv_obj_set_width(labelMinZ, 200);
nathanld 6:09e7353d7e54 164 lv_obj_align(labelMinZ, LV_ALIGN_BOTTOM_LEFT, 10, -70);
nathanld 6:09e7353d7e54 165
nathanld 6:09e7353d7e54 166 //VALEUR MAX GX
nathanld 6:09e7353d7e54 167 lv_obj_t * labelMaxXV = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 168 lv_label_set_text_fmt(labelMaxXV, "MX");
nathanld 6:09e7353d7e54 169 lv_obj_set_width(labelMaxXV, 200);
nathanld 6:09e7353d7e54 170 lv_obj_align(labelMaxXV, LV_ALIGN_TOP_RIGHT, 125,70);
nathanld 6:09e7353d7e54 171
nathanld 6:09e7353d7e54 172 //VALEUR MAX GY
nathanld 6:09e7353d7e54 173 lv_obj_t * labelMaxYV = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 174 lv_label_set_text_fmt(labelMaxYV, "MX");
nathanld 6:09e7353d7e54 175 lv_obj_set_width(labelMaxYV, 200);
nathanld 6:09e7353d7e54 176 lv_obj_align(labelMaxYV, LV_ALIGN_CENTER, 267,0);
nathanld 6:09e7353d7e54 177
nathanld 6:09e7353d7e54 178 //VALEUR MAX GZ
nathanld 6:09e7353d7e54 179 lv_obj_t * labelMaxZV = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 180 lv_label_set_text_fmt(labelMaxZV, "MX");
nathanld 6:09e7353d7e54 181 lv_obj_set_width(labelMaxZV, 200);
nathanld 6:09e7353d7e54 182 lv_obj_align(labelMaxZV, LV_ALIGN_BOTTOM_RIGHT, 125,-70);
nathanld 6:09e7353d7e54 183
nathanld 6:09e7353d7e54 184 //VALEUR Direct GX
nathanld 6:09e7353d7e54 185 lv_obj_t * labelMinXV = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 186 lv_label_set_text_fmt(labelMinXV, "MX");
nathanld 6:09e7353d7e54 187 lv_obj_set_width(labelMinXV, 200);
nathanld 6:09e7353d7e54 188 lv_obj_align(labelMinXV, LV_ALIGN_TOP_LEFT, 105,70);
nathanld 6:09e7353d7e54 189
nathanld 6:09e7353d7e54 190 //VALEUR Direct GY
nathanld 6:09e7353d7e54 191 lv_obj_t * labelMinYV = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 192 lv_label_set_text_fmt(labelMinYV, "MX");
nathanld 6:09e7353d7e54 193 lv_obj_set_width(labelMinYV, 200);
nathanld 6:09e7353d7e54 194 lv_obj_align(labelMinYV, LV_ALIGN_CENTER, -35, 0);
nathanld 6:09e7353d7e54 195
nathanld 6:09e7353d7e54 196 //VALEUR Direct GZ
nathanld 6:09e7353d7e54 197 lv_obj_t * labelMinZV = lv_label_create(lv_scr_act());
nathanld 6:09e7353d7e54 198 lv_label_set_text_fmt(labelMinZV, "MX");
nathanld 6:09e7353d7e54 199 lv_obj_set_width(labelMinZV, 200);
nathanld 6:09e7353d7e54 200 lv_obj_align(labelMinZV, LV_ALIGN_BOTTOM_LEFT, 105,-70);
nathanld 6:09e7353d7e54 201
nathanld 6:09e7353d7e54 202
nathanld 6:09e7353d7e54 203
JohnnyK 3:4f5dc253eb7b 204 while (true){
nathanld 6:09e7353d7e54 205 module.getAccelero(accelero);
JohnnyK 3:4f5dc253eb7b 206 lv_task_handler();
JohnnyK 3:4f5dc253eb7b 207 //Call lv_task_handler() periodically every few milliseconds.
JohnnyK 3:4f5dc253eb7b 208 //It will redraw the screen if required, handle input devices etc.
nathanld 6:09e7353d7e54 209 thread_sleep_for(LVGL_TICK);
nathanld 6:09e7353d7e54 210
nathanld 6:09e7353d7e54 211 fabs(accelero[0]);
nathanld 6:09e7353d7e54 212 fabs(accelero[1]);
nathanld 6:09e7353d7e54 213 fabs(accelero[2]);
nathanld 6:09e7353d7e54 214
nathanld 7:349cc40eeb9c 215 accelero[0] = accelero[0]/9,81;
nathanld 7:349cc40eeb9c 216 accelero[1] = accelero[1]/9,81;
nathanld 7:349cc40eeb9c 217 accelero[2] = accelero[2]/9,81;
nathanld 7:349cc40eeb9c 218
nathanld 6:09e7353d7e54 219 if (accelero[0] < 0){
nathanld 6:09e7353d7e54 220 fabs(accelero[0]);
nathanld 6:09e7353d7e54 221 }
nathanld 6:09e7353d7e54 222
nathanld 6:09e7353d7e54 223 if (accelero[1] < 0){
nathanld 6:09e7353d7e54 224 accelero[1] = !accelero[1];
nathanld 6:09e7353d7e54 225 }
nathanld 6:09e7353d7e54 226
nathanld 6:09e7353d7e54 227 if (accelero[2] < 0){
nathanld 6:09e7353d7e54 228 accelero[2] = !accelero[2];
nathanld 6:09e7353d7e54 229 }
nathanld 6:09e7353d7e54 230
nathanld 6:09e7353d7e54 231 if (accelero[0] > MAAccelero[0]){
nathanld 6:09e7353d7e54 232 MAAccelero[0] = accelero[0];
nathanld 6:09e7353d7e54 233 }
nathanld 6:09e7353d7e54 234
nathanld 6:09e7353d7e54 235 if (accelero[1] > MAAccelero[1]){
nathanld 6:09e7353d7e54 236 MAAccelero[1] = accelero[1];
nathanld 6:09e7353d7e54 237 }
nathanld 6:09e7353d7e54 238
nathanld 6:09e7353d7e54 239 if (accelero[2] > MAAccelero[2]){
nathanld 6:09e7353d7e54 240 MAAccelero[2] = accelero[2];
nathanld 6:09e7353d7e54 241 }
nathanld 6:09e7353d7e54 242
nathanld 6:09e7353d7e54 243 /*if (accelero[0] < MIAccelero[0]){
nathanld 6:09e7353d7e54 244 MIAccelero[0] = accelero[0];
nathanld 6:09e7353d7e54 245 }
nathanld 6:09e7353d7e54 246
nathanld 6:09e7353d7e54 247 if (accelero[1] < MIAccelero[1]){
nathanld 6:09e7353d7e54 248 MIAccelero[1] = accelero[1];
nathanld 6:09e7353d7e54 249 }
nathanld 6:09e7353d7e54 250
nathanld 6:09e7353d7e54 251 if (accelero[2] < MIAccelero[2]){
nathanld 6:09e7353d7e54 252 MIAccelero[2] = accelero[2];
nathanld 6:09e7353d7e54 253 }*/
nathanld 6:09e7353d7e54 254
nathanld 6:09e7353d7e54 255
nathanld 6:09e7353d7e54 256
nathanld 6:09e7353d7e54 257
nathanld 6:09e7353d7e54 258
nathanld 6:09e7353d7e54 259 //VALEUR MAX GX
nathanld 6:09e7353d7e54 260 lv_label_set_text_fmt(labelMaxXV, "%f",MAAccelero[0]);
nathanld 6:09e7353d7e54 261
nathanld 6:09e7353d7e54 262 //VALEUR MAX GY
nathanld 6:09e7353d7e54 263 lv_label_set_text_fmt(labelMaxYV, "%f",MAAccelero[2]);
nathanld 6:09e7353d7e54 264
nathanld 6:09e7353d7e54 265 //VALEUR MAX GZ
nathanld 6:09e7353d7e54 266 lv_label_set_text_fmt(labelMaxZV, "%f",MAAccelero[1]);
nathanld 6:09e7353d7e54 267
nathanld 6:09e7353d7e54 268 if(i>50){
nathanld 6:09e7353d7e54 269 //VALEUR Direct GX
nathanld 6:09e7353d7e54 270 lv_label_set_text_fmt(labelMinXV, "%2.2f",accelero[0]);
nathanld 6:09e7353d7e54 271
nathanld 6:09e7353d7e54 272 //VALEUR Direct GY
nathanld 6:09e7353d7e54 273 lv_label_set_text_fmt(labelMinYV, "%2.2f",accelero[2]);
nathanld 6:09e7353d7e54 274
nathanld 6:09e7353d7e54 275 //VALEUR Direct GZ
nathanld 6:09e7353d7e54 276 lv_label_set_text_fmt(labelMinZV, "%2.2f",accelero[1]);
nathanld 6:09e7353d7e54 277
nathanld 6:09e7353d7e54 278 i=0;
nathanld 6:09e7353d7e54 279 }
nathanld 6:09e7353d7e54 280
nathanld 6:09e7353d7e54 281 i++;
nathanld 6:09e7353d7e54 282
nathanld 6:09e7353d7e54 283
nathanld 6:09e7353d7e54 284
nathanld 6:09e7353d7e54 285
nathanld 6:09e7353d7e54 286
nathanld 6:09e7353d7e54 287
nathanld 6:09e7353d7e54 288
nathanld 6:09e7353d7e54 289
JohnnyK 0:10c4b83c458d 290 }
JohnnyK 3:4f5dc253eb7b 291 }