refactor(color): use LVGL styles and objects for UI, legacy cleanup (#4407)
This commit is contained in:
+177
-108
@@ -20,15 +20,15 @@
|
||||
*/
|
||||
|
||||
#include "strhelpers.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(BOOT)
|
||||
#include "opentx.h"
|
||||
|
||||
#include "hal/switch_driver.h"
|
||||
#include "hal/adc_driver.h"
|
||||
#include "switches.h"
|
||||
#include "analogs.h"
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/switch_driver.h"
|
||||
#include "opentx.h"
|
||||
#include "switches.h"
|
||||
|
||||
static char _static_str_buffer[32];
|
||||
static const char s_charTab[] = "_-.,";
|
||||
@@ -173,7 +173,8 @@ char *strAppendStringWithIndex(char *dest, const char *s, int idx)
|
||||
#define SECONDSPERDAY (24 * SECONDSPERHOUR)
|
||||
#define SECONDSPERYEAR (365 * SECONDSPERDAY)
|
||||
|
||||
char *getFormattedTimerString(char *dest, int32_t tme, TimerOptions timerOptions)
|
||||
char *getFormattedTimerString(char *dest, int32_t tme,
|
||||
TimerOptions timerOptions)
|
||||
{
|
||||
char *s = dest;
|
||||
div_t qr;
|
||||
@@ -184,7 +185,7 @@ char *getFormattedTimerString(char *dest, int32_t tme, TimerOptions timerOptions
|
||||
uint8_t numDigitGroupRequired = (timerOptions.options >> 2) & 0x7;
|
||||
const bool hmFormat = timerOptions.options & SHOW_TIMER_HM_FORMAT;
|
||||
|
||||
if(!numDigitGroupRequired) numDigitGroupRequired = 3;
|
||||
if (!numDigitGroupRequired) numDigitGroupRequired = 3;
|
||||
|
||||
if (tme < 0) {
|
||||
tme = -tme;
|
||||
@@ -201,10 +202,10 @@ char *getFormattedTimerString(char *dest, int32_t tme, TimerOptions timerOptions
|
||||
val = qr.rem;
|
||||
digit_group++;
|
||||
}
|
||||
if (digit_group == numDigitGroupRequired) {
|
||||
if (digit_group == numDigitGroupRequired) {
|
||||
*s = 0;
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
// days
|
||||
qr = div((int)val, SECONDSPERDAY);
|
||||
if (qr.quot != 0 || digit_group != 0) {
|
||||
@@ -231,7 +232,7 @@ char *getFormattedTimerString(char *dest, int32_t tme, TimerOptions timerOptions
|
||||
*s = 0;
|
||||
return dest;
|
||||
}
|
||||
if(numDigitGroupRequired < 3 || hmFormat)
|
||||
if (numDigitGroupRequired < 3 || hmFormat)
|
||||
*s++ = bLowerCase ? 'h' : 'H';
|
||||
else
|
||||
*s++ = ':';
|
||||
@@ -250,11 +251,11 @@ char *getFormattedTimerString(char *dest, int32_t tme, TimerOptions timerOptions
|
||||
*s = 0;
|
||||
return dest;
|
||||
}
|
||||
if(!showTime && hmFormat)
|
||||
if (!showTime && hmFormat)
|
||||
*s++ = bLowerCase ? 'm' : 'M';
|
||||
else
|
||||
*s++ = ':';
|
||||
|
||||
|
||||
// seconds
|
||||
*s++ = '0' + (qr.rem / 10);
|
||||
*s++ = '0' + (qr.rem % 10);
|
||||
@@ -388,7 +389,7 @@ char *getGVarString(char *dest, int idx)
|
||||
s[0] = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
if (g_model.gvars[idx].name[0])
|
||||
strAppend(s, g_model.gvars[idx].name, LEN_GVAR_NAME);
|
||||
else
|
||||
@@ -398,8 +399,9 @@ char *getGVarString(char *dest, int idx)
|
||||
}
|
||||
|
||||
#if defined(LIBOPENUI)
|
||||
char *getValueOrGVarString(char *dest, size_t len, gvar_t value, gvar_t vmin, gvar_t vmax,
|
||||
LcdFlags flags, const char* suffix, gvar_t offset)
|
||||
char *getValueOrGVarString(char *dest, size_t len, gvar_t value, gvar_t vmin,
|
||||
gvar_t vmax, LcdFlags flags, const char *suffix,
|
||||
gvar_t offset)
|
||||
{
|
||||
if (GV_IS_GV_VALUE(value, vmin, vmax)) {
|
||||
int index = GV_INDEX_CALC_DELTA(value, GV_GET_GV1_VALUE(vmin, vmax));
|
||||
@@ -431,7 +433,7 @@ char *getFlightModeString(char *dest, int8_t idx)
|
||||
return dest;
|
||||
}
|
||||
|
||||
char* getSwitchName(char *dest, uint8_t idx)
|
||||
char *getSwitchName(char *dest, uint8_t idx)
|
||||
{
|
||||
if (switchHasCustomName(idx)) {
|
||||
dest = strAppend(dest, switchGetCustomName(idx), LEN_SWITCH_NAME);
|
||||
@@ -442,14 +444,14 @@ char* getSwitchName(char *dest, uint8_t idx)
|
||||
return dest;
|
||||
}
|
||||
|
||||
static const char* _switch_state_str[] {
|
||||
" ",
|
||||
STR_CHAR_UP,
|
||||
"-",
|
||||
STR_CHAR_DOWN,
|
||||
static const char *_switch_state_str[]{
|
||||
" ",
|
||||
STR_CHAR_UP,
|
||||
"-",
|
||||
STR_CHAR_DOWN,
|
||||
};
|
||||
|
||||
const char* getSwitchWarnSymbol(uint8_t pos)
|
||||
const char *getSwitchWarnSymbol(uint8_t pos)
|
||||
{
|
||||
// 0: NONE
|
||||
// 1: UP
|
||||
@@ -459,7 +461,7 @@ const char* getSwitchWarnSymbol(uint8_t pos)
|
||||
return _switch_state_str[pos];
|
||||
}
|
||||
|
||||
const char* getSwitchPositionSymbol(uint8_t pos)
|
||||
const char *getSwitchPositionSymbol(uint8_t pos)
|
||||
{
|
||||
// 0: UP
|
||||
// 1: MIDDLE
|
||||
@@ -487,13 +489,11 @@ char *getSwitchPositionName(char *dest, swsrc_t idx)
|
||||
s = getSwitchName(s, swinfo.quot);
|
||||
s = strAppend(s, getSwitchPositionSymbol(swinfo.rem), 2);
|
||||
*s = '\0';
|
||||
}
|
||||
else if (idx <= SWSRC_LAST_MULTIPOS_SWITCH) {
|
||||
} else if (idx <= SWSRC_LAST_MULTIPOS_SWITCH) {
|
||||
div_t swinfo =
|
||||
div(int(idx - SWSRC_FIRST_MULTIPOS_SWITCH), XPOTS_MULTIPOS_COUNT);
|
||||
s = strAppendStringWithIndex(s, getPotLabel(swinfo.quot), swinfo.rem + 1);
|
||||
}
|
||||
else if (idx <= SWSRC_LAST_TRIM) {
|
||||
} else if (idx <= SWSRC_LAST_TRIM) {
|
||||
idx -= SWSRC_FIRST_TRIM;
|
||||
// TODO: 't' or STR_CHAR_TRIM
|
||||
s = strAppend(s, getTrimLabel(idx / 2));
|
||||
@@ -528,10 +528,9 @@ char *getSwitchPositionName(char *dest, swsrc_t idx)
|
||||
return dest;
|
||||
}
|
||||
|
||||
const char* getAnalogLabel(uint8_t type, uint8_t idx)
|
||||
const char *getAnalogLabel(uint8_t type, uint8_t idx)
|
||||
{
|
||||
if (analogHasCustomLabel(type, idx))
|
||||
return analogGetCustomLabel(type, idx);
|
||||
if (analogHasCustomLabel(type, idx)) return analogGetCustomLabel(type, idx);
|
||||
|
||||
if (type == ADC_INPUT_MAIN) {
|
||||
// main controls: translated label is stored in "short label"
|
||||
@@ -541,11 +540,11 @@ const char* getAnalogLabel(uint8_t type, uint8_t idx)
|
||||
if (type == ADC_INPUT_FLEX) {
|
||||
return adcGetInputLabel(type, idx);
|
||||
}
|
||||
|
||||
|
||||
return analogGetCanonicalName(type, idx);
|
||||
}
|
||||
|
||||
const char* getAnalogShortLabel(uint8_t idx)
|
||||
const char *getAnalogShortLabel(uint8_t idx)
|
||||
{
|
||||
auto max = adcGetMaxInputs(ADC_INPUT_MAIN);
|
||||
if (idx < max) {
|
||||
@@ -573,12 +572,12 @@ const char* getAnalogShortLabel(uint8_t idx)
|
||||
return "";
|
||||
}
|
||||
|
||||
const char* getMainControlLabel(uint8_t idx)
|
||||
const char *getMainControlLabel(uint8_t idx)
|
||||
{
|
||||
return getAnalogLabel(ADC_INPUT_MAIN, idx);
|
||||
}
|
||||
|
||||
const char* getTrimLabel(uint8_t idx)
|
||||
const char *getTrimLabel(uint8_t idx)
|
||||
{
|
||||
if (idx < adcGetMaxInputs(ADC_INPUT_MAIN)) {
|
||||
return getMainControlLabel(idx);
|
||||
@@ -590,7 +589,7 @@ const char* getTrimLabel(uint8_t idx)
|
||||
return _trim_buffer;
|
||||
}
|
||||
|
||||
const char* getTrimSourceLabel(uint16_t src_raw, int8_t trim_src)
|
||||
const char *getTrimSourceLabel(uint16_t src_raw, int8_t trim_src)
|
||||
{
|
||||
if (trim_src < TRIM_ON) {
|
||||
return getTrimLabel(-trim_src - 1);
|
||||
@@ -602,7 +601,7 @@ const char* getTrimSourceLabel(uint16_t src_raw, int8_t trim_src)
|
||||
}
|
||||
}
|
||||
|
||||
const char* getPotLabel(uint8_t idx)
|
||||
const char *getPotLabel(uint8_t idx)
|
||||
{
|
||||
return getAnalogLabel(ADC_INPUT_FLEX, idx);
|
||||
}
|
||||
@@ -620,49 +619,54 @@ char *getSourceString(char (&dest)[L], mixsrc_t idx)
|
||||
idx -= MIXSRC_FIRST_INPUT;
|
||||
static_assert(L > sizeof(STR_CHAR_INPUT) - 1, "dest string too small");
|
||||
dest_len -= sizeof(STR_CHAR_INPUT) - 1;
|
||||
char* pos = strAppend(dest, STR_CHAR_INPUT, sizeof(STR_CHAR_INPUT) - 1);
|
||||
if (g_model.inputNames[idx][0] != '\0' && (dest_len > sizeof(g_model.inputNames[idx]))) {
|
||||
char *pos = strAppend(dest, STR_CHAR_INPUT, sizeof(STR_CHAR_INPUT) - 1);
|
||||
if (g_model.inputNames[idx][0] != '\0' &&
|
||||
(dest_len > sizeof(g_model.inputNames[idx]))) {
|
||||
memset(pos, 0, sizeof(g_model.inputNames[idx]) + 1);
|
||||
size_t input_len = std::min(dest_len - 1, sizeof(g_model.inputNames[idx]));
|
||||
size_t input_len =
|
||||
std::min(dest_len - 1, sizeof(g_model.inputNames[idx]));
|
||||
strncpy(pos, g_model.inputNames[idx], input_len);
|
||||
pos[input_len] = '\0';
|
||||
} else {
|
||||
strAppendUnsigned(pos, idx + 1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LUA_INPUTS)
|
||||
else if (idx <= MIXSRC_LAST_LUA) {
|
||||
#if defined(LUA_MODEL_SCRIPTS)
|
||||
div_t qr = div(idx - MIXSRC_FIRST_LUA, MAX_SCRIPT_OUTPUTS);
|
||||
if (qr.quot < MAX_SCRIPTS &&
|
||||
qr.rem < scriptInputsOutputs[qr.quot].outputsCount) {
|
||||
|
||||
static_assert(L > sizeof(STR_CHAR_LUA) - 1, "dest string too small");
|
||||
dest_len -= sizeof(STR_CHAR_LUA) - 1;
|
||||
char* pos = strAppend(dest, STR_CHAR_LUA, sizeof(STR_CHAR_LUA) - 1);
|
||||
char *pos = strAppend(dest, STR_CHAR_LUA, sizeof(STR_CHAR_LUA) - 1);
|
||||
|
||||
if (g_model.scriptsData[qr.quot].name[0] != '\0') {
|
||||
// instance Name is not empty : dest = InstanceName/OutputName
|
||||
snprintf(pos, dest_len, "%.*s/%.*s", (int)sizeof(g_model.scriptsData[qr.quot].name), g_model.scriptsData[qr.quot].name,
|
||||
(int)sizeof(scriptInputsOutputs[qr.quot].outputs[qr.rem].name), scriptInputsOutputs[qr.quot].outputs[qr.rem].name);
|
||||
snprintf(pos, dest_len, "%.*s/%.*s",
|
||||
(int)sizeof(g_model.scriptsData[qr.quot].name),
|
||||
g_model.scriptsData[qr.quot].name,
|
||||
(int)sizeof(scriptInputsOutputs[qr.quot].outputs[qr.rem].name),
|
||||
scriptInputsOutputs[qr.quot].outputs[qr.rem].name);
|
||||
} else {
|
||||
// instance Name is empty : dest = n-ScriptFileName/OutputName
|
||||
snprintf(pos, dest_len, "%d-%.*s/%.*s", qr.quot + 1,
|
||||
(int)sizeof(g_model.scriptsData[qr.quot].file), g_model.scriptsData[qr.quot].file,
|
||||
(int)sizeof(scriptInputsOutputs[qr.quot].outputs[qr.rem].name), scriptInputsOutputs[qr.quot].outputs[qr.rem].name);
|
||||
(int)sizeof(g_model.scriptsData[qr.quot].file),
|
||||
g_model.scriptsData[qr.quot].file,
|
||||
(int)sizeof(scriptInputsOutputs[qr.quot].outputs[qr.rem].name),
|
||||
scriptInputsOutputs[qr.quot].outputs[qr.rem].name);
|
||||
}
|
||||
}
|
||||
#else
|
||||
strncpy(dest, "N/A", L-1);
|
||||
strncpy(dest, "N/A", L - 1);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
else if (idx <= MIXSRC_LAST_POT) {
|
||||
char* pos = dest;
|
||||
char *pos = dest;
|
||||
idx -= MIXSRC_FIRST_STICK;
|
||||
|
||||
const char* name;
|
||||
const char *name;
|
||||
if (idx < MAX_STICKS) {
|
||||
pos = strAppend(pos, STR_CHAR_STICK, sizeof(STR_CHAR_STICK) - 1);
|
||||
dest_len -= sizeof(STR_CHAR_STICK) - 1;
|
||||
@@ -696,19 +700,18 @@ char *getSourceString(char (&dest)[L], mixsrc_t idx)
|
||||
#endif
|
||||
else if (idx == MIXSRC_MIN) {
|
||||
strncpy(dest, STR_MENU_MIN, dest_len - 1);
|
||||
}
|
||||
else if (idx == MIXSRC_MAX) {
|
||||
} else if (idx == MIXSRC_MAX) {
|
||||
strncpy(dest, STR_MENU_MAX, dest_len - 1);
|
||||
} else if (idx <= MIXSRC_LAST_HELI) {
|
||||
idx -= MIXSRC_FIRST_HELI;
|
||||
getStringAtIndex(dest, STR_CYC_VSRCRAW, idx);
|
||||
} else if (idx <= MIXSRC_LAST_TRIM) {
|
||||
idx -= MIXSRC_FIRST_TRIM;
|
||||
char* pos = strAppend(dest, STR_CHAR_TRIM, sizeof(STR_CHAR_TRIM) - 1);
|
||||
char *pos = strAppend(dest, STR_CHAR_TRIM, sizeof(STR_CHAR_TRIM) - 1);
|
||||
strAppend(pos, getTrimLabel(idx));
|
||||
} else if (idx <= MIXSRC_LAST_SWITCH) {
|
||||
idx -= MIXSRC_FIRST_SWITCH;
|
||||
char* pos = strAppend(dest, STR_CHAR_SWITCH, sizeof(STR_CHAR_SWITCH) - 1);
|
||||
char *pos = strAppend(dest, STR_CHAR_SWITCH, sizeof(STR_CHAR_SWITCH) - 1);
|
||||
getSwitchName(pos, idx);
|
||||
} else if (idx <= MIXSRC_LAST_LOGICAL_SWITCH) {
|
||||
// TODO: unnecessary, use the direct way instead
|
||||
@@ -727,7 +730,7 @@ char *getSourceString(char (&dest)[L], mixsrc_t idx)
|
||||
} else if (idx <= MIXSRC_LAST_GVAR) {
|
||||
idx -= MIXSRC_FIRST_GVAR;
|
||||
#if defined(LIBOPENUI)
|
||||
char* s = strAppendStringWithIndex(dest, STR_GV, idx + 1);
|
||||
char *s = strAppendStringWithIndex(dest, STR_GV, idx + 1);
|
||||
if (g_model.gvars[idx].name[0]) {
|
||||
s = strAppend(s, ":");
|
||||
getGVarString(s, idx);
|
||||
@@ -737,21 +740,21 @@ char *getSourceString(char (&dest)[L], mixsrc_t idx)
|
||||
#endif
|
||||
} else if (idx < MIXSRC_FIRST_TIMER) {
|
||||
// Built-in sources: TX Voltage, Time, GPS (+ reserved)
|
||||
const char* src_str;
|
||||
switch(idx) {
|
||||
case MIXSRC_TX_VOLTAGE:
|
||||
src_str = STR_SRC_BATT;
|
||||
break;
|
||||
case MIXSRC_TX_TIME:
|
||||
src_str = STR_SRC_TIME;
|
||||
break;
|
||||
case MIXSRC_TX_GPS:
|
||||
src_str = STR_SRC_GPS;
|
||||
break;
|
||||
default:
|
||||
src_str = "";
|
||||
break;
|
||||
}
|
||||
const char *src_str;
|
||||
switch (idx) {
|
||||
case MIXSRC_TX_VOLTAGE:
|
||||
src_str = STR_SRC_BATT;
|
||||
break;
|
||||
case MIXSRC_TX_TIME:
|
||||
src_str = STR_SRC_TIME;
|
||||
break;
|
||||
case MIXSRC_TX_GPS:
|
||||
src_str = STR_SRC_GPS;
|
||||
break;
|
||||
default:
|
||||
src_str = "";
|
||||
break;
|
||||
}
|
||||
strncpy(dest, src_str, dest_len - 1);
|
||||
} else if (idx <= MIXSRC_LAST_TIMER) {
|
||||
idx -= MIXSRC_FIRST_TIMER;
|
||||
@@ -763,14 +766,14 @@ char *getSourceString(char (&dest)[L], mixsrc_t idx)
|
||||
} else {
|
||||
idx -= MIXSRC_FIRST_TELEM;
|
||||
div_t qr = div(idx, 3);
|
||||
char* pos = strAppend(dest, STR_CHAR_TELEMETRY, 2);
|
||||
char *pos = strAppend(dest, STR_CHAR_TELEMETRY, 2);
|
||||
pos = strAppend(pos, g_model.telemetrySensors[qr.quot].label,
|
||||
sizeof(g_model.telemetrySensors[qr.quot].label));
|
||||
if (qr.rem) *pos = (qr.rem == 2 ? '+' : '-');
|
||||
*++pos = '\0';
|
||||
}
|
||||
dest[L - 1] = '\0'; // assert the termination
|
||||
return dest;
|
||||
dest[L - 1] = '\0'; // assert the termination
|
||||
return dest;
|
||||
}
|
||||
|
||||
// pre-instantiate for use from external
|
||||
@@ -782,7 +785,10 @@ char *getSourceString(mixsrc_t idx)
|
||||
return getSourceString(_static_str_buffer, idx);
|
||||
}
|
||||
|
||||
char *getCurveString(int idx) { return getCurveString(_static_str_buffer, idx); }
|
||||
char *getCurveString(int idx)
|
||||
{
|
||||
return getCurveString(_static_str_buffer, idx);
|
||||
}
|
||||
|
||||
char *getTimerString(int32_t tme, TimerOptions timerOptions)
|
||||
{
|
||||
@@ -811,7 +817,7 @@ char *getValueWithUnit(char *dest, size_t len, int32_t val, uint8_t unit,
|
||||
formatNumberAsString(dest, len, val, flags);
|
||||
} else {
|
||||
formatNumberAsString(dest, len, val, flags, 0, nullptr,
|
||||
STR_VTELEMUNIT[unit]);
|
||||
STR_VTELEMUNIT[unit]);
|
||||
}
|
||||
|
||||
return dest;
|
||||
@@ -821,9 +827,11 @@ template <size_t L>
|
||||
char *getSensorCustomValueString(char (&dest)[L], uint8_t sensor, int32_t val,
|
||||
LcdFlags flags)
|
||||
{
|
||||
if (sensor >= MAX_TELEMETRY_SENSORS) { return dest; }
|
||||
if (sensor >= MAX_TELEMETRY_SENSORS) {
|
||||
return dest;
|
||||
}
|
||||
|
||||
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[sensor];
|
||||
TelemetrySensor &telemetrySensor = g_model.telemetrySensors[sensor];
|
||||
|
||||
size_t len = L - 1;
|
||||
// TODO: display TEXT sensors?
|
||||
@@ -849,8 +857,7 @@ char *getSourceCustomValueString(char (&dest)[L], source_t source, int32_t val,
|
||||
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) {
|
||||
} else if (source >= MIXSRC_FIRST_TIMER || source == MIXSRC_TX_TIME) {
|
||||
if (L < LEN_TIMER_STRING) return dest;
|
||||
if (source == MIXSRC_TX_TIME) flags |= TIMEHOUR;
|
||||
|
||||
@@ -859,14 +866,18 @@ char *getSourceCustomValueString(char (&dest)[L], source_t source, int32_t val,
|
||||
if ((flags & TIMEHOUR) != 0) timerOptions.options = SHOW_TIME;
|
||||
|
||||
return getTimerString(dest, val, timerOptions);
|
||||
}
|
||||
else if (source == MIXSRC_TX_VOLTAGE) {
|
||||
} else if (source == MIXSRC_TX_VOLTAGE) {
|
||||
formatNumberAsString(dest, len, val, flags | PREC1);
|
||||
return dest;
|
||||
}
|
||||
#if defined(INTERNAL_GPS)
|
||||
else if (source == MIXSRC_TX_GPS) {
|
||||
strAppend(dest, "N/A", len);
|
||||
if (gpsData.fix) {
|
||||
std::string s = getGPSSensorValue(gpsData.longitude, gpsData.latitude, flags);
|
||||
strAppend(dest, s.c_str(), L);
|
||||
} else {
|
||||
formatNumberAsString(dest, L, gpsData.numSat, flags, len, "sats: ");
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
#endif
|
||||
@@ -890,8 +901,7 @@ char *getSourceCustomValueString(char (&dest)[L], source_t source, int32_t val,
|
||||
else if (source < MIXSRC_FIRST_CH) {
|
||||
val = calcRESXto100(val);
|
||||
formatNumberAsString(dest, len, val, flags);
|
||||
}
|
||||
else if (source <= MIXSRC_LAST_CH) {
|
||||
} else if (source <= MIXSRC_LAST_CH) {
|
||||
if (g_eeGeneral.ppmunit == PPM_PERCENT_PREC1) {
|
||||
val = calcRESXto1000(val);
|
||||
formatNumberAsString(dest, len, val, flags | PREC1);
|
||||
@@ -899,18 +909,20 @@ char *getSourceCustomValueString(char (&dest)[L], source_t source, int32_t val,
|
||||
val = calcRESXto100(val);
|
||||
formatNumberAsString(dest, len, val, flags);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
formatNumberAsString(dest, len, val, flags);
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
void formatNumberAsString(char *buffer, uint8_t buffer_size, int32_t val, LcdFlags flags, uint8_t len, const char * prefix, const char * suffix)
|
||||
void formatNumberAsString(char *buffer, uint8_t buffer_size, int32_t val,
|
||||
LcdFlags flags, uint8_t len, const char *prefix,
|
||||
const char *suffix)
|
||||
{
|
||||
if (buffer) {
|
||||
char str[48+1]; // max=16 for the prefix, 16 chars for the number, 16 chars for the suffix
|
||||
char str[48 + 1]; // max=16 for the prefix, 16 chars for the number, 16
|
||||
// chars for the suffix
|
||||
char *s = str + 32;
|
||||
*s = '\0';
|
||||
int idx = 0;
|
||||
@@ -927,8 +939,7 @@ void formatNumberAsString(char *buffer, uint8_t buffer_size, int32_t val, LcdFla
|
||||
if (mode != 0 && idx == mode) {
|
||||
mode = 0;
|
||||
*--s = '.';
|
||||
if (val == 0)
|
||||
*--s = '0';
|
||||
if (val == 0) *--s = '0';
|
||||
}
|
||||
} while (val != 0 || mode > 0 || (mode == MODE(LEADING0) && idx < len));
|
||||
if (neg) *--s = '-';
|
||||
@@ -980,8 +991,78 @@ std::string getGVarValue(uint8_t gvar, gvar_t value, LcdFlags flags)
|
||||
value, g_model.gvars[gvar].unit ? UNIT_PERCENT : UNIT_RAW, flags);
|
||||
}
|
||||
|
||||
#endif // defined(LIBOPENUI)
|
||||
#endif // !defined(BOOT)
|
||||
std::string getGPSCoord(int32_t value, const char *direction, bool seconds)
|
||||
{
|
||||
char s[32] = {};
|
||||
uint32_t absvalue = abs(value);
|
||||
char *tmp = strAppendUnsigned(s, absvalue / 1000000);
|
||||
tmp = strAppend(tmp, "°");
|
||||
absvalue = absvalue % 1000000;
|
||||
absvalue *= 60;
|
||||
if (g_eeGeneral.gpsFormat == 0 || !seconds) {
|
||||
tmp = strAppendUnsigned(tmp, absvalue / 1000000, 2);
|
||||
*tmp++ = '\'';
|
||||
if (seconds) {
|
||||
absvalue %= 1000000;
|
||||
absvalue *= 60;
|
||||
absvalue /= 100000;
|
||||
tmp = strAppendUnsigned(tmp, absvalue / 10);
|
||||
*tmp++ = '.';
|
||||
tmp = strAppendUnsigned(tmp, absvalue % 10);
|
||||
*tmp++ = '"';
|
||||
}
|
||||
} else {
|
||||
tmp = strAppendUnsigned(tmp, absvalue / 1000000, 2);
|
||||
*tmp++ = '.';
|
||||
absvalue /= 1000;
|
||||
tmp = strAppendUnsigned(tmp, absvalue, 3);
|
||||
}
|
||||
*tmp++ = direction[value >= 0 ? 0 : 1];
|
||||
*tmp = '\0';
|
||||
return std::string(s);
|
||||
}
|
||||
|
||||
std::string getGPSSensorValue(int32_t longitude, int32_t latitude, LcdFlags flags)
|
||||
{
|
||||
if (flags & PREC1) {
|
||||
return getGPSCoord(latitude, "NS", true) + " " +
|
||||
getGPSCoord(longitude, "EW", true);
|
||||
} else {
|
||||
if (flags & RIGHT)
|
||||
return getGPSCoord(longitude, "EW", true) + " " +
|
||||
getGPSCoord(latitude, "NS", true);
|
||||
|
||||
return getGPSCoord(latitude, "NS", true) + " " +
|
||||
getGPSCoord(longitude, "EW", true);
|
||||
}
|
||||
}
|
||||
|
||||
std::string getGPSSensorValue(TelemetryItem &telemetryItem, LcdFlags flags)
|
||||
{
|
||||
return getGPSSensorValue(telemetryItem.gps.longitude, telemetryItem.gps.latitude, flags);
|
||||
}
|
||||
|
||||
std::string getTelemDate(TelemetryItem &telemetryItem)
|
||||
{
|
||||
return formatNumberAsString(telemetryItem.datetime.year, LEADING0 | LEFT, 4) +
|
||||
"-" +
|
||||
formatNumberAsString(telemetryItem.datetime.month, LEADING0 | LEFT,
|
||||
2) +
|
||||
"-" +
|
||||
formatNumberAsString(telemetryItem.datetime.day, LEADING0 | LEFT, 2);
|
||||
}
|
||||
|
||||
std::string getTelemTime(TelemetryItem &telemetryItem)
|
||||
{
|
||||
return formatNumberAsString(telemetryItem.datetime.hour, LEADING0 | LEFT, 2) +
|
||||
":" +
|
||||
formatNumberAsString(telemetryItem.datetime.min, LEADING0 | LEFT, 2) +
|
||||
":" +
|
||||
formatNumberAsString(telemetryItem.datetime.sec, LEADING0 | LEFT, 2);
|
||||
}
|
||||
|
||||
#endif // defined(LIBOPENUI)
|
||||
#endif // !defined(BOOT)
|
||||
|
||||
char *strAppendUnsigned(char *dest, uint32_t value, uint8_t digits,
|
||||
uint8_t radix)
|
||||
@@ -1098,22 +1179,16 @@ char *strAppendDate(char *str, bool time)
|
||||
// timezone = hour value
|
||||
// timezoneMinutes - minute value / 15
|
||||
|
||||
int8_t minTimezone()
|
||||
{
|
||||
return -12 * 4;
|
||||
}
|
||||
int8_t minTimezone() { return -12 * 4; }
|
||||
|
||||
int8_t maxTimezone()
|
||||
{
|
||||
return 14 * 4;
|
||||
}
|
||||
int8_t maxTimezone() { return 14 * 4; }
|
||||
|
||||
std::string timezoneDisplay(int tz)
|
||||
{
|
||||
char s[16];
|
||||
int h = abs(tz / 4);
|
||||
int m = abs(tz % 4) * 15;
|
||||
sprintf(s,"%s%d:%02d", (tz < 0) ? "-" : "", h, m);
|
||||
sprintf(s, "%s%d:%02d", (tz < 0) ? "-" : "", h, m);
|
||||
return std::string(s);
|
||||
}
|
||||
|
||||
@@ -1122,15 +1197,9 @@ int timezoneIndex(int8_t tzHour, int8_t tzMinute)
|
||||
return (tzHour * 4) + tzMinute;
|
||||
}
|
||||
|
||||
int8_t timezoneHour(int tz)
|
||||
{
|
||||
return tz / 4;
|
||||
}
|
||||
int8_t timezoneHour(int tz) { return tz / 4; }
|
||||
|
||||
int8_t timezoneMinute(int tz)
|
||||
{
|
||||
return tz % 4;
|
||||
}
|
||||
int8_t timezoneMinute(int tz) { return tz % 4; }
|
||||
|
||||
int timezoneOffsetSeconds(int8_t tzHour, int8_t tzMinute)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user