solve conflicts
This commit is contained in:
116
lv_misc/lv_utils.c
Normal file
116
lv_misc/lv_utils.c
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
/**
|
||||||
|
* @file lv_utils.c
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* INCLUDES
|
||||||
|
*********************/
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "lv_utils.h"
|
||||||
|
#include "lv_math.h"
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* DEFINES
|
||||||
|
*********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* TYPEDEFS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* STATIC PROTOTYPES
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* STATIC VARIABLES
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* MACROS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* GLOBAL FUNCTIONS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a number to string
|
||||||
|
* @param num a number
|
||||||
|
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
|
||||||
|
* @return same as `buf` (just for convenience)
|
||||||
|
*/
|
||||||
|
char * lv_utils_num_to_str(int32_t num, char * buf)
|
||||||
|
{
|
||||||
|
if (num == 0) {
|
||||||
|
buf[0] = '0';
|
||||||
|
buf[1] = '\0';
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
int8_t digitCount = 0;
|
||||||
|
int8_t i = 0;
|
||||||
|
if (num < 0) {
|
||||||
|
buf[digitCount++] = '-';
|
||||||
|
num = abs(num);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
while (num) {
|
||||||
|
char digit = num % 10;
|
||||||
|
buf[digitCount++] = digit + 48;
|
||||||
|
num /= 10;
|
||||||
|
}
|
||||||
|
buf[digitCount] = '\0';
|
||||||
|
digitCount--;
|
||||||
|
while (digitCount > i) {
|
||||||
|
char temp = buf[i];
|
||||||
|
buf[i] = buf[digitCount];
|
||||||
|
buf[digitCount] = temp;
|
||||||
|
digitCount--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Searches base[0] to base[n - 1] for an item that matches *key.
|
||||||
|
*
|
||||||
|
* @note The function cmp must return negative if its first
|
||||||
|
* argument (the search key) is less that its second (a table entry),
|
||||||
|
* zero if equal, and positive if greater.
|
||||||
|
*
|
||||||
|
* @note Items in the array must be in ascending order.
|
||||||
|
*
|
||||||
|
* @param key Pointer to item being searched for
|
||||||
|
* @param base Pointer to first element to search
|
||||||
|
* @param n Number of elements
|
||||||
|
* @param size Size of each element
|
||||||
|
* @param cmp Pointer to comparison function (see #lv_font_codeCompare as a comparison function example)
|
||||||
|
*
|
||||||
|
* @return a pointer to a matching item, or NULL if none exists.
|
||||||
|
*/
|
||||||
|
void * lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, int32_t (* cmp)(const void * pRef, const void * pElement))
|
||||||
|
{
|
||||||
|
const char * middle;
|
||||||
|
int32_t c;
|
||||||
|
|
||||||
|
for (middle = base; n != 0;) {
|
||||||
|
middle += (n/2) * size;
|
||||||
|
if ((c = (*cmp)(key, middle)) > 0) {
|
||||||
|
n = (n/2) - ((n&1) == 0);
|
||||||
|
base = (middle += size);
|
||||||
|
} else if (c < 0) {
|
||||||
|
n /= 2;
|
||||||
|
middle = base;
|
||||||
|
} else {
|
||||||
|
return (char *) middle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* STATIC FUNCTIONS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
|
||||||
65
lv_misc/lv_utils.h
Normal file
65
lv_misc/lv_utils.h
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/**
|
||||||
|
* @file lv_utils.h
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LV_UTILS_H
|
||||||
|
#define LV_UTILS_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* INCLUDES
|
||||||
|
*********************/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/*********************
|
||||||
|
* DEFINES
|
||||||
|
*********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* TYPEDEFS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* GLOBAL PROTOTYPES
|
||||||
|
**********************/
|
||||||
|
/**
|
||||||
|
* Convert a number to string
|
||||||
|
* @param num a number
|
||||||
|
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
|
||||||
|
* @return same as `buf` (just for convenience)
|
||||||
|
*/
|
||||||
|
char * lv_utils_num_to_str(int32_t num, char * buf);
|
||||||
|
|
||||||
|
/** Searches base[0] to base[n - 1] for an item that matches *key.
|
||||||
|
*
|
||||||
|
* @note The function cmp must return negative if its first
|
||||||
|
* argument (the search key) is less that its second (a table entry),
|
||||||
|
* zero if equal, and positive if greater.
|
||||||
|
*
|
||||||
|
* @note Items in the array must be in ascending order.
|
||||||
|
*
|
||||||
|
* @param key Pointer to item being searched for
|
||||||
|
* @param base Pointer to first element to search
|
||||||
|
* @param n Number of elements
|
||||||
|
* @param size Size of each element
|
||||||
|
* @param cmp Pointer to comparison function (see #lv_font_codeCompare as a comparison function example)
|
||||||
|
*
|
||||||
|
* @return a pointer to a matching item, or NULL if none exists.
|
||||||
|
*/
|
||||||
|
void * lv_utils_bsearch(const void * key, const void * base, uint32_t n, uint32_t size, int32_t (* cmp)(const void * pRef, const void * pElement));
|
||||||
|
|
||||||
|
/**********************
|
||||||
|
* MACROS
|
||||||
|
**********************/
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,9 +6,10 @@
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include <stddef.h>
|
|
||||||
#include "lv_font.h"
|
#include "lv_font.h"
|
||||||
#include "lv_log.h"
|
#include "lv_log.h"
|
||||||
|
#include "lv_utils.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@@ -22,6 +23,8 @@
|
|||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
static int32_t lv_font_codeCompare (const void* pRef, const void* pElement);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
**********************/
|
**********************/
|
||||||
@@ -216,11 +219,17 @@ const uint8_t * lv_font_get_bitmap_sparse(const lv_font_t * font, uint32_t unico
|
|||||||
/*Check the range*/
|
/*Check the range*/
|
||||||
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
|
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t* pUnicode;
|
||||||
for(i = 0; font->unicode_list[i] != 0; i++) {
|
|
||||||
if(font->unicode_list[i] == unicode_letter) {
|
pUnicode = lv_utils_bsearch(&unicode_letter,
|
||||||
return &font->glyph_bitmap[font->glyph_dsc[i].glyph_index];
|
(uint32_t*) font->unicode_list,
|
||||||
}
|
font->glyph_cnt,
|
||||||
|
sizeof(uint32_t),
|
||||||
|
lv_font_codeCompare);
|
||||||
|
|
||||||
|
if (pUnicode != NULL) {
|
||||||
|
uint32_t idx = (uint32_t) (pUnicode - font->unicode_list);
|
||||||
|
return &font->glyph_bitmap[font->glyph_dsc[idx].glyph_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -254,11 +263,17 @@ int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter
|
|||||||
/*Check the range*/
|
/*Check the range*/
|
||||||
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return -1;
|
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return -1;
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t* pUnicode;
|
||||||
for(i = 0; font->unicode_list[i] != 0; i++) {
|
|
||||||
if(font->unicode_list[i] == unicode_letter) {
|
pUnicode = lv_utils_bsearch(&unicode_letter,
|
||||||
return font->glyph_dsc[i].w_px;
|
(uint32_t*) font->unicode_list,
|
||||||
}
|
font->glyph_cnt,
|
||||||
|
sizeof(uint32_t),
|
||||||
|
lv_font_codeCompare);
|
||||||
|
|
||||||
|
if (pUnicode != NULL) {
|
||||||
|
uint32_t idx = (uint32_t) (pUnicode - font->unicode_list);
|
||||||
|
return font->glyph_dsc[idx].w_px;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
@@ -267,3 +282,22 @@ int16_t lv_font_get_width_sparse(const lv_font_t * font, uint32_t unicode_letter
|
|||||||
/**********************
|
/**********************
|
||||||
* STATIC FUNCTIONS
|
* STATIC FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
|
/** Code Comparator.
|
||||||
|
*
|
||||||
|
* Compares the value of both input arguments.
|
||||||
|
*
|
||||||
|
* @param[in] pRef Pointer to the reference.
|
||||||
|
* @param[in] pElement Pointer to the element to compare.
|
||||||
|
*
|
||||||
|
* @return Result of comparison.
|
||||||
|
* @retval < 0 Reference is greater than element.
|
||||||
|
* @retval = 0 Reference is equal to element.
|
||||||
|
* @retval > 0 Reference is less than element.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static int32_t lv_font_codeCompare (const void* pRef,
|
||||||
|
const void* pElement)
|
||||||
|
{
|
||||||
|
return (*(uint32_t*) pRef) - (*(uint32_t*) pElement);
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,43 +47,6 @@ static int16_t sin0_90_table[] = {
|
|||||||
* GLOBAL FUNCTIONS
|
* GLOBAL FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert a number to string
|
|
||||||
* @param num a number
|
|
||||||
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
|
|
||||||
* @return same as `buf` (just for convenience)
|
|
||||||
*/
|
|
||||||
char * lv_math_num_to_str(int32_t num, char * buf)
|
|
||||||
{
|
|
||||||
if (num == 0) {
|
|
||||||
buf[0] = '0';
|
|
||||||
buf[1] = '\0';
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
int8_t digitCount = 0;
|
|
||||||
int8_t i = 0;
|
|
||||||
if (num < 0) {
|
|
||||||
buf[digitCount++] = '-';
|
|
||||||
num = abs(num);
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
while (num) {
|
|
||||||
char digit = num % 10;
|
|
||||||
buf[digitCount++] = digit + 48;
|
|
||||||
num /= 10;
|
|
||||||
}
|
|
||||||
buf[digitCount] = '\0';
|
|
||||||
digitCount--;
|
|
||||||
while (digitCount > i) {
|
|
||||||
char temp = buf[i];
|
|
||||||
buf[i] = buf[digitCount];
|
|
||||||
buf[digitCount] = temp;
|
|
||||||
digitCount--;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return with sinus of an angle
|
* Return with sinus of an angle
|
||||||
* @param angle
|
* @param angle
|
||||||
|
|||||||
@@ -36,13 +36,6 @@ extern "C" {
|
|||||||
/**********************
|
/**********************
|
||||||
* GLOBAL PROTOTYPES
|
* GLOBAL PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
/**
|
|
||||||
* Convert a number to string
|
|
||||||
* @param num a number
|
|
||||||
* @param buf pointer to a `char` buffer. The result will be stored here (max 10 elements)
|
|
||||||
* @return same as `buf` (just for convenience)
|
|
||||||
*/
|
|
||||||
char * lv_math_num_to_str(int32_t num, char * buf);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return with sinus of an angle
|
* Return with sinus of an angle
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ CSRCS += lv_txt.c
|
|||||||
CSRCS += lv_math.c
|
CSRCS += lv_math.c
|
||||||
CSRCS += lv_log.c
|
CSRCS += lv_log.c
|
||||||
CSRCS += lv_gc.c
|
CSRCS += lv_gc.c
|
||||||
|
CSRCS += lv_utils.c
|
||||||
|
|
||||||
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/src/lv_misc
|
DEPPATH += --dep-path $(LVGL_DIR)/lvgl/src/lv_misc
|
||||||
VPATH += :$(LVGL_DIR)/lvgl/src/lv_misc
|
VPATH += :$(LVGL_DIR)/lvgl/src/lv_misc
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include "../lv_draw/lv_draw.h"
|
#include "../lv_draw/lv_draw.h"
|
||||||
#include "../lv_hal/lv_hal_indev.h"
|
#include "../lv_hal/lv_hal_indev.h"
|
||||||
#include "../lv_misc/lv_math.h"
|
#include "../lv_misc/lv_utils.h"
|
||||||
#include "../lv_core/lv_indev.h"
|
#include "../lv_core/lv_indev.h"
|
||||||
#include "../lv_themes/lv_theme.h"
|
#include "../lv_themes/lv_theme.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -681,7 +681,7 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
|
|||||||
|
|
||||||
/*Add the year + month name*/
|
/*Add the year + month name*/
|
||||||
char txt_buf[64];
|
char txt_buf[64];
|
||||||
lv_math_num_to_str(ext->showed_date.year, txt_buf);
|
lv_utils_num_to_str(ext->showed_date.year, txt_buf);
|
||||||
txt_buf[4] = ' ';
|
txt_buf[4] = ' ';
|
||||||
txt_buf[5] = '\0';
|
txt_buf[5] = '\0';
|
||||||
strcpy(&txt_buf[5], get_month_name(calendar, ext->showed_date.month));
|
strcpy(&txt_buf[5], get_month_name(calendar, ext->showed_date.month));
|
||||||
@@ -851,7 +851,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
|||||||
else final_style = act_style;
|
else final_style = act_style;
|
||||||
|
|
||||||
/*Write the day's number*/
|
/*Write the day's number*/
|
||||||
lv_math_num_to_str(day_cnt, buf);
|
lv_utils_num_to_str(day_cnt, buf);
|
||||||
lv_draw_label(&label_area, mask, final_style, opa_scale, buf, LV_TXT_FLAG_CENTER, NULL);
|
lv_draw_label(&label_area, mask, final_style, opa_scale, buf, LV_TXT_FLAG_CENTER, NULL);
|
||||||
|
|
||||||
/*Go to the next day*/
|
/*Go to the next day*/
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "../lv_themes/lv_theme.h"
|
#include "../lv_themes/lv_theme.h"
|
||||||
#include "../lv_misc/lv_txt.h"
|
#include "../lv_misc/lv_txt.h"
|
||||||
#include "../lv_misc/lv_math.h"
|
#include "../lv_misc/lv_math.h"
|
||||||
|
#include "../lv_misc/lv_utils.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -371,7 +372,7 @@ static void lv_gauge_draw_scale(lv_obj_t * gauge, const lv_area_t * mask)
|
|||||||
|
|
||||||
int16_t scale_act = (int32_t)((int32_t)(max - min) * i) / (label_num - 1);
|
int16_t scale_act = (int32_t)((int32_t)(max - min) * i) / (label_num - 1);
|
||||||
scale_act += min;
|
scale_act += min;
|
||||||
lv_math_num_to_str(scale_act, scale_txt);
|
lv_utils_num_to_str(scale_act, scale_txt);
|
||||||
|
|
||||||
lv_area_t label_cord;
|
lv_area_t label_cord;
|
||||||
lv_point_t label_size;
|
lv_point_t label_size;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#if LV_USE_SPINBOX != 0
|
#if LV_USE_SPINBOX != 0
|
||||||
#include "../lv_themes/lv_theme.h"
|
#include "../lv_themes/lv_theme.h"
|
||||||
#include "../lv_misc/lv_math.h"
|
#include "../lv_misc/lv_math.h"
|
||||||
|
#include "../lv_misc/lv_utils.h"
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@@ -403,7 +404,7 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox)
|
|||||||
|
|
||||||
char digits[64];
|
char digits[64];
|
||||||
/*Convert the numbers to string (the sign is already handled so always covert positive number)*/
|
/*Convert the numbers to string (the sign is already handled so always covert positive number)*/
|
||||||
lv_math_num_to_str(ext->value < 0 ? -ext->value : ext->value, digits);
|
lv_utils_num_to_str(ext->value < 0 ? -ext->value : ext->value, digits);
|
||||||
|
|
||||||
/*Add leading zeros*/
|
/*Add leading zeros*/
|
||||||
int lz_cnt = ext->digit_count - (int)strlen(digits);
|
int lz_cnt = ext->digit_count - (int)strlen(digits);
|
||||||
|
|||||||
Reference in New Issue
Block a user