Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F746NG GRecorder BSP_DISCO_F746NG
main.cpp
00001 /** 00002 * Notebook page https://os.mbed.com/users/JohnnyK/notebook/how-start-with-the-littlevgl/ 00003 */ 00004 00005 #include "mbed.h" 00006 #include "MPU6050.h" 00007 #include "LCD_DISCO_F746NG.h" 00008 #include "lvgl/lvgl.h" 00009 #include "hal_stm_lvgl/tft/tft.h " 00010 #include "hal_stm_lvgl/touchpad/touchpad.h" 00011 #include "lv_demo.h" /*Comment/uncomment will switch between LVGL demo and Hello word example*/ 00012 00013 #define LVGL_TICK 10 //Time tick value for lvgl in ms (1-10msa) 00014 #define TICKER_TIME 10ms //modified to miliseconds 00015 00016 Ticker ticker; //Ticker for lvgl 00017 00018 00019 /* 00020 * Callback function for lvgl timing. 00021 * Call lv_tick_inc(x) every x milliseconds in a Timer or Task (x should be between 1 and 10). 00022 * It is required for the internal timing of LittlevGL. 00023 */ 00024 void lv_ticker_func(){ 00025 lv_tick_inc(LVGL_TICK); 00026 } 00027 00028 //definition des connexion serie 00029 //Serial pc(USBTX, USBRX); 00030 00031 00032 //I2C test(I2C_SDA, I2C_SCL); 00033 const int addr = 0x68; 00034 00035 //acquisition position angulaire 00036 float accelero[3]= {1}; 00037 float gyro[3]= {1}; 00038 float temperature =0; 00039 float MAAccelero[3]= {0,0,0}; 00040 float MIAccelero[3]= {0,0,0}; 00041 int i=0; 00042 00043 00044 MPU6050 module(D14,D15); 00045 00046 static void event_MAX(lv_event_t* e) 00047 { 00048 LV_LOG_USER("btn_max et min was Clicked"); 00049 00050 00051 00052 } 00053 00054 00055 static void event_handler(lv_event_t* event) 00056 { 00057 lv_event_code_t code = lv_event_get_code(event); 00058 if(code == LV_EVENT_CLICKED) { 00059 printf("Clicked\n"); 00060 00061 MAAccelero[0]= 0; 00062 MAAccelero[1]= 0; 00063 MAAccelero[2]= 0; 00064 00065 } 00066 else if(code == LV_EVENT_VALUE_CHANGED) { 00067 printf("Toggled\n"); 00068 } 00069 } 00070 00071 00072 00073 // main() runs in its own thread in the OS 00074 int main() 00075 { 00076 00077 //changement du l'echelle du module 00078 module.setGyroRange(MPU6050_GYRO_RANGE_2000); 00079 module.setAcceleroRange(MPU6050_ACCELERO_RANGE_16G); 00080 00081 //Event lorsqu'appuie sur bouton MIN/MAX 00082 00083 00084 printf("LVGL-"); 00085 lv_init(); //Initialize the LVGL 00086 tft_init(); //Initialize diplay 00087 touchpad_init(); //Initialize touchpad 00088 ticker.attach(callback(&lv_ticker_func),TICKER_TIME); //Attach callback to ticker 00089 00090 LV_IMG_DECLARE(Logoiut); 00091 00092 printf("Hello world\n"); 00093 00094 /*lv_obj_t * label1 = lv_label_create(lv_scr_act()); 00095 lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); //Break the long lines 00096 lv_label_set_recolor(label1, true); //Enable re-coloring by commands in the text 00097 lv_label_set_text(label1, "#0000ff Hello# #ff00ff world# #ff0000 - the LVGL and MbedOS#"); 00098 lv_obj_set_width(label1, 150); 00099 lv_obj_align(label1, LV_ALIGN_TOP_MID, 0, 20);*/ 00100 00101 //Circular scroll 00102 lv_obj_t * label2 = lv_label_create(lv_scr_act()); 00103 lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR); 00104 lv_obj_set_width(label2, 300); 00105 lv_label_set_text(label2, "IUT CACHAN - Enregistreur de g - Leprevier-Destas Nathan - LP MECSE -"); 00106 lv_obj_align(label2, LV_ALIGN_BOTTOM_MID, -30, 0); 00107 00108 00109 lv_obj_t * label; 00110 00111 //Bouton MAX/MIN 00112 lv_obj_t * btn2 = lv_btn_create(lv_scr_act()); 00113 lv_obj_add_event_cb(btn2, event_handler,LV_EVENT_ALL, NULL); 00114 lv_obj_align(btn2, LV_ALIGN_TOP_LEFT, 25, 5); 00115 label = lv_label_create(btn2); 00116 lv_label_set_text(label, "Reset Valeurs Max"); 00117 00118 //Logo IUT 00119 lv_obj_t * img = lv_img_create(lv_scr_act()); 00120 lv_img_set_src(img, &Logoiut); 00121 lv_obj_set_width(img, 250); 00122 lv_obj_align(img, LV_ALIGN_TOP_RIGHT, -5, 7); 00123 00124 //MAX GX 00125 lv_obj_t * labelMaxX = lv_label_create(lv_scr_act()); 00126 lv_label_set_recolor(labelMaxX, true); //Enable re-coloring by commands in the text 00127 lv_label_set_text(labelMaxX, "#0080ff MAX# G sur #0080ff Axe X :#"); 00128 lv_obj_set_width(labelMaxX, 200); 00129 lv_obj_align(labelMaxX, LV_ALIGN_TOP_RIGHT, -5, 70); 00130 00131 //MAX GY 00132 lv_obj_t * labelMaxY = lv_label_create(lv_scr_act()); 00133 lv_label_set_recolor(labelMaxY, true); //Enable re-coloring by commands in the text 00134 lv_label_set_text(labelMaxY, "#0080ff MAX G# sur #0080ff Axe Y :#"); 00135 lv_obj_set_width(labelMaxY, 200); 00136 lv_obj_align(labelMaxY, LV_ALIGN_CENTER, 138, 0); 00137 00138 //MAX GZ 00139 lv_obj_t * labelMaxZ = lv_label_create(lv_scr_act()); 00140 lv_label_set_recolor(labelMaxZ, true); //Enable re-coloring by commands in the text 00141 lv_label_set_text(labelMaxZ, "#0080ff MAX G# sur #0080ff Axe Z :#"); 00142 lv_obj_set_width(labelMaxZ, 200); 00143 lv_obj_align(labelMaxZ, LV_ALIGN_BOTTOM_RIGHT, -5, -70); 00144 00145 //MIN GX 00146 lv_obj_t * labelMinX = lv_label_create(lv_scr_act()); 00147 lv_label_set_recolor(labelMinX, true); //Enable re-coloring by commands in the text 00148 lv_label_set_text(labelMinX, "G sur #ff0000 Axe X :#"); 00149 lv_obj_set_width(labelMinX, 200); 00150 lv_obj_align(labelMinX, LV_ALIGN_TOP_LEFT, 10, 70); 00151 00152 //MIN GY 00153 lv_obj_t * labelMinY = lv_label_create(lv_scr_act()); 00154 lv_label_set_recolor(labelMinY, true); //Enable re-coloring by commands in the text 00155 lv_label_set_text(labelMinY, "G sur #ff0000 Axe Y :#"); 00156 lv_obj_set_width(labelMinY, 200); 00157 lv_obj_align(labelMinY, LV_ALIGN_CENTER, -130, 0); 00158 00159 //MIN GZ 00160 lv_obj_t * labelMinZ = lv_label_create(lv_scr_act()); 00161 lv_label_set_recolor(labelMinZ, true); //Enable re-coloring by commands in the text 00162 lv_label_set_text(labelMinZ, "G sur #ff0000 Axe Z :#"); 00163 lv_obj_set_width(labelMinZ, 200); 00164 lv_obj_align(labelMinZ, LV_ALIGN_BOTTOM_LEFT, 10, -70); 00165 00166 //VALEUR MAX GX 00167 lv_obj_t * labelMaxXV = lv_label_create(lv_scr_act()); 00168 lv_label_set_text_fmt(labelMaxXV, "MX"); 00169 lv_obj_set_width(labelMaxXV, 200); 00170 lv_obj_align(labelMaxXV, LV_ALIGN_TOP_RIGHT, 125,70); 00171 00172 //VALEUR MAX GY 00173 lv_obj_t * labelMaxYV = lv_label_create(lv_scr_act()); 00174 lv_label_set_text_fmt(labelMaxYV, "MX"); 00175 lv_obj_set_width(labelMaxYV, 200); 00176 lv_obj_align(labelMaxYV, LV_ALIGN_CENTER, 267,0); 00177 00178 //VALEUR MAX GZ 00179 lv_obj_t * labelMaxZV = lv_label_create(lv_scr_act()); 00180 lv_label_set_text_fmt(labelMaxZV, "MX"); 00181 lv_obj_set_width(labelMaxZV, 200); 00182 lv_obj_align(labelMaxZV, LV_ALIGN_BOTTOM_RIGHT, 125,-70); 00183 00184 //VALEUR Direct GX 00185 lv_obj_t * labelMinXV = lv_label_create(lv_scr_act()); 00186 lv_label_set_text_fmt(labelMinXV, "MX"); 00187 lv_obj_set_width(labelMinXV, 200); 00188 lv_obj_align(labelMinXV, LV_ALIGN_TOP_LEFT, 105,70); 00189 00190 //VALEUR Direct GY 00191 lv_obj_t * labelMinYV = lv_label_create(lv_scr_act()); 00192 lv_label_set_text_fmt(labelMinYV, "MX"); 00193 lv_obj_set_width(labelMinYV, 200); 00194 lv_obj_align(labelMinYV, LV_ALIGN_CENTER, -35, 0); 00195 00196 //VALEUR Direct GZ 00197 lv_obj_t * labelMinZV = lv_label_create(lv_scr_act()); 00198 lv_label_set_text_fmt(labelMinZV, "MX"); 00199 lv_obj_set_width(labelMinZV, 200); 00200 lv_obj_align(labelMinZV, LV_ALIGN_BOTTOM_LEFT, 105,-70); 00201 00202 00203 00204 while (true){ 00205 module.getAccelero(accelero); 00206 lv_task_handler(); 00207 //Call lv_task_handler() periodically every few milliseconds. 00208 //It will redraw the screen if required, handle input devices etc. 00209 thread_sleep_for(LVGL_TICK); 00210 00211 fabs(accelero[0]); 00212 fabs(accelero[1]); 00213 fabs(accelero[2]); 00214 00215 accelero[0] = accelero[0]/9,81; 00216 accelero[1] = accelero[1]/9,81; 00217 accelero[2] = accelero[2]/9,81; 00218 00219 if (accelero[0] < 0){ 00220 fabs(accelero[0]); 00221 } 00222 00223 if (accelero[1] < 0){ 00224 accelero[1] = !accelero[1]; 00225 } 00226 00227 if (accelero[2] < 0){ 00228 accelero[2] = !accelero[2]; 00229 } 00230 00231 if (accelero[0] > MAAccelero[0]){ 00232 MAAccelero[0] = accelero[0]; 00233 } 00234 00235 if (accelero[1] > MAAccelero[1]){ 00236 MAAccelero[1] = accelero[1]; 00237 } 00238 00239 if (accelero[2] > MAAccelero[2]){ 00240 MAAccelero[2] = accelero[2]; 00241 } 00242 00243 /*if (accelero[0] < MIAccelero[0]){ 00244 MIAccelero[0] = accelero[0]; 00245 } 00246 00247 if (accelero[1] < MIAccelero[1]){ 00248 MIAccelero[1] = accelero[1]; 00249 } 00250 00251 if (accelero[2] < MIAccelero[2]){ 00252 MIAccelero[2] = accelero[2]; 00253 }*/ 00254 00255 00256 00257 00258 00259 //VALEUR MAX GX 00260 lv_label_set_text_fmt(labelMaxXV, "%f",MAAccelero[0]); 00261 00262 //VALEUR MAX GY 00263 lv_label_set_text_fmt(labelMaxYV, "%f",MAAccelero[2]); 00264 00265 //VALEUR MAX GZ 00266 lv_label_set_text_fmt(labelMaxZV, "%f",MAAccelero[1]); 00267 00268 if(i>50){ 00269 //VALEUR Direct GX 00270 lv_label_set_text_fmt(labelMinXV, "%2.2f",accelero[0]); 00271 00272 //VALEUR Direct GY 00273 lv_label_set_text_fmt(labelMinYV, "%2.2f",accelero[2]); 00274 00275 //VALEUR Direct GZ 00276 lv_label_set_text_fmt(labelMinZV, "%2.2f",accelero[1]); 00277 00278 i=0; 00279 } 00280 00281 i++; 00282 00283 00284 00285 00286 00287 00288 00289 00290 } 00291 }
Generated on Thu Jul 14 2022 20:43:54 by
1.7.2