/** * Get elapsed time since last press * @param indev pointer to an input device (NULL to get the overall smallest inactivity) * @return Elapsed ticks (milliseconds) since last press */ uint32_t lv_indev_get_inactive_time(const lv_indev_t * indev) { uint32_t t; if(indev) return t = lv_tick_elaps(indev->last_activity_time); lv_indev_t * i; t = UINT16_MAX; i = lv_indev_next(NULL); while(i) { t = LV_MATH_MIN(t, lv_tick_elaps(i->last_activity_time)); i = lv_indev_next(i); } return t; }
/** * Execute task if its the priority is appropriate * @param lv_task_p pointer to lv_task * @param prio_act the current priority * @return true: execute, false: not executed */ static bool lv_task_exec (lv_task_t* lv_task_p, lv_task_prio_t prio_act) { bool exec = false; /*Execute lv_task if its prio is 'prio_act'*/ if(lv_task_p->prio == prio_act) { /*Execute if at least 'period' time elapsed*/ uint32_t elp = lv_tick_elaps(lv_task_p->last_run); if(elp >= lv_task_p->period) { lv_task_p->last_run = lv_tick_get(); lv_task_p->task(lv_task_p->param); /*Delete if it was a one shot lv_task*/ if(lv_task_p->once != 0) lv_task_del(lv_task_p); exec = true; } } return exec; }
/** * Call it periodically to handle lv_tasks. */ inline void LV_ATTRIBUTE_TASK_HANDLER lv_task_handler(void) { static uint32_t idle_period_start = 0; static uint32_t handler_start = 0; static uint32_t busy_time = 0; if(lv_task_run == false) return; handler_start = lv_tick_get(); lv_task_t* lv_task_prio_a[LV_TASK_PRIO_NUM]; /*Lists for all prio.*/ lv_task_prio_t prio_act; bool prio_reset = false; /*Used to go back to the highest priority*/ lv_task_t* lv_task_next; /*Init. the lists*/ for(prio_act = LV_TASK_PRIO_LOWEST; prio_act <= LV_TASK_PRIO_HIGHEST; prio_act++) { lv_task_prio_a[prio_act] = lv_ll_get_head(&lv_task_ll); } /*Handle the lv_tasks on all priority*/ for(prio_act = LV_TASK_PRIO_HIGHEST; prio_act > LV_TASK_PRIO_OFF; prio_act --) { /*Reset the prio. if necessary*/ if(prio_reset != false) { prio_reset = false; prio_act = LV_TASK_PRIO_HIGHEST; /*Go again with highest prio */ } /* Read all lv_task on 'prio_act' but stop on 'prio_reset' */ while(lv_task_prio_a[prio_act] != NULL && prio_reset == false) { /* Get the next task. (Invalid pointer if a lv_task deletes itself)*/ lv_task_next = lv_ll_get_next(&lv_task_ll, lv_task_prio_a[prio_act]); /*Execute the current lv_task*/ bool executed = lv_task_exec(lv_task_prio_a[prio_act], prio_act); if(executed != false) { /*If the task is executed*/ /* During the execution higher priority lv_tasks * can be ready, so reset the priority if it is not highest*/ if(prio_act != LV_TASK_PRIO_HIGHEST) { prio_reset = true; } } lv_task_prio_a[prio_act] = lv_task_next; /*Load the next task*/ } /*Reset higher priority lists on 'prio_reset' query*/ if(prio_reset != false) { for(prio_act = prio_act + 1; prio_act <= LV_TASK_PRIO_HIGHEST; prio_act++) { lv_task_prio_a[prio_act] = lv_ll_get_head(&lv_task_ll); } } } busy_time += lv_tick_elaps(handler_start); uint32_t idle_period_time = lv_tick_elaps(idle_period_start); if(idle_period_time >= IDLE_MEAS_PERIOD) { idle_last = (uint32_t)((uint32_t)busy_time * 100) / IDLE_MEAS_PERIOD; /*Calculate the busy percentage*/ idle_last = idle_last > 100 ? 0 : 100 - idle_last; /*But we need idle time*/ busy_time = 0; idle_period_start = lv_tick_get(); } }