feat: H7 support (#5738)
Co-authored-by: Richard Li <richard.li@ces.hk> Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com>
This commit is contained in:
co-authored by
Richard Li
philmoz
raphaelcoeffic
parent
5a15ffb017
commit
3d25c2a0f8
@@ -64,12 +64,12 @@ uint16_t lcdColorTable[] = {
|
||||
|
||||
uint32_t HSVtoRGB(float H, float S, float V)
|
||||
{
|
||||
if (H > 360 || H < 0 || S > 100 || S < 0 || V > 100 || V < 0) {
|
||||
if (H > 360 || H < 0 || S > MAX_SATURATION || S < 0 || V > MAX_BRIGHTNESS || V < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float s = S / 100;
|
||||
float v = V / 100;
|
||||
float s = S / MAX_SATURATION;
|
||||
float v = V / MAX_BRIGHTNESS;
|
||||
float C = s * v;
|
||||
float X = C * (1 - abs(fmod(H / 60.0, 2) - 1));
|
||||
float m = v - C;
|
||||
@@ -95,6 +95,39 @@ uint32_t HSVtoRGB(float H, float S, float V)
|
||||
return RGB(R, G, B);
|
||||
}
|
||||
|
||||
uint32_t HSVtoRGB32(float H, float S, float V)
|
||||
{
|
||||
if (H > 360 || H < 0 || S > MAX_SATURATION || S < 0 || V > MAX_BRIGHTNESS || V < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
float s = S / MAX_SATURATION;
|
||||
float v = V / MAX_BRIGHTNESS;
|
||||
float C = s * v;
|
||||
float X = C * (1 - abs(fmod(H / 60.0, 2) - 1));
|
||||
float m = v - C;
|
||||
float r, g, b;
|
||||
|
||||
if (H >= 0 && H < 60) {
|
||||
r = C, g = X, b = 0;
|
||||
} else if (H >= 60 && H < 120) {
|
||||
r = X, g = C, b = 0;
|
||||
} else if (H >= 120 && H < 180) {
|
||||
r = 0, g = C, b = X;
|
||||
} else if (H >= 180 && H < 240) {
|
||||
r = 0, g = X, b = C;
|
||||
} else if (H >= 240 && H < 300) {
|
||||
r = X, g = 0, b = C;
|
||||
} else {
|
||||
r = C, g = 0, b = X;
|
||||
}
|
||||
int R = (r + m) * 255;
|
||||
int G = (g + m) * 255;
|
||||
int B = (b + m) * 255;
|
||||
|
||||
return RGB32(R, G, B);
|
||||
}
|
||||
|
||||
void RGBtoHSV(uint8_t R, uint8_t G, uint8_t B, float &fH, float &fS, float &fV)
|
||||
{
|
||||
float fR = (float)R / 255;
|
||||
@@ -152,6 +185,19 @@ LcdFlags colorToRGB(LcdFlags colorFlags)
|
||||
return (colorFlags & 0xFFFF) | COLOR(COLOR_VAL(colorFlags)) | RGB_FLAG;
|
||||
}
|
||||
|
||||
uint32_t color32ToRGB(uint32_t color)
|
||||
{
|
||||
// RGB or indexed color?
|
||||
if (color & RGB888_FLAG)
|
||||
return color;
|
||||
|
||||
color = COLOR_VAL(COLOR(color));
|
||||
auto r = GET_RED(color);
|
||||
auto g = GET_GREEN(color);
|
||||
auto b = GET_BLUE(color);
|
||||
return RGB32(r, g, b) | RGB888_FLAG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to translate a colorFlags value to a lv_color_t suitable
|
||||
* for passing to an lv_obj function
|
||||
|
||||
@@ -132,9 +132,25 @@ constexpr int MAX_HUE = 360;
|
||||
constexpr int MAX_BRIGHTNESS = 100;
|
||||
|
||||
extern uint32_t HSVtoRGB(float H, float S, float V);
|
||||
extern uint32_t HSVtoRGB32(float H, float S, float V);
|
||||
extern void RGBtoHSV(uint8_t R, uint8_t G, uint8_t B, float& fH, float& fS,
|
||||
float& fV);
|
||||
|
||||
LcdFlags colorToRGB(LcdFlags colorFlags);
|
||||
uint32_t color32ToRGB(uint32_t color);
|
||||
|
||||
lv_color_t makeLvColor(uint32_t colorFlags);
|
||||
|
||||
constexpr uint32_t RGB888_FLAG = 0x1000000;
|
||||
|
||||
enum COLOR_EDITOR_FMT {
|
||||
RGB565 = 0,
|
||||
RGB888
|
||||
};
|
||||
|
||||
#define RGB32(r, g, b) \
|
||||
(uint32_t)((((r) & 0xFF) << 16) + (((g) & 0xFF) << 8) + ((b) & 0xFF))
|
||||
|
||||
#define GET_RED32(color) (((color) & 0xFF0000) >> 16)
|
||||
#define GET_GREEN32(color) (((color) & 0x00FF00) >> 8)
|
||||
#define GET_BLUE32(color) ((color) & 0x0000FF)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "color_editor.h"
|
||||
|
||||
#include "button.h"
|
||||
@@ -162,7 +163,7 @@ class ColorBar : public FormField
|
||||
p2.x = area->x2 - 1;
|
||||
}
|
||||
auto c = bar->getRGB(bar->screenToValue(i));
|
||||
line_dsc.color = lv_color_make(GET_RED(c), GET_GREEN(c), GET_BLUE(c));
|
||||
line_dsc.color = lv_color_make(GET_RED32(c), GET_GREEN32(c), GET_BLUE32(c));
|
||||
lv_draw_line(dsc->draw_ctx, &line_dsc, &p1, &p2);
|
||||
}
|
||||
|
||||
@@ -289,42 +290,42 @@ class HSVColorType : public BarColorType
|
||||
public:
|
||||
HSVColorType(Window* parent, uint32_t color) : BarColorType(parent)
|
||||
{
|
||||
auto rgb = COLOR_VAL(colorToRGB(color));
|
||||
auto rgb = color32ToRGB(color);
|
||||
|
||||
auto r = GET_RED(rgb), g = GET_GREEN(rgb), b = GET_BLUE(rgb);
|
||||
auto r = GET_RED32(rgb), g = GET_GREEN32(rgb), b = GET_BLUE32(rgb);
|
||||
float values[MAX_BARS];
|
||||
RGBtoHSV(r, g, b, values[0], values[1], values[2]);
|
||||
values[1] *= MAX_SATURATION; // convert the proper base
|
||||
values[2] *= MAX_BRIGHTNESS;
|
||||
|
||||
for (auto i = 0; i < MAX_BARS; i++) {
|
||||
bars[i]->maxValue = i == 0 ? MAX_HUE : MAX_BRIGHTNESS;
|
||||
bars[i]->maxValue = (i == 0) ? MAX_HUE : (i == 1) ? MAX_SATURATION : MAX_BRIGHTNESS;
|
||||
bars[i]->invert = i != 0;
|
||||
bars[i]->value = values[i];
|
||||
}
|
||||
|
||||
// hue
|
||||
bars[0]->getRGB = [=](int pos) {
|
||||
auto rgb = HSVtoRGB(pos, bars[1]->value, bars[2]->value);
|
||||
auto rgb = HSVtoRGB32(pos, bars[1]->value, bars[2]->value);
|
||||
return rgb;
|
||||
};
|
||||
|
||||
// saturation
|
||||
bars[1]->getRGB = [=](int pos) {
|
||||
auto rgb = HSVtoRGB(bars[0]->value, pos, bars[2]->value);
|
||||
auto rgb = HSVtoRGB32(bars[0]->value, pos, bars[2]->value);
|
||||
return rgb;
|
||||
};
|
||||
|
||||
// brightness
|
||||
bars[2]->getRGB = [=](int pos) {
|
||||
auto rgb = HSVtoRGB(bars[0]->value, bars[1]->value, pos);
|
||||
auto rgb = HSVtoRGB32(bars[0]->value, bars[1]->value, pos);
|
||||
return rgb;
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t getRGB() override
|
||||
{
|
||||
return COLOR2FLAGS(HSVtoRGB(bars[0]->value, bars[1]->value, bars[2]->value)) | RGB_FLAG;
|
||||
return HSVtoRGB32(bars[0]->value, bars[1]->value, bars[2]->value) | RGB888_FLAG;
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -337,9 +338,9 @@ class RGBColorType : public BarColorType
|
||||
public:
|
||||
RGBColorType(Window* parent, uint32_t color) : BarColorType(parent)
|
||||
{
|
||||
auto rgb = COLOR_VAL(colorToRGB(color));
|
||||
auto rgb = color32ToRGB(color);
|
||||
|
||||
auto r = GET_RED(rgb), g = GET_GREEN(rgb), b = GET_BLUE(rgb);
|
||||
auto r = GET_RED32(rgb), g = GET_GREEN32(rgb), b = GET_BLUE32(rgb);
|
||||
float values[MAX_BARS];
|
||||
values[0] = r;
|
||||
values[1] = g;
|
||||
@@ -351,14 +352,14 @@ class RGBColorType : public BarColorType
|
||||
bars[i]->invert = true;
|
||||
}
|
||||
|
||||
bars[0]->getRGB = [=](int pos) { return RGB(pos, 0, 0); };
|
||||
bars[1]->getRGB = [=](int pos) { return RGB(0, pos, 0); };
|
||||
bars[2]->getRGB = [=](int pos) { return RGB(0, 0, pos); };
|
||||
bars[0]->getRGB = [=](int pos) { return RGB32(pos, 0, 0); };
|
||||
bars[1]->getRGB = [=](int pos) { return RGB32(0, pos, 0); };
|
||||
bars[2]->getRGB = [=](int pos) { return RGB32(0, 0, pos); };
|
||||
}
|
||||
|
||||
uint32_t getRGB() override
|
||||
{
|
||||
return RGB2FLAGS(bars[0]->value, bars[1]->value, bars[2]->value);
|
||||
return RGB32(bars[0]->value, bars[1]->value, bars[2]->value) | RGB888_FLAG;
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -396,7 +397,7 @@ class ThemeColorType : public ColorType
|
||||
auto btn = new TextButton(parent, rect_t{}, " ");
|
||||
etx_bg_color(btn->getLvObj(), (LcdColorIndex)color);
|
||||
btn->setPressHandler([=]() {
|
||||
m_color = COLOR2FLAGS(color);
|
||||
m_color = color;
|
||||
lv_event_send(parent->getParent()->getParent()->getLvObj(),
|
||||
LV_EVENT_VALUE_CHANGED, nullptr);
|
||||
return 0;
|
||||
@@ -421,14 +422,31 @@ class ThemeColorType : public ColorType
|
||||
////// ColorEditor Base class
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
ColorEditor::ColorEditor(Window* parent, const rect_t& rect, uint32_t color,
|
||||
std::function<void(uint32_t rgb)> setValue) :
|
||||
Window(parent, rect), _setValue(std::move(setValue)), _color(color)
|
||||
std::function<void(uint32_t rgb)> setValue,
|
||||
std::function<void(uint32_t rgb)> preview,
|
||||
COLOR_EDITOR_FMT fmt) :
|
||||
Window(parent, rect), _setValue(std::move(setValue)), _preview(std::move(preview)),
|
||||
format(fmt)
|
||||
{
|
||||
_colorType = new HSVColorType(this, color);
|
||||
if (format == RGB565) {
|
||||
if (color & RGB_FLAG) {
|
||||
color = COLOR_VAL(color);
|
||||
auto r = GET_RED(color);
|
||||
auto g = GET_GREEN(color);
|
||||
auto b = GET_BLUE(color);
|
||||
color = RGB32(r, g, b) | RGB888_FLAG;
|
||||
} else {
|
||||
color = COLOR_VAL(color);
|
||||
}
|
||||
}
|
||||
_color = color;
|
||||
_colorType = new HSVColorType(this, _color);
|
||||
_colorType->setText();
|
||||
|
||||
lv_obj_add_event_cb(lvobj, ColorEditor::value_changed, LV_EVENT_VALUE_CHANGED,
|
||||
nullptr);
|
||||
|
||||
if (_preview) _preview(_color);
|
||||
}
|
||||
|
||||
void ColorEditor::setColorEditorType(COLOR_EDITOR_TYPE colorType)
|
||||
@@ -439,10 +457,10 @@ void ColorEditor::setColorEditorType(COLOR_EDITOR_TYPE colorType)
|
||||
}
|
||||
if (colorType == RGB_COLOR_EDITOR) {
|
||||
_colorType = new RGBColorType(this, _color);
|
||||
setRGB();
|
||||
setText();
|
||||
} else if (colorType == HSV_COLOR_EDITOR) {
|
||||
_colorType = new HSVColorType(this, _color);
|
||||
setHSV();
|
||||
setText();
|
||||
} else {
|
||||
_colorType = new ThemeColorType(this, _color);
|
||||
setText();
|
||||
@@ -454,7 +472,20 @@ void ColorEditor::setColorEditorType(COLOR_EDITOR_TYPE colorType)
|
||||
void ColorEditor::setText()
|
||||
{
|
||||
_colorType->setText();
|
||||
if (_setValue != nullptr) _setValue(_color);
|
||||
if (_setValue != nullptr) {
|
||||
uint32_t c = _color;
|
||||
if (format == RGB565) {
|
||||
if (c & RGB888_FLAG) {
|
||||
auto r = GET_RED32(c);
|
||||
auto g = GET_GREEN32(c);
|
||||
auto b = GET_BLUE32(c);
|
||||
c = RGB2FLAGS(r, g, b);
|
||||
} else {
|
||||
c = COLOR2FLAGS(c);
|
||||
}
|
||||
}
|
||||
_setValue(c);
|
||||
}
|
||||
}
|
||||
|
||||
void ColorEditor::setRGB()
|
||||
@@ -462,12 +493,7 @@ void ColorEditor::setRGB()
|
||||
_color = _colorType->getRGB();
|
||||
// update bars & labels
|
||||
setText();
|
||||
}
|
||||
|
||||
void ColorEditor::setHSV()
|
||||
{
|
||||
// update bars & labels
|
||||
setText();
|
||||
if (_preview) _preview(_color);
|
||||
}
|
||||
|
||||
void ColorEditor::value_changed(lv_event_t* e)
|
||||
|
||||
@@ -37,7 +37,9 @@ class ColorEditor : public Window
|
||||
{
|
||||
public:
|
||||
ColorEditor(Window* parent, const rect_t& rect, uint32_t color,
|
||||
std::function<void(uint32_t rgb)> setValue = nullptr);
|
||||
std::function<void(uint32_t rgb)> setValue = nullptr,
|
||||
std::function<void(uint32_t rgb)> preview = nullptr,
|
||||
COLOR_EDITOR_FMT fmt = RGB565);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "ColorEditor"; }
|
||||
@@ -57,10 +59,11 @@ class ColorEditor : public Window
|
||||
protected:
|
||||
ColorType* _colorType = nullptr;
|
||||
std::function<void(uint32_t)> _setValue;
|
||||
std::function<void(uint32_t)> _preview;
|
||||
uint32_t _color;
|
||||
COLOR_EDITOR_FMT format;
|
||||
|
||||
void setText();
|
||||
void setHSV();
|
||||
void setRGB();
|
||||
static void value_changed(lv_event_t* e);
|
||||
};
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "color_picker.h"
|
||||
|
||||
#include "color_editor.h"
|
||||
#include "color_list.h"
|
||||
#include "etx_lv_theme.h"
|
||||
|
||||
@@ -44,14 +43,23 @@ class ColorEditorPopup : public BaseDialog
|
||||
ColorSwatch* colorPad = nullptr;
|
||||
StaticText* hexStr = nullptr;
|
||||
uint32_t m_color;
|
||||
uint32_t origColor;
|
||||
std::function<void(uint32_t)> setValue;
|
||||
COLOR_EDITOR_FMT format;
|
||||
|
||||
void updateColor(uint32_t c)
|
||||
{
|
||||
m_color = c;
|
||||
|
||||
auto rgb = COLOR_VAL(colorToRGB(m_color));
|
||||
uint8_t r, g, b;
|
||||
|
||||
uint8_t r = GET_RED(rgb), g = GET_GREEN(rgb), b = GET_BLUE(rgb);
|
||||
if (format == RGB565) {
|
||||
auto rgb = COLOR_VAL(colorToRGB(m_color));
|
||||
r = GET_RED(rgb); g = GET_GREEN(rgb); b = GET_BLUE(rgb);
|
||||
} else {
|
||||
auto rgb = color32ToRGB(m_color);
|
||||
r = GET_RED32(rgb); g = GET_GREEN32(rgb); b = GET_BLUE32(rgb);
|
||||
}
|
||||
|
||||
colorPad->setColor(r, g, b);
|
||||
|
||||
@@ -60,18 +68,27 @@ class ColorEditorPopup : public BaseDialog
|
||||
hexStr->setText(s);
|
||||
}
|
||||
|
||||
void onCancel() override
|
||||
{
|
||||
if (setValue) setValue(origColor);
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
public:
|
||||
ColorEditorPopup(uint32_t color,
|
||||
std::function<void(uint32_t)> _setValue) :
|
||||
std::function<void(uint32_t)> _setValue,
|
||||
std::function<void(uint32_t)> _preview,
|
||||
COLOR_EDITOR_FMT fmt) :
|
||||
BaseDialog(STR_COLOR_PICKER, false, COLOR_EDIT_WIDTH,
|
||||
LV_SIZE_CONTENT)
|
||||
LV_SIZE_CONTENT),
|
||||
origColor(color), setValue(std::move(_setValue)), format(fmt)
|
||||
{
|
||||
FlexGridLayout grid(col_dsc, row_dsc);
|
||||
auto line = form->newLine(grid);
|
||||
|
||||
rect_t r{0, 0, CE_SZ, CE_SZ};
|
||||
auto cedit =
|
||||
new ColorEditor(line, r, color, [=](uint32_t c) { updateColor(c); });
|
||||
new ColorEditor(line, r, color, [=](uint32_t c) { updateColor(c); }, _preview, format);
|
||||
lv_obj_set_style_grid_cell_x_align(cedit->getLvObj(), LV_GRID_ALIGN_CENTER,
|
||||
0);
|
||||
|
||||
@@ -138,12 +155,12 @@ class ColorEditorPopup : public BaseDialog
|
||||
lv_obj_set_flex_grow(hbox->getLvObj(), 1);
|
||||
|
||||
new TextButton(hbox, rect_t{0, 0, BTN_W, 0}, STR_CANCEL, [=]() -> int8_t {
|
||||
this->deleteLater();
|
||||
onCancel();
|
||||
return 0;
|
||||
});
|
||||
|
||||
new TextButton(hbox, rect_t{0, 0, BTN_W, 0}, STR_SAVE, [=]() -> int8_t {
|
||||
if (_setValue) _setValue(m_color);
|
||||
if (setValue) setValue(m_color);
|
||||
this->deleteLater();
|
||||
return 0;
|
||||
});
|
||||
@@ -161,16 +178,18 @@ class ColorEditorPopup : public BaseDialog
|
||||
|
||||
ColorPicker::ColorPicker(Window* parent, const rect_t& rect,
|
||||
std::function<uint32_t()> getValue,
|
||||
std::function<void(uint32_t)> setValue) :
|
||||
Button(parent, {rect.x, rect.y, ColorEditorPopup::COLOR_PAD_WIDTH, ColorEditorPopup::COLOR_PAD_HEIGHT}),
|
||||
setValue(std::move(setValue))
|
||||
std::function<void(uint32_t)> setValue,
|
||||
std::function<void(uint32_t)> preview,
|
||||
COLOR_EDITOR_FMT fmt) :
|
||||
Button(parent, {rect.x, rect.y, rect.w == 0 ? ColorEditorPopup::COLOR_PAD_WIDTH : rect.w, ColorEditorPopup::COLOR_PAD_HEIGHT}),
|
||||
setValue(std::move(setValue)), preview(std::move(preview)), format(fmt)
|
||||
{
|
||||
updateColor(getValue());
|
||||
}
|
||||
|
||||
void ColorPicker::onClicked()
|
||||
{
|
||||
new ColorEditorPopup(getColor(), [=](uint32_t c) { setColor(c); });
|
||||
new ColorEditorPopup(getColor(), [=](uint32_t c) { setColor(c); }, preview, format);
|
||||
}
|
||||
|
||||
void ColorPicker::setColor(uint32_t c)
|
||||
@@ -183,8 +202,16 @@ void ColorPicker::updateColor(uint32_t c)
|
||||
{
|
||||
color = c;
|
||||
|
||||
auto rgb = COLOR_VAL(colorToRGB(color));
|
||||
auto lvcolor =
|
||||
lv_color_make(GET_RED(rgb), GET_GREEN(rgb), GET_BLUE(rgb));
|
||||
uint8_t r, g, b;
|
||||
|
||||
if (format == RGB565) {
|
||||
auto rgb = COLOR_VAL(colorToRGB(color));
|
||||
r = GET_RED(rgb); g = GET_GREEN(rgb); b = GET_BLUE(rgb);
|
||||
} else {
|
||||
auto rgb = color32ToRGB(color);
|
||||
r = GET_RED32(rgb); g = GET_GREEN32(rgb); b = GET_BLUE32(rgb);
|
||||
}
|
||||
|
||||
auto lvcolor = lv_color_make(r, g, b);
|
||||
lv_obj_set_style_bg_color(lvobj, lvcolor, LV_PART_MAIN);
|
||||
}
|
||||
|
||||
@@ -22,18 +22,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "button.h"
|
||||
#include "color_editor.h"
|
||||
|
||||
class ColorPicker : public Button
|
||||
{
|
||||
uint32_t color;
|
||||
std::function<void(uint32_t)> setValue;
|
||||
std::function<void(uint32_t)> preview;
|
||||
COLOR_EDITOR_FMT format;
|
||||
|
||||
void updateColor(uint32_t c);
|
||||
|
||||
public:
|
||||
ColorPicker(Window* parent, const rect_t& rect,
|
||||
std::function<uint32_t()> getValue,
|
||||
std::function<void(uint32_t)> setValue = nullptr);
|
||||
std::function<void(uint32_t)> setValue = nullptr,
|
||||
std::function<void(uint32_t)> preview = nullptr,
|
||||
COLOR_EDITOR_FMT fmt = RGB565);
|
||||
|
||||
void setColor(uint32_t c);
|
||||
uint32_t getColor() const { return color; }
|
||||
|
||||
@@ -56,7 +56,10 @@ class NumberArea : public FormField
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override
|
||||
{
|
||||
return "NumberArea(" + std::to_string(getValue()) + ")";
|
||||
if(numEdit)
|
||||
return "NumberArea(" + numEdit->getName() + ")";
|
||||
else
|
||||
return "NumberArea(unknown)";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class TextEdit : public TextButton
|
||||
std::function<void(void)> updateHandler = nullptr);
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() const override { return "TextEdit \"" + text + "\""; }
|
||||
std::string getName() const override { return std::string("TextEdit \"") + text + "\""; }
|
||||
#endif
|
||||
|
||||
void preview(bool edited, char* text, uint8_t length);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
/* clang-format off */
|
||||
|
||||
#include <stdint.h>
|
||||
#include "definitions.h"
|
||||
|
||||
/*====================
|
||||
COLOR SETTINGS
|
||||
@@ -185,8 +186,10 @@
|
||||
#if LV_USE_GPU_STM32_DMA2D
|
||||
/*Must be defined to include path of CMSIS header of target processor
|
||||
e.g. "stm32f769xx.h" or "stm32f429xx.h"*/
|
||||
#ifdef STM32H7
|
||||
#if defined(STM32H7)
|
||||
#define LV_GPU_DMA2D_CMSIS_INCLUDE "stm32h7xx.h"
|
||||
#elif defined(STM32H7RS)
|
||||
#define LV_GPU_DMA2D_CMSIS_INCLUDE "stm32h7rsxx.h"
|
||||
#else
|
||||
#define LV_GPU_DMA2D_CMSIS_INCLUDE "stm32f4xx.h"
|
||||
#endif
|
||||
@@ -353,10 +356,10 @@
|
||||
#define LV_ATTRIBUTE_LARGE_RAM_ARRAY
|
||||
|
||||
/*Place performance critical functions into a faster memory (e.g RAM)*/
|
||||
#define LV_ATTRIBUTE_FAST_MEM
|
||||
#define LV_ATTRIBUTE_FAST_MEM __IRAM
|
||||
|
||||
/*Prefix variables that are used in GPU accelerated operations, often these need to be placed in RAM sections that are DMA accessible*/
|
||||
#define LV_ATTRIBUTE_DMA
|
||||
#define LV_ATTRIBUTE_DMA __DMA
|
||||
|
||||
/*Export integer constant to binding. This macro is used with constants in the form of LV_<CONST> that
|
||||
*should also appear on LVGL binding API such as Micropython.*/
|
||||
|
||||
@@ -28,20 +28,21 @@
|
||||
#include "switches.h"
|
||||
#include "color_picker.h"
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
static constexpr coord_t LH = 72;
|
||||
#else
|
||||
static constexpr coord_t LH = 36;
|
||||
#endif
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
static const lv_coord_t line_col_dsc1[] = {LV_GRID_CONTENT,
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
static const lv_coord_t line_col_dsc2[] = {
|
||||
LV_GRID_FR(13), LV_GRID_FR(11), LV_GRID_FR(11),
|
||||
LV_GRID_FR(12), LV_GRID_FR(10), LV_GRID_FR(7), LV_GRID_FR(7),
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
#else
|
||||
static const lv_coord_t line_col_dsc2[] = {
|
||||
LV_GRID_FR(10), LV_GRID_FR(10), LV_GRID_FR(10),
|
||||
LV_GRID_FR(12), LV_GRID_FR(8), LV_GRID_TEMPLATE_LAST};
|
||||
#endif
|
||||
|
||||
static const lv_coord_t line_row_dsc[] = {LV_GRID_CONTENT,
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
@@ -124,60 +125,110 @@ class FunctionSwitch : public Window
|
||||
});
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
new StaticText(this, {8 , 6 + 36, SW_W, EdgeTxStyles::PAGE_LINE_HEIGHT}, STR_FS_OFF_COLOR, COLOR_THEME_PRIMARY1);
|
||||
offValue = g_model.functionSwitchLedOFFColor[switchIndex];
|
||||
onValue = g_model.functionSwitchLedONColor[switchIndex];
|
||||
|
||||
auto offcolor = new ColorPicker(
|
||||
this, rect_t{},
|
||||
offColor = new ColorPicker(
|
||||
this, {C1_X, 0, C1_W, 0},
|
||||
[=]() -> int { // getValue
|
||||
return g_model.functionSwitchLedOFFColor[switchIndex];
|
||||
return g_model.functionSwitchLedOFFColor[switchIndex].getColor();
|
||||
},
|
||||
[=](int newValue) { // setValue
|
||||
g_model.functionSwitchLedOFFColor[switchIndex] =
|
||||
(uint32_t)newValue;
|
||||
TRACE("Color: %x", g_model.functionSwitchLedOFFColor[switchIndex]);
|
||||
g_model.functionSwitchLedOFFColor[switchIndex] = offValue;
|
||||
g_model.functionSwitchLedONColor[switchIndex] = onValue;
|
||||
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
g_model.functionSwitchLedOFFColor[switchIndex].setColor(newValue);
|
||||
|
||||
offValue = g_model.functionSwitchLedOFFColor[switchIndex];
|
||||
SET_DIRTY();
|
||||
});
|
||||
offcolor->setPos(NM_X, 36);
|
||||
},
|
||||
[=](int newValue) { previewColor(newValue); }, RGB888);
|
||||
|
||||
new StaticText(this, {TP_X, 6 + 36, SW_W, EdgeTxStyles::PAGE_LINE_HEIGHT}, STR_FS_ON_COLOR, COLOR_THEME_PRIMARY1);
|
||||
|
||||
auto oncolor = new ColorPicker(
|
||||
this, rect_t{},
|
||||
onColor = new ColorPicker(
|
||||
this, {C2_X, 0, C2_W, 0},
|
||||
[=]() -> int { // getValue
|
||||
return g_model.functionSwitchLedONColor[switchIndex];
|
||||
return g_model.functionSwitchLedONColor[switchIndex].getColor();
|
||||
},
|
||||
[=](int newValue) { // setValue
|
||||
g_model.functionSwitchLedONColor[switchIndex] =
|
||||
(uint32_t)newValue;
|
||||
g_model.functionSwitchLedOFFColor[switchIndex] = offValue;
|
||||
g_model.functionSwitchLedONColor[switchIndex] = onValue;
|
||||
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
g_model.functionSwitchLedONColor[switchIndex].setColor(newValue);
|
||||
|
||||
onValue = g_model.functionSwitchLedONColor[switchIndex];
|
||||
SET_DIRTY();
|
||||
});
|
||||
oncolor->setPos(GR_X, 36);
|
||||
},
|
||||
[=](int newValue) { previewColor(newValue); }, RGB888);
|
||||
#endif //FUNCTION_SWITCHES_RGB_LEDS
|
||||
|
||||
setState();
|
||||
}
|
||||
|
||||
static constexpr coord_t SW_W = (LCD_W - 4 * 2 - 2 * 4) / 5;
|
||||
static constexpr coord_t NM_X = SW_W + 2;
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
static constexpr coord_t SW_X = PAD_SMALL;
|
||||
static constexpr coord_t SW_W = 70;
|
||||
static constexpr coord_t NM_X = SW_X + SW_W;
|
||||
static constexpr coord_t NM_W = 60;
|
||||
static constexpr coord_t TP_X = NM_X + NM_W + PAD_SMALL;
|
||||
static constexpr coord_t TP_W = 78;
|
||||
static constexpr coord_t GR_X = TP_X + TP_W + PAD_SMALL;
|
||||
static constexpr coord_t GR_W = 84;
|
||||
static constexpr coord_t ST_X = GR_X + GR_W + PAD_SMALL;
|
||||
static constexpr coord_t ST_W = 60;
|
||||
static constexpr coord_t C1_X = ST_X + ST_W + PAD_SMALL;
|
||||
static constexpr coord_t C1_W = 40;
|
||||
static constexpr coord_t C2_X = C1_X + C1_W + PAD_SMALL;
|
||||
static constexpr coord_t C2_W = 40;
|
||||
#else
|
||||
static constexpr coord_t SW_W = (LCD_W - PAD_SMALL * 2 - PAD_TINY_GAP * 4) / 5;
|
||||
static constexpr coord_t NM_X = SW_W + PAD_TINY_GAP;
|
||||
static constexpr coord_t NM_W = 80;
|
||||
static constexpr coord_t TP_X = NM_X + SW_W + 2;
|
||||
static constexpr coord_t TP_X = NM_X + SW_W + PAD_TINY_GAP;
|
||||
static constexpr coord_t TP_W = 86;
|
||||
static constexpr coord_t GR_X = TP_X + SW_W + 2;
|
||||
static constexpr coord_t GR_X = TP_X + SW_W + PAD_TINY_GAP;
|
||||
static constexpr coord_t GR_W = 94;
|
||||
static constexpr coord_t ST_X = GR_X + SW_W + 20;
|
||||
static constexpr coord_t ST_W = 70;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
uint8_t switchIndex;
|
||||
Choice* typeChoice = nullptr;
|
||||
Choice* groupChoice = nullptr;
|
||||
Choice* startChoice = nullptr;
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
ColorPicker* offColor = nullptr;
|
||||
ColorPicker* onColor = nullptr;
|
||||
RGBLedColor offValue;
|
||||
RGBLedColor onValue;
|
||||
#endif
|
||||
int lastType = -1;
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
void previewColor(int newValue)
|
||||
{
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
if (getFSLogicalState(switchIndex)) {
|
||||
g_model.functionSwitchLedONColor[switchIndex].setColor(newValue);
|
||||
} else {
|
||||
g_model.functionSwitchLedOFFColor[switchIndex].setColor(newValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void setState()
|
||||
{
|
||||
startChoice->show(FSWITCH_CONFIG(switchIndex) == SWITCH_2POS && FSWITCH_GROUP(switchIndex) == 0);
|
||||
groupChoice->show(FSWITCH_CONFIG(switchIndex) != SWITCH_NONE);
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
offColor->show(FSWITCH_CONFIG(switchIndex) != SWITCH_NONE);
|
||||
onColor->show(FSWITCH_CONFIG(switchIndex) != SWITCH_NONE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
@@ -276,6 +327,10 @@ ModelFunctionSwitches::ModelFunctionSwitches() : Page(ICON_MODEL_SETUP)
|
||||
new StaticText(line, rect_t{}, STR_GROUP, COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
startupHeader = new StaticText(line, rect_t{}, STR_SWITCH_STARTUP,
|
||||
COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
new StaticText(line, rect_t{}, STR_OFF, COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
new StaticText(line, rect_t{}, STR_ON_ONE_SWITCHES[0], COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
#endif
|
||||
|
||||
for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
|
||||
new FunctionSwitch(body, i);
|
||||
|
||||
@@ -603,6 +603,7 @@ class ModuleSubTypeChoice : public Choice
|
||||
g_model.moduleData[moduleIdx].subType = newValue;
|
||||
SET_DIRTY();
|
||||
} else {
|
||||
#if defined(MULTIMODULE)
|
||||
g_model.moduleData[moduleIdx].multi.rfProtocol = newValue;
|
||||
g_model.moduleData[moduleIdx].subType = 0;
|
||||
resetMultiProtocolsOptions(moduleIdx);
|
||||
@@ -614,6 +615,7 @@ class ModuleSubTypeChoice : public Choice
|
||||
while (!status.isValid() && (RTOS_GET_MS() - startUpdate < 250))
|
||||
;
|
||||
SET_DIRTY();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (moduleWindow)
|
||||
|
||||
@@ -88,4 +88,4 @@ RadioCustSwitchesDiagsPage::RadioCustSwitchesDiagsPage() :
|
||||
buildBody(body);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "io/frsky_firmware_update.h"
|
||||
#include "io/multi_firmware_update.h"
|
||||
#include "io/bootloader_flash.h"
|
||||
#include "io/uf2_flash.h"
|
||||
#include "standalone_lua.h"
|
||||
#include "sdcard.h"
|
||||
#include "view_text.h"
|
||||
@@ -354,6 +355,7 @@ void RadioSdManagerPage::fileAction(const char* path, const char* name,
|
||||
menu->addLine(STR_FLASH_EXTERNAL_ELRS, [=]() {
|
||||
MultiFirmwareUpdate(fullpath, EXTERNAL_MODULE, MULTI_TYPE_ELRS);
|
||||
});
|
||||
#endif
|
||||
} else if (!strcasecmp(BITMAPS_PATH, path) &&
|
||||
isExtensionMatching(ext, BITMAPS_EXT) &&
|
||||
strlen(name) <= LEN_BITMAP_NAME) {
|
||||
@@ -382,10 +384,18 @@ void RadioSdManagerPage::fileAction(const char* path, const char* name,
|
||||
});
|
||||
}
|
||||
if (!strcasecmp(ext, FIRMWARE_EXT)) {
|
||||
#if defined(FIRMWARE_FORMAT_UF2)
|
||||
if (isUF2FirmwareFile(fullpath)) {
|
||||
menu->addLine(STR_FLASH_BOOTLOADER,
|
||||
[=]() { FirmwareUpdate(fullpath); });
|
||||
}
|
||||
#else
|
||||
if (isBootloader(fullpath)) {
|
||||
menu->addLine(STR_FLASH_BOOTLOADER,
|
||||
[=]() { BootloaderUpdate(fullpath); });
|
||||
}
|
||||
#endif
|
||||
#if defined(HARDWARE_INTERNAL_MODULE) || defined(HARDWARE_EXTERNAL_MODULE)
|
||||
} else if (!strcasecmp(ext, SPORT_FIRMWARE_EXT)) {
|
||||
|
||||
auto mod_desc = modulePortGetModuleDescription(SPORT_MODULE);
|
||||
@@ -535,6 +545,15 @@ void RadioSdManagerPage::fileAction(const char* path, const char* name,
|
||||
});
|
||||
}
|
||||
|
||||
#if defined(FIRMWARE_FORMAT_UF2)
|
||||
void RadioSdManagerPage::FirmwareUpdate(const char* fn)
|
||||
{
|
||||
UF2FirmwareUpdate firmwareUpdate;
|
||||
auto dialog =
|
||||
new FlashDialog<UF2FirmwareUpdate>(firmwareUpdate);
|
||||
dialog->flash(fn);
|
||||
}
|
||||
#else
|
||||
void RadioSdManagerPage::BootloaderUpdate(const char* fn)
|
||||
{
|
||||
BootloaderFirmwareUpdate bootloaderFirmwareUpdate;
|
||||
@@ -542,6 +561,7 @@ void RadioSdManagerPage::BootloaderUpdate(const char* fn)
|
||||
new FlashDialog<BootloaderFirmwareUpdate>(bootloaderFirmwareUpdate);
|
||||
dialog->flash(fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BLUETOOTH)
|
||||
void RadioSdManagerPage::BluetoothFirmwareUpdate(const char* fn)
|
||||
@@ -551,6 +571,7 @@ void RadioSdManagerPage::BluetoothFirmwareUpdate(const char* fn)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HARDWARE_INTERNAL_MODULE) || defined(HARDWARE_EXTERNAL_MODULE)
|
||||
void RadioSdManagerPage::FrSkyFirmwareUpdate(const char* fn,
|
||||
ModuleIndex module)
|
||||
{
|
||||
@@ -569,3 +590,4 @@ void RadioSdManagerPage::MultiFirmwareUpdate(const char* fn,
|
||||
new FlashDialog<MultiDeviceFirmwareUpdate>(deviceFirmwareUpdate);
|
||||
dialog->flash(fn);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -48,14 +48,20 @@ class RadioSdManagerPage : public PageTab
|
||||
|
||||
void fileAction(const char* path, const char* name, const char* fullpath);
|
||||
void dirAction(const char* path, const char* name, const char* fullpath);
|
||||
|
||||
|
||||
#if defined(FIRMWARE_FORMAT_UF2)
|
||||
void FirmwareUpdate(const char* fn);
|
||||
#else
|
||||
void BootloaderUpdate(const char* fn);
|
||||
#endif
|
||||
#if defined(BLUETOOTH)
|
||||
void BluetoothFirmwareUpdate(const char* fn);
|
||||
#endif
|
||||
#if defined(HARDWARE_INTERNAL_MODULE) || defined(HARDWARE_EXTERNAL_MODULE)
|
||||
void FrSkyFirmwareUpdate(const char* fn, ModuleIndex module);
|
||||
void MultiFirmwareUpdate(const char* fn, ModuleIndex module,
|
||||
MultiModuleType type);
|
||||
#endif
|
||||
|
||||
void checkEvents() override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user