acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_demo_stress.c (16439B)
1 /** 2 * @file lv_demo_stress.c 3 * 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 #include "lv_demo_stress.h" 10 11 #if LV_USE_DEMO_STRESS 12 /********************* 13 * DEFINES 14 *********************/ 15 16 /********************** 17 * TYPEDEFS 18 **********************/ 19 20 /********************** 21 * STATIC PROTOTYPES 22 **********************/ 23 static void auto_del(lv_obj_t * obj, uint32_t delay); 24 static void msgbox_del(lv_timer_t * tmr); 25 static void set_y_anim(void * obj, int32_t v); 26 static void set_width_anim(void * obj, int32_t v); 27 static void arc_set_end_angle_anim(void * obj, int32_t v); 28 static void obj_test_task_cb(lv_timer_t * tmr); 29 30 /********************** 31 * STATIC VARIABLES 32 **********************/ 33 static lv_obj_t * main_page; 34 static lv_obj_t * ta; 35 static const char * mbox_btns[] = {"Ok", "Cancel", ""}; 36 static uint32_t mem_free_start = 0; 37 /********************** 38 * MACROS 39 **********************/ 40 41 /********************** 42 * GLOBAL FUNCTIONS 43 **********************/ 44 45 void lv_demo_stress(void) 46 { 47 LV_LOG_USER("Starting stress test. (< 100 bytes permanent memory leak is normal due to fragmentation)"); 48 lv_timer_create(obj_test_task_cb, LV_DEMO_STRESS_TIME_STEP, NULL); 49 } 50 51 /********************** 52 * STATIC FUNCTIONS 53 **********************/ 54 55 static void obj_test_task_cb(lv_timer_t * tmr) 56 { 57 (void) tmr; /*Unused*/ 58 static int16_t state = -1; 59 60 lv_anim_t a; 61 lv_obj_t * obj; 62 63 // printf("step start: %d\n", state); 64 65 switch(state) { 66 case -1: { 67 lv_res_t res = lv_mem_test(); 68 if(res != LV_RES_OK) { 69 LV_LOG_ERROR("Memory integrity error"); 70 } 71 72 lv_mem_monitor_t mon; 73 lv_mem_monitor(&mon); 74 75 if(mem_free_start == 0) mem_free_start = mon.free_size; 76 77 LV_LOG_USER("mem leak since start: %d, frag: %3d %%", mem_free_start - mon.free_size, mon.frag_pct); 78 } 79 break; 80 case 0: 81 /* Holder for all object types */ 82 main_page = lv_obj_create(lv_scr_act()); 83 lv_obj_set_size(main_page, LV_HOR_RES / 2, LV_VER_RES); 84 lv_obj_set_flex_flow(main_page, LV_FLEX_FLOW_COLUMN); 85 86 87 obj = lv_btn_create(main_page); 88 lv_obj_set_size(obj, 100, 70); 89 obj = lv_label_create(obj); 90 lv_label_set_text(obj, "Multi line\n"LV_SYMBOL_OK LV_SYMBOL_CLOSE LV_SYMBOL_WIFI); 91 break; 92 93 case 1: { 94 obj = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, 50); 95 lv_obj_set_size(obj, LV_HOR_RES / 2, LV_VER_RES / 2); 96 lv_obj_align(obj, LV_ALIGN_BOTTOM_RIGHT, 0, 0); 97 lv_obj_t * t = lv_tabview_add_tab(obj, "First"); 98 99 t = lv_tabview_add_tab(obj, "Second"); 100 lv_obj_t * c = lv_colorwheel_create(t, true); 101 lv_obj_set_size(c, 150, 150); 102 // c = lv_led_create(t, NULL); 103 // lv_obj_set_pos(c, 160, 20); 104 t = lv_tabview_add_tab(obj, LV_SYMBOL_EDIT " Edit"); 105 t = lv_tabview_add_tab(obj, LV_SYMBOL_CLOSE); 106 107 lv_tabview_set_act(obj, 1, LV_ANIM_ON); 108 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 5 + 30); 109 } 110 break; 111 112 case 2: 113 obj = lv_btn_create(main_page); 114 lv_obj_set_size(obj, 200, 70); 115 116 /*Move to disabled state very slowly*/ 117 lv_obj_add_state(obj, LV_STATE_DISABLED); 118 119 /*Add an infinite width change animation*/ 120 lv_anim_init(&a); 121 lv_anim_set_var(&a, obj); 122 lv_anim_set_time(&a, LV_DEMO_STRESS_TIME_STEP * 2); 123 lv_anim_set_exec_cb(&a, set_width_anim); 124 lv_anim_set_values(&a, 100, 200); 125 lv_anim_set_playback_time(&a, LV_DEMO_STRESS_TIME_STEP * 2); 126 lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); 127 lv_anim_start(&a); 128 129 /*Delete the object a few sec later*/ 130 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 10); 131 132 obj = lv_label_create(obj); 133 lv_label_set_text_fmt(obj, "Formatted:\n%d %s", 12, "Volt"); 134 break; 135 136 case 3: 137 ta = lv_textarea_create(lv_scr_act()); 138 lv_obj_align_to(ta, main_page, LV_ALIGN_OUT_RIGHT_TOP, 10, 10); 139 lv_obj_set_size(ta, LV_HOR_RES / 3, LV_VER_RES / 4); 140 lv_textarea_set_placeholder_text(ta, "The placeholder"); 141 break; 142 143 case 4: 144 obj = lv_btn_create(main_page); 145 lv_obj_set_size(obj, 100, 70); 146 lv_obj_set_style_bg_img_src(obj, LV_SYMBOL_DUMMY"Text from\nstyle", 0); 147 lv_obj_del_async(obj); /*Delete on next call of `lv_task_handler` (so not now)*/ 148 149 // obj = lv_btn_create(main_page); 150 // lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT); 151 // lv_obj_set_style_bg_img_src(obj, LV_SYMBOL_LEFT); 152 // lv_obj_set_style_bg_img_opa(obj, LV_OPA_50); 153 // lv_obj_set_style_bg_img_tiled(obj, true); 154 // lv_obj_scroll_to_view(obj, LV_ANIM_ON); 155 break; 156 157 case 5: 158 lv_textarea_set_one_line(ta, true); 159 break; 160 case 6: 161 lv_obj_set_flex_flow(main_page, LV_FLEX_FLOW_COLUMN_WRAP); 162 break; 163 164 case 7: 165 obj = lv_bar_create(main_page); 166 lv_bar_set_range(obj, -1000, 2000); 167 lv_bar_set_value(obj, 1800, LV_ANIM_ON); 168 lv_bar_set_start_value(obj, -500, LV_ANIM_ON); 169 170 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 2 + 70); 171 172 obj = lv_slider_create(main_page); 173 lv_obj_set_style_anim_time(obj, LV_DEMO_STRESS_TIME_STEP * 8, 0); 174 lv_slider_set_value(obj, 5000, LV_ANIM_ON); /*Animate to out of range value*/ 175 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 5 + 22); 176 177 obj = lv_switch_create(main_page); 178 179 obj = lv_switch_create(main_page); 180 lv_obj_add_state(obj, LV_STATE_CHECKED); 181 auto_del(obj, 730); 182 break; 183 184 case 8: 185 obj = lv_win_create(lv_scr_act(), 50); 186 lv_obj_set_size(obj, LV_HOR_RES / 2, LV_VER_RES / 2); 187 lv_obj_align(obj, LV_ALIGN_BOTTOM_RIGHT, 0, 0); 188 lv_win_add_title(obj, "Window title"); 189 lv_win_add_btn(obj, LV_SYMBOL_CLOSE, 40); 190 lv_win_add_btn(obj, LV_SYMBOL_DOWN, 40); 191 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 3 + 5); 192 193 obj = lv_calendar_create(lv_win_get_content(obj)); 194 break; 195 case 9: 196 lv_textarea_set_text(ta, "A very very long text which will should make the text area scrollable" 197 "Here area some dummy sentences to be sure the text area will be really scrollable."); 198 break; 199 case 10: 200 obj = lv_keyboard_create(lv_scr_act()); 201 lv_keyboard_set_mode(obj, LV_KEYBOARD_MODE_TEXT_UPPER); 202 lv_anim_init(&a); 203 lv_anim_set_var(&a, obj); 204 lv_anim_set_values(&a, LV_VER_RES, LV_VER_RES - lv_obj_get_height(obj)); 205 lv_anim_set_time(&a, LV_DEMO_STRESS_TIME_STEP + 3); 206 lv_anim_set_exec_cb(&a, set_y_anim); 207 lv_anim_start(&a); 208 209 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 2 + 18); 210 break; 211 212 case 11: 213 obj = lv_dropdown_create(main_page); 214 lv_dropdown_set_options(obj, "Zero\nOne\nTwo\nThree\nFour\nFive\nSix\nSeven\nEight"); 215 lv_dropdown_open(obj); 216 lv_dropdown_set_selected(obj, 2); 217 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 3 + 11); 218 break; 219 220 case 12: 221 obj = lv_roller_create(main_page); 222 lv_roller_set_options(obj, "Zero\nOne\nTwo\nThree\nFour\nFive\nSix\nSeven\nEight", LV_ROLLER_MODE_INFINITE); 223 lv_roller_set_selected(obj, 2, LV_ANIM_ON); 224 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 20 + 22); 225 break; 226 227 case 13: 228 obj = lv_arc_create(main_page); 229 lv_anim_init(&a); 230 lv_anim_set_var(&a, obj); 231 lv_anim_set_values(&a, 180, 400); 232 lv_anim_set_time(&a, LV_DEMO_STRESS_TIME_STEP * 2); 233 lv_anim_set_delay(&a, LV_DEMO_STRESS_TIME_STEP + 25); 234 lv_anim_set_playback_time(&a, LV_DEMO_STRESS_TIME_STEP * 5); 235 lv_anim_set_repeat_count(&a, 3); 236 lv_anim_set_exec_cb(&a, arc_set_end_angle_anim); 237 lv_anim_start(&a); 238 239 obj = lv_meter_create(main_page); 240 lv_obj_scroll_to_view(obj, LV_ANIM_ON); 241 lv_meter_scale_t * scale = lv_meter_add_scale(obj); 242 lv_meter_add_needle_line(obj, scale, 3, lv_palette_main(LV_PALETTE_RED), -10); 243 244 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 6 + 30); 245 break; 246 247 case 14: 248 obj = lv_msgbox_create(NULL, "Title", "Some text on the message box with average length", mbox_btns, true); 249 250 lv_timer_t * msgbox_tmr = lv_timer_create(msgbox_del, LV_DEMO_STRESS_TIME_STEP * 5 + 30, obj); 251 lv_timer_set_repeat_count(msgbox_tmr, 1); 252 lv_obj_align(obj, LV_ALIGN_RIGHT_MID, -10, 0); 253 break; 254 255 case 15: 256 lv_textarea_set_one_line(ta, false); 257 break; 258 259 case 16: { 260 lv_obj_t * tv = lv_tileview_create(lv_scr_act()); 261 lv_obj_set_size(tv, 200, 200); 262 auto_del(tv, LV_DEMO_STRESS_TIME_STEP * 4 + 5); 263 264 obj = lv_tileview_add_tile(tv, 0, 0, LV_DIR_ALL); 265 obj = lv_label_create(obj); 266 lv_label_set_text(obj, "Tile: 0;0"); 267 268 obj = lv_tileview_add_tile(tv, 0, 1, LV_DIR_ALL); 269 obj = lv_label_create(obj); 270 lv_label_set_text(obj, "Tile: 0;1"); 271 272 obj = lv_tileview_add_tile(tv, 1, 1, LV_DIR_ALL); 273 obj = lv_label_create(obj); 274 lv_label_set_text(obj, "Tile: 1;1"); 275 276 lv_obj_set_tile_id(tv, 1, 1, LV_ANIM_ON); 277 } 278 break; 279 280 case 18: 281 obj = lv_list_create(main_page); 282 { 283 lv_obj_t * b; 284 b = lv_list_add_btn(obj, LV_SYMBOL_OK, "1. Some very long text to scroll"); 285 auto_del(b, 10); 286 lv_list_add_btn(obj, LV_SYMBOL_OK, "2. Some very long text to scroll"); 287 lv_list_add_btn(obj, LV_SYMBOL_OK, "3. Some very long text to scroll"); 288 b = lv_list_add_btn(obj, LV_SYMBOL_OK, "4. Some very long text to scroll"); 289 auto_del(b, LV_DEMO_STRESS_TIME_STEP); 290 b = lv_list_add_btn(obj, LV_SYMBOL_OK, "5. Some very long text to scroll"); 291 auto_del(b, LV_DEMO_STRESS_TIME_STEP + 90); 292 b = lv_list_add_btn(obj, LV_SYMBOL_OK, "6. Some very long text to scroll"); 293 auto_del(b, LV_DEMO_STRESS_TIME_STEP + 10); 294 lv_obj_scroll_to_view(lv_obj_get_child(obj, -1), LV_ANIM_ON); 295 } 296 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 5 + 15); 297 298 obj = lv_table_create(main_page); 299 lv_table_set_cell_value(obj, 0, 0, "0,0"); 300 lv_table_set_cell_value_fmt(obj, 3, 0, "%d,%d", 5, 0); 301 lv_table_set_row_cnt(obj, 5); 302 lv_table_set_cell_value_fmt(obj, 1, 0, "%s", "1,0"); 303 lv_table_set_cell_value(obj, 1, 3, "1,3"); 304 break; 305 306 case 19: 307 lv_textarea_set_cursor_pos(ta, 10); 308 lv_textarea_set_text(ta, "__INSERTED TEXT" LV_SYMBOL_EDIT"__"); 309 break; 310 311 case 20: 312 lv_obj_set_flex_flow(main_page, LV_FLEX_FLOW_ROW_WRAP); 313 break; 314 315 case 21: 316 lv_textarea_set_cursor_pos(ta, 0); 317 lv_textarea_add_char(ta, '0'); 318 lv_textarea_add_char(ta, '1'); 319 lv_textarea_add_char(ta, '2'); 320 lv_textarea_add_char(ta, '3'); 321 lv_textarea_add_char(ta, '4'); 322 lv_textarea_add_char(ta, '5'); 323 lv_textarea_add_char(ta, '6'); 324 lv_textarea_add_char(ta, '7'); 325 lv_textarea_add_char(ta, '8'); 326 lv_textarea_add_char(ta, '9'); 327 lv_textarea_add_char(ta, 'A'); 328 lv_textarea_add_char(ta, 'B'); 329 lv_textarea_add_char(ta, 'C'); 330 lv_textarea_add_char(ta, 'D'); 331 lv_textarea_add_char(ta, 'E'); 332 lv_textarea_add_char(ta, 'F'); 333 lv_textarea_add_text(ta, LV_SYMBOL_OK); 334 lv_textarea_add_text(ta, LV_SYMBOL_CLOSE); 335 lv_textarea_add_text(ta, LV_SYMBOL_COPY); 336 lv_textarea_add_text(ta, LV_SYMBOL_SAVE); 337 lv_textarea_add_text(ta, LV_SYMBOL_PASTE); 338 break; 339 340 case 22: 341 obj = lv_spinbox_create(main_page); 342 lv_spinbox_set_digit_format(obj, 6, 3); 343 lv_spinbox_set_value(obj, 5678); 344 lv_spinbox_set_step(obj, 10); 345 lv_spinbox_increment(obj); 346 lv_spinbox_increment(obj); 347 lv_spinbox_increment(obj); 348 lv_spinbox_set_step(obj, 100); 349 lv_spinbox_increment(obj); 350 lv_spinbox_increment(obj); 351 lv_spinbox_set_step(obj, 1); 352 lv_spinbox_increment(obj); 353 lv_spinbox_increment(obj); 354 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 2 + 15); 355 356 lv_obj_scroll_by(main_page, 0, 20, LV_ANIM_ON); 357 358 break; 359 360 case 23: 361 obj = lv_chart_create(main_page); 362 { 363 lv_chart_series_t * s1 = lv_chart_add_series(obj, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y); 364 lv_chart_set_next_value(obj, s1, 36); 365 lv_chart_set_next_value(obj, s1, -29); 366 lv_chart_set_next_value(obj, s1, 51); 367 lv_chart_set_next_value(obj, s1, 107); 368 lv_chart_set_next_value(obj, s1, 70); 369 lv_chart_set_next_value(obj, s1, 36); 370 lv_chart_set_next_value(obj, s1, -2); 371 lv_chart_set_next_value(obj, s1, 63); 372 lv_chart_set_next_value(obj, s1, 48); 373 lv_chart_set_next_value(obj, s1, 72); 374 375 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 3); 376 } 377 378 lv_obj_scroll_by(main_page, 0, 20, LV_ANIM_ON); 379 break; 380 381 case 24: 382 obj = lv_checkbox_create(main_page); 383 lv_checkbox_set_text(obj, "An option to select"); 384 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 2 + 20); 385 386 obj = lv_checkbox_create(main_page); 387 lv_obj_add_state(obj, LV_STATE_CHECKED); 388 389 obj = lv_checkbox_create(main_page); 390 lv_obj_add_state(obj, LV_STATE_CHECKED | LV_STATE_DISABLED); 391 auto_del(obj, LV_DEMO_STRESS_TIME_STEP * 1 + 60); 392 393 lv_obj_scroll_by(main_page, 0, 20, LV_ANIM_ON); 394 395 break; 396 397 case 25: 398 lv_textarea_set_cursor_pos(ta, 20); 399 { 400 uint16_t i; 401 for(i = 0; i < 64; i++) { 402 lv_textarea_del_char_forward(ta); 403 } 404 } 405 break; 406 407 case 26: 408 lv_textarea_set_one_line(ta, true); 409 break; 410 case 29: 411 lv_obj_clean(main_page); 412 lv_obj_del(ta); 413 ta = NULL; 414 break; 415 case 31: 416 lv_obj_clean(lv_scr_act()); 417 main_page = NULL; 418 state = -2; 419 break; 420 default: 421 break; 422 } 423 424 // printf("step end: %d\n", state); 425 state++; 426 } 427 428 static void auto_del(lv_obj_t * obj, uint32_t delay) 429 { 430 lv_anim_t a; 431 lv_anim_init(&a); 432 lv_anim_set_var(&a, obj); 433 lv_anim_set_time(&a, 0); 434 lv_anim_set_delay(&a, delay); 435 lv_anim_set_ready_cb(&a, lv_obj_del_anim_ready_cb); 436 lv_anim_start(&a); 437 438 } 439 440 static void msgbox_del(lv_timer_t * tmr) 441 { 442 lv_msgbox_close(tmr->user_data); 443 } 444 445 static void set_y_anim(void * obj, int32_t v) 446 { 447 lv_obj_set_y(obj, v); 448 } 449 450 static void set_width_anim(void * obj, int32_t v) 451 { 452 lv_obj_set_width(obj, v); 453 } 454 455 static void arc_set_end_angle_anim(void * obj, int32_t v) 456 { 457 lv_arc_set_end_angle(obj, v); 458 } 459 460 #endif /* LV_USE_DEMO_STRESS */