feat(color): Implement DISPLAY_TRIMS_CHANGE option (#3288)

* Implement DISPLAY_TRIMS_CHANGE option for color LCD trim widget.
Refactor code.

* Change data type to prevent build tests failing.

* Display trim value to the side like B&W radios.
This commit is contained in:
philmoz
2023-03-14 13:08:28 +10:00
committed by GitHub
parent 8cdd756c0a
commit 667cc845f8
2 changed files with 131 additions and 85 deletions
+106 -78
View File
@@ -45,17 +45,68 @@ static void trim_self_size(lv_event_t* e)
} }
} }
MainViewTrim::MainViewTrim(Window * parent, const rect_t & rect, uint8_t idx):
Window(parent, rect),
idx(idx)
{
setRange();
}
void MainViewTrim::setRange()
{
if (g_model.extendedTrims) {
trimMin = TRIM_EXTENDED_MIN;
trimMax = TRIM_EXTENDED_MAX;
}
else {
trimMin = TRIM_MIN;
trimMax = TRIM_MAX;
}
}
void MainViewTrim::checkEvents() void MainViewTrim::checkEvents()
{ {
Window::checkEvents(); Window::checkEvents();
int8_t stickIndex = CONVERT_MODE(idx); int8_t stickIndex = CONVERT_MODE(idx);
int newValue = getTrimValue(mixerCurrentFlightMode, stickIndex); int newValue = getTrimValue(mixerCurrentFlightMode, stickIndex);
if (value != newValue) {
setRange();
newValue = min(max(newValue, trimMin), trimMax);
if (value != newValue ||
(g_model.displayTrims == DISPLAY_TRIMS_CHANGE && showChange && trimsDisplayTimer == 0)) {
value = newValue; value = newValue;
invalidate(); invalidate();
} }
} }
void MainViewTrim::paint(BitmapBuffer * dc)
{
// Trim line
drawLine(dc);
coord_t x = sx();
coord_t y = sy();
// Trim square
drawTrimSquare(dc, x, y,
(value < TRIM_MIN || value > TRIM_MAX)
? COLOR_THEME_ACTIVE /* TODO add a color */
: COLOR_THEME_FOCUS);
drawMarkerLines(dc, x, y);
// Trim value / small lines on the square
if ((g_model.displayTrims == DISPLAY_TRIMS_ALWAYS) ||
((g_model.displayTrims == DISPLAY_TRIMS_CHANGE) && (trimsDisplayTimer > 0) && (trimsDisplayMask & (1 << idx)))) {
if (value) {
showChange = true;
drawValue(dc);
}
} else {
showChange = false;
}
}
MainViewHorizontalTrim::MainViewHorizontalTrim(Window* parent, uint8_t idx) : MainViewHorizontalTrim::MainViewHorizontalTrim(Window* parent, uint8_t idx) :
MainViewTrim(parent, rect_t{}, idx) MainViewTrim(parent, rect_t{}, idx)
{ {
@@ -66,49 +117,38 @@ MainViewHorizontalTrim::MainViewHorizontalTrim(Window* parent, uint8_t idx) :
setHeight(TRIM_SQUARE_SIZE); setHeight(TRIM_SQUARE_SIZE);
} }
void MainViewHorizontalTrim::paint(BitmapBuffer * dc) coord_t MainViewHorizontalTrim::sx()
{ {
int32_t trimMin, trimMax; return divRoundClosest((HORIZONTAL_SLIDERS_WIDTH - TRIM_SQUARE_SIZE) * (value - trimMin),
if (g_model.extendedTrims) { trimMax - trimMin);
trimMin = TRIM_EXTENDED_MIN; }
trimMax = TRIM_EXTENDED_MAX;
}
else {
trimMin = TRIM_MIN;
trimMax = TRIM_MAX;
}
int16_t dispVal = value; void MainViewHorizontalTrim::drawLine(BitmapBuffer * dc)
if (dispVal < trimMin) dispVal = trimMin; {
if (dispVal > trimMax) dispVal = trimMax;
// Trim line // Trim line
dc->drawSolidFilledRect( dc->drawSolidFilledRect(
TRIM_SQUARE_SIZE / 2, (height() - TRIM_LINE_WIDTH - 1) / 2, TRIM_SQUARE_SIZE / 2, (TRIM_SQUARE_SIZE - TRIM_LINE_WIDTH - 1) / 2,
width() - TRIM_SQUARE_SIZE + 1, TRIM_LINE_WIDTH, COLOR_THEME_SECONDARY1); HORIZONTAL_SLIDERS_WIDTH - TRIM_SQUARE_SIZE + 1, TRIM_LINE_WIDTH, COLOR_THEME_SECONDARY1);
}
// Trim square void MainViewHorizontalTrim::drawMarkerLines(BitmapBuffer * dc, coord_t x, coord_t y)
coord_t x = divRoundClosest((width() - TRIM_SQUARE_SIZE) * (dispVal - trimMin), {
trimMax - trimMin); // Small lines on the square
drawTrimSquare(dc, x, 0, if (value >= 0) {
(value < TRIM_MIN || value > TRIM_MAX) dc->drawSolidVerticalLine(x + 4, 3, 9, COLOR_THEME_PRIMARY2);
? COLOR_THEME_ACTIVE /* TODO add a color */
: COLOR_THEME_FOCUS);
// Trim value / small lines on the square
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS) {
// TODO DISPLAY_TRIMS_CHANGE
dc->drawNumber(x + (TRIM_SQUARE_SIZE + 1) / 2, 3,
divRoundClosest(value * 100, trimMax),
FONT(XXS) | COLOR_THEME_PRIMARY2 | CENTERED);
} else {
if (value >= 0) {
dc->drawSolidVerticalLine(x + 4, 3, 9, COLOR_THEME_PRIMARY2);
}
if (value <= 0) {
dc->drawSolidVerticalLine(x + 10, 3, 9, COLOR_THEME_PRIMARY2);
}
} }
if (value <= 0) {
dc->drawSolidVerticalLine(x + 10, 3, 9, COLOR_THEME_PRIMARY2);
}
}
void MainViewHorizontalTrim::drawValue(BitmapBuffer * dc)
{
coord_t x = (value < 0) ? HORIZONTAL_SLIDERS_WIDTH * 4 / 5 : HORIZONTAL_SLIDERS_WIDTH / 5;
dc->drawSolidFilledRect(x - TRIM_SQUARE_SIZE/2, (TRIM_SQUARE_SIZE-12)/2, TRIM_SQUARE_SIZE, 12, COLOR_THEME_SECONDARY1);
dc->drawNumber(x, 2,
divRoundClosest(abs(value) * 100, trimMax),
FONT(XXS) | COLOR_THEME_PRIMARY2 | CENTERED);
} }
MainViewVerticalTrim::MainViewVerticalTrim(Window* parent, uint8_t idx) : MainViewVerticalTrim::MainViewVerticalTrim(Window* parent, uint8_t idx) :
@@ -117,53 +157,41 @@ MainViewVerticalTrim::MainViewVerticalTrim(Window* parent, uint8_t idx) :
void* user_data = (void*)TRIM_VERT; void* user_data = (void*)TRIM_VERT;
lv_obj_add_event_cb(lvobj, trim_self_size, LV_EVENT_GET_SELF_SIZE, user_data); lv_obj_add_event_cb(lvobj, trim_self_size, LV_EVENT_GET_SELF_SIZE, user_data);
setHeight(VERTICAL_SLIDERS_HEIGHT);
setWidth(TRIM_SQUARE_SIZE); setWidth(TRIM_SQUARE_SIZE);
setHeight(VERTICAL_SLIDERS_HEIGHT);
} }
void MainViewVerticalTrim::paint(BitmapBuffer * dc) coord_t MainViewVerticalTrim::sy()
{ {
int32_t trimMin, trimMax; return VERTICAL_SLIDERS_HEIGHT - TRIM_SQUARE_SIZE -
if (g_model.extendedTrims) { divRoundClosest((VERTICAL_SLIDERS_HEIGHT - TRIM_SQUARE_SIZE) * (value - trimMin),
trimMin = TRIM_EXTENDED_MIN; trimMax - trimMin);
trimMax = TRIM_EXTENDED_MAX; }
}
else {
trimMin = TRIM_MIN;
trimMax = TRIM_MAX;
}
int16_t dispVal = value;
if (dispVal < trimMin) dispVal = trimMin;
if (dispVal > trimMax) dispVal = trimMax;
void MainViewVerticalTrim::drawLine(BitmapBuffer * dc)
{
// Trim line // Trim line
dc->drawSolidFilledRect((width() - TRIM_LINE_WIDTH) / 2, TRIM_SQUARE_SIZE / 2, dc->drawSolidFilledRect((TRIM_SQUARE_SIZE - TRIM_LINE_WIDTH) / 2, TRIM_SQUARE_SIZE / 2,
TRIM_LINE_WIDTH, height() - TRIM_SQUARE_SIZE + 1, TRIM_LINE_WIDTH, VERTICAL_SLIDERS_HEIGHT - TRIM_SQUARE_SIZE + 1,
COLOR_THEME_SECONDARY1); COLOR_THEME_SECONDARY1);
}
// Trim square void MainViewVerticalTrim::drawMarkerLines(BitmapBuffer * dc, coord_t x, coord_t y)
coord_t y = {
height() - TRIM_SQUARE_SIZE - // Small lines on the square
divRoundClosest((height() - TRIM_SQUARE_SIZE) * (dispVal - trimMin), if (value >= 0) {
trimMax - trimMin); dc->drawSolidHorizontalLine(3, y + 4, 9, COLOR_THEME_PRIMARY2);
drawTrimSquare(dc, 0, y, }
(value < TRIM_MIN || value > TRIM_MAX) if (value <= 0) {
? COLOR_THEME_ACTIVE /* TODO add a color */ dc->drawSolidHorizontalLine(3, y + 10, 9, COLOR_THEME_PRIMARY2);
: COLOR_THEME_FOCUS);
// Trim value / small lines on the square
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS) {
// TODO DISPLAY_TRIMS_CHANGE
dc->drawNumber((TRIM_SQUARE_SIZE + 1) / 2, y + 3,
divRoundClosest(value * 100, trimMax),
FONT(XXS) | COLOR_THEME_PRIMARY2 | CENTERED);
} else {
if (value >= 0) {
dc->drawSolidHorizontalLine(3, y + 4, 9, COLOR_THEME_PRIMARY2);
}
if (value <= 0) {
dc->drawSolidHorizontalLine(3, y + 10, 9, COLOR_THEME_PRIMARY2);
}
} }
} }
void MainViewVerticalTrim::drawValue(BitmapBuffer * dc)
{
coord_t y = (value > 0) ? VERTICAL_SLIDERS_HEIGHT * 4 / 5 : VERTICAL_SLIDERS_HEIGHT / 5 - 11;
dc->drawSolidFilledRect(0, y, TRIM_SQUARE_SIZE, 11, COLOR_THEME_SECONDARY1);
dc->drawNumber(TRIM_SQUARE_SIZE/2, y,
divRoundClosest(abs(value) * 100, trimMax),
FONT(XXS) | COLOR_THEME_PRIMARY2 | CENTERED);
}
+25 -7
View File
@@ -26,17 +26,25 @@
class MainViewTrim : public Window class MainViewTrim : public Window
{ {
public: public:
MainViewTrim(Window * parent, const rect_t & rect, uint8_t idx): MainViewTrim(Window * parent, const rect_t & rect, uint8_t idx);
Window(parent, rect),
idx(idx)
{
}
void checkEvents() override; void checkEvents() override;
void paint(BitmapBuffer * dc) override;
protected: protected:
uint8_t idx; uint8_t idx;
int value = 0; int value = 0;
bool showChange = false;
int trimMin = 0, trimMax = 0;
void setRange();
virtual coord_t sx() { return 0; }
virtual coord_t sy() { return 0; }
virtual void drawLine(BitmapBuffer * dc) = 0;
virtual void drawMarkerLines(BitmapBuffer * dc, coord_t x, coord_t y) = 0;
virtual void drawValue(BitmapBuffer * dc) = 0;
}; };
class MainViewHorizontalTrim : public MainViewTrim class MainViewHorizontalTrim : public MainViewTrim
@@ -44,12 +52,22 @@ class MainViewHorizontalTrim : public MainViewTrim
public: public:
using MainViewTrim::MainViewTrim; using MainViewTrim::MainViewTrim;
MainViewHorizontalTrim(Window* parent, uint8_t idx); MainViewHorizontalTrim(Window* parent, uint8_t idx);
void paint(BitmapBuffer * dc) override;
protected:
coord_t sx() override;
void drawLine(BitmapBuffer * dc) override;
void drawMarkerLines(BitmapBuffer * dc, coord_t x, coord_t y) override;
void drawValue(BitmapBuffer * dc) override;
}; };
class MainViewVerticalTrim : public MainViewTrim class MainViewVerticalTrim : public MainViewTrim
{ {
public: public:
MainViewVerticalTrim(Window* parent, uint8_t idx); MainViewVerticalTrim(Window* parent, uint8_t idx);
void paint(BitmapBuffer * dc) override;
protected:
coord_t sy() override;
void drawLine(BitmapBuffer * dc) override;
void drawMarkerLines(BitmapBuffer * dc, coord_t x, coord_t y) override;
void drawValue(BitmapBuffer * dc) override;
}; };