Skip to content

Commit

Permalink
Fix rebase.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Nov 13, 2023
1 parent e5bbed3 commit fb501cb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 106 deletions.
158 changes: 53 additions & 105 deletions radio/src/gui/colorlcd/model_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,11 @@ class SensorButton : public Button {
}
};

class TelemetrySourceChoice : public ChoiceEx
class TelemetrySourceChoice : public Choice
{
public:
TelemetrySourceChoice(FormGroup *window, const rect_t &rect, uint8_t *source, IsValueAvailable isValueAvailable, char negativeGVarPrefix=0) :
ChoiceEx(window, rect, negativeGVarPrefix!=0?-128:0, 127, GET_DEFAULT(static_cast<int8_t>(*source)), [=](int16_t newValue){*source=newValue;})
TelemetrySourceChoice(Window *window, const rect_t &rect, uint8_t *source, IsValueAvailable isValueAvailable) :
Choice(window, rect, 0, 127, GET_DEFAULT(static_cast<int8_t>(*source)), [=](int16_t newValue){*source=newValue;})
{
setAvailableHandler([=](int16_t value) -> bool {
if (value == 0) return true;
Expand All @@ -365,6 +365,7 @@ class TelemetrySourceChoice : public ChoiceEx
if(GV_IS_GV_VALUE(value, -MAX_TELEMETRY_SENSORS, MAX_TELEMETRY_SENSORS)) {
int index = GV_INDEX_CALCULATION(value, -MAX_TELEMETRY_SENSORS, MAX_TELEMETRY_SENSORS);
std::string ret(getGVarString(index));
fprintf(stderr,">>>>>> GV %d %d %s\n",value,index,ret.c_str());
if(value>0) {
ret[0] = negativeGVarPrefix;
}
Expand All @@ -379,76 +380,28 @@ class TelemetrySourceChoice : public ChoiceEx
return std::string(getSourceString(MIXSRC_FIRST_TELEM+(value-1)*3));
}
});
}
};

class SensorButton : public Button {
public:
SensorButton(FormGroup * parent, const rect_t &rect, uint8_t index, uint8_t number) :
Button(parent, rect),
index(index),
number(number)
{
}

static constexpr coord_t line1 = 1;

void checkEvents() override
{
uint32_t now = RTOS_GET_MS();
if (now - lastRefresh >= 200) {
// update at least every 200ms
invalidate();
}

TelemetryItem & telemetryItem = telemetryItems[index];
if (telemetryItem.isFresh()) {
invalidate();
}

Button::checkEvents();
setRangeMapHandler([=](int n) {
// Map range of choice values so GVars are in correct order.
if (n <= -120)
n += GV1_SMALL * 2 - MAX_GVARS;
else if (n >= 119)
n -= GV1_SMALL * 2 - MAX_GVARS;
return n;
});
}

void paint(BitmapBuffer * dc) override
void setGVPrefix(char prefix)
{
TelemetryItem &telemetryItem = telemetryItems[index];

if (telemetryItem.isAvailable())
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, COLOR_THEME_ACTIVE);
else
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, COLOR_THEME_PRIMARY2);

if (telemetryItem.isFresh())
dc->drawFilledCircle(SENSOR_COL2 - 10, (2 + rect.h - 4)/2, 4, COLOR_THEME_SECONDARY1);

dc->drawSizedText(SENSOR_COL1, line1, g_model.telemetrySensors[index].label, TELEM_LABEL_LEN);

if (telemetryItem.isAvailable()) {
LcdFlags color = telemetryItem.isOld() ? COLOR_THEME_WARNING : COLOR_THEME_SECONDARY1;
drawSensorCustomValue(dc, SENSOR_COL2, line1, index, getValue(MIXSRC_FIRST_TELEM + 3 * index), LEFT | color);
}
else {
dc->drawText(SENSOR_COL2, line1, "---", COLOR_THEME_SECONDARY1);
}

TelemetrySensor * sensor = & g_model.telemetrySensors[index];
if (IS_SPEKTRUM_PROTOCOL()) {
drawHexNumber(dc, SENSOR_COL3, line1, sensor->id, LEFT);
}
else if (sensor->type == TELEM_TYPE_CUSTOM && !g_model.ignoreSensorIds) {
dc->drawNumber(SENSOR_COL3, line1, sensor->instance, LEFT);
if (modelGVEnabled()) {
negativeGVarPrefix = prefix;
setMin(negativeGVarPrefix != 0 ? -128 : 0);
if (getIntValue() < getMin())
setValue(getMin());
}

if (hasFocus())
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, COLOR_THEME_FOCUS);
else
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, COLOR_THEME_SECONDARY2);
}

protected:
uint8_t index;
uint8_t number;
uint32_t lastRefresh = 0;
char negativeGVarPrefix;
};

class SensorLiveValue: public Window {
Expand Down Expand Up @@ -534,6 +487,7 @@ class SensorEditWindow : public Page {
};

FormWindow::Line* paramLines[P_COUNT] = {};
TelemetrySourceChoice* calcSource[4] = {};

void buildHeader(Window * window)
{
Expand Down Expand Up @@ -571,6 +525,16 @@ class SensorEditWindow : public Page {
}
}

void setGVPrefix(int n, uint8_t formula)
{
if (formula == TELEM_FORMULA_MULTIPLY)
calcSource[n]->setGVPrefix('/');
else if (formula < TELEM_FORMULA_MULTIPLY)
calcSource[n]->setGVPrefix('-');
else
calcSource[n]->setGVPrefix(0);
}

void updateSensorParameters()
{
TelemetrySensor * sensor = &g_model.telemetrySensors[index];
Expand Down Expand Up @@ -601,28 +565,20 @@ class SensorEditWindow : public Page {
if (sensor->unit < UNIT_FIRST_VIRTUAL) {
if (sensor->type == TELEM_TYPE_CALCULATED) {
if (sensor->formula == TELEM_FORMULA_CELL) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_CELLSENSOR, 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->cell.source, isCellsSensor);
lv_obj_clear_flag(paramLines[P_CELLSENSOR]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
else if (sensor->formula == TELEM_FORMULA_DIST) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_GPSSENSOR, 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->dist.gps, isGPSSensor);
lv_obj_clear_flag(paramLines[P_GPSSENSOR]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_CURRENTSENSOR, 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable);
lv_obj_clear_flag(paramLines[P_CURRENTSENSOR]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
else if (sensor->formula == TELEM_FORMULA_TOTALIZE) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE, 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable);
}
else if (sensor->formula == TELEM_FORMULA_MULTIPLY) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(1), 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[0], isSensorAvailable, '/');
lv_obj_clear_flag(paramLines[P_CONSUMPTIONSOURCE]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
else {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(1), 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[0], isSensorAvailable, '-');
lv_obj_clear_flag(paramLines[P_CALC0]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
setGVPrefix(0, sensor->formula);
}
}
else {
Expand All @@ -642,16 +598,11 @@ class SensorEditWindow : public Page {
lv_obj_clear_flag(paramLines[P_CELLINDEX]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
else if (sensor->formula == TELEM_FORMULA_DIST) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_ALTSENSOR, 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->dist.alt, isAltSensor);
}
else if (sensor->formula == TELEM_FORMULA_MULTIPLY) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(2), 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[1], isSensorAvailable, '/');
lv_obj_clear_flag(paramLines[P_ALTSENSOR]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
}
else {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(2), 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[1], isSensorAvailable, '-');
lv_obj_clear_flag(paramLines[P_CALC1]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
setGVPrefix(1, sensor->formula);
}
}
else if (sensor->unit == UNIT_RPMS) {
Expand All @@ -663,13 +614,10 @@ class SensorEditWindow : public Page {
}

if ((sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY)) {
new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(3), 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[2], isSensorAvailable, '-');
grid.nextLine();

new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(4), 0, COLOR_THEME_PRIMARY1);
new TelemetrySourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[3], isSensorAvailable, '-');
grid.nextLine();
lv_obj_clear_flag(paramLines[P_CALC2]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
setGVPrefix(2, sensor->formula);
lv_obj_clear_flag(paramLines[P_CALC3]->getLvObj(), LV_OBJ_FLAG_HIDDEN);
setGVPrefix(3, sensor->formula);
}

// Auto Offset
Expand Down Expand Up @@ -795,23 +743,23 @@ class SensorEditWindow : public Page {

paramLines[P_CELLSENSOR] = form->newLine(&grid);
new StaticText(paramLines[P_CELLSENSOR], rect_t{}, STR_CELLSENSOR, 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_CELLSENSOR], rect_t{}, &sensor->cell.source, isCellsSensor);
new TelemetrySourceChoice(paramLines[P_CELLSENSOR], rect_t{}, &sensor->cell.source, isCellsSensor);

paramLines[P_GPSSENSOR] = form->newLine(&grid);
new StaticText(paramLines[P_GPSSENSOR], rect_t{}, STR_GPSSENSOR, 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_GPSSENSOR], rect_t{}, &sensor->dist.gps, isGPSSensor);
new TelemetrySourceChoice(paramLines[P_GPSSENSOR], rect_t{}, &sensor->dist.gps, isGPSSensor);

paramLines[P_CURRENTSENSOR] = form->newLine(&grid);
new StaticText(paramLines[P_CURRENTSENSOR], rect_t{}, STR_CURRENTSENSOR, 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_CURRENTSENSOR], rect_t{}, &sensor->consumption.source, isSensorAvailable);
new TelemetrySourceChoice(paramLines[P_CURRENTSENSOR], rect_t{}, &sensor->consumption.source, isSensorAvailable);

paramLines[P_CONSUMPTIONSOURCE] = form->newLine(&grid);
new StaticText(paramLines[P_CONSUMPTIONSOURCE], rect_t{}, STR_SOURCE, 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_CONSUMPTIONSOURCE], rect_t{}, &sensor->consumption.source, isSensorAvailable);
new TelemetrySourceChoice(paramLines[P_CONSUMPTIONSOURCE], rect_t{}, &sensor->consumption.source, isSensorAvailable);

paramLines[P_CALC0] = form->newLine(&grid);
new StaticText(paramLines[P_CALC0], rect_t{}, STR_SOURCE + std::to_string(1), 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_CALC0], rect_t{}, (uint8_t *) &sensor->calc.sources[0], isSensorAvailable);
calcSource[0] = new TelemetrySourceChoice(paramLines[P_CALC0], rect_t{}, (uint8_t *) &sensor->calc.sources[0], isSensorAvailable);

paramLines[P_BLADES] = form->newLine(&grid);
new StaticText(paramLines[P_BLADES], rect_t{}, STR_BLADES, 0, COLOR_THEME_PRIMARY1);
Expand All @@ -828,11 +776,11 @@ class SensorEditWindow : public Page {

paramLines[P_ALTSENSOR] = form->newLine(&grid);
new StaticText(paramLines[P_ALTSENSOR], rect_t{}, STR_ALTSENSOR, 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_ALTSENSOR], rect_t{}, &sensor->dist.alt, isAltSensor);
new TelemetrySourceChoice(paramLines[P_ALTSENSOR], rect_t{}, &sensor->dist.alt, isAltSensor);

paramLines[P_CALC1] = form->newLine(&grid);
new StaticText(paramLines[P_CALC1], rect_t{}, STR_SOURCE + std::to_string(2), 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_CALC1], rect_t{}, (uint8_t *) &sensor->calc.sources[1], isSensorAvailable);
calcSource[1] = new TelemetrySourceChoice(paramLines[P_CALC1], rect_t{}, (uint8_t *) &sensor->calc.sources[1], isSensorAvailable);

paramLines[P_MULT] = form->newLine(&grid);
new StaticText(paramLines[P_MULT], rect_t{}, STR_MULTIPLIER, 0, COLOR_THEME_PRIMARY1);
Expand All @@ -845,11 +793,11 @@ class SensorEditWindow : public Page {

paramLines[P_CALC2] = form->newLine(&grid);
new StaticText(paramLines[P_CALC2], rect_t{}, STR_SOURCE + std::to_string(3), 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_CALC2], rect_t{}, (uint8_t *) &sensor->calc.sources[2], isSensorAvailable);
calcSource[2] = new TelemetrySourceChoice(paramLines[P_CALC2], rect_t{}, (uint8_t *) &sensor->calc.sources[2], isSensorAvailable);

paramLines[P_CALC3] = form->newLine(&grid);
new StaticText(paramLines[P_CALC3], rect_t{}, STR_SOURCE + std::to_string(4), 0, COLOR_THEME_PRIMARY1);
new SensorSourceChoice(paramLines[P_CALC3], rect_t{}, (uint8_t *) &sensor->calc.sources[3], isSensorAvailable);
calcSource[3] = new TelemetrySourceChoice(paramLines[P_CALC3], rect_t{}, (uint8_t *) &sensor->calc.sources[3], isSensorAvailable);

paramLines[P_AUTOOFFSET] = form->newLine(&grid);
new StaticText(paramLines[P_AUTOOFFSET], rect_t{}, STR_AUTOOFFSET, 0, COLOR_THEME_PRIMARY1);
Expand Down
4 changes: 3 additions & 1 deletion radio/src/thirdparty/libopenui/src/choice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ void Choice::fillMenu(Menu* menu, const FilterFct& filter)
int count = 0;
int selectedIx = -1;
selectedIx0 = -1;
for (int i = vmin; i <= vmax; ++i) {
for (int n = vmin; n <= vmax; ++n) {
int i = n;
if (rangeMapHandler) i = rangeMapHandler(i);
if (filter && !filter(i)) continue;
if (isValueAvailable && !isValueAvailable(i)) continue;
if (textHandler) {
Expand Down
6 changes: 6 additions & 0 deletions radio/src/thirdparty/libopenui/src/choice.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ class Choice : public ChoiceBase
lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr);
}

void setRangeMapHandler(std::function<int(int)> handler)
{
rangeMapHandler = handler;
}

void setMenuTitle(std::string value) { menuTitle = std::move(value); }
std::string getMenuTitle() const { return menuTitle; }

Expand Down Expand Up @@ -190,6 +195,7 @@ class Choice : public ChoiceBase
std::function<void(int)> _setValue;
std::function<bool(int)> isValueAvailable;
std::function<std::string(int)> textHandler;
std::function<int(int)> rangeMapHandler;
std::function<void(Menu *, int, int&)> fillMenuHandler;
std::function<void(Menu *)> beforeDisplayMenuHandler;

Expand Down

0 comments on commit fb501cb

Please sign in to comment.