314 lines
12 KiB
C
Executable File
314 lines
12 KiB
C
Executable File
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "utility_functions.h"
|
|
|
|
extern PopupWindow_t popupWindows[NUM_OF_POPUP_WINDOWS];
|
|
|
|
static void lv_spinbox_increment_event_cb(lv_event_t *e);
|
|
static void lv_spinbox_decrement_event_cb(lv_event_t *e);
|
|
static void popupBtnCb(lv_event_t *e);
|
|
|
|
lv_obj_t *createRoller(lv_obj_t *parent, char *options, int rows) {
|
|
lv_obj_t *roller = lv_roller_create(parent);
|
|
lv_roller_set_options(roller, options, LV_ROLLER_MODE_NORMAL);
|
|
lv_roller_set_visible_row_count(roller, rows);
|
|
lv_obj_set_width(roller, 75);
|
|
lv_obj_add_style(roller, &styleRollerMain, LV_PART_MAIN);
|
|
lv_obj_add_style(roller, &styleRollerSelected, LV_PART_SELECTED);
|
|
return roller;
|
|
}
|
|
|
|
void createRollerOptions(int start, int finish, int step, uint8_t minWidth, char *dst, size_t len) {
|
|
minWidth = MIN(minWidth, 4);
|
|
char formatNewline[6];
|
|
sprintf(formatNewline, "%%0%dd\n", minWidth);
|
|
|
|
char format[5];
|
|
sprintf(format, "%%0%dd", minWidth);
|
|
|
|
memset(dst, 0, len);
|
|
for (int i = start; i < finish; i += step) {
|
|
char new[20];
|
|
sprintf(new, formatNewline, i);
|
|
strcat(dst, new);
|
|
}
|
|
char new[20];
|
|
sprintf(new, format, finish);
|
|
strcat(dst, new);
|
|
}
|
|
|
|
void createRollerOptionsPercent(int start, int finish, int step, uint8_t minWidth, char *dst, size_t len) {
|
|
minWidth = MIN(minWidth, 4);
|
|
char formatNewline[9];
|
|
sprintf(formatNewline, "%%0%dd %%\n", minWidth);
|
|
|
|
char format[8];
|
|
sprintf(format, "%%0%dd %%", minWidth);
|
|
|
|
memset(dst, 0, len);
|
|
for (int i = start; i < finish; i += step) {
|
|
char new[20];
|
|
sprintf(new, formatNewline, i);
|
|
strcat(dst, new);
|
|
}
|
|
char new[20];
|
|
sprintf(new, format, finish);
|
|
strcat(dst, new);
|
|
}
|
|
|
|
lv_obj_t *createSpinbox(lv_obj_t *parent, int min, int max, int step, int numDigits, int decimal) {
|
|
lv_obj_t *cont = lv_obj_create(parent);
|
|
lv_obj_set_style_bg_opa(cont, LV_OPA_TRANSP, 0);
|
|
lv_obj_set_style_border_width(cont, 0, 0);
|
|
lv_obj_set_size(cont, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
|
lv_obj_set_layout(cont, LV_LAYOUT_FLEX);
|
|
lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_set_style_pad_all(cont, 0, 0);
|
|
|
|
lv_obj_t *btnMinus = lv_btn_create(cont);
|
|
lv_obj_set_style_text_font(btnMinus, &lv_font_montserrat_20, 0);
|
|
lv_obj_set_style_bg_img_src(btnMinus, LV_SYMBOL_MINUS, 0);
|
|
|
|
lv_obj_t *spinbox = lv_spinbox_create(cont);
|
|
lv_obj_set_style_text_font(spinbox, &lv_font_montserrat_20, 0);
|
|
lv_obj_set_style_bg_opa(spinbox, LV_OPA_TRANSP, LV_PART_CURSOR);
|
|
lv_obj_set_style_text_color(spinbox, lv_color_black(), LV_PART_CURSOR);
|
|
lv_spinbox_set_range(spinbox, min, max);
|
|
lv_spinbox_set_digit_format(spinbox, numDigits, decimal);
|
|
lv_spinbox_set_step(spinbox, step);
|
|
lv_obj_set_size(spinbox, 100, 50);
|
|
lv_obj_clear_flag(spinbox, LV_OBJ_FLAG_CLICKABLE);
|
|
|
|
lv_obj_t *btnPlus = lv_btn_create(cont);
|
|
lv_obj_set_style_text_font(btnPlus, &lv_font_montserrat_20, 0);
|
|
lv_obj_set_style_bg_img_src(btnPlus, LV_SYMBOL_PLUS, 0);
|
|
|
|
lv_coord_t h = lv_obj_get_height(spinbox);
|
|
lv_obj_set_size(btnMinus, h, h);
|
|
lv_obj_set_size(btnPlus, h, h);
|
|
|
|
lv_obj_add_event_cb(btnMinus, lv_spinbox_decrement_event_cb, LV_EVENT_ALL, spinbox);
|
|
lv_obj_add_event_cb(btnPlus, lv_spinbox_increment_event_cb, LV_EVENT_ALL, spinbox);
|
|
|
|
return cont;
|
|
}
|
|
|
|
lv_obj_t *createTempSetting(lv_obj_t *parent, char *label, lv_obj_t **tempLabel, lv_obj_t **setting) {
|
|
lv_obj_t *line = lv_obj_create(parent);
|
|
lv_obj_set_size(line, LV_PCT(100), LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_flow(line, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_flex_align(line, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_clear_flag(line, LV_OBJ_FLAG_SCROLLABLE);
|
|
lv_obj_set_style_pad_all(line, 0, 0);
|
|
lv_obj_set_style_pad_hor(line, 10, 0);
|
|
lv_obj_set_style_pad_ver(line, 4, 0);
|
|
|
|
lv_obj_t *desc = lv_label_create(line);
|
|
lv_label_set_text(desc, label);
|
|
lv_obj_add_style(desc, &text_20, 0);
|
|
lv_obj_set_width(desc, LV_PCT(40));
|
|
|
|
*tempLabel = lv_label_create(line);
|
|
lv_label_set_text(*tempLabel, "");
|
|
lv_obj_add_style(*tempLabel, &text_20, 0);
|
|
lv_obj_set_width(*tempLabel, LV_PCT(20));
|
|
|
|
lv_obj_t *spinbox = createSpinbox(line, -50, 50, 1, 2, 1);
|
|
*setting = lv_obj_get_child(spinbox, 1);
|
|
|
|
return line;
|
|
}
|
|
|
|
lv_obj_t *createStateLine(lv_obj_t *parent, char *label, lv_obj_t **stateLabel) {
|
|
lv_obj_t *line = lv_obj_create(parent);
|
|
lv_obj_set_style_bg_opa(line, LV_OPA_TRANSP, 0);
|
|
lv_obj_set_style_border_width(line, 0, 0);
|
|
lv_obj_set_size(line, LV_PCT(100), LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_flow(line, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_flex_align(line, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_set_style_pad_all(line, 10, 0);
|
|
|
|
lv_obj_t *labelObj = lv_label_create(line);
|
|
lv_obj_add_style(labelObj, &text_24, 0);
|
|
lv_obj_set_width(labelObj, LV_PCT(60));
|
|
lv_label_set_text(labelObj, label);
|
|
|
|
*stateLabel = lv_label_create(line);
|
|
lv_obj_add_style(*stateLabel, &text_24, 0);
|
|
lv_obj_set_size(*stateLabel, LV_PCT(35), 35);
|
|
lv_label_set_text(*stateLabel, "");
|
|
|
|
return line;
|
|
}
|
|
|
|
static void lv_spinbox_increment_event_cb(lv_event_t * e) {
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
if (code == LV_EVENT_SHORT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) {
|
|
lv_spinbox_increment(lv_event_get_user_data(e));
|
|
}
|
|
}
|
|
|
|
static void lv_spinbox_decrement_event_cb(lv_event_t * e) {
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
if (code == LV_EVENT_SHORT_CLICKED || code == LV_EVENT_LONG_PRESSED_REPEAT) {
|
|
lv_spinbox_decrement(lv_event_get_user_data(e));
|
|
}
|
|
}
|
|
|
|
void createPopup(lv_obj_t *parent, const char *text, bool addBtn, uint8_t id, PopupWindow_t *out) {
|
|
out->id = id;
|
|
out->ignored = false;
|
|
|
|
lv_obj_t *window = lv_obj_create(parent);
|
|
lv_obj_set_size(window, LV_PCT(70), LV_PCT(70));
|
|
lv_obj_set_style_border_color(window, lv_palette_main(LV_PALETTE_BLUE), 0);
|
|
lv_obj_set_style_border_width(window, 3, 0);
|
|
lv_obj_center(window);
|
|
|
|
lv_obj_set_flex_flow(window, LV_FLEX_FLOW_COLUMN);
|
|
lv_obj_set_flex_align(window, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
|
|
out->window = window;
|
|
|
|
lv_obj_t *labelPopup = lv_label_create(window);
|
|
lv_obj_add_style(labelPopup, &text_28, 0);
|
|
lv_label_set_text(labelPopup, text);
|
|
lv_obj_set_style_text_align(labelPopup, LV_TEXT_ALIGN_CENTER, 0);
|
|
lv_obj_set_size(labelPopup, LV_PCT(100), LV_PCT(60));
|
|
|
|
if (addBtn) {
|
|
lv_obj_t *btnPopup = lv_btn_create(window);
|
|
lv_obj_t *btnLabel = lv_label_create(btnPopup);
|
|
lv_obj_add_event_cb(btnPopup, popupBtnCb, LV_EVENT_CLICKED, out);
|
|
lv_obj_add_style(btnLabel, &text_28, 0);
|
|
lv_label_set_text(btnLabel, "Закрыть");
|
|
lv_obj_center(btnLabel);
|
|
}
|
|
}
|
|
|
|
void deletePopup(PopupWindow_t *popup) {
|
|
popup->ignored = false;
|
|
if (popup->window) {
|
|
lv_obj_del(popup->window);
|
|
popup->window = NULL;
|
|
}
|
|
}
|
|
|
|
static void popupBtnCb(lv_event_t *e) {
|
|
PopupWindow_t *popup = lv_event_get_user_data(e);
|
|
lv_obj_add_flag(popup->window, LV_OBJ_FLAG_HIDDEN);
|
|
popup->ignored = true;
|
|
}
|
|
|
|
static lv_obj_t *createContForDescr(lv_obj_t *parent) {
|
|
lv_obj_t *mainCont = lv_obj_create(parent);
|
|
lv_obj_set_style_bg_opa(mainCont, LV_OPA_TRANSP, 0);
|
|
lv_obj_set_style_border_width(mainCont, 0, 0);
|
|
lv_obj_set_size(mainCont, LV_PCT(100), LV_SIZE_CONTENT);
|
|
lv_obj_set_flex_flow(mainCont, LV_FLEX_FLOW_ROW);
|
|
lv_obj_set_flex_align(mainCont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
|
lv_obj_set_style_pad_all(mainCont, 0, 0);
|
|
lv_obj_set_style_pad_column(mainCont, 20, 0);
|
|
|
|
lv_obj_t *iconCont = lv_obj_create(mainCont);
|
|
lv_obj_set_style_bg_opa(iconCont, LV_OPA_TRANSP, 0);
|
|
lv_obj_set_style_border_width(iconCont, 0, 0);
|
|
lv_obj_set_size(iconCont, LV_PCT(15), LV_SIZE_CONTENT);
|
|
lv_obj_set_style_pad_all(iconCont, 0, 0);
|
|
|
|
return mainCont;
|
|
}
|
|
|
|
void createSliderDescr(lv_obj_t *parent, char *text, lv_color_t color) {
|
|
lv_obj_t *sliderSection = createContForDescr(parent);
|
|
lv_obj_t *sliderCont = lv_obj_get_child(sliderSection, 0);
|
|
|
|
lv_obj_t *slider = lv_slider_create(sliderCont);
|
|
lv_obj_set_style_bg_color(slider, color, LV_PART_MAIN);
|
|
lv_obj_set_style_bg_color(slider, color, LV_PART_INDICATOR);
|
|
lv_obj_set_style_bg_color(slider, color, LV_PART_KNOB );
|
|
lv_obj_clear_flag(slider, LV_OBJ_FLAG_CLICKABLE);
|
|
lv_slider_set_range(slider, 0, 100);
|
|
lv_slider_set_value(slider, 50, LV_ANIM_OFF);
|
|
lv_obj_set_width(slider, LV_PCT(100));
|
|
lv_obj_center(slider);
|
|
lv_obj_set_style_bg_opa(slider, LV_OPA_TRANSP, LV_PART_KNOB);
|
|
|
|
lv_obj_t *label = lv_label_create(sliderSection);
|
|
lv_obj_add_style(label, &text_24, 0);
|
|
lv_label_set_text(label, text);
|
|
lv_obj_set_width(label, LV_PCT(80));
|
|
lv_obj_center(label);
|
|
}
|
|
|
|
void createArrowDescr(lv_obj_t *parent, char *text, lv_color_t color, bool flip) {
|
|
lv_obj_t *imgSection = createContForDescr(parent);
|
|
lv_obj_t *imgCont = lv_obj_get_child(imgSection, 0);
|
|
|
|
lv_obj_t *imgArrow = lv_img_create(imgCont);
|
|
lv_img_set_src(imgArrow, &arrow);
|
|
lv_obj_set_style_img_recolor_opa(imgArrow, 255, 0);
|
|
lv_obj_set_style_img_recolor(imgArrow, color, 0);
|
|
if (flip) lv_img_set_angle(imgArrow, 1800);
|
|
lv_img_set_zoom(imgArrow, 256 * 0.7);
|
|
lv_obj_set_size(imgArrow, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
|
lv_obj_center(imgArrow);
|
|
|
|
lv_obj_t *label = lv_label_create(imgSection);
|
|
lv_obj_add_style(label, &text_24, 0);
|
|
lv_label_set_text(label, text);
|
|
lv_obj_set_width(label, LV_PCT(80));
|
|
}
|
|
|
|
void createConditionerBtnMock(lv_obj_t *parent, char *text, lv_color_t color) {
|
|
lv_obj_t *btnSection = createContForDescr(parent);
|
|
lv_obj_t *btnCont = lv_obj_get_child(btnSection, 0);
|
|
|
|
lv_obj_t *btn = lv_btn_create(btnCont);
|
|
lv_obj_set_size(btn, 70, 70);
|
|
lv_obj_set_style_bg_opa(btn, LV_OPA_TRANSP, 0);
|
|
lv_obj_set_style_border_color(btn, color, 0);
|
|
lv_obj_set_style_border_width(btn, 3, 0);
|
|
lv_obj_clear_flag(btn, LV_OBJ_FLAG_CLICKABLE);
|
|
lv_obj_center(btn);
|
|
|
|
lv_obj_t *icon = lv_label_create(btn);
|
|
lv_obj_set_style_text_color(icon, color, 0);
|
|
lv_obj_set_style_text_font(icon, &lv_font_montserrat_24, 0);
|
|
lv_label_set_text(icon, LV_SYMBOL_REFRESH);
|
|
lv_obj_center(icon);
|
|
|
|
lv_obj_t *label = lv_label_create(btnSection);
|
|
lv_obj_add_style(label, &text_24, 0);
|
|
lv_label_set_text(label, text);
|
|
lv_obj_set_width(label, LV_PCT(80));
|
|
}
|
|
|
|
void createDateSetting(lv_obj_t *parent, const char *options, lv_obj_t **dd) {
|
|
*dd = lv_dropdown_create(parent);
|
|
lv_dropdown_set_options(*dd, options);
|
|
lv_obj_set_width(*dd, 200);
|
|
lv_obj_add_style(*dd, &text_24, LV_PART_MAIN);
|
|
lv_obj_set_style_text_font(*dd, &lv_font_montserrat_24, LV_PART_INDICATOR);
|
|
lv_obj_add_style(lv_dropdown_get_list(*dd), &text_24, 0);
|
|
lv_obj_set_style_border_width(*dd, 3, 0);
|
|
lv_obj_set_style_border_color(*dd, lv_palette_lighten(LV_PALETTE_BLUE, 1), 0);
|
|
}
|
|
|
|
bool isLeapYear(uint16_t year) {
|
|
if (year % 4 == 0) {
|
|
if (year % 100 == 0) {
|
|
if (year % 400 == 0) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return true;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|