2013-01-11 01:48:46 +08:00
|
|
|
#include "task_control.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-03-28 23:33:35 +08:00
|
|
|
/*! \var gmio_bool_t (*gmio_task_control::handle_progress_func)(void*, uint8_t)
|
2014-02-13 23:25:37 +08:00
|
|
|
*
|
|
|
|
* Frequent example of hook functions is update of a UI progress bar
|
|
|
|
*
|
2014-03-28 23:33:35 +08:00
|
|
|
* The return value is important : it is used as an interruption request status. If GMIO_TRUE then
|
2014-02-13 23:25:37 +08:00
|
|
|
* the current task can continue, otherwise it should abort as soon as possible.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*! \details Basically the same as :
|
|
|
|
* \code
|
|
|
|
* ctrl->handle_progress_func(ctrl->cookie, progress_pc)
|
|
|
|
* \endcode
|
|
|
|
*/
|
2014-03-28 23:33:35 +08:00
|
|
|
gmio_bool_t gmio_task_control_handle_progress(gmio_task_control_t* ctrl, uint8_t progress_pc)
|
2013-01-11 01:48:46 +08:00
|
|
|
{
|
2013-03-05 08:04:29 +08:00
|
|
|
if (ctrl != NULL && ctrl->handle_progress_func != NULL)
|
2014-01-27 22:03:50 +08:00
|
|
|
return ctrl->handle_progress_func(ctrl->cookie, progress_pc);
|
2013-03-05 08:04:29 +08:00
|
|
|
return 1;
|
2013-01-11 01:48:46 +08:00
|
|
|
}
|
|
|
|
|
2014-02-13 23:25:37 +08:00
|
|
|
/*! \details \p value is assumed to be relative to the interval (range) defined by
|
|
|
|
* [ \p range_min , \p range_max ]
|
|
|
|
*/
|
2014-03-28 23:33:35 +08:00
|
|
|
uint8_t gmio_percentage(size_t range_min, size_t range_max, size_t value)
|
2013-01-11 01:48:46 +08:00
|
|
|
{
|
2013-03-05 08:04:29 +08:00
|
|
|
if (value >= range_max)
|
|
|
|
return 100;
|
|
|
|
else if (value <= range_min)
|
|
|
|
return 0;
|
|
|
|
else if (range_min < range_max)
|
|
|
|
return (value * 100) / (range_max - range_min);
|
|
|
|
return 0;
|
2013-01-11 01:48:46 +08:00
|
|
|
}
|