Skip to content

Commit

Permalink
Merge branch 'EdgeTX:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dwheeld authored Jun 12, 2022
2 parents 3fc5c07 + d1f94af commit 9ece353
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- x9lite;x9lites
- xlite;xlites
container:
image: ghcr.io/edgetx/edgetx-commit-tests
image: ghcr.io/edgetx/edgetx-dev:latest
volumes:
- ${{ github.workspace }}:/src
steps:
Expand Down
2 changes: 2 additions & 0 deletions companion/src/simulation/simulateduiwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ void SimulatedUIWidget::onLcdChange(bool backlightEnable)
return;

m_lcd->onLcdChanged(backlightEnable);
m_simulator->lcdFlushed();

setLightOn(backlightEnable);
}

Expand Down
1 change: 1 addition & 0 deletions companion/src/simulation/simulatorinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class SimulatorInterface : public QObject
virtual void setInputValue(int type, uint8_t index, int16_t value) = 0;
virtual void rotaryEncoderEvent(int steps) = 0;
virtual void touchEvent(int type, int x, int y) = 0;
virtual void lcdFlushed() = 0;
virtual void setTrainerTimeout(uint16_t ms) = 0;
virtual void sendTelemetry(const QByteArray data) = 0;
virtual void setLuaStateReloadPermanentScripts() = 0;
Expand Down
28 changes: 10 additions & 18 deletions radio/src/gui/colorlcd/model_logical_switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ class LogicalSwitchEditPage: public Page
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V1, 0, COLOR_THEME_PRIMARY1);
auto timer = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), -128, 122, GET_SET_DEFAULT(cs->v1));
timer->setDisplayHandler([](int32_t value) {
char s[50];
BitmapBuffer::formatNumberAsString(s, 49, lswTimerValue(value), PREC1);
return std::string(s);
// dc->drawNumber(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, lswTimerValue(value), flags | PREC1);
return formatNumberAsString(lswTimerValue(value), PREC1);
});
grid.nextLine();

Expand All @@ -167,26 +164,28 @@ class LogicalSwitchEditPage: public Page
new SourceChoice(logicalSwitchOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM, GET_DEFAULT(cs->v1),
[=](int32_t newValue) {
cs->v1 = newValue;
SET_DIRTY();
if (v2Edit != nullptr)
{
int16_t v2_min = 0, v2_max = 0;
getMixSrcRange(cs->v1, v2_min, v2_max);
v2Edit->setMin(v2_min);
v2Edit->setMax(v2_max);
v2Edit->invalidate();
v2Edit->setValue(cs->v2);
}
SET_DIRTY();
});
grid.nextLine();

new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V2, 0, COLOR_THEME_PRIMARY1);
int16_t v2_min = 0, v2_max = 0;
getMixSrcRange(cs->v1, v2_min, v2_max);
v2Edit = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), v2_min, v2_max, GET_SET_DEFAULT(cs->v2));
v2Edit->setDisplayHandler(
[=](int value) {
// drawSourceCustomValue(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, cs->v1, (cs->v1 <= MIXSRC_LAST_CH ? calc100toRESX(value) : value), flags);
return "ddd"; // ToDo This is not good
v2Edit = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(),
v2_min, v2_max, GET_SET_DEFAULT(cs->v2));

v2Edit->setDisplayHandler([=](int value) -> std::string {
if (cs->v1 <= MIXSRC_LAST_CH) value = calc100toRESX(value);
std::string txt = getSourceCustomValueString(cs->v1, value, 0);
return txt;
});
grid.nextLine();
}
Expand Down Expand Up @@ -434,13 +433,6 @@ void ModelLogicalSwitchesPage::build(FormWindow* window, int8_t focusIndex)
txt->invalidate();
});

// if (focusIndex == i) {
// button->setFocus(SET_FOCUS_DEFAULT);
// txt->setBackgroundColor(COLOR_THEME_FOCUS);
// txt->setTextFlags(COLOR_THEME_PRIMARY2 | CENTERED);
// txt->invalidate();
// }

txt->setHeight(button->height());
grid.spacer(button->height() + 5);
}
Expand Down
1 change: 0 additions & 1 deletion radio/src/simu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ FXIMPLEMENT(OpenTxSim, FXMainWindow, OpenTxSimMap, ARRAYNUMBER(OpenTxSimMap))
OpenTxSim::OpenTxSim(FXApp* a):
FXMainWindow(a, "OpenTX Simu", nullptr, nullptr, DECOR_ALL, 20, 90, 0, 0)
{
lcdInit();
bmp = new FXPPMImage(getApp(), nullptr, IMAGE_OWNED|IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP, W2, H2);

#if defined(SIMU_AUDIO)
Expand Down
235 changes: 190 additions & 45 deletions radio/src/strhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,9 @@ char *getSwitchPositionName(char *dest, swsrc_t idx)
return dest;
}

// this should be declared in header, but it used so much foreign symbols that we declare it in cpp-file and pre-instantiate it for the uses
template<size_t L>
// this should be declared in header, but it used so much foreign symbols that
// we declare it in cpp-file and pre-instantiate it for the uses
template <size_t L>
char *getSourceString(char (&dest)[L], mixsrc_t idx)
{
size_t dest_len = L;
Expand Down Expand Up @@ -704,9 +705,195 @@ char *getSourceString(char (&dest)[L], mixsrc_t idx)

// pre-instantiate for use from external
// all other instantiations are done from this file
template char *getSourceString<16>(char (&dest)[16], mixsrc_t idx);
template char *getSourceString<16>(char (&dest)[16], mixsrc_t idx);

static char tmpHelpersString[32];

char *getSourceString(mixsrc_t idx)
{
return getSourceString(tmpHelpersString, idx);
}

char *getCurveString(int idx) { return getCurveString(tmpHelpersString, idx); }

char *getTimerString(int32_t tme, TimerOptions timerOptions)
{
return getFormattedTimerString(tmpHelpersString, tme, timerOptions);
}

char *getTimerString(char *dest, int32_t tme, TimerOptions timerOptions)
{
return getFormattedTimerString(dest, tme, timerOptions);
}

char *getSwitchPositionName(swsrc_t idx)
{
return getSwitchPositionName(tmpHelpersString, idx);
}

char *getGVarString(int idx) { return getGVarString(tmpHelpersString, idx); }

#if defined(LIBOPENUI)
char *getValueWithUnit(char *dest, size_t len, int32_t val, uint8_t unit,
LcdFlags flags)
{
if (unit == UNIT_CELLS) unit = UNIT_VOLTS;
if ((flags & NO_UNIT) || (unit == UNIT_RAW)) {
flags = flags & (~NO_UNIT);
BitmapBuffer::formatNumberAsString(dest, len, val, flags);
} else {
BitmapBuffer::formatNumberAsString(dest, len, val, flags, 0, nullptr,
STR_VTELEMUNIT[unit]);
}

return dest;
}

template <size_t L>
char *getSensorCustomValueString(char (&dest)[L], uint8_t sensor, int32_t val,
LcdFlags flags)
{
if (sensor >= MAX_TELEMETRY_SENSORS) { return dest; }

// TelemetryItem & telemetryItem = telemetryItems[sensor];
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[sensor];

size_t len = L - 1;
if (telemetrySensor.unit == UNIT_DATETIME ||
telemetrySensor.unit == UNIT_GPS || telemetrySensor.unit == UNIT_TEXT) {
strAppend(dest, "N/A", len);
return dest;
}

if (telemetrySensor.unit == UNIT_BITFIELD) {
if (IS_FRSKY_SPORT_PROTOCOL()) {
if (telemetrySensor.id >= RBOX_STATE_FIRST_ID &&
telemetrySensor.id <= RBOX_STATE_LAST_ID) {
if (telemetrySensor.subId == 0) {
if (val == 0) {
strAppend(dest, "OK", len);
return dest;
}
for (uint8_t i = 0; i < 16; i++) {
if (val & (1 << i)) {
if (len < 8) return dest;
auto pos = strAppend(dest, "CH", len);
len -= 2;
pos = strAppendUnsigned(pos, i + 1, 2);
len -= 2;
strAppend(pos, " KO", len);
return dest;
}
}
} else {
if (val == 0) {
strAppend(dest, "Rx OK", len);
return dest;
}

static const char *const RXS_STATUS[] = {
"Rx1 Ovl", "Rx2 Ovl", "SBUS Ovl", "Rx1 FS", "Rx1 LF", "Rx2 FS",
"Rx2 LF", "Rx1 Lost", "Rx2 Lost", "Rx1 NS", "Rx2 NS",
};
for (uint8_t i = 0; i < DIM(RXS_STATUS); i++) {
if (val & (1 << i)) {
strAppend(dest, RXS_STATUS[i], len);
return dest;
}
}
}
}
}
} else {
if (telemetrySensor.prec > 0) {
flags |= (telemetrySensor.prec == 1 ? PREC1 : PREC2);
}
getValueWithUnit(dest, len, val, telemetrySensor.unit, flags);
}

return dest;
}

template <size_t L>
char *getSourceCustomValueString(char (&dest)[L], source_t source, int32_t val,
LcdFlags flags)
{
size_t len = L - 1;
if (source >= MIXSRC_FIRST_TELEM) {
source = (source - MIXSRC_FIRST_TELEM) / 3;
return getSensorCustomValueString(dest, source, val, flags);
}
else if (source >= MIXSRC_FIRST_TIMER || source == MIXSRC_TX_TIME) {
if (L < LEN_TIMER_STRING) return dest;
if (source == MIXSRC_TX_TIME) flags |= TIMEHOUR;

TimerOptions timerOptions;
timerOptions.options = SHOW_TIMER;
if ((flags & TIMEHOUR) != 0) timerOptions.options = SHOW_TIME;

return getTimerString(dest, val, timerOptions);
}
else if (source == MIXSRC_TX_VOLTAGE) {
BitmapBuffer::formatNumberAsString(dest, len, val, flags | PREC1);
return dest;
}
#if defined(INTERNAL_GPS)
else if (source == MIXSRC_TX_GPS) {
strAppend(dest, "N/A", len);
return dest;
}
#endif
#if defined(GVARS)
else if (source >= MIXSRC_FIRST_GVAR && source <= MIXSRC_LAST_GVAR) {
uint8_t gvar_idx = source - MIXSRC_FIRST_GVAR;
auto gvar = &g_model.gvars[gvar_idx];
uint8_t prec = gvar->prec;
if (prec > 0) {
flags |= (prec == 1 ? PREC1 : PREC2);
}
uint8_t unit = gvar->unit ? UNIT_PERCENT : UNIT_RAW;
getValueWithUnit(dest, len, val, unit, flags);
}
#endif
#if defined(LUA_INPUTS)
else if (source >= MIXSRC_FIRST_LUA && source <= MIXSRC_LAST_LUA) {
BitmapBuffer::formatNumberAsString(dest, len, val, flags);
}
#endif
else if (source < MIXSRC_FIRST_CH) {
val = calcRESXto100(val);
BitmapBuffer::formatNumberAsString(dest, len, val, flags);
}
else if (source <= MIXSRC_LAST_CH) {
val = calcRESXto100(val);
#if defined(PPM_UNIT_PERCENT_PREC1)
BitmapBuffer::formatNumberAsString(dest, len, val, flags | PREC1);
#else
BitmapBuffer::formatNumberAsString(dest, len, val, flags);
#endif
}
else {
BitmapBuffer::formatNumberAsString(dest, len, val, flags);
}

return dest;
}

std::string formatNumberAsString(int32_t val, LcdFlags flags, uint8_t len,
const char *prefix, const char *suffix)
{
char s[49];
BitmapBuffer::formatNumberAsString(s, 49, val, flags, len, prefix, suffix);
return std::string(s);
}

char *getSourceCustomValueString(source_t source, int32_t val, LcdFlags flags)
{
return getSourceCustomValueString(tmpHelpersString, source, val, flags);
}

#endif // defined(LIBOPENUI)
#endif // !defined(BOOT)

char *strAppendUnsigned(char *dest, uint32_t value, uint8_t digits,
uint8_t radix)
Expand Down Expand Up @@ -771,18 +958,6 @@ char *strAppendFilename(char *dest, const char *filename, const int size)
return dest;
}

#if defined(LIBOPENUI)
#include "bitmapbuffer.h"

std::string formatNumberAsString(int32_t val, LcdFlags flags, uint8_t len,
const char *prefix, const char *suffix)
{
char s[100];
BitmapBuffer::formatNumberAsString(s, 99, val, flags, len, prefix, suffix);
return std::string(s);
}
#endif

#if defined(RTCLOCK)
#include "rtc.h"

Expand Down Expand Up @@ -828,34 +1003,4 @@ char *strAppendDate(char *str, bool time)
#endif

#if !defined(BOOT)
static char tmpHelpersString[32];

// char * getSwitchWarningString(swsrc_t idx)
// {
// return getSwitchWarningString(tmpHelpersString, idx);
// }

char *getSourceString(mixsrc_t idx)
{
return getSourceString(tmpHelpersString, idx);
}

char *getCurveString(int idx) { return getCurveString(tmpHelpersString, idx); }

char *getTimerString(int32_t tme, TimerOptions timerOptions)
{
return getFormattedTimerString(tmpHelpersString, tme, timerOptions);
}

char *getTimerString(char *dest, int32_t tme, TimerOptions timerOptions)
{
return getFormattedTimerString(dest, tme, timerOptions);
}

char *getSwitchPositionName(swsrc_t idx)
{
return getSwitchPositionName(tmpHelpersString, idx);
}

char *getGVarString(int idx) { return getGVarString(tmpHelpersString, idx); }
#endif
9 changes: 5 additions & 4 deletions radio/src/strhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,19 @@ char *getSwitchName(char *dest, swsrc_t idx);
template<size_t L>
char* getSourceString(char (&dest)[L], mixsrc_t idx);

template <size_t L>
char *getSourceCustomValueString(char (&dest)[L], source_t source, int32_t val,
LcdFlags flags);

int getRawSwitchIdx(char sw);
char getRawSwitchFromIdx(int sw);
#endif

char *getFlightModeString(char *dest, int8_t idx);

#define SWITCH_WARNING_STR_SIZE 3
// char *getSwitchWarningString(char *dest, swsrc_t idx);

char *getSourceString(mixsrc_t idx);
char *getSourceCustomValueString(source_t source, int32_t val, LcdFlags flags);
char *getSwitchPositionName(swsrc_t idx);
// char *getSwitchWarningString(swsrc_t idx);
char *getCurveString(int idx);
char *getTimerString(int32_t tme, TimerOptions timerOptions = {.options = 0});
void splitTimer(char *s0, char *s1, char *s2, char *s3, int tme,
Expand Down
Loading

0 comments on commit 9ece353

Please sign in to comment.