Bsongis/gui refactoring for x7 d (#3701)

* [X7D] New board added
* Cosmetics
This commit is contained in:
Bertrand Songis
2016-08-18 11:49:16 +02:00
committed by GitHub
parent 282b856309
commit d3ae3c035d
233 changed files with 7472 additions and 4560 deletions
+12 -206
View File
@@ -210,9 +210,9 @@ void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, Lc
}
#endif
void putsRtcTime(coord_t x, coord_t y, LcdFlags att)
void drawRtcTime(coord_t x, coord_t y, LcdFlags att)
{
putsTimer(x, y, getValue(MIXSRC_TX_TIME), att);
drawTimer(x, y, getValue(MIXSRC_TX_TIME), att);
}
void getTimerString(char * str, putstime_t tme, LcdFlags att)
@@ -243,7 +243,7 @@ void getTimerString(char * str, putstime_t tme, LcdFlags att)
*str = '\0';
}
void putsTimer(coord_t x, coord_t y, putstime_t tme, LcdFlags att)
void drawTimer(coord_t x, coord_t y, putstime_t tme, LcdFlags att)
{
char str[LEN_TIMER_STRING]; // "-00:00:00"
getTimerString(str, tme, att);
@@ -263,152 +263,7 @@ void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
lcdDrawSizedText(x, y, STR_VSRCRAW+2+length*(idx+1), length-1, att);
}
char * getStringAtIndex(char * dest, const char * s, int idx)
{
uint8_t len = s[0];
strncpy(dest, s+1+len*idx, len);
dest[len] = '\0';
return dest;
}
char * getStringWithIndex(char * dest, const char * s, int idx)
{
strAppendUnsigned(strAppend(dest, s), abs(idx));
return dest;
}
char * getSwitchString(char * dest, swsrc_t idx)
{
if (idx == SWSRC_NONE) {
return getStringAtIndex(dest, STR_VSWITCHES, 0);
}
else if (idx == SWSRC_OFF) {
return getStringAtIndex(dest, STR_OFFON, 0);
}
char * s = dest;
if (idx < 0) {
*s++ = '!';
idx = -idx;
}
if (idx <= SWSRC_LAST_SWITCH) {
div_t swinfo = switchInfo(idx);
if (ZEXIST(g_eeGeneral.switchNames[swinfo.quot])) {
s += zchar2str(s, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME);
// TODO tous zchar2str
}
else {
*s++ = 'S';
*s++ = 'A'+swinfo.quot;
}
*s++ = "\300-\301"[swinfo.rem];
*s = '\0';
}
else if (idx <= SWSRC_LAST_MULTIPOS_SWITCH) {
div_t swinfo = div(idx - SWSRC_FIRST_MULTIPOS_SWITCH, XPOTS_MULTIPOS_COUNT);
getStringWithIndex(s, "S", swinfo.quot*10+swinfo.rem+11);
}
else if (idx <= SWSRC_LAST_TRIM) {
getStringAtIndex(s, STR_VSWITCHES, idx-SWSRC_FIRST_TRIM+1);
}
else if (idx <= SWSRC_LAST_LOGICAL_SWITCH) {
getStringWithIndex(s, "L", idx-SWSRC_FIRST_LOGICAL_SWITCH+1);
}
else if (idx <= SWSRC_ONE) {
getStringAtIndex(s, STR_VSWITCHES, idx-SWSRC_ON+2+(SWSRC_LAST_TRIM-SWSRC_FIRST_TRIM));
}
else if (idx <= SWSRC_LAST_FLIGHT_MODE) {
getStringWithIndex(s, STR_FP, idx-SWSRC_FIRST_FLIGHT_MODE);
}
else if (idx == SWSRC_TELEMETRY_STREAMING) {
strcpy(s, "Tele");
}
else {
zchar2str(s, g_model.telemetrySensors[idx-SWSRC_FIRST_SENSOR].label, TELEM_LABEL_LEN);
}
return dest;
}
char * getSourceString(char * dest, mixsrc_t idx)
{
if (idx == MIXSRC_NONE) {
return getStringAtIndex(dest, STR_VSRCRAW, 0);
}
else if (idx <= MIXSRC_LAST_INPUT) {
idx -= MIXSRC_FIRST_INPUT;
*dest++ = '\314';
if (ZEXIST(g_model.inputNames[idx])) {
zchar2str(dest, g_model.inputNames[idx], LEN_INPUT_NAME);
dest[LEN_INPUT_NAME] = '\0';
}
else {
strAppendUnsigned(dest, idx, 2);
}
}
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) {
*dest++ = '\322';
// *dest++ = '1'+qr.quot;
strcpy(dest, scriptInputsOutputs[qr.quot].outputs[qr.rem].name);
}
#endif
}
else if (idx <= MIXSRC_LAST_POT) {
idx -= MIXSRC_Rud;
if (ZEXIST(g_eeGeneral.anaNames[idx])) {
zchar2str(dest, g_eeGeneral.anaNames[idx], LEN_ANA_NAME);
dest[LEN_ANA_NAME] = '\0';
}
else {
getStringAtIndex(dest, STR_VSRCRAW, idx + 1);
}
}
else if (idx <= MIXSRC_LAST_TRIM) {
idx -= MIXSRC_Rud;
getStringAtIndex(dest, STR_VSRCRAW, idx + 1);
}
else if (idx <= MIXSRC_LAST_SWITCH) {
idx -= MIXSRC_FIRST_SWITCH;
if (ZEXIST(g_eeGeneral.switchNames[idx])) {
zchar2str(dest, g_eeGeneral.switchNames[idx], LEN_SWITCH_NAME);
dest[LEN_SWITCH_NAME] = '\0';
}
else {
getStringAtIndex(dest, STR_VSRCRAW, idx + MIXSRC_FIRST_SWITCH - MIXSRC_Rud + 1);
}
}
else if (idx <= MIXSRC_LAST_LOGICAL_SWITCH) {
getSwitchString(dest, SWSRC_SW1 + idx - MIXSRC_SW1);
}
else if (idx <= MIXSRC_LAST_TRAINER) {
getStringWithIndex(dest, STR_PPM_TRAINER, idx - MIXSRC_FIRST_TRAINER + 1);
}
else if (idx <= MIXSRC_LAST_CH) {
getStringWithIndex(dest, STR_CH, idx - MIXSRC_CH1 + 1);
}
else if (idx <= MIXSRC_LAST_GVAR) {
getStringWithIndex(dest, STR_GV, idx - MIXSRC_GVAR1 + 1);
}
else if (idx < MIXSRC_FIRST_TELEM) {
getStringAtIndex(dest, STR_VSRCRAW, idx-MIXSRC_Rud+1-NUM_LOGICAL_SWITCH-NUM_TRAINER-NUM_CHNOUT-MAX_GVARS);
}
else {
idx -= MIXSRC_FIRST_TELEM;
div_t qr = div(idx, 3);
dest[0] = '\321';
int pos = 1 + zchar2str(&dest[1], g_model.telemetrySensors[qr.quot].label, sizeof(g_model.telemetrySensors[qr.quot].label));
if (qr.rem) dest[pos++] = (qr.rem==2 ? '+' : '-');
dest[pos] = '\0';
}
return dest;
}
void putsMixerSource(coord_t x, coord_t y, uint32_t idx, LcdFlags flags)
void drawSource(coord_t x, coord_t y, uint32_t idx, LcdFlags flags)
{
char s[16];
getSourceString(s, idx);
@@ -432,70 +287,21 @@ void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att)
}
}
void putsSwitches(coord_t x, coord_t y, swsrc_t idx, LcdFlags flags)
void drawSwitch(coord_t x, coord_t y, swsrc_t idx, LcdFlags flags)
{
char s[8];
getSwitchString(s, idx);
lcdDrawText(x, y, s, flags);
}
void putsFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att)
{
if (idx==0) {
lcdDrawTextAtIndex(x, y, STR_MMMINV, 0, att);
}
else {
drawStringWithIndex(x, y, STR_FP, abs(idx)-1, att);
}
}
void putsCurveRef(coord_t x, coord_t y, CurveRef &curve, LcdFlags att)
{
if (curve.value != 0) {
switch (curve.type) {
case CURVE_REF_DIFF:
lcdDrawText(x, y, "D", att);
GVAR_MENU_ITEM(lcdNextPos, y, curve.value, -100, 100, LEFT|att, 0, 0);
break;
case CURVE_REF_EXPO:
lcdDrawText(x, y, "E", att);
GVAR_MENU_ITEM(lcdNextPos, y, curve.value, -100, 100, LEFT|att, 0, 0);
break;
case CURVE_REF_FUNC:
lcdDrawTextAtIndex(x, y, STR_VCURVEFUNC, curve.value, att);
break;
case CURVE_REF_CUSTOM:
drawCurveName(x, y, curve.value, att);
break;
}
}
}
void drawCurveName(coord_t x, coord_t y, int8_t idx, LcdFlags flags)
{
if (idx == 0) {
return lcdDrawTextAtIndex(x, y, STR_MMMINV, 0, flags);
}
bool neg = false;
if (idx < 0) {
idx = -idx;
neg = true;
}
if (ZEXIST(g_model.curves[idx-1].name))
lcdDrawSizedText(x, y, g_model.curves[idx-1].name, LEN_CURVE_NAME, ZCHAR|flags);
else
drawStringWithIndex(x, y, STR_CV, idx, flags);
if (neg) {
if ((flags&INVERS) && ((~flags&BLINK) || BLINK_ON_PHASE))
flags &= ~(INVERS|BLINK);
lcdDrawChar(x-3, y, '!', flags);
}
char s[8];
getCurveString(s, idx);
lcdDrawText(x, y, s, flags);
}
void putsTimerMode(coord_t x, coord_t y, int8_t mode, LcdFlags att)
void drawTimerMode(coord_t x, coord_t y, int8_t mode, LcdFlags att)
{
if (mode >= 0) {
if (mode < TMRMODE_COUNT)
@@ -503,10 +309,10 @@ void putsTimerMode(coord_t x, coord_t y, int8_t mode, LcdFlags att)
else
mode -= (TMRMODE_COUNT-1);
}
putsSwitches(x, y, mode, att);
drawSwitch(x, y, mode, att);
}
void putsTrimMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att)
void drawTrimMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att)
{
trim_t v = getRawTrimValue(phase, idx);
unsigned int mode = v.mode;
@@ -583,7 +389,7 @@ void putsChannelValue(coord_t x, coord_t y, source_t channel, int32_t value, Lcd
putsTelemetryChannelValue(x, y, channel, value, att);
}
else if (channel >= MIXSRC_FIRST_TIMER || channel == MIXSRC_TX_TIME) {
putsTimer(x, y, value, att);
drawTimer(x, y, value, att);
}
else if (channel == MIXSRC_TX_VOLTAGE) {
lcdDrawNumber(x, y, value, att|PREC1);