2017-04-21 17:11:47 +02:00
|
|
|
/**
|
2020-02-14 12:36:44 +01:00
|
|
|
* @file lv_linemeter.c
|
2018-06-19 09:49:58 +02:00
|
|
|
*
|
2017-04-21 17:11:47 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2020-02-14 12:36:44 +01:00
|
|
|
#include "lv_linemeter.h"
|
2020-02-22 01:05:13 +01:00
|
|
|
#if LV_USE_LINEMETER != 0
|
2017-04-21 17:11:47 +02:00
|
|
|
|
2019-09-24 16:30:38 +02:00
|
|
|
#include "../lv_core/lv_debug.h"
|
2017-04-21 17:11:47 +02:00
|
|
|
#include "../lv_draw/lv_draw.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-11-30 11:35:33 +01:00
|
|
|
#include "../lv_core/lv_group.h"
|
2018-06-06 06:30:44 +02:00
|
|
|
#include "../lv_misc/lv_math.h"
|
2017-04-21 17:11:47 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2020-02-14 12:36:44 +01:00
|
|
|
#define LV_OBJX_NAME "lv_linemeter"
|
2019-09-26 10:51:54 +02:00
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_design_res_t lv_linemeter_design(lv_obj_t * lmeter, const lv_area_t * clip_area, lv_design_mode_t mode);
|
|
|
|
static lv_res_t lv_linemeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * param);
|
2017-04-21 17:11:47 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2017-04-21 17:11:47 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a line meter objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new line meter
|
2019-04-04 07:15:40 +02:00
|
|
|
* @param copy pointer to a line meter object, if not NULL then the new object will be copied from
|
|
|
|
* it
|
2017-04-21 17:11:47 +02:00
|
|
|
* @return pointer to the created line meter
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_t * lv_linemeter_create(lv_obj_t * par, const lv_obj_t * copy)
|
2017-04-21 17:11:47 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("line meter create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
/*Create the ancestor of line meter*/
|
2017-11-05 00:48:57 +01:00
|
|
|
lv_obj_t * new_lmeter = lv_obj_create(par, copy);
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(new_lmeter);
|
2018-10-05 17:22:49 +02:00
|
|
|
if(new_lmeter == NULL) return NULL;
|
2018-07-25 13:33:53 +02:00
|
|
|
|
2019-04-10 06:40:49 +02:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(new_lmeter);
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
/*Allocate the line meter type specific extended data*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_allocate_ext_attr(new_lmeter, sizeof(lv_linemeter_ext_t));
|
2019-09-24 23:14:17 +02:00
|
|
|
LV_ASSERT_MEM(ext);
|
2019-12-03 18:16:14 +01:00
|
|
|
if(ext == NULL) {
|
|
|
|
lv_obj_del(new_lmeter);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-04-21 17:11:47 +02:00
|
|
|
|
|
|
|
/*Initialize the allocated 'ext' */
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->min_value = 0;
|
|
|
|
ext->max_value = 100;
|
|
|
|
ext->cur_value = 0;
|
|
|
|
ext->line_cnt = 21; /*Odd scale number looks better*/
|
2017-04-21 17:11:47 +02:00
|
|
|
ext->scale_angle = 240; /*(scale_num - 1) * N looks better */
|
2019-11-16 11:27:35 +01:00
|
|
|
ext->angle_ofs = 0;
|
2017-04-21 17:11:47 +02:00
|
|
|
|
|
|
|
/*The signal and design functions are not copied so set them here*/
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_set_signal_cb(new_lmeter, lv_linemeter_signal);
|
|
|
|
lv_obj_set_design_cb(new_lmeter, lv_linemeter_design);
|
2017-04-21 17:11:47 +02:00
|
|
|
|
|
|
|
/*Init the new line meter line meter*/
|
|
|
|
if(copy == NULL) {
|
2017-11-16 15:32:33 +01:00
|
|
|
lv_obj_set_size(new_lmeter, LV_DPI, LV_DPI);
|
2020-02-14 17:03:25 +01:00
|
|
|
lv_theme_apply(new_lmeter, LV_THEME_LINEMETER);
|
2017-04-21 17:11:47 +02:00
|
|
|
}
|
|
|
|
/*Copy an existing line meter*/
|
|
|
|
else {
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->scale_angle = copy_ext->scale_angle;
|
|
|
|
ext->line_cnt = copy_ext->line_cnt;
|
|
|
|
ext->min_value = copy_ext->min_value;
|
|
|
|
ext->max_value = copy_ext->max_value;
|
|
|
|
ext->cur_value = copy_ext->cur_value;
|
2017-04-21 17:11:47 +02:00
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
// /*Refresh the style with new signal function*/
|
|
|
|
// lv_obj_refresh_style(new_lmeter);
|
2017-04-21 17:11:47 +02:00
|
|
|
}
|
2018-06-19 09:49:58 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("line meter created");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
return new_lmeter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/**
|
|
|
|
* Set a new value on the line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @param value new value
|
|
|
|
*/
|
2020-03-17 09:45:44 -07:00
|
|
|
void lv_linemeter_set_value(lv_obj_t * lmeter, lv_linemeter_value_t value)
|
2017-11-05 00:48:57 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2018-05-16 23:09:30 +02:00
|
|
|
if(ext->cur_value == value) return;
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
ext->cur_value = value > ext->max_value ? ext->max_value : value;
|
2017-11-05 00:48:57 +01:00
|
|
|
ext->cur_value = ext->cur_value < ext->min_value ? ext->min_value : ext->cur_value;
|
|
|
|
lv_obj_invalidate(lmeter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set minimum and the maximum values of a line meter
|
|
|
|
* @param lmeter pointer to he line meter object
|
|
|
|
* @param min minimum value
|
|
|
|
* @param max maximum value
|
|
|
|
*/
|
2020-03-17 09:45:44 -07:00
|
|
|
void lv_linemeter_set_range(lv_obj_t * lmeter, lv_linemeter_value_t min, lv_linemeter_value_t max)
|
2017-11-05 00:48:57 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2018-05-16 23:09:30 +02:00
|
|
|
if(ext->min_value == min && ext->max_value == max) return;
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
ext->max_value = max;
|
|
|
|
ext->min_value = min;
|
|
|
|
if(ext->cur_value > max) {
|
|
|
|
ext->cur_value = max;
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_set_value(lmeter, ext->cur_value);
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
|
|
|
if(ext->cur_value < min) {
|
|
|
|
ext->cur_value = min;
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_set_value(lmeter, ext->cur_value);
|
2017-11-05 00:48:57 +01:00
|
|
|
}
|
|
|
|
lv_obj_invalidate(lmeter);
|
|
|
|
}
|
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
/**
|
|
|
|
* Set the scale settings of a line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @param angle angle of the scale (0..360)
|
2017-11-05 00:48:57 +01:00
|
|
|
* @param line_cnt number of lines
|
2017-04-21 17:11:47 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_linemeter_set_scale(lv_obj_t * lmeter, uint16_t angle, uint16_t line_cnt)
|
2017-04-21 17:11:47 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2018-05-16 23:09:30 +02:00
|
|
|
if(ext->scale_angle == angle && ext->line_cnt == line_cnt) return;
|
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
ext->scale_angle = angle;
|
2019-04-04 07:15:40 +02:00
|
|
|
ext->line_cnt = line_cnt;
|
2017-04-21 17:11:47 +02:00
|
|
|
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_invalidate(lmeter);
|
2017-04-21 17:11:47 +02:00
|
|
|
}
|
|
|
|
|
2019-11-12 13:07:26 +01:00
|
|
|
/**
|
2019-11-16 11:27:35 +01:00
|
|
|
* Set the set an offset for the line meter's angles to rotate it.
|
2019-11-12 13:07:26 +01:00
|
|
|
* @param lmeter pointer to a line meter object
|
2019-11-12 16:14:18 +01:00
|
|
|
* @param angle angle where the meter will be facing (with its center)
|
2019-11-12 13:07:26 +01:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_linemeter_set_angle_offset(lv_obj_t * lmeter, uint16_t angle)
|
2019-11-12 13:07:26 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2019-11-16 11:27:35 +01:00
|
|
|
if(ext->angle_ofs == angle) return;
|
2019-11-12 13:07:26 +01:00
|
|
|
|
2019-11-16 11:27:35 +01:00
|
|
|
ext->angle_ofs = angle;
|
2019-11-12 13:07:26 +01:00
|
|
|
|
|
|
|
lv_obj_invalidate(lmeter);
|
|
|
|
}
|
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
2017-11-05 00:48:57 +01:00
|
|
|
/**
|
|
|
|
* Get the value of a line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @return the value of the line meter
|
|
|
|
*/
|
2020-03-17 09:45:44 -07:00
|
|
|
lv_linemeter_value_t lv_linemeter_get_value(const lv_obj_t * lmeter)
|
2017-11-05 00:48:57 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2017-11-05 00:48:57 +01:00
|
|
|
return ext->cur_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the minimum value of a line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @return the minimum value of the line meter
|
|
|
|
*/
|
2020-03-17 09:45:44 -07:00
|
|
|
lv_linemeter_value_t lv_linemeter_get_min_value(const lv_obj_t * lmeter)
|
2017-11-05 00:48:57 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2017-11-05 00:48:57 +01:00
|
|
|
return ext->min_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the maximum value of a line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @return the maximum value of the line meter
|
|
|
|
*/
|
2020-03-17 09:45:44 -07:00
|
|
|
lv_linemeter_value_t lv_linemeter_get_max_value(const lv_obj_t * lmeter)
|
2017-11-05 00:48:57 +01:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2017-11-05 00:48:57 +01:00
|
|
|
return ext->max_value;
|
|
|
|
}
|
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
/**
|
|
|
|
* Get the scale number of a line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @return number of the scale units
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_linemeter_get_line_count(const lv_obj_t * lmeter)
|
2017-04-21 17:11:47 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2019-04-04 07:15:40 +02:00
|
|
|
return ext->line_cnt;
|
2017-04-21 17:11:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the scale angle of a line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
2019-11-16 11:27:35 +01:00
|
|
|
* @return angle_ofs of the scale
|
2017-04-21 17:11:47 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_linemeter_get_scale_angle(const lv_obj_t * lmeter)
|
2017-04-21 17:11:47 +02:00
|
|
|
{
|
2019-09-26 12:54:40 +02:00
|
|
|
LV_ASSERT_OBJ(lmeter, LV_OBJX_NAME);
|
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2017-04-21 17:11:47 +02:00
|
|
|
return ext->scale_angle;
|
|
|
|
}
|
|
|
|
|
2019-11-16 11:27:35 +01:00
|
|
|
/**
|
2020-03-06 13:14:25 +01:00
|
|
|
* Get the offset for the line meter.
|
2019-11-16 11:27:35 +01:00
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @return angle offset (0..360)
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
uint16_t lv_linemeter_get_angle_offset(lv_obj_t * lmeter)
|
2019-11-16 11:27:35 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2019-11-16 11:27:35 +01:00
|
|
|
|
|
|
|
return ext->angle_ofs;
|
|
|
|
}
|
2019-11-30 11:41:18 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
void lv_linemeter_draw_scale(lv_obj_t * lmeter, const lv_area_t * clip_area, uint8_t part)
|
2020-01-01 21:44:16 +01:00
|
|
|
{
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter);
|
2020-01-01 21:44:16 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_style_int_t left = lv_obj_get_style_pad_left(lmeter, LV_LINEMETER_PART_MAIN);
|
|
|
|
lv_style_int_t right = lv_obj_get_style_pad_right(lmeter, LV_LINEMETER_PART_MAIN);
|
|
|
|
lv_style_int_t top = lv_obj_get_style_pad_top(lmeter, LV_LINEMETER_PART_MAIN);
|
2020-02-04 02:09:15 +01:00
|
|
|
|
|
|
|
lv_coord_t r_out = (lv_obj_get_width(lmeter) - left - right) / 2 ;
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_coord_t r_in = r_out - lv_obj_get_style_scale_width(lmeter, part);
|
2020-01-01 21:44:16 +01:00
|
|
|
if(r_in < 1) r_in = 1;
|
|
|
|
|
2020-02-04 02:09:15 +01:00
|
|
|
lv_coord_t x_ofs = lmeter->coords.x1 + r_out + left;
|
|
|
|
lv_coord_t y_ofs = lmeter->coords.y1 + r_out + top;
|
2020-01-01 21:44:16 +01:00
|
|
|
int16_t angle_ofs = ext->angle_ofs + 90 + (360 - ext->scale_angle) / 2;
|
|
|
|
int16_t level =
|
|
|
|
(int32_t)((int32_t)(ext->cur_value - ext->min_value) * ext->line_cnt) / (ext->max_value - ext->min_value);
|
|
|
|
uint8_t i;
|
|
|
|
|
2020-02-21 10:50:50 +01:00
|
|
|
lv_color_t main_color = lv_obj_get_style_line_color(lmeter, part);
|
2020-02-02 15:58:08 +01:00
|
|
|
lv_color_t grad_color = lv_obj_get_style_scale_grad_color(lmeter, part);
|
2020-02-03 20:49:34 +01:00
|
|
|
lv_color_t end_color = lv_obj_get_style_scale_end_color(lmeter, part);
|
|
|
|
|
2020-01-01 21:44:16 +01:00
|
|
|
|
|
|
|
lv_draw_line_dsc_t line_dsc;
|
|
|
|
lv_draw_line_dsc_init(&line_dsc);
|
|
|
|
lv_obj_init_draw_line_dsc(lmeter, part, &line_dsc);
|
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
lv_style_int_t end_line_width = lv_obj_get_style_scale_end_line_width(lmeter, part);
|
|
|
|
|
2020-03-04 12:09:29 +01:00
|
|
|
lv_area_t mask_area;
|
|
|
|
mask_area.x1 = x_ofs - r_in;
|
|
|
|
mask_area.x2 = x_ofs + r_in-1;
|
|
|
|
mask_area.y1 = y_ofs - r_in;
|
|
|
|
mask_area.y2 = y_ofs + r_in-1;
|
2020-03-04 14:43:08 +01:00
|
|
|
lv_draw_mask_radius_param_t mask_in_param;
|
|
|
|
lv_draw_mask_radius_init(&mask_in_param, &mask_area, LV_RADIUS_CIRCLE, true);
|
|
|
|
int16_t mask_in_id = lv_draw_mask_add(&mask_in_param, 0);
|
|
|
|
|
|
|
|
mask_area.x1 = x_ofs - r_out;
|
|
|
|
mask_area.x2 = x_ofs + r_out-1;
|
|
|
|
mask_area.y1 = y_ofs - r_out;
|
|
|
|
mask_area.y2 = y_ofs + r_out-1;
|
|
|
|
lv_draw_mask_radius_param_t mask_out_param;
|
|
|
|
lv_draw_mask_radius_init(&mask_out_param, &mask_area, LV_RADIUS_CIRCLE, false);
|
|
|
|
int16_t mask_out_id = lv_draw_mask_add(&mask_out_param, 0);
|
|
|
|
|
|
|
|
/*In calculation use a larger radius to avoid rounding errors */
|
|
|
|
lv_coord_t r_out_extra = r_out + LV_DPI;
|
|
|
|
for(i = 0; i < ext->line_cnt; i++) {
|
2020-03-04 16:44:20 +01:00
|
|
|
/* `* 256` for extra precision*/
|
|
|
|
int32_t angle_upscale = (i * ext->scale_angle * 256) / (ext->line_cnt - 1);
|
|
|
|
int32_t angle_normal = angle_upscale >> 8;
|
2020-03-04 12:09:29 +01:00
|
|
|
|
2020-03-04 16:44:20 +01:00
|
|
|
int32_t angle_low = (angle_upscale >> 8);
|
2020-03-04 14:43:08 +01:00
|
|
|
int32_t angle_high = angle_low + 1;
|
2020-03-04 16:44:20 +01:00
|
|
|
int32_t angle_rem = angle_upscale & 0xFF;
|
2020-03-04 12:09:29 +01:00
|
|
|
|
2020-03-04 14:43:08 +01:00
|
|
|
/*Interpolate sine and cos*/
|
|
|
|
int32_t sin_low = lv_trigo_sin(angle_low + angle_ofs);
|
|
|
|
int32_t sin_high = lv_trigo_sin(angle_high + angle_ofs);
|
2020-03-04 16:44:20 +01:00
|
|
|
int32_t sin_mid = (sin_low * (256 - angle_rem) + sin_high * angle_rem) >> 8;
|
2020-03-04 14:43:08 +01:00
|
|
|
|
|
|
|
int32_t cos_low = lv_trigo_sin(angle_low + 90 + angle_ofs);
|
|
|
|
int32_t cos_high = lv_trigo_sin(angle_high + 90 + angle_ofs);
|
2020-03-04 16:44:20 +01:00
|
|
|
int32_t cos_mid = (cos_low * (256 - angle_rem) + cos_high * angle_rem) >> 8;
|
2020-01-01 21:44:16 +01:00
|
|
|
|
2020-03-04 14:43:08 +01:00
|
|
|
/*Use the interpolated values to get x and y coordinates*/
|
|
|
|
int32_t y_out = (int32_t)((int32_t)sin_mid * r_out_extra) >> (LV_TRIGO_SHIFT - 8);
|
|
|
|
int32_t x_out = (int32_t)((int32_t)cos_mid * r_out_extra) >> (LV_TRIGO_SHIFT - 8);
|
2020-01-01 21:44:16 +01:00
|
|
|
|
|
|
|
/*Rounding*/
|
2020-03-04 14:43:08 +01:00
|
|
|
if(x_out > 0) x_out = (x_out + 127) >> 8;
|
2020-01-01 21:44:16 +01:00
|
|
|
else x_out = (x_out - 127) >> 8;
|
|
|
|
|
2020-03-04 14:43:08 +01:00
|
|
|
if(y_out > 0) y_out = (y_out + 127) >> 8;
|
2020-01-01 21:44:16 +01:00
|
|
|
else y_out = (y_out - 127) >> 8;
|
|
|
|
|
2020-03-04 12:09:29 +01:00
|
|
|
x_out += x_ofs;
|
|
|
|
y_out += y_ofs;
|
|
|
|
|
2020-03-04 14:43:08 +01:00
|
|
|
/*Use smaller clip area only around the visible line*/
|
|
|
|
int32_t y_in = (int32_t)((int32_t)lv_trigo_sin(angle_normal + angle_ofs) * r_in) >> LV_TRIGO_SHIFT;
|
|
|
|
int32_t x_in = (int32_t)((int32_t)lv_trigo_sin(angle_normal + 90 + angle_ofs) * r_in) >> LV_TRIGO_SHIFT;
|
2020-03-04 12:09:29 +01:00
|
|
|
|
|
|
|
x_in += x_ofs;
|
|
|
|
y_in += y_ofs;
|
|
|
|
|
|
|
|
lv_area_t clip_sub;
|
|
|
|
clip_sub.x1 = LV_MATH_MIN(x_in, x_out) - line_dsc.width;
|
|
|
|
clip_sub.x2 = LV_MATH_MAX(x_in, x_out) + line_dsc.width;
|
|
|
|
clip_sub.y1 = LV_MATH_MIN(y_in, y_out) - line_dsc.width;
|
|
|
|
clip_sub.y2 = LV_MATH_MAX(y_in, y_out) + line_dsc.width;
|
|
|
|
|
|
|
|
if(lv_area_intersect(&clip_sub, &clip_sub, clip_area) == false) continue;
|
2020-01-01 21:44:16 +01:00
|
|
|
|
|
|
|
lv_point_t p1;
|
|
|
|
lv_point_t p2;
|
|
|
|
|
2020-03-04 12:09:29 +01:00
|
|
|
p2.x = x_ofs;
|
|
|
|
p2.y = y_ofs;
|
2020-01-01 21:44:16 +01:00
|
|
|
|
2020-03-04 12:09:29 +01:00
|
|
|
p1.x = x_out;
|
|
|
|
p1.y = y_out;
|
2020-01-01 21:44:16 +01:00
|
|
|
|
2020-02-12 08:54:03 +01:00
|
|
|
if(i >= level) {
|
|
|
|
line_dsc.color = end_color;
|
|
|
|
line_dsc.width = end_line_width;
|
|
|
|
}
|
2020-03-04 14:43:08 +01:00
|
|
|
else {
|
|
|
|
line_dsc.color = lv_color_mix(grad_color, main_color, (255 * i) / ext->line_cnt);
|
|
|
|
}
|
2020-01-01 21:44:16 +01:00
|
|
|
|
2020-03-04 12:09:29 +01:00
|
|
|
lv_draw_line(&p1, &p2, &clip_sub, &line_dsc);
|
2020-01-01 21:44:16 +01:00
|
|
|
}
|
2020-02-03 20:49:34 +01:00
|
|
|
|
2020-03-04 14:43:08 +01:00
|
|
|
lv_draw_mask_remove_id(mask_in_id);
|
|
|
|
lv_draw_mask_remove_id(mask_out_id);
|
2020-03-04 12:09:29 +01:00
|
|
|
|
2020-02-14 12:36:44 +01:00
|
|
|
if(part == LV_LINEMETER_PART_MAIN) {
|
2020-02-03 20:49:34 +01:00
|
|
|
lv_style_int_t border_width = lv_obj_get_style_scale_border_width(lmeter, part);
|
|
|
|
lv_style_int_t end_border_width = lv_obj_get_style_scale_end_border_width(lmeter, part);
|
|
|
|
|
2020-02-26 19:48:27 +01:00
|
|
|
if(border_width || end_border_width) {
|
2020-02-03 20:49:34 +01:00
|
|
|
int16_t end_angle = (level * ext->scale_angle) / (ext->line_cnt - 1) + angle_ofs - 1;
|
|
|
|
lv_draw_line_dsc_t arc_dsc;
|
|
|
|
lv_draw_line_dsc_init(&arc_dsc);
|
|
|
|
lv_obj_init_draw_line_dsc(lmeter, part, &arc_dsc);
|
|
|
|
|
|
|
|
if(border_width) {
|
|
|
|
arc_dsc.width = border_width;
|
|
|
|
arc_dsc.color = main_color;
|
|
|
|
lv_draw_arc(x_ofs, y_ofs, r_out, angle_ofs, end_angle, clip_area, &arc_dsc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(end_border_width) {
|
|
|
|
arc_dsc.width = end_border_width;
|
2020-02-26 19:48:27 +01:00
|
|
|
arc_dsc.color = end_color;
|
|
|
|
lv_draw_arc(x_ofs, y_ofs, r_out, end_angle, (angle_ofs + ext->scale_angle) % 360, clip_area, &arc_dsc);
|
2020-02-03 20:49:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-01 21:44:16 +01:00
|
|
|
}
|
|
|
|
|
2017-04-21 17:11:47 +02:00
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
2020-01-01 21:44:16 +01:00
|
|
|
#include <stdlib.h>
|
2017-04-21 17:11:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the drawing related tasks of the line meters
|
|
|
|
* @param lmeter pointer to an object
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param clip_area the object will be drawn only in this area
|
2017-04-21 17:11:47 +02:00
|
|
|
* @param mode LV_DESIGN_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
|
|
|
* (return 'true' if yes)
|
|
|
|
* LV_DESIGN_DRAW: draw the object (always return 'true')
|
|
|
|
* LV_DESIGN_DRAW_POST: drawing after every children are drawn
|
2019-09-06 19:53:39 +02:00
|
|
|
* @param return an element of `lv_design_res_t`
|
2017-04-21 17:11:47 +02:00
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_design_res_t lv_linemeter_design(lv_obj_t * lmeter, const lv_area_t * clip_area, lv_design_mode_t mode)
|
2017-04-21 17:11:47 +02:00
|
|
|
{
|
|
|
|
/*Return false if the object is not covers the mask_p area*/
|
|
|
|
if(mode == LV_DESIGN_COVER_CHK) {
|
2019-09-06 19:53:39 +02:00
|
|
|
return LV_DESIGN_RES_NOT_COVER;
|
2017-04-21 17:11:47 +02:00
|
|
|
}
|
|
|
|
/*Draw the object*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_MAIN) {
|
2020-02-04 02:09:15 +01:00
|
|
|
lv_draw_rect_dsc_t bg_dsc;
|
|
|
|
lv_draw_rect_dsc_init(&bg_dsc);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_obj_init_draw_rect_dsc(lmeter, LV_LINEMETER_PART_MAIN, &bg_dsc);
|
2020-02-04 02:09:15 +01:00
|
|
|
lv_draw_rect(&lmeter->coords, clip_area, &bg_dsc);
|
2020-02-14 12:36:44 +01:00
|
|
|
lv_linemeter_draw_scale(lmeter, clip_area, LV_LINEMETER_PART_MAIN);
|
2017-04-21 17:11:47 +02:00
|
|
|
}
|
|
|
|
/*Post draw when the children are drawn*/
|
|
|
|
else if(mode == LV_DESIGN_DRAW_POST) {
|
|
|
|
}
|
|
|
|
|
2019-09-06 19:53:39 +02:00
|
|
|
return LV_DESIGN_RES_OK;
|
2017-04-21 17:11:47 +02:00
|
|
|
}
|
|
|
|
|
2017-11-11 14:23:05 +01:00
|
|
|
/**
|
|
|
|
* Signal function of the line meter
|
|
|
|
* @param lmeter pointer to a line meter object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
|
|
|
*/
|
2020-02-14 12:36:44 +01:00
|
|
|
static lv_res_t lv_linemeter_signal(lv_obj_t * lmeter, lv_signal_t sign, void * param)
|
2017-11-11 14:23:05 +01:00
|
|
|
{
|
|
|
|
lv_res_t res;
|
|
|
|
|
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(lmeter, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
2019-09-26 12:54:40 +02:00
|
|
|
if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
|
2017-11-11 14:23:05 +01:00
|
|
|
|
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
|
|
|
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
2020-02-26 19:48:27 +01:00
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_STYLE_CHG) {
|
2019-04-11 06:26:41 +02:00
|
|
|
lv_obj_refresh_ext_draw_pad(lmeter);
|
2020-02-14 10:21:38 +01:00
|
|
|
lv_obj_invalidate(lmeter);
|
2018-02-28 15:37:41 +01:00
|
|
|
}
|
2017-11-11 14:23:05 +01:00
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
return res;
|
2017-11-11 14:23:05 +01:00
|
|
|
}
|
2017-04-21 17:11:47 +02:00
|
|
|
#endif
|