Telemetry screen fixes

This commit is contained in:
Bertrand Songis
2019-08-29 14:11:51 +02:00
parent 3f9a863b00
commit abe761af5a
2 changed files with 71 additions and 67 deletions
+70 -66
View File
@@ -119,7 +119,7 @@ class SensorEditWindow : public Page {
protected: protected:
uint8_t index; uint8_t index;
Window * sensorOneWindow = nullptr; Window * sensorParametersWindow = nullptr;
void buildHeader(Window * window) void buildHeader(Window * window)
{ {
@@ -128,17 +128,19 @@ class SensorEditWindow : public Page {
//new StaticText(window, {70, 28, 100, 20}, "SF" + std::to_string(index), MENU_TITLE_COLOR); //new StaticText(window, {70, 28, 100, 20}, "SF" + std::to_string(index), MENU_TITLE_COLOR);
} }
void updateSensorOneWindow() void updateSensorParametersWindow()
{ {
return;
// Sensor variable part // Sensor variable part
FormGridLayout grid; FormGridLayout grid;
sensorOneWindow->clear(); sensorParametersWindow->clear();
TelemetrySensor * sensor = &g_model.telemetrySensors[index]; TelemetrySensor * sensor = &g_model.telemetrySensors[index];
if (sensor->type == TELEM_TYPE_CALCULATED) { if (sensor->type == TELEM_TYPE_CALCULATED) {
// Formula // Formula
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_FORMULA); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_FORMULA);
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VFORMULAS, 0, TELEM_FORMULA_LAST, GET_DEFAULT(sensor->formula), new Choice(sensorParametersWindow, grid.getFieldSlot(), STR_VFORMULAS, 0, TELEM_FORMULA_LAST, GET_DEFAULT(sensor->formula),
[=](uint8_t newValue) { [=](uint8_t newValue) {
sensor->formula = newValue; sensor->formula = newValue;
sensor->param = 0; sensor->param = 0;
@@ -156,24 +158,24 @@ class SensorEditWindow : public Page {
} }
SET_DIRTY(); SET_DIRTY();
telemetryItems[index].clear(); telemetryItems[index].clear();
updateSensorOneWindow(); updateSensorParametersWindow();
}); });
grid.nextLine(); grid.nextLine();
} }
else { else {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_ID); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_ID);
auto hex = new NumberEdit(sensorOneWindow, grid.getFieldSlot(2, 0), 0, 0xffff, GET_SET_DEFAULT(sensor->id)); auto hex = new NumberEdit(sensorParametersWindow, grid.getFieldSlot(2, 0), 0, 0xffff, GET_SET_DEFAULT(sensor->id));
hex->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) { hex->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
drawHexNumber(dc, 2, 2, value, 0); drawHexNumber(dc, 2, 2, value, 0);
}); });
new NumberEdit(sensorOneWindow, grid.getFieldSlot(2, 1), 0, 0xff, GET_SET_DEFAULT(sensor->instance)); new NumberEdit(sensorParametersWindow, grid.getFieldSlot(2, 1), 0, 0xff, GET_SET_DEFAULT(sensor->instance));
grid.nextLine(); grid.nextLine();
} }
// Unit // Unit
if ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable()) { if ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable()) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_UNIT); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_UNIT);
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VTELEMUNIT, 0, UNIT_MAX, GET_DEFAULT(sensor->unit), new Choice(sensorParametersWindow, grid.getFieldSlot(), STR_VTELEMUNIT, 0, UNIT_MAX, GET_DEFAULT(sensor->unit),
[=](uint8_t newValue) { [=](uint8_t newValue) {
sensor->unit = newValue; sensor->unit = newValue;
if (sensor->unit == UNIT_FAHRENHEIT) { if (sensor->unit == UNIT_FAHRENHEIT) {
@@ -181,20 +183,20 @@ class SensorEditWindow : public Page {
} }
SET_DIRTY(); SET_DIRTY();
telemetryItems[index].clear(); telemetryItems[index].clear();
updateSensorOneWindow(); updateSensorParametersWindow();
}); });
grid.nextLine(); grid.nextLine();
} }
// Precision // Precision
if (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT) { if (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_PRECISION); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_PRECISION);
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VPREC, 0, 2, GET_DEFAULT(sensor->prec), new Choice(sensorParametersWindow, grid.getFieldSlot(), STR_VPREC, 0, 2, GET_DEFAULT(sensor->prec),
[=](uint8_t newValue) { [=](uint8_t newValue) {
sensor->prec = newValue; sensor->prec = newValue;
SET_DIRTY(); SET_DIRTY();
telemetryItems[index].clear(); telemetryItems[index].clear();
updateSensorOneWindow(); updateSensorParametersWindow();
}); });
grid.nextLine(); grid.nextLine();
} }
@@ -203,34 +205,34 @@ class SensorEditWindow : public Page {
if (sensor->unit < UNIT_FIRST_VIRTUAL) { if (sensor->unit < UNIT_FIRST_VIRTUAL) {
if (sensor->type == TELEM_TYPE_CALCULATED) { if (sensor->type == TELEM_TYPE_CALCULATED) {
if (sensor->formula == TELEM_FORMULA_CELL) { if (sensor->formula == TELEM_FORMULA_CELL) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_CELLSENSOR); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_CELLSENSOR);
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->cell.source, isCellsSensor); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->cell.source, isCellsSensor);
} }
else if (sensor->formula == TELEM_FORMULA_DIST) { else if (sensor->formula == TELEM_FORMULA_DIST) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_GPSSENSOR); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_GPSSENSOR);
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->dist.gps, isGPSSensor); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->dist.gps, isGPSSensor);
} }
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) { else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_CURRENTSENSOR); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_CURRENTSENSOR);
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable);
} }
else if (sensor->formula == TELEM_FORMULA_TOTALIZE) { else if (sensor->formula == TELEM_FORMULA_TOTALIZE) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE);
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable);
} }
else { else {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(1)); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(1));
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[0], isSensorAvailable); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[0], isSensorAvailable);
} }
} }
else { else {
if (sensor->unit == UNIT_RPMS) { if (sensor->unit == UNIT_RPMS) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_BLADES); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_BLADES);
new NumberEdit(sensorOneWindow, grid.getFieldSlot(), 1, 30000, GET_SET_DEFAULT(sensor->custom.ratio)); new NumberEdit(sensorParametersWindow, grid.getFieldSlot(), 1, 30000, GET_SET_DEFAULT(sensor->custom.ratio));
} }
else { else {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_RATIO); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_RATIO);
auto edit = new NumberEdit(sensorOneWindow, grid.getFieldSlot(), 0, 30000, GET_SET_DEFAULT(sensor->custom.ratio)); auto edit = new NumberEdit(sensorParametersWindow, grid.getFieldSlot(), 0, 30000, GET_SET_DEFAULT(sensor->custom.ratio));
edit->setZeroText("-"); edit->setZeroText("-");
} }
} }
@@ -241,62 +243,62 @@ class SensorEditWindow : public Page {
(sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_CONSUMPTION || sensor->formula == TELEM_FORMULA_TOTALIZE)))) { (sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_CONSUMPTION || sensor->formula == TELEM_FORMULA_TOTALIZE)))) {
if (sensor->type == TELEM_TYPE_CALCULATED) { if (sensor->type == TELEM_TYPE_CALCULATED) {
if (sensor->formula == TELEM_FORMULA_CELL) { if (sensor->formula == TELEM_FORMULA_CELL) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_CELLINDEX); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_CELLINDEX);
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VCELLINDEX, 0, 8, GET_SET_DEFAULT(sensor->cell.index)); new Choice(sensorParametersWindow, grid.getFieldSlot(), STR_VCELLINDEX, 0, 8, GET_SET_DEFAULT(sensor->cell.index));
} }
else if (sensor->formula == TELEM_FORMULA_DIST) { else if (sensor->formula == TELEM_FORMULA_DIST) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_ALTSENSOR); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_ALTSENSOR);
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->dist.alt, isAltSensor); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), &sensor->dist.alt, isAltSensor);
} }
else { else {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(2)); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(2));
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[1], isSensorAvailable); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[1], isSensorAvailable);
} }
} }
else if (sensor->unit == UNIT_RPMS) { else if (sensor->unit == UNIT_RPMS) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_MULTIPLIER); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_MULTIPLIER);
new NumberEdit(sensorOneWindow, grid.getFieldSlot(), 1, 30000, GET_SET_DEFAULT(sensor->custom.offset)); new NumberEdit(sensorParametersWindow, grid.getFieldSlot(), 1, 30000, GET_SET_DEFAULT(sensor->custom.offset));
} }
else { else {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_OFFSET); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_OFFSET);
new NumberEdit(sensorOneWindow, grid.getFieldSlot(), -30000, 30000, GET_SET_DEFAULT(sensor->custom.offset), new NumberEdit(sensorParametersWindow, grid.getFieldSlot(), -30000, 30000, GET_SET_DEFAULT(sensor->custom.offset),
(sensor->prec > 0) ? (sensor->prec == 2 ? PREC2 : PREC1) : 0); (sensor->prec > 0) ? (sensor->prec == 2 ? PREC2 : PREC1) : 0);
} }
grid.nextLine(); grid.nextLine();
} }
if ((sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY)) { if ((sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY)) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(3)); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(3));
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[2], isSensorAvailable); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[2], isSensorAvailable);
grid.nextLine(); grid.nextLine();
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(4)); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(4));
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[3], isSensorAvailable); new SensorSourceChoice(sensorParametersWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[3], isSensorAvailable);
grid.nextLine(); grid.nextLine();
} }
// Auto Offset // Auto Offset
if (sensor->unit != UNIT_RPMS && sensor->isConfigurable()) { if (sensor->unit != UNIT_RPMS && sensor->isConfigurable()) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_AUTOOFFSET); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_AUTOOFFSET);
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->autoOffset)); new CheckBox(sensorParametersWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->autoOffset));
grid.nextLine(); grid.nextLine();
} }
if (sensor->isConfigurable()) { if (sensor->isConfigurable()) {
// Only positive // Only positive
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_ONLYPOSITIVE); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_ONLYPOSITIVE);
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->onlyPositive)); new CheckBox(sensorParametersWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->onlyPositive));
grid.nextLine(); grid.nextLine();
// Filter // Filter
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_FILTER); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_FILTER);
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->filter)); new CheckBox(sensorParametersWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->filter));
grid.nextLine(); grid.nextLine();
} }
if (sensor->type == TELEM_TYPE_CALCULATED) { if (sensor->type == TELEM_TYPE_CALCULATED) {
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_PERSISTENT); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_PERSISTENT);
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_DEFAULT(sensor->persistent), [=](int32_t newValue) { new CheckBox(sensorParametersWindow, grid.getFieldSlot(), GET_DEFAULT(sensor->persistent), [=](int32_t newValue) {
sensor->persistent = newValue; sensor->persistent = newValue;
if (!sensor->persistent) if (!sensor->persistent)
sensor->persistentValue = 0; sensor->persistentValue = 0;
@@ -305,29 +307,30 @@ class SensorEditWindow : public Page {
grid.nextLine(); grid.nextLine();
} }
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_LOGS); new StaticText(sensorParametersWindow, grid.getLabelSlot(), STR_LOGS);
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_DEFAULT(sensor->logs), [=](int32_t newValue) { new CheckBox(sensorParametersWindow, grid.getFieldSlot(), GET_DEFAULT(sensor->logs), [=](int32_t newValue) {
sensor->logs = newValue; sensor->logs = newValue;
logsClose(); logsClose();
SET_DIRTY(); SET_DIRTY();
}); });
coord_t delta = sensorOneWindow->adjustHeight(); coord_t delta = sensorParametersWindow->adjustHeight();
Window * parent = sensorOneWindow->getParent(); Window * parent = sensorParametersWindow->getParent();
parent->moveWindowsTop(sensorOneWindow->top(), delta); parent->moveWindowsTop(sensorParametersWindow->top(), delta);
} }
void buildBody(Window * window) void buildBody(FormWindow * window)
{ {
// Sensor one // Sensor one
FormGridLayout grid; FormGridLayout grid;
grid.spacer(8); grid.spacer(PAGE_PADDING);
TelemetrySensor * sensor = &g_model.telemetrySensors[index]; TelemetrySensor * sensor = &g_model.telemetrySensors[index];
// Name // Sensor name
new StaticText(window, grid.getLabelSlot(), STR_NAME); new StaticText(window, grid.getLabelSlot(), STR_NAME);
new TextEdit(window, grid.getFieldSlot(), sensor->label, TELEM_LABEL_LEN); auto edit = new TextEdit(window, grid.getFieldSlot(), sensor->label, sizeof(sensor->label));
window->setFirstField(edit);
grid.nextLine(); grid.nextLine();
// Type // Type
@@ -342,13 +345,13 @@ class SensorEditWindow : public Page {
sensor->autoOffset = 0; sensor->autoOffset = 0;
} }
SET_DIRTY(); SET_DIRTY();
updateSensorOneWindow(); updateSensorParametersWindow();
}); });
grid.nextLine(); grid.nextLine();
sensorOneWindow = new Window(window, {0, grid.getWindowHeight(), LCD_W, 0}); sensorParametersWindow = new Window(window, {0, grid.getWindowHeight(), LCD_W, 0});
updateSensorOneWindow(); updateSensorParametersWindow();
grid.addWindow(sensorOneWindow); grid.addWindow(sensorParametersWindow);
window->setInnerHeight(grid.getWindowHeight()); window->setInnerHeight(grid.getWindowHeight());
} }
@@ -361,8 +364,7 @@ ModelTelemetryPage::ModelTelemetryPage() :
void ModelTelemetryPage::checkEvents() void ModelTelemetryPage::checkEvents()
{ {
if (lastKnownIndex != availableTelemetryIndex()) { if (lastKnownIndex >= 0 && lastKnownIndex != availableTelemetryIndex()) {
lastKnownIndex = availableTelemetryIndex();
rebuild(window); rebuild(window);
} }
@@ -375,11 +377,13 @@ void ModelTelemetryPage::rebuild(FormWindow * window, int8_t focusSensorIndex)
window->clear(); window->clear();
build(window, focusSensorIndex); build(window, focusSensorIndex);
window->setScrollPositionY(scrollPosition); window->setScrollPositionY(scrollPosition);
lastKnownIndex = availableTelemetryIndex();
} }
void ModelTelemetryPage::editSensor(FormWindow * window, uint8_t index) void ModelTelemetryPage::editSensor(FormWindow * window, uint8_t index)
{ {
lastKnownIndex = -1;
Window * editWindow = new SensorEditWindow(index); Window * editWindow = new SensorEditWindow(index);
editWindow->setCloseHandler([=]() { editWindow->setCloseHandler([=]() {
rebuild(window, index); rebuild(window, index);
+1 -1
View File
@@ -27,7 +27,7 @@ class ModelTelemetryPage: public PageTab {
public: public:
ModelTelemetryPage(); ModelTelemetryPage();
virtual void build(FormWindow * window) override void build(FormWindow * window) override
{ {
build(window, -1); build(window, -1);
} }