Native channel monitor widget (#3530)

* Commit following git issues

* Remove unseless floor()

* Fix cmake resources compile problem

* Better fix for cmake resources compile problem

* - overdraw rectangle on gauge (looks better)
- use divRoundClosest

* Cosmetics
This commit is contained in:
3djc
2016-05-26 18:20:48 +02:00
committed by Bertrand Songis
parent d471dc6216
commit 4fcf8ab7ff
+49 -18
View File
@@ -20,6 +20,10 @@
#include "opentx.h"
#define RECT_OFFSET 80
#define RECT_WIDTH (w - RECT_OFFSET)
#define ROW_HEIGHT 20
class OutputsWidget: public Widget
{
public:
@@ -29,33 +33,60 @@ class OutputsWidget: public Widget
}
virtual void refresh();
uint8_t drawChannels(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t firstChan)
{
char chanString[] = "CH32";
uint8_t lastChan = firstChan + h / ROW_HEIGHT;
for (uint8_t curChan = firstChan; curChan <= lastChan and curChan < 33; curChan++) {
int16_t chanVal = calcRESXto100(channelOutputs[curChan-1]);
strAppend(chanString, "CH");
strAppendSigned(&chanString[2], curChan, 2);
lcdDrawText(x, y + (curChan - firstChan) * ROW_HEIGHT, chanString, SMLSIZE | TEXT_COLOR | LEFT);
strAppendSigned(chanString, chanVal);
lcdDrawText(x + RECT_OFFSET - 2, y + (curChan - firstChan) * ROW_HEIGHT, chanString, SMLSIZE | TEXT_COLOR | RIGHT);
if (chanVal > 0) {
lcdDrawSolidFilledRect(x + RECT_OFFSET + RECT_WIDTH / 2, y + (curChan -firstChan) * ROW_HEIGHT, divRoundClosest(RECT_WIDTH * chanVal, 200), ROW_HEIGHT, MAINVIEW_GRAPHICS_COLOR);
}
else if (chanVal < 0) {
uint16_t startpoint = x + RECT_OFFSET;
uint16_t endpoint = startpoint + RECT_WIDTH / 2;
uint16_t size = divRoundClosest(- RECT_WIDTH * chanVal, 200);
lcdDrawSolidFilledRect(endpoint - size, y + (curChan - firstChan) * ROW_HEIGHT, size, ROW_HEIGHT, MAINVIEW_GRAPHICS_COLOR);
}
lcdDrawRect(x + RECT_OFFSET, y + (curChan -firstChan) * ROW_HEIGHT, RECT_WIDTH, ROW_HEIGHT);
lcd->drawSolidVerticalLine(x + RECT_OFFSET + RECT_WIDTH / 2, y + (curChan - firstChan) * ROW_HEIGHT, ROW_HEIGHT, MAINVIEW_GRAPHICS_COLOR);
}
return lastChan;
}
void twoColumns()
{
uint8_t endColumn = drawChannels(zone.x, zone.y, zone.w / 2, zone.h, persistentData->options[0].unsignedValue);
drawChannels(zone.x + zone.w / 2 + 2, zone.y, zone.w / 2, zone.h, endColumn + 1);
}
void oneColumn()
{
drawChannels(zone.x, zone.y, zone.w, zone.h, persistentData->options[0].unsignedValue);
}
static const ZoneOption options[];
};
const ZoneOption OutputsWidget::options[] = {
{ "Min", ZoneOption::Integer, OPTION_DEFAULT_VALUE_UNSIGNED(0) },
{ "Max", ZoneOption::Integer, OPTION_DEFAULT_VALUE_UNSIGNED(7) },
{ "Color", ZoneOption::Color, OPTION_DEFAULT_VALUE_UNSIGNED(RED) },
{ "First", ZoneOption::Integer, OPTION_DEFAULT_VALUE_UNSIGNED(1) },
{ NULL, ZoneOption::Bool }
};
void OutputsWidget::refresh()
{
int firstChannel = MIXSRC_CH1 + persistentData->options[0].unsignedValue;
int lastChannel = MIXSRC_CH1 + persistentData->options[1].unsignedValue;
uint16_t color = persistentData->options[2].unsignedValue;
lcdSetColor(color);
lcd->drawSolidHorizontalLine(zone.x, zone.y+zone.h/2, zone.w, CUSTOM_COLOR);
int count = lastChannel - firstChannel + 1;
for (int ch=firstChannel, i=0; ch<=lastChannel; ch++, i++) {
int32_t value = limit<int32_t>(-RESX, getValue(ch), RESX);
int h = divRoundClosest((zone.h-1)/2 * value, RESX);
lcdDrawSolidFilledRect(zone.x+(zone.w*i)/count, zone.y + zone.h/2, zone.w/count-1, -h, CUSTOM_COLOR);
}
}
if (zone.w > 300 and zone.h > 20)
twoColumns();
else if (zone.w > 150 and zone.h > 20)
oneColumn();
};
BaseWidgetFactory<OutputsWidget> outputsWidget("Outputs", OutputsWidget::options);