New UI merged
@@ -557,10 +557,10 @@ void lcdDrawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat, LcdFlags
|
||||
y = (y & 0x07);
|
||||
if (y) {
|
||||
ASSERT_IN_DISPLAY(p);
|
||||
uint8_t msk = ~(BITMASK(y)-1);
|
||||
uint8_t msk = ~(bfBitmask<uint8_t>(y));
|
||||
h -= 8-y;
|
||||
if (h < 0)
|
||||
msk -= ~(BITMASK(8+h)-1);
|
||||
msk -= ~(bfBitmask<uint8_t>(8 + h));
|
||||
lcdMaskPoint(p, msk & pat, att);
|
||||
p += LCD_W;
|
||||
}
|
||||
@@ -572,7 +572,7 @@ void lcdDrawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat, LcdFlags
|
||||
}
|
||||
if (h > 0) {
|
||||
ASSERT_IN_DISPLAY(p);
|
||||
lcdMaskPoint(p, (BITMASK(h)-1) & pat, att);
|
||||
lcdMaskPoint(p, (bfBitmask<uint8_t>(h)) & pat, att);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -953,7 +953,7 @@ void lcdDrawPoint(coord_t x, coord_t y, LcdFlags att)
|
||||
{
|
||||
uint8_t * p = &displayBuf[ y / 8 * LCD_W + x ];
|
||||
if (p < DISPLAY_END) {
|
||||
lcdMaskPoint(p, BITMASK(y % 8), att);
|
||||
lcdMaskPoint(p, bfBit<uint8_t>(y % 8), att);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -975,7 +975,7 @@ void lcdDrawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlag
|
||||
if (x+w > LCD_W) { w = LCD_W - x; }
|
||||
|
||||
uint8_t *p = &displayBuf[ y / 8 * LCD_W + x ];
|
||||
uint8_t msk = BITMASK(y%8);
|
||||
uint8_t msk = bfBit<uint8_t>(y % 8);
|
||||
while (w--) {
|
||||
if(pat&1) {
|
||||
lcdMaskPoint(p, msk, att);
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef int coord_t;
|
||||
struct point_t
|
||||
{
|
||||
coord_t x;
|
||||
coord_t y;
|
||||
};
|
||||
typedef uint32_t LcdFlags;
|
||||
typedef uint8_t display_t;
|
||||
|
||||
|
||||
@@ -46,16 +46,19 @@ enum MenuModelSetupItems {
|
||||
ITEM_MODEL_SETUP_NAME,
|
||||
ITEM_MODEL_SETUP_TIMER1,
|
||||
ITEM_MODEL_SETUP_TIMER1_NAME,
|
||||
ITEM_MODEL_SETUP_TIMER1_START,
|
||||
ITEM_MODEL_SETUP_TIMER1_PERSISTENT,
|
||||
ITEM_MODEL_SETUP_TIMER1_MINUTE_BEEP,
|
||||
ITEM_MODEL_SETUP_TIMER1_COUNTDOWN_BEEP,
|
||||
ITEM_MODEL_SETUP_TIMER2,
|
||||
ITEM_MODEL_SETUP_TIMER2_NAME,
|
||||
ITEM_MODEL_SETUP_TIMER2_START,
|
||||
ITEM_MODEL_SETUP_TIMER2_PERSISTENT,
|
||||
ITEM_MODEL_SETUP_TIMER2_MINUTE_BEEP,
|
||||
ITEM_MODEL_SETUP_TIMER2_COUNTDOWN_BEEP,
|
||||
ITEM_MODEL_SETUP_TIMER3,
|
||||
ITEM_MODEL_SETUP_TIMER3_NAME,
|
||||
ITEM_MODEL_SETUP_TIMER3_START,
|
||||
ITEM_MODEL_SETUP_TIMER3_PERSISTENT,
|
||||
ITEM_MODEL_SETUP_TIMER3_MINUTE_BEEP,
|
||||
ITEM_MODEL_SETUP_TIMER3_COUNTDOWN_BEEP,
|
||||
@@ -207,7 +210,7 @@ inline uint8_t EXTERNAL_MODULE_TYPE_ROW()
|
||||
}
|
||||
|
||||
#define POT_WARN_ROWS ((g_model.potsWarnMode) ? (uint8_t)(NUM_POTS+NUM_SLIDERS) : (uint8_t)0)
|
||||
#define TIMER_ROWS 2, 0, 0, 0, 0
|
||||
#define TIMER_ROWS 1, 0, 1, 0, 0, 0
|
||||
|
||||
#if defined(PCBSKY9X)
|
||||
#define EXTRA_MODULE_ROWS LABEL(ExtraModule), 1, 2,
|
||||
@@ -409,41 +412,42 @@ void menuModelSetup(event_t event)
|
||||
unsigned int timerIdx = (k>=ITEM_MODEL_SETUP_TIMER3 ? 2 : (k>=ITEM_MODEL_SETUP_TIMER2 ? 1 : 0));
|
||||
TimerData * timer = &g_model.timers[timerIdx];
|
||||
drawStringWithIndex(0*FW, y, STR_TIMER, timerIdx+1);
|
||||
drawTimerMode(MODEL_SETUP_2ND_COLUMN, y, timer->mode, menuHorizontalPosition==0 ? attr : 0);
|
||||
drawTimer(MODEL_SETUP_2ND_COLUMN+5*FW-2+5*FWNUM+1, y, timer->start, RIGHT | (menuHorizontalPosition==1 ? attr : 0), menuHorizontalPosition==2 ? attr : 0);
|
||||
lcdDrawTextAtIndex(MODEL_SETUP_2ND_COLUMN, y, STR_VTMRMODES, timer->mode, menuHorizontalPosition==0 ? attr : 0);
|
||||
drawSwitch(MODEL_SETUP_2ND_COLUMN+5*FW, y, timer->swtch, menuHorizontalPosition==1 ? attr : 0);
|
||||
if (attr && s_editMode > 0) {
|
||||
switch (menuHorizontalPosition) {
|
||||
case 0:
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, timer->mode, TMRMODE_MAX);
|
||||
break;
|
||||
case 1:
|
||||
CHECK_INCDEC_MODELSWITCH(event, timer->swtch, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, isSwitchAvailableInMixes);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_MODEL_SETUP_TIMER1_START:
|
||||
case ITEM_MODEL_SETUP_TIMER2_START:
|
||||
case ITEM_MODEL_SETUP_TIMER3_START:
|
||||
{
|
||||
lcdDrawText(INDENT_WIDTH, y, STR_START);
|
||||
TimerData *timer = &g_model.timers[k >= ITEM_MODEL_SETUP_TIMER3 ? 2 : (k >= ITEM_MODEL_SETUP_TIMER2 ? 1 : 0)];
|
||||
drawTimer(MODEL_SETUP_2ND_COLUMN, y, timer->start, menuHorizontalPosition == 0 ? attr : 0, menuHorizontalPosition == 1 ? attr : 0);
|
||||
if (attr && s_editMode > 0) {
|
||||
div_t qr = div(timer->start, 60);
|
||||
switch (menuHorizontalPosition) {
|
||||
case 0:
|
||||
{
|
||||
swsrc_t timerMode = timer->mode;
|
||||
if (timerMode < 0)
|
||||
timerMode -= TMRMODE_COUNT-1;
|
||||
CHECK_INCDEC_MODELVAR_CHECK(event, timerMode, -TMRMODE_COUNT-SWSRC_LAST+1, TMRMODE_COUNT+SWSRC_LAST-1, isSwitchAvailableInTimers);
|
||||
if (timerMode < 0)
|
||||
timerMode += TMRMODE_COUNT-1;
|
||||
timer->mode = timerMode;
|
||||
#if defined(AUTOSWITCH)
|
||||
if (s_editMode>0) {
|
||||
int8_t val = timer->mode - (TMRMODE_COUNT-1);
|
||||
int8_t switchVal = checkIncDecMovedSwitch(val);
|
||||
if (val != switchVal) {
|
||||
timer->mode = switchVal + (TMRMODE_COUNT-1);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, qr.quot, 539); // 8:59
|
||||
timer->start = qr.rem + qr.quot*60;
|
||||
timer->start = qr.rem + qr.quot * 60;
|
||||
break;
|
||||
case 2:
|
||||
qr.rem -= checkIncDecModel(event, qr.rem+2, 1, 62)-2;
|
||||
timer->start -= qr.rem ;
|
||||
if ((int16_t)timer->start < 0) timer->start=0;
|
||||
if ((int16_t)timer->start > 5999) timer->start=32399; // 8:59:59
|
||||
case 1:
|
||||
qr.rem -= checkIncDecModel(event, qr.rem + 2, 1, 62) - 2;
|
||||
timer->start -= qr.rem;
|
||||
if ((int16_t) timer->start < 0)
|
||||
timer->start = 0;
|
||||
if ((int16_t) timer->start > 5999)
|
||||
timer->start = 32399; // 8:59:59
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +522,7 @@ void menuRadioSetup(event_t event)
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.pwrOffSpeed, -1, 2);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(PXX2)
|
||||
case ITEM_RADIO_SETUP_OWNER_ID:
|
||||
editSingleName(RADIO_SETUP_2ND_COLUMN, y, STR_OWNER_ID, g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID, event, attr);
|
||||
|
||||
@@ -179,12 +179,10 @@ void drawTimerWithMode(coord_t x, coord_t y, uint8_t index)
|
||||
drawTimer(x, y, timerState.val, att, att);
|
||||
uint8_t xLabel = (negative ? x-56 : x-49);
|
||||
uint8_t len = zlen(timer.name, LEN_TIMER_NAME);
|
||||
if (len > 0) {
|
||||
if (len > 0)
|
||||
lcdDrawSizedText(xLabel, y+FH, timer.name, len, RIGHT | ZCHAR);
|
||||
}
|
||||
else {
|
||||
drawTimerMode(xLabel, y+FH, timer.mode, RIGHT);
|
||||
}
|
||||
else
|
||||
lcdDrawTextAtIndex(xLabel, y+FH, STR_VTMRMODES, timer.mode, RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
#define _LCD_H_
|
||||
|
||||
typedef int coord_t;
|
||||
struct point_t
|
||||
{
|
||||
coord_t x;
|
||||
coord_t y;
|
||||
};
|
||||
typedef uint32_t LcdFlags;
|
||||
typedef uint8_t display_t;
|
||||
|
||||
|
||||
@@ -155,11 +155,12 @@ void onModelSetupBitmapMenu(const char * result)
|
||||
}
|
||||
}
|
||||
|
||||
#warning "TODO Timer mode needs more work"
|
||||
void editTimerMode(int timerIdx, coord_t y, LcdFlags attr, event_t event)
|
||||
{
|
||||
TimerData & timer = g_model.timers[timerIdx];
|
||||
drawStringWithIndex(0*FW, y, STR_TIMER, timerIdx+1);
|
||||
drawTimerMode(MODEL_SETUP_2ND_COLUMN, y, timer.mode, menuHorizontalPosition==0 ? attr : 0);
|
||||
lcdDrawTextAtIndex(MODEL_SETUP_2ND_COLUMN, y, STR_VTMRMODES, timer.mode, menuHorizontalPosition==0 ? attr : 0);
|
||||
drawTimer(MODEL_SETUP_3RD_COLUMN, y, timer.start, menuHorizontalPosition==1 ? attr|TIMEHOUR : TIMEHOUR, menuHorizontalPosition==2 ? attr|TIMEHOUR : TIMEHOUR);
|
||||
if (attr && menuHorizontalPosition < 0) {
|
||||
lcdDrawFilledRect(MODEL_SETUP_2ND_COLUMN-1, y-1, 13*FW-3, FH+1);
|
||||
@@ -170,8 +171,7 @@ void editTimerMode(int timerIdx, coord_t y, LcdFlags attr, event_t event)
|
||||
case 0:
|
||||
{
|
||||
swsrc_t timerMode = timer.mode;
|
||||
if (timerMode < 0) timerMode -= TMRMODE_COUNT-1;
|
||||
CHECK_INCDEC_MODELVAR_CHECK(event, timerMode, -TMRMODE_COUNT-SWSRC_LAST+1, TMRMODE_COUNT+SWSRC_LAST-1, isSwitchAvailableInTimers);
|
||||
// TODO later CHECK_INCDEC_MODELVAR_CHECK(event, timerMode, -TMRMODE_COUNT-SWSRC_LAST+1, TMRMODE_COUNT+SWSRC_LAST-1, isSwitchAvailableInTimers);
|
||||
if (timerMode < 0) timerMode += TMRMODE_COUNT-1;
|
||||
timer.mode = timerMode;
|
||||
#if defined(AUTOSWITCH)
|
||||
|
||||
@@ -314,7 +314,7 @@ void displayTimers()
|
||||
lcdDrawSizedText(TIMERS_X, y-7, timerData.name, LEN_TIMER_NAME, ZCHAR|SMLSIZE);
|
||||
}
|
||||
else {
|
||||
drawTimerMode(TIMERS_X, y-7, timerData.mode, SMLSIZE);
|
||||
lcdDrawTextAtIndex(TIMERS_X, y-7, STR_VTMRMODES, timerData.mode, SMLSIZE);
|
||||
}
|
||||
drawTimer(TIMERS_X, y, timerState.val, TIMEHOUR|MIDSIZE|LEFT, TIMEHOUR|MIDSIZE|LEFT);
|
||||
if (timerData.persistent) {
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
lcd.cpp
|
||||
splash.cpp
|
||||
fonts.cpp
|
||||
popups.cpp
|
||||
widgets.cpp
|
||||
menu_model.cpp
|
||||
model_select.cpp
|
||||
model_setup.cpp
|
||||
model_module_options.cpp
|
||||
model_receiver_options.cpp
|
||||
model_failsafe.cpp
|
||||
model_logical_switches.cpp
|
||||
model_special_functions.cpp
|
||||
model_outputs.cpp
|
||||
model_telemetry.cpp
|
||||
model_telemetry_sensor.cpp
|
||||
menu_radio.cpp
|
||||
radio_setup.cpp
|
||||
radio_trainer.cpp
|
||||
radio_version.cpp
|
||||
radio_hardware.cpp
|
||||
radio_calibration.cpp
|
||||
view_main.cpp
|
||||
view_statistics.cpp
|
||||
)
|
||||
|
||||
if(FLIGHT_MODES)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
model_flightmodes.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(LUA STREQUAL YES)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
model_custom_scripts.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
include(gui/common/colorlcd/CMakeLists.txt)
|
||||
@@ -1,513 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "opentx.h"
|
||||
#include "strhelpers.h"
|
||||
|
||||
#if defined(SIMU)
|
||||
display_t displayBuf[DISPLAY_BUFFER_SIZE];
|
||||
#endif
|
||||
|
||||
uint16_t lcdColorTable[LCD_COLOR_COUNT];
|
||||
|
||||
coord_t lcdNextPos;
|
||||
|
||||
uint8_t getMappedChar(uint8_t c)
|
||||
{
|
||||
uint8_t result;
|
||||
if (c == 0)
|
||||
result = 0;
|
||||
#if defined(TRANSLATIONS_FR)
|
||||
else if (c >= 0x80 && c <= 0x84) {
|
||||
result = 115 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_DE)
|
||||
else if (c >= 0x80 && c <= 0x86) {
|
||||
result = 120 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_CZ)
|
||||
else if (c >= 0x80 && c <= 0x80+29) {
|
||||
result = 127 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_ES)
|
||||
else if (c >= 0x80 && c <= 0x81) {
|
||||
result = 157 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_FI)
|
||||
else if (c >= 0x80 && c <= 0x85) {
|
||||
result = 159 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_IT)
|
||||
else if (c >= 0x80 && c <= 0x81) {
|
||||
result = 165 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_PL)
|
||||
else if (c >= 0x80 && c <= 0x80+17) {
|
||||
result = 167 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_PT)
|
||||
else if (c >= 0x80 && c <= 0x80+21) {
|
||||
result = 185 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_SE)
|
||||
else if (c >= 0x80 && c <= 0x85) {
|
||||
result = 207 + c - 0x80;
|
||||
}
|
||||
#endif
|
||||
else if (c < 0xC0)
|
||||
result = c - 0x20;
|
||||
else
|
||||
result = c - 0xC0 + 96;
|
||||
// TRACE("getMappedChar '%c' (%d) = %d", c, c, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int getFontPatternWidth(const uint16_t * spec, uint8_t index)
|
||||
{
|
||||
return spec[index+1] - spec[index];
|
||||
}
|
||||
|
||||
int getCharWidth(uint8_t c, const uint16_t * spec)
|
||||
{
|
||||
return getFontPatternWidth(spec, getMappedChar(c));
|
||||
}
|
||||
|
||||
void lcdPutFontPattern(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags)
|
||||
{
|
||||
coord_t offset = spec[index];
|
||||
coord_t width = spec[index+1] - offset;
|
||||
if (width > 0) lcdDrawBitmapPattern(x, y, font, flags, offset, width);
|
||||
lcdNextPos = x + width;
|
||||
}
|
||||
|
||||
void lcdDrawChar(coord_t x, coord_t y, char c, LcdFlags flags)
|
||||
{
|
||||
uint32_t fontindex = FONTINDEX(flags);
|
||||
const unsigned char * font = fontsTable[fontindex];
|
||||
const uint16_t * fontspecs = fontspecsTable[fontindex];
|
||||
lcdPutFontPattern(x, y, font, fontspecs, getMappedChar(c), flags);
|
||||
}
|
||||
|
||||
uint8_t getStringInfo(const char *s)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
for (int i=0; s[i]; i++) {
|
||||
result += s[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t getFontHeight(LcdFlags flags)
|
||||
{
|
||||
static const uint8_t heightTable[16] = { 9, 13, 16, 24, 32, 64, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 };
|
||||
return heightTable[FONTINDEX(flags)];
|
||||
}
|
||||
|
||||
int getTextWidth(const char * s, int len, LcdFlags flags)
|
||||
{
|
||||
const uint16_t * specs = fontspecsTable[FONTINDEX(flags)];
|
||||
|
||||
int result = 0;
|
||||
for (int i=0; len==0 || i<len; ++i) {
|
||||
|
||||
#if !defined(BOOT)
|
||||
char c = (flags & ZCHAR) ? zchar2char(*s) : *s;
|
||||
#else
|
||||
char c = *s;
|
||||
#endif
|
||||
if (c == '\0')
|
||||
break;
|
||||
result += getCharWidth(c, specs);
|
||||
++s;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void lcdDrawTextAtIndex(coord_t x, coord_t y, const char * s, uint8_t idx, LcdFlags flags)
|
||||
{
|
||||
uint8_t length;
|
||||
length = *(s++);
|
||||
lcdDrawSizedText(x, y, s+length*idx, length, flags & ~ZCHAR);
|
||||
}
|
||||
|
||||
void lcdDrawHexNumber(coord_t x, coord_t y, uint32_t val, LcdFlags flags)
|
||||
{
|
||||
char s[5];
|
||||
for (int i=0; i<4; i++) {
|
||||
char c = val & 0xf;
|
||||
s[3-i] = c>9 ? c+'A'-10 : c+'0';
|
||||
val >>= 4;
|
||||
}
|
||||
s[4] = '\0';
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t len, const char * prefix, const char * 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;
|
||||
int mode = MODE(flags);
|
||||
bool neg = false;
|
||||
if (val < 0) {
|
||||
val = -val;
|
||||
neg = true;
|
||||
}
|
||||
do {
|
||||
*--s = '0' + (val % 10);
|
||||
++idx;
|
||||
val /= 10;
|
||||
if (mode!=0 && idx==mode) {
|
||||
mode = 0;
|
||||
*--s = '.';
|
||||
if (val==0)
|
||||
*--s = '0';
|
||||
}
|
||||
} while (val!=0 || mode>0 || (mode==MODE(LEADING0) && idx<len));
|
||||
if (neg) *--s = '-';
|
||||
|
||||
// TODO needs check on all string lengths ...
|
||||
if (prefix) {
|
||||
int len = strlen(prefix);
|
||||
if (len <= 16) {
|
||||
s -= len;
|
||||
strncpy(s, prefix, len);
|
||||
}
|
||||
}
|
||||
if (suffix) {
|
||||
strncpy(&str[32], suffix, 16);
|
||||
}
|
||||
flags &= ~LEADING0;
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat, LcdFlags att)
|
||||
{
|
||||
int dx = x2-x1; /* the horizontal distance of the line */
|
||||
int dy = y2-y1; /* the vertical distance of the line */
|
||||
int dxabs = abs(dx);
|
||||
int dyabs = abs(dy);
|
||||
int sdx = sgn(dx);
|
||||
int sdy = sgn(dy);
|
||||
int x = dyabs>>1;
|
||||
int y = dxabs>>1;
|
||||
int px = x1;
|
||||
int py = y1;
|
||||
|
||||
if (dxabs >= dyabs) {
|
||||
/* the line is more horizontal than vertical */
|
||||
for (int i=0; i<=dxabs; i++) {
|
||||
if ((1<<(px%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
y += dyabs;
|
||||
if (y>=dxabs) {
|
||||
y -= dxabs;
|
||||
py += sdy;
|
||||
}
|
||||
px += sdx;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* the line is more vertical than horizontal */
|
||||
for (int i=0; i<=dyabs; i++) {
|
||||
if ((1<<(py%8)) & pat) {
|
||||
lcdDrawPoint(px, py, att);
|
||||
}
|
||||
x += dxabs;
|
||||
if (x >= dyabs) {
|
||||
x -= dyabs;
|
||||
px += sdx;
|
||||
}
|
||||
py += sdy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
void drawRtcTime(coord_t x, coord_t y, LcdFlags flags)
|
||||
{
|
||||
drawTimer(x, y, getValue(MIXSRC_TX_TIME), flags);
|
||||
}
|
||||
|
||||
void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags flags)
|
||||
{
|
||||
char str[LEN_TIMER_STRING];
|
||||
getTimerString(str, tme, (flags & TIMEHOUR) != 0);
|
||||
lcdDrawText(x, y, str, flags);
|
||||
}
|
||||
|
||||
void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
|
||||
{
|
||||
uint8_t length = STR_VSRCRAW[0];
|
||||
lcdDrawSizedText(x, y, STR_VSRCRAW+2+length*(idx+1), length-1, att);
|
||||
}
|
||||
|
||||
void drawSource(coord_t x, coord_t y, mixsrc_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[16];
|
||||
getSourceString(s, idx);
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void putsChnLetter(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
|
||||
{
|
||||
lcdDrawTextAtIndex(x, y, STR_RETA123, idx-1, att);
|
||||
}
|
||||
|
||||
void putsModelName(coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att)
|
||||
{
|
||||
uint8_t len = sizeof(g_model.header.name);
|
||||
while (len>0 && !name[len-1]) --len;
|
||||
if (len==0) {
|
||||
drawStringWithIndex(x, y, STR_MODEL, id+1, att|LEADING0);
|
||||
}
|
||||
else {
|
||||
lcdDrawSizedText(x, y, name, sizeof(g_model.header.name), ZCHAR|att);
|
||||
}
|
||||
}
|
||||
|
||||
void drawSwitch(coord_t x, coord_t y, swsrc_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[8];
|
||||
getSwitchPositionName(s, idx);
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void drawCurveName(coord_t x, coord_t y, int8_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[8];
|
||||
getCurveString(s, idx);
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void drawTimerMode(coord_t x, coord_t y, swsrc_t mode, LcdFlags att)
|
||||
{
|
||||
if (mode >= 0) {
|
||||
if (mode < TMRMODE_COUNT) {
|
||||
lcdDrawTextAtIndex(x, y, STR_VTMRMODES, mode, att);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
mode -= (TMRMODE_COUNT-1);
|
||||
}
|
||||
}
|
||||
drawSwitch(x, y, mode, 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;
|
||||
unsigned int p = mode >> 1;
|
||||
|
||||
if (mode == TRIM_MODE_NONE) {
|
||||
lcdDrawText(x, y, "--", att);
|
||||
}
|
||||
else {
|
||||
char s[2];
|
||||
s[0] = (mode % 2 == 0) ? ':' : '+';
|
||||
s[1] = '0'+p;
|
||||
lcdDrawSizedText(x, y, s, 2, att);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void drawDate(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags att)
|
||||
{
|
||||
// TODO
|
||||
if (att & DBLSIZE) {
|
||||
x -= 42;
|
||||
att &= ~FONTSIZE_MASK;
|
||||
lcdDrawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos-1, y, telemetryItem.datetime.month, att|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos-1, y, telemetryItem.datetime.year-2000, att|LEFT);
|
||||
y += FH;
|
||||
lcdDrawNumber(x, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.month, att|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.year-2000, att|LEFT);
|
||||
lcdDrawNumber(lcdNextPos+11, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
|
||||
}
|
||||
}
|
||||
|
||||
void drawGPSCoord(coord_t x, coord_t y, int32_t value, const char * direction, LcdFlags flags, bool seconds=true)
|
||||
{
|
||||
char s[32];
|
||||
uint32_t absvalue = abs(value);
|
||||
char * tmp = strAppendUnsigned(s, absvalue / 1000000);
|
||||
*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';
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void drawGPSPosition(coord_t x, coord_t y, int32_t longitude, int32_t latitude, LcdFlags flags)
|
||||
{
|
||||
if (flags & EXPANDED) {
|
||||
drawGPSCoord(x, y, latitude, "NS", flags, true);
|
||||
drawGPSCoord(x, y + FH, longitude, "EW", flags, true);
|
||||
}
|
||||
else {
|
||||
drawGPSCoord(x, y, latitude, "NS", flags, false);
|
||||
drawGPSCoord(lcdNextPos+5, y, longitude, "EW", flags, false);
|
||||
}
|
||||
}
|
||||
|
||||
void drawGPSSensorValue(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags)
|
||||
{
|
||||
drawGPSPosition(x, y, telemetryItem.gps.longitude, telemetryItem.gps.latitude, flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
void lcdSetContrast()
|
||||
{
|
||||
lcdSetRefVolt(g_eeGeneral.contrast);
|
||||
}
|
||||
|
||||
void lcdDrawPoint(coord_t x, coord_t y, LcdFlags att)
|
||||
{
|
||||
display_t * p = PIXEL_PTR(x, y);
|
||||
display_t color = lcdColorTable[COLOR_IDX(att)];
|
||||
if (p < DISPLAY_END) {
|
||||
*p = color;
|
||||
}
|
||||
}
|
||||
|
||||
void lcdDrawBlackOverlay()
|
||||
{
|
||||
lcdDrawFilledRect(0, 0, LCD_W, LCD_H, SOLID, OVERLAY_COLOR | OPACITY(8));
|
||||
}
|
||||
|
||||
#if defined(SIMU)
|
||||
BitmapBuffer _lcd(BMP_RGB565, LCD_W, LCD_H, displayBuf);
|
||||
BitmapBuffer * lcd = &_lcd;
|
||||
|
||||
void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
|
||||
{
|
||||
#if defined(PCBX10) && !defined(SIMU)
|
||||
x = destw - (x + w);
|
||||
y = desth - (y + h);
|
||||
#endif
|
||||
|
||||
for (int i=0; i<h; i++) {
|
||||
for (int j=0; j<w; j++) {
|
||||
dest[(y+i)*destw+x+j] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
#if defined(PCBX10) && !defined(SIMU)
|
||||
x = destw - (x + w);
|
||||
y = desth - (y + h);
|
||||
srcx = srcw - (srcx + w);
|
||||
srcy = srch - (srcy + h);
|
||||
#endif
|
||||
|
||||
for (int i=0; i<h; i++) {
|
||||
memcpy(dest+(y+i)*destw+x, src+(srcy+i)*srcw+srcx, 2*w);
|
||||
}
|
||||
}
|
||||
|
||||
void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
#if defined(PCBX10) && !defined(SIMU)
|
||||
x = destw - (x + w);
|
||||
y = desth - (y + h);
|
||||
srcx = srcw - (srcx + w);
|
||||
srcy = srch - (srcy + h);
|
||||
#endif
|
||||
|
||||
for (coord_t line=0; line<h; line++) {
|
||||
uint16_t * p = dest + (y+line)*destw + x;
|
||||
const uint16_t * q = src + (srcy+line)*srcw + srcx;
|
||||
for (coord_t col=0; col<w; col++) {
|
||||
uint8_t alpha = *q >> 12;
|
||||
uint8_t red = ((((*q >> 8) & 0x0f) << 1) * alpha + (*p >> 11) * (0x0f-alpha)) / 0x0f;
|
||||
uint8_t green = ((((*q >> 4) & 0x0f) << 2) * alpha + ((*p >> 5) & 0x3f) * (0x0f-alpha)) / 0x0f;
|
||||
uint8_t blue = ((((*q >> 0) & 0x0f) << 1) * alpha + ((*p >> 0) & 0x1f) * (0x0f-alpha)) / 0x0f;
|
||||
*p = (red << 11) + (green << 5) + (blue << 0);
|
||||
p++; q++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format)
|
||||
{
|
||||
if (format == DMA2D_ARGB4444) {
|
||||
for (int row = 0; row < h; ++row) {
|
||||
for (int col = 0; col < w; ++col) {
|
||||
*dest = ARGB(src[0], src[1], src[2], src[3]);
|
||||
++dest;
|
||||
src += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int row = 0; row < h; ++row) {
|
||||
for(int col = 0; col < w; ++col) {
|
||||
*dest = RGB(src[1], src[2], src[3]);
|
||||
++dest;
|
||||
src += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
const MenuHandlerFunc menuTabModel[] = {
|
||||
menuModelSetup,
|
||||
CASE_HELI(menuModelHeli)
|
||||
CASE_FLIGHT_MODES(menuModelFlightModesAll)
|
||||
menuModelExposAll,
|
||||
menuModelMixAll,
|
||||
menuModelLimits,
|
||||
menuModelCurvesAll,
|
||||
#if defined(GVARS) && defined(FLIGHT_MODES)
|
||||
CASE_GVARS(menuModelGVars)
|
||||
#endif
|
||||
menuModelLogicalSwitches,
|
||||
menuModelSpecialFunctions,
|
||||
#if defined(LUA_MODEL_SCRIPTS)
|
||||
menuModelCustomScripts,
|
||||
#endif
|
||||
menuModelTelemetry
|
||||
};
|
||||
|
||||
void editCurveRef(coord_t x, coord_t y, CurveRef & curve, event_t event, LcdFlags attr);
|
||||
|
||||
uint8_t editDelay(coord_t x, coord_t y, event_t event, uint8_t attr, uint8_t delay)
|
||||
{
|
||||
lcdDrawNumber(x+MIXES_2ND_COLUMN, y, (10/DELAY_STEP)*delay, attr|PREC1|LEFT);
|
||||
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, delay, DELAY_MAX);
|
||||
return delay;
|
||||
}
|
||||
|
||||
uint8_t s_copyMode = 0;
|
||||
int8_t s_copySrcRow;
|
||||
int8_t s_copyTgtOfs;
|
||||
uint8_t s_copySrcIdx;
|
||||
uint8_t s_copySrcCh;
|
||||
|
||||
uint8_t editNameCursorPos = 0;
|
||||
|
||||
void editName(coord_t x, coord_t y, char * name, uint8_t size, event_t event, uint8_t active, LcdFlags flags)
|
||||
{
|
||||
if (active && s_editMode <= 0) {
|
||||
flags |= INVERS;
|
||||
}
|
||||
|
||||
if (!active || s_editMode <= 0) {
|
||||
if (flags & ZCHAR) {
|
||||
uint8_t len = zlen(name, size);
|
||||
if (len == 0) {
|
||||
char tmp[] = "---";
|
||||
lcdDrawSizedText(x, y, tmp, size, flags-ZCHAR);
|
||||
}
|
||||
else {
|
||||
lcdDrawSizedText(x, y, name, len, flags);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawText(x, y, name, flags);
|
||||
}
|
||||
}
|
||||
|
||||
if (active) {
|
||||
if (s_editMode > 0) {
|
||||
int8_t c = name[editNameCursorPos];
|
||||
if (!(flags & ZCHAR)) {
|
||||
c = char2zchar(c);
|
||||
}
|
||||
int8_t v = c;
|
||||
|
||||
if (event==EVT_ROTARY_RIGHT || event==EVT_ROTARY_LEFT) {
|
||||
v = checkIncDec(event, abs(v), 0, ZCHAR_MAX, 0);
|
||||
if (c <= 0) v = -v;
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
case EVT_KEY_BREAK(KEY_LEFT):
|
||||
if (editNameCursorPos>0) editNameCursorPos--;
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_RIGHT):
|
||||
if (editNameCursorPos<size-1) editNameCursorPos++;
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (s_editMode == EDIT_MODIFY_FIELD) {
|
||||
s_editMode = EDIT_MODIFY_STRING;
|
||||
editNameCursorPos = 0;
|
||||
}
|
||||
else if (editNameCursorPos<size-1)
|
||||
editNameCursorPos++;
|
||||
else
|
||||
s_editMode = 0;
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
if (v == 0) {
|
||||
s_editMode = 0;
|
||||
killEvents(event);
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
|
||||
case EVT_KEY_LONG(KEY_LEFT):
|
||||
case EVT_KEY_LONG(KEY_RIGHT):
|
||||
if (v>=-26 && v<=26) {
|
||||
v = -v; // toggle case
|
||||
if (event==EVT_KEY_LONG(KEY_LEFT))
|
||||
killEvents(KEY_LEFT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (c != v) {
|
||||
if (!(flags & ZCHAR)) {
|
||||
if (v != '\0' || name[editNameCursorPos+1] != '\0')
|
||||
v = zchar2char(v);
|
||||
}
|
||||
name[editNameCursorPos] = v;
|
||||
storageDirty(isModelMenuDisplayed() ? EE_MODEL : EE_GENERAL);
|
||||
}
|
||||
|
||||
lcdDrawSizedText(x, y, name, size, flags);
|
||||
coord_t left = (editNameCursorPos == 0 ? 0 : getTextWidth(name, editNameCursorPos, flags));
|
||||
char s[] = { (flags & ZCHAR) ? zchar2char(name[editNameCursorPos]) : name[editNameCursorPos], '\0' };
|
||||
lcdDrawSolidFilledRect(x+left-1, y, getTextWidth(s, 1)+1, INVERT_LINE_HEIGHT, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawText(x+left, y, s, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
else {
|
||||
editNameCursorPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t s_currIdx;
|
||||
|
||||
void copySelection(char * dst, const char * src, uint8_t size)
|
||||
{
|
||||
if (memcmp(src, "---", 3) == 0)
|
||||
memset(dst, 0, size);
|
||||
else
|
||||
memcpy(dst, src, size);
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
MenuHandlerFunc menuHandlers[5];
|
||||
event_t menuEvent = 0;
|
||||
uint8_t menuVerticalPositions[4];
|
||||
uint8_t menuLevel = 0;
|
||||
|
||||
void popMenu()
|
||||
{
|
||||
assert(menuLevel>0);
|
||||
menuLevel = menuLevel-1;
|
||||
menuEvent = EVT_ENTRY_UP;
|
||||
AUDIO_KEY_PRESS();
|
||||
TRACE("popMenu(%d)", menuLevel);
|
||||
}
|
||||
|
||||
void abortPopMenu()
|
||||
{
|
||||
menuLevel = menuLevel + 1;
|
||||
menuEvent = 0;
|
||||
TRACE("popMenu(%d) aborted", menuLevel);
|
||||
}
|
||||
|
||||
|
||||
void chainMenu(MenuHandlerFunc newMenu)
|
||||
{
|
||||
menuHandlers[menuLevel] = newMenu;
|
||||
menuEvent = EVT_ENTRY;
|
||||
AUDIO_KEY_PRESS();
|
||||
TRACE("chainMenu(%d, %p)", menuLevel, newMenu);
|
||||
}
|
||||
|
||||
void pushMenu(MenuHandlerFunc newMenu)
|
||||
{
|
||||
killEvents(KEY_ENTER);
|
||||
|
||||
if (menuLevel == 0) {
|
||||
if (newMenu == menuRadioSetup)
|
||||
menuVerticalPositions[0] = 1;
|
||||
if (newMenu == menuModelSetup)
|
||||
menuVerticalPositions[0] = 0;
|
||||
}
|
||||
else {
|
||||
menuVerticalPositions[menuLevel] = menuVerticalPosition;
|
||||
}
|
||||
|
||||
menuLevel++;
|
||||
|
||||
assert(menuLevel < DIM(menuHandlers));
|
||||
|
||||
menuHandlers[menuLevel] = newMenu;
|
||||
menuEvent = EVT_ENTRY;
|
||||
AUDIO_KEY_PRESS();
|
||||
TRACE("pushMenu(%d, %p)", menuLevel, newMenu);
|
||||
}
|
||||
|
||||
void readModelNotes()
|
||||
{
|
||||
LED_ERROR_BEGIN();
|
||||
|
||||
strcpy(s_text_file, MODELS_PATH "/");
|
||||
char *buf = strcat_currentmodelname(&s_text_file[sizeof(MODELS_PATH)]);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
if (!isFileAvailable(s_text_file)) {
|
||||
char *buf = strAppendFilename(&s_text_file[sizeof(MODELS_PATH)], g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
}
|
||||
|
||||
waitKeysReleased();
|
||||
event_t event = EVT_ENTRY;
|
||||
while (event != EVT_KEY_FIRST(KEY_EXIT)) {
|
||||
lcdRefreshWait();
|
||||
lcdClear();
|
||||
menuTextView(event);
|
||||
event = getEvent();
|
||||
lcdRefresh();
|
||||
wdt_reset();
|
||||
}
|
||||
|
||||
LED_ERROR_END();
|
||||
}
|
||||
|
||||
bool menuModelNotes(event_t event)
|
||||
{
|
||||
if (event == EVT_ENTRY) {
|
||||
strcpy(s_text_file, MODELS_PATH "/");
|
||||
char *buf = strcat_currentmodelname(&s_text_file[sizeof(MODELS_PATH)]);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
if (!isFileAvailable(s_text_file)) {
|
||||
char *buf = strAppendFilename(&s_text_file[sizeof(MODELS_PATH)], g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
}
|
||||
}
|
||||
return menuTextView(event);
|
||||
}
|
||||
|
||||
void pushModelNotes()
|
||||
{
|
||||
pushMenu(menuModelNotes);
|
||||
}
|
||||
@@ -1,615 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MENUS_H_
|
||||
#define _MENUS_H_
|
||||
|
||||
#include "keys.h"
|
||||
#include "audio.h"
|
||||
|
||||
#define MENU_COLUMN2_X 280
|
||||
#define MIXES_2ND_COLUMN 140
|
||||
#define COLUMN_HEADER_X 150
|
||||
|
||||
extern uint8_t menuPageIndex;
|
||||
extern uint8_t menuPageCount;
|
||||
extern uint16_t linesCount;
|
||||
extern uint8_t linesDisplayed;
|
||||
extern int menuVerticalPosition;
|
||||
extern int menuHorizontalPosition;
|
||||
extern int menuVerticalOffset;
|
||||
extern uint8_t menuCalibrationState;
|
||||
|
||||
// Temporary no highlight
|
||||
extern uint8_t noHighlightCounter;
|
||||
#define NO_HIGHLIGHT() (noHighlightCounter > 0)
|
||||
#define START_NO_HIGHLIGHT() do { noHighlightCounter = 25; } while(0)
|
||||
|
||||
typedef bool (*MenuHandlerFunc)(event_t event);
|
||||
|
||||
extern MenuHandlerFunc menuHandlers[5];
|
||||
extern uint8_t menuVerticalPositions[4];
|
||||
extern uint8_t menuLevel;
|
||||
extern event_t menuEvent;
|
||||
|
||||
void chainMenu(MenuHandlerFunc newMenu);
|
||||
void pushMenu(MenuHandlerFunc newMenu);
|
||||
void popMenu();
|
||||
void abortPopMenu();
|
||||
|
||||
inline bool isRadioMenuDisplayed()
|
||||
{
|
||||
return menuVerticalPositions[0] == 1;
|
||||
}
|
||||
|
||||
inline bool isModelMenuDisplayed()
|
||||
{
|
||||
return menuVerticalPositions[0] == 0;
|
||||
}
|
||||
|
||||
enum MenuIcons {
|
||||
ICON_OPENTX,
|
||||
ICON_RADIO,
|
||||
ICON_RADIO_SETUP,
|
||||
ICON_RADIO_SD_MANAGER,
|
||||
ICON_RADIO_TOOLS,
|
||||
ICON_RADIO_GLOBAL_FUNCTIONS,
|
||||
ICON_RADIO_TRAINER,
|
||||
ICON_RADIO_HARDWARE,
|
||||
ICON_RADIO_CALIBRATION,
|
||||
ICON_RADIO_VERSION,
|
||||
ICON_MODEL,
|
||||
ICON_MODEL_SETUP,
|
||||
ICON_MODEL_HELI,
|
||||
ICON_MODEL_FLIGHT_MODES,
|
||||
ICON_MODEL_INPUTS,
|
||||
ICON_MODEL_MIXER,
|
||||
ICON_MODEL_OUTPUTS,
|
||||
ICON_MODEL_CURVES,
|
||||
ICON_MODEL_GVARS,
|
||||
ICON_MODEL_LOGICAL_SWITCHES,
|
||||
ICON_MODEL_SPECIAL_FUNCTIONS,
|
||||
ICON_MODEL_LUA_SCRIPTS,
|
||||
ICON_MODEL_TELEMETRY,
|
||||
ICON_THEME,
|
||||
ICON_THEME_SETUP,
|
||||
ICON_THEME_VIEW1,
|
||||
ICON_THEME_VIEW2,
|
||||
ICON_THEME_VIEW3,
|
||||
ICON_THEME_VIEW4,
|
||||
ICON_THEME_VIEW5,
|
||||
ICON_THEME_ADD_VIEW,
|
||||
ICON_STATS,
|
||||
ICON_STATS_THROTTLE_GRAPH,
|
||||
ICON_STATS_TIMERS,
|
||||
ICON_STATS_ANALOGS,
|
||||
ICON_STATS_DEBUG,
|
||||
ICON_MONITOR,
|
||||
ICON_MONITOR_CHANNELS1,
|
||||
ICON_MONITOR_CHANNELS2,
|
||||
ICON_MONITOR_CHANNELS3,
|
||||
ICON_MONITOR_CHANNELS4,
|
||||
ICON_MONITOR_LOGICAL_SWITCHES,
|
||||
ICON_RADIO_SPECTRUM_ANALYSER,
|
||||
MENUS_ICONS_COUNT
|
||||
};
|
||||
|
||||
enum EnumTabModel {
|
||||
MENU_MODEL_SETUP,
|
||||
CASE_HELI(MENU_MODEL_HELI)
|
||||
CASE_FLIGHT_MODES(MENU_MODEL_FLIGHT_MODES)
|
||||
MENU_MODEL_INPUTS,
|
||||
MENU_MODEL_MIXES,
|
||||
MENU_MODEL_OUTPUTS,
|
||||
MENU_MODEL_CURVES,
|
||||
CASE_GVARS(MENU_MODEL_GVARS)
|
||||
MENU_MODEL_LOGICAL_SWITCHES,
|
||||
MENU_MODEL_SPECIAL_FUNCTIONS,
|
||||
#if defined(LUA_MODEL_SCRIPTS)
|
||||
MENU_MODEL_CUSTOM_SCRIPTS,
|
||||
#endif
|
||||
MENU_MODEL_TELEMETRY,
|
||||
MENU_MODEL_PAGES_COUNT
|
||||
};
|
||||
|
||||
const uint8_t MODEL_ICONS[MENU_MODEL_PAGES_COUNT + 1] = {
|
||||
ICON_MODEL,
|
||||
ICON_MODEL_SETUP,
|
||||
CASE_HELI(ICON_MODEL_HELI)
|
||||
CASE_FLIGHT_MODES(ICON_MODEL_FLIGHT_MODES)
|
||||
ICON_MODEL_INPUTS,
|
||||
ICON_MODEL_MIXER,
|
||||
ICON_MODEL_OUTPUTS,
|
||||
ICON_MODEL_CURVES,
|
||||
CASE_GVARS(ICON_MODEL_GVARS)
|
||||
ICON_MODEL_LOGICAL_SWITCHES,
|
||||
ICON_MODEL_SPECIAL_FUNCTIONS,
|
||||
#if defined(LUA_MODEL_SCRIPTS)
|
||||
ICON_MODEL_LUA_SCRIPTS,
|
||||
#endif
|
||||
ICON_MODEL_TELEMETRY
|
||||
};
|
||||
|
||||
const uint8_t STATS_ICONS[] = {
|
||||
ICON_STATS,
|
||||
ICON_STATS_THROTTLE_GRAPH,
|
||||
ICON_STATS_DEBUG,
|
||||
ICON_STATS_ANALOGS,
|
||||
#if defined(DEBUG_TRACE_BUFFER)
|
||||
ICON_STATS_TIMERS
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8_t MONITOR_ICONS[] = {
|
||||
ICON_MONITOR,
|
||||
ICON_MONITOR_CHANNELS1,
|
||||
ICON_MONITOR_CHANNELS2,
|
||||
ICON_MONITOR_CHANNELS3,
|
||||
ICON_MONITOR_CHANNELS4,
|
||||
ICON_MONITOR_LOGICAL_SWITCHES
|
||||
};
|
||||
|
||||
bool menuModelSetup(event_t event);
|
||||
bool menuModelFailsafe(event_t event);
|
||||
bool menuModelHeli(event_t event);
|
||||
bool menuModelFlightModesAll(event_t event);
|
||||
bool menuModelExposAll(event_t event);
|
||||
bool menuModelMixAll(event_t event);
|
||||
bool menuModelLimits(event_t event);
|
||||
bool menuModelCurvesAll(event_t event);
|
||||
bool menuModelCurveOne(event_t event);
|
||||
bool menuModelGVars(event_t event);
|
||||
bool menuModelLogicalSwitches(event_t event);
|
||||
bool menuModelSpecialFunctions(event_t event);
|
||||
bool menuModelCustomScripts(event_t event);
|
||||
bool menuModelTelemetry(event_t event);
|
||||
bool menuModelSensor(event_t event);
|
||||
bool menuModelExpoOne(event_t event);
|
||||
bool menuModelModuleOptions(event_t event);
|
||||
bool menuModelReceiverOptions(event_t event);
|
||||
|
||||
extern const MenuHandlerFunc menuTabModel[MENU_MODEL_PAGES_COUNT];
|
||||
|
||||
enum EnumTabRadio {
|
||||
MENU_RADIO_SETUP,
|
||||
MENU_RADIO_SD_MANAGER,
|
||||
#if defined(LUA) || defined(PXX2)
|
||||
MENU_RADIO_TOOLS,
|
||||
#endif
|
||||
MENU_RADIO_SPECIAL_FUNCTIONS,
|
||||
MENU_RADIO_TRAINER,
|
||||
MENU_RADIO_HARDWARE,
|
||||
MENU_RADIO_VERSION,
|
||||
MENU_RADIO_PAGES_COUNT
|
||||
};
|
||||
|
||||
const uint8_t RADIO_ICONS[MENU_RADIO_PAGES_COUNT + 1] = {
|
||||
ICON_RADIO,
|
||||
ICON_RADIO_SETUP,
|
||||
ICON_RADIO_SD_MANAGER,
|
||||
#if defined(LUA) || defined(PXX2)
|
||||
ICON_RADIO_TOOLS,
|
||||
#endif
|
||||
ICON_RADIO_GLOBAL_FUNCTIONS,
|
||||
ICON_RADIO_TRAINER,
|
||||
ICON_RADIO_HARDWARE,
|
||||
ICON_RADIO_VERSION
|
||||
};
|
||||
|
||||
bool menuRadioSetup(event_t event);
|
||||
bool menuRadioSdManager(event_t event);
|
||||
bool menuRadioTools(event_t event);
|
||||
bool menuRadioSpecialFunctions(event_t event);
|
||||
bool menuRadioTrainer(event_t event);
|
||||
bool menuRadioVersion(event_t event);
|
||||
bool menuRadioHardware(event_t event);
|
||||
bool menuRadioCalibration(event_t event);
|
||||
bool menuRadioSpectrumAnalyser(event_t event);
|
||||
bool menuRadioPowerMeter(event_t event);
|
||||
|
||||
extern const MenuHandlerFunc menuTabGeneral[MENU_RADIO_PAGES_COUNT];
|
||||
|
||||
enum MenuRadioIndexes
|
||||
{
|
||||
e_StatsGraph,
|
||||
e_StatsDebug,
|
||||
e_StatsAnalogs,
|
||||
#if defined(DEBUG_TRACE_BUFFER)
|
||||
e_StatsTraces,
|
||||
#endif
|
||||
};
|
||||
|
||||
bool menuStatsGraph(event_t event);
|
||||
bool menuStatsDebug(event_t event);
|
||||
bool menuStatsAnalogs(event_t event);
|
||||
bool menuStatsTraces(event_t event);
|
||||
|
||||
static const MenuHandlerFunc menuTabStats[] = {
|
||||
menuStatsGraph,
|
||||
menuStatsDebug,
|
||||
menuStatsAnalogs,
|
||||
#if defined(DEBUG_TRACE_BUFFER)
|
||||
menuStatsTraces,
|
||||
#endif
|
||||
};
|
||||
|
||||
enum EnumTabMonitors
|
||||
{
|
||||
e_MonChannelsFirst,
|
||||
e_MonChannels1 = e_MonChannelsFirst,
|
||||
e_MonChannels2,
|
||||
e_MonChannels3,
|
||||
e_MonChannels4,
|
||||
e_MonLogicalSwitches,
|
||||
e_MonTabChannelsPagesCount
|
||||
};
|
||||
|
||||
extern const MenuHandlerFunc menuTabMonitors[e_MonTabChannelsPagesCount];
|
||||
extern uint8_t lastMonitorPage;
|
||||
extern void drawSingleMixerBar(coord_t, coord_t, coord_t, coord_t, uint8_t);
|
||||
extern void drawSingleOutputBar(coord_t, coord_t, coord_t, coord_t, uint8_t);
|
||||
|
||||
extern const MenuHandlerFunc menuTabScreensSetup[1+MAX_CUSTOM_SCREENS] ;
|
||||
|
||||
bool menuFirstCalib(event_t event);
|
||||
bool menuMainView(event_t event);
|
||||
bool menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomFunctionsContext & functionsContext);
|
||||
bool menuModelSelect(event_t event);
|
||||
bool menuAboutView(event_t event);
|
||||
bool menuMainViewChannelsMonitor(event_t event);
|
||||
bool menuTextView(event_t event);
|
||||
bool menuScreensTheme(event_t event);
|
||||
|
||||
extern int8_t checkIncDec_Ret; // global helper vars
|
||||
|
||||
#define EDIT_SELECT_FIELD 0
|
||||
#define EDIT_MODIFY_FIELD 1
|
||||
#define EDIT_MODIFY_STRING 2
|
||||
extern int8_t s_editMode; // global editmode
|
||||
|
||||
// checkIncDec flags
|
||||
#define EE_GENERAL 0x01
|
||||
#define EE_MODEL 0x02
|
||||
#define NO_INCDEC_MARKS 0x04
|
||||
#define INCDEC_SWITCH 0x08
|
||||
#define INCDEC_SOURCE 0x10
|
||||
#define INCDEC_REP10 0x40
|
||||
#define NO_DBLKEYS 0x80
|
||||
|
||||
// mawrow special values
|
||||
#define ORPHAN_ROW ((uint8_t)-3)
|
||||
#define NAVIGATION_LINE_BY_LINE 0x40
|
||||
#define CURSOR_ON_LINE() (menuHorizontalPosition<0)
|
||||
|
||||
struct CheckIncDecStops {
|
||||
const int count;
|
||||
const int stops[];
|
||||
int min() const
|
||||
{
|
||||
return stops[0];
|
||||
}
|
||||
int max() const
|
||||
{
|
||||
return stops[count-1];
|
||||
}
|
||||
bool contains(int value) const
|
||||
{
|
||||
for (int i=0; i<count; ++i) {
|
||||
int stop = stops[i];
|
||||
if (value == stop)
|
||||
return true;
|
||||
else if (value < stop)
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
extern const CheckIncDecStops &stops100;
|
||||
extern const CheckIncDecStops &stops1000;
|
||||
extern const CheckIncDecStops &stopsSwitch;
|
||||
|
||||
#define INIT_STOPS(var, ...) \
|
||||
const int _ ## var[] = { __VA_ARGS__ }; \
|
||||
const CheckIncDecStops &var = (const CheckIncDecStops&)_ ## var;
|
||||
#define CATEGORY_END(val) \
|
||||
(val), (val+1)
|
||||
|
||||
int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_flags=0, IsValueAvailable isValueAvailable=NULL, const CheckIncDecStops &stops=stops100);
|
||||
|
||||
#define checkIncDecModel(event, i_val, i_min, i_max) checkIncDec(event, i_val, i_min, i_max, EE_MODEL)
|
||||
#define checkIncDecModelZero(event, i_val, i_max) checkIncDec(event, i_val, 0, i_max, EE_MODEL)
|
||||
#define checkIncDecGen(event, i_val, i_min, i_max) checkIncDec(event, i_val, i_min, i_max, EE_GENERAL)
|
||||
|
||||
#define CHECK_INCDEC_MODELVAR(event, var, min, max) \
|
||||
var = checkIncDecModel(event, var, min, max)
|
||||
|
||||
#define CHECK_INCDEC_MODELVAR_ZERO(event, var, max) \
|
||||
var = checkIncDecModelZero(event, var, max)
|
||||
|
||||
#define CHECK_INCDEC_MODELVAR_CHECK(event, var, min, max, check) \
|
||||
var = checkIncDec(event, var, min, max, EE_MODEL, check)
|
||||
|
||||
#define CHECK_INCDEC_MODELVAR_ZERO_CHECK(event, var, max, check) \
|
||||
var = checkIncDec(event, var, 0, max, EE_MODEL, check)
|
||||
|
||||
#define AUTOSWITCH_ENTER_LONG() (attr && event==EVT_KEY_LONG(KEY_ENTER))
|
||||
#define CHECK_INCDEC_SWITCH(event, var, min, max, flags, available) \
|
||||
var = checkIncDec(event, var, min, max, (flags)|INCDEC_SWITCH, available)
|
||||
#define CHECK_INCDEC_MODELSWITCH(event, var, min, max, available) \
|
||||
CHECK_INCDEC_SWITCH(event, var, min, max, EE_MODEL, available)
|
||||
|
||||
#define CHECK_INCDEC_MODELSOURCE(event, var, min, max) \
|
||||
var = checkIncDec(event, var, min, max, EE_MODEL|INCDEC_SOURCE|NO_INCDEC_MARKS, isSourceAvailable)
|
||||
|
||||
#define CHECK_INCDEC_GENVAR(event, var, min, max) \
|
||||
var = checkIncDecGen(event, var, min, max)
|
||||
|
||||
#define INCDEC_DECLARE_VARS(f) uint8_t incdecFlag = (f); IsValueAvailable isValueAvailable = NULL
|
||||
#define INCDEC_SET_FLAG(f) incdecFlag = (f)
|
||||
#define INCDEC_ENABLE_CHECK(fn) isValueAvailable = fn
|
||||
#define CHECK_INCDEC_PARAM(event, var, min, max) \
|
||||
checkIncDec(event, var, min, max, incdecFlag, isValueAvailable)
|
||||
|
||||
int8_t navigate(event_t event, int count, int rows, int columns=1, bool loop=true);
|
||||
bool check(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t menuTabSize, const uint8_t * horTab, uint8_t horTabMax, int maxrow, uint8_t flags=0);
|
||||
bool check_simple(event_t event, uint8_t curr, const MenuHandlerFunc * menuTab, uint8_t menuTabSize, int maxrow);
|
||||
bool check_submenu_simple(event_t event, uint8_t maxrow);
|
||||
|
||||
#define MENU_TAB(...) const uint8_t mstate_tab[] = __VA_ARGS__
|
||||
|
||||
#define MENU_WITH_OPTIONS(title, icons, tab, tabCount, menu, lines_count, ...) \
|
||||
MENU_TAB(__VA_ARGS__); \
|
||||
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) TRACE("Menu %s displayed ...", title); \
|
||||
if (!check(event, menu, tab, tabCount, mstate_tab, DIM(mstate_tab)-1, lines_count)) return false; \
|
||||
drawMenuTemplate(title, 0, icons, OPTION_MENU_TITLE_BAR);
|
||||
|
||||
#define CUSTOM_MENU_WITH_OPTIONS(title, icons, tab, tabCount, menu, lines_count) \
|
||||
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) TRACE("Menu %s displayed ...", title); \
|
||||
if (!check(event, menu, tab, tabCount, mstate_tab, DIM(mstate_tab)-1, lines_count)) return false; \
|
||||
drawMenuTemplate(title, 0, icons, OPTION_MENU_TITLE_BAR);
|
||||
|
||||
#define MENU(title, icons, tab, menu, lines_count, ...) \
|
||||
MENU_WITH_OPTIONS(title, icons, tab, DIM(tab), menu, lines_count, __VA_ARGS__)
|
||||
|
||||
#define SIMPLE_MENU_WITH_OPTIONS(title, icons, tab, tabCount, menu, lines_count) \
|
||||
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) TRACE("Menu %s displayed ...", title); \
|
||||
if (!check_simple(event, menu, tab, tabCount, lines_count)) return false; \
|
||||
drawMenuTemplate(title, 0, icons, OPTION_MENU_TITLE_BAR);
|
||||
|
||||
#define SIMPLE_MENU(title, icons, tab, menu, lines_count) \
|
||||
SIMPLE_MENU_WITH_OPTIONS(title, icons, tab, DIM(tab), menu, lines_count)
|
||||
|
||||
#define SUBMENU(title, icon, lines_count, ...) \
|
||||
MENU_TAB(__VA_ARGS__); \
|
||||
if (!check(event, 0, NULL, 0, mstate_tab, DIM(mstate_tab)-1, lines_count)) return false; \
|
||||
drawMenuTemplate(title, icon);
|
||||
|
||||
#define SUBMENU_WITH_OPTIONS(title, icon, lines_count, options, ...) \
|
||||
MENU_TAB(__VA_ARGS__); \
|
||||
if (!check(event, 0, NULL, 0, mstate_tab, DIM(mstate_tab)-1, lines_count)) return false; \
|
||||
drawMenuTemplate(title, icon, NULL, options);
|
||||
|
||||
#define CUSTOM_SUBMENU_WITH_OPTIONS(title, icon, lines_count, options) \
|
||||
if (!check(event, 0, NULL, 0, mstate_tab, DIM(mstate_tab)-1, lines_count)) return false; \
|
||||
drawMenuTemplate(title, icon, NULL, options);
|
||||
|
||||
#define SIMPLE_SUBMENU(title, icon, lines_count) \
|
||||
if (!check_submenu_simple(event, lines_count)) return false; \
|
||||
drawMenuTemplate(title, icon, NULL)
|
||||
|
||||
#define SIMPLE_SUBMENU_WITH_OPTIONS(title, icon, lines_count, options) \
|
||||
if (!check_submenu_simple(event, lines_count)) return false; \
|
||||
drawMenuTemplate(title, icon, NULL, options)
|
||||
|
||||
#if defined(GVARS)
|
||||
#define GVAR_MENU_ITEM(x, y, v, min, max, lcdattr, editflags, event) editGVarFieldValue(x, y, v, min, max, lcdattr, editflags, event)
|
||||
#else
|
||||
#define GVAR_MENU_ITEM(x, y, v, min, max, lcdattr, editflags, event) editGVarFieldValue(x, y, v, min, max, lcdattr, event)
|
||||
#endif
|
||||
|
||||
#if defined(GVARS)
|
||||
int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int16_t max, LcdFlags attr, uint8_t editflags, event_t event);
|
||||
#define displayGVar(x, y, v, min, max) GVAR_MENU_ITEM(x, y, v, min, max, 0, 0, 0)
|
||||
#else
|
||||
int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int16_t max, LcdFlags attr, event_t event);
|
||||
#define displayGVar(x, y, v, min, max) lcdDrawNumber(x, y, v)
|
||||
#endif
|
||||
|
||||
extern uint8_t editNameCursorPos;
|
||||
void editName(coord_t x, coord_t y, char *name, uint8_t size, event_t event, uint8_t active, LcdFlags flags=ZCHAR);
|
||||
|
||||
uint8_t editDelay(coord_t x, coord_t y, event_t event, uint8_t attr, uint8_t delay);
|
||||
void editCurveRef(coord_t x, coord_t y, CurveRef & curve, event_t event, LcdFlags flags);
|
||||
|
||||
extern uint8_t s_curveChan;
|
||||
|
||||
enum
|
||||
{
|
||||
WARNING_TYPE_WAIT,
|
||||
WARNING_TYPE_INFO,
|
||||
WARNING_TYPE_ASTERISK,
|
||||
WARNING_TYPE_CONFIRM,
|
||||
WARNING_TYPE_INPUT,
|
||||
WARNING_TYPE_ALERT
|
||||
};
|
||||
|
||||
extern const char * warningText;
|
||||
extern const char * warningInfoText;
|
||||
extern uint8_t warningInfoLength;
|
||||
extern uint8_t warningResult;
|
||||
extern uint8_t warningType;
|
||||
|
||||
#define COPY_MODE 1
|
||||
#define MOVE_MODE 2
|
||||
extern uint8_t s_copyMode;
|
||||
extern int8_t s_copySrcRow;
|
||||
extern int8_t s_copyTgtOfs;
|
||||
extern uint8_t s_currIdx;
|
||||
extern int8_t s_currCh;
|
||||
extern uint8_t s_copySrcIdx;
|
||||
extern uint8_t s_copySrcCh;
|
||||
|
||||
uint8_t getExposCount();
|
||||
void deleteExpo(uint8_t idx);
|
||||
void insertExpo(uint8_t idx);
|
||||
|
||||
uint8_t getMixesCount();
|
||||
void deleteMix(uint8_t idx);
|
||||
void insertMix(uint8_t idx);
|
||||
|
||||
#define MENU_X 80
|
||||
#define MENU_W LCD_W-(2*MENU_X)
|
||||
#define POPUP_X 120
|
||||
#define POPUP_Y 70
|
||||
#define POPUP_W 300
|
||||
#define POPUP_H 130
|
||||
#define WARNING_LINE_LEN 32
|
||||
#define WARNING_LINE_X (POPUP_X+66)
|
||||
#define WARNING_LINE_Y (POPUP_Y+9)
|
||||
#define WARNING_INFOLINE_Y (WARNING_LINE_Y+68)
|
||||
|
||||
void copySelection(char * dst, const char * src, uint8_t size);
|
||||
void drawPopupBackgroundAndBorder(coord_t x, coord_t y, coord_t w, coord_t h);
|
||||
void showMessageBox(const char * title);
|
||||
void runPopupWarning(event_t event);
|
||||
|
||||
typedef void (* PopupFunc)(event_t event);
|
||||
extern PopupFunc popupFunc;
|
||||
|
||||
extern uint8_t warningInfoFlags;
|
||||
|
||||
inline void DISPLAY_WARNING(event_t event)
|
||||
{
|
||||
(*popupFunc)(event);
|
||||
}
|
||||
|
||||
#define POPUP_MENU_MAX_LINES 12
|
||||
#define MENU_MAX_DISPLAY_LINES 9
|
||||
#define MENU_LINE_LENGTH (LEN_MODEL_NAME+12)
|
||||
|
||||
extern const char * popupMenuItems[POPUP_MENU_MAX_LINES];
|
||||
extern uint16_t popupMenuItemsCount;
|
||||
extern uint16_t popupMenuOffset;
|
||||
enum {
|
||||
MENU_OFFSET_INTERNAL,
|
||||
MENU_OFFSET_EXTERNAL
|
||||
};
|
||||
extern uint8_t popupMenuOffsetType;
|
||||
extern uint8_t popupMenuSelectedItem;
|
||||
const char * runPopupMenu(event_t event);
|
||||
|
||||
typedef void (* PopupMenuHandler)(const char * result);
|
||||
extern PopupMenuHandler popupMenuHandler;
|
||||
|
||||
inline void POPUP_INPUT(const char * s, PopupFunc func)
|
||||
{
|
||||
warningText = s;
|
||||
warningInfoText = nullptr;
|
||||
warningType = WARNING_TYPE_INPUT;
|
||||
popupFunc = func;
|
||||
}
|
||||
|
||||
inline void SET_WARNING_INFO(const char * info, uint8_t length, uint8_t flags)
|
||||
{
|
||||
warningInfoText = info;
|
||||
warningInfoLength = length;
|
||||
warningInfoFlags = flags;
|
||||
}
|
||||
|
||||
inline void POPUP_MENU_ADD_ITEM(const char * s)
|
||||
{
|
||||
popupMenuOffsetType = MENU_OFFSET_INTERNAL;
|
||||
if (popupMenuItemsCount < POPUP_MENU_MAX_LINES)
|
||||
popupMenuItems[popupMenuItemsCount++] = s;
|
||||
}
|
||||
|
||||
inline void POPUP_MENU_SELECT_ITEM(uint8_t index)
|
||||
{
|
||||
popupMenuSelectedItem = (index > 0 ? (index < popupMenuItemsCount ? index : popupMenuItemsCount - 1) : 0);
|
||||
}
|
||||
|
||||
inline void POPUP_MENU_START(PopupMenuHandler handler)
|
||||
{
|
||||
popupMenuHandler = handler;
|
||||
AUDIO_KEY_PRESS();
|
||||
}
|
||||
|
||||
inline void CLEAR_POPUP()
|
||||
{
|
||||
warningText = nullptr;
|
||||
}
|
||||
|
||||
inline void POPUP_WAIT(const char * s)
|
||||
{
|
||||
warningText = s;
|
||||
warningInfoText = nullptr;
|
||||
warningType = WARNING_TYPE_WAIT;
|
||||
popupFunc = runPopupWarning;
|
||||
}
|
||||
|
||||
inline void POPUP_INFORMATION(const char * s)
|
||||
{
|
||||
warningText = s;
|
||||
warningInfoText = nullptr;
|
||||
warningType = WARNING_TYPE_INFO;
|
||||
popupFunc = runPopupWarning;
|
||||
}
|
||||
|
||||
inline void POPUP_WARNING(const char * s)
|
||||
{
|
||||
warningText = s;
|
||||
warningInfoText = nullptr;
|
||||
warningType = WARNING_TYPE_ASTERISK;
|
||||
popupFunc = runPopupWarning;
|
||||
}
|
||||
|
||||
inline void POPUP_CONFIRMATION(const char *s, void (* confirmHandler)(const char *) = nullptr)
|
||||
{
|
||||
warningText = s;
|
||||
warningType = WARNING_TYPE_CONFIRM;
|
||||
warningInfoText = nullptr;
|
||||
popupFunc = runPopupWarning;
|
||||
popupMenuHandler = confirmHandler;
|
||||
}
|
||||
|
||||
#define TEXT_FILENAME_MAXLEN 40
|
||||
extern char s_text_file[TEXT_FILENAME_MAXLEN];
|
||||
void pushMenuTextView(const char * filename);
|
||||
void pushModelNotes();
|
||||
void readModelNotes();
|
||||
|
||||
#define LABEL(...) (uint8_t)-1
|
||||
|
||||
#define CURSOR_MOVED_LEFT(event) (event==EVT_ROTARY_LEFT || EVT_KEY_MASK(event) == KEY_LEFT)
|
||||
#define CURSOR_MOVED_RIGHT(event) (event==EVT_ROTARY_RIGHT || EVT_KEY_MASK(event) == KEY_RIGHT)
|
||||
#define REPEAT_LAST_CURSOR_MOVE(last, refresh) { if (CURSOR_MOVED_RIGHT(event)) menuHorizontalPosition = (menuHorizontalPosition >= (last) ? 0 : menuHorizontalPosition + 1); else menuHorizontalPosition = (menuHorizontalPosition <= (0) ? last : menuHorizontalPosition - 1); if (refresh) putEvent(EVT_REFRESH); }
|
||||
|
||||
#define MENU_FIRST_LINE_EDIT (MAXCOL((uint16_t)0) >= HIDDEN_ROW ? (MAXCOL((uint16_t)1) >= HIDDEN_ROW ? 2 : 1) : 0)
|
||||
#define POS_HORZ_INIT(posVert) ((COLATTR(posVert) & NAVIGATION_LINE_BY_LINE) ? -1 : 0)
|
||||
#define EDIT_MODE_INIT 0 // TODO enum
|
||||
|
||||
typedef int (*FnFuncP) (int x);
|
||||
void drawFunction(FnFuncP fn, int x, int y, int width);
|
||||
|
||||
void onSourceLongEnterPress(const char *result);
|
||||
|
||||
uint8_t switchToMix(uint8_t source);
|
||||
|
||||
#endif // _MENUS_H_
|
||||
@@ -1,344 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
void drawCurve(int x, int y, int width)
|
||||
{
|
||||
drawFunction(applyCurrentCurve, x, y, width);
|
||||
}
|
||||
|
||||
void runPopupCurvePreset(event_t event)
|
||||
{
|
||||
warningResult = false;
|
||||
|
||||
theme->drawMessageBox(warningText, warningInfoText, STR_POPUPS_ENTER_EXIT, warningType);
|
||||
|
||||
switch (event) {
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
warningResult = true;
|
||||
// no break
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
warningText = NULL;
|
||||
warningType = WARNING_TYPE_ASTERISK;
|
||||
break;
|
||||
|
||||
default:
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
reusableBuffer.curveEdit.preset = checkIncDec(event, reusableBuffer.curveEdit.preset, -4, +4);
|
||||
s_editMode = EDIT_SELECT_FIELD;
|
||||
break;
|
||||
}
|
||||
|
||||
lcdDrawNumber(WARNING_LINE_X, WARNING_INFOLINE_Y-10, 45 * reusableBuffer.curveEdit.preset / 4, LEFT|INVERS, 0, NULL, "@");
|
||||
|
||||
if (warningResult) {
|
||||
warningResult = 0;
|
||||
CurveInfo & crv = g_model.curves[s_curveChan];
|
||||
int8_t * points = curveAddress(s_curveChan);
|
||||
int k = 25 * reusableBuffer.curveEdit.preset;
|
||||
int dx = 2000 / (5+crv.points-1);
|
||||
for (uint8_t i=0; i<5+crv.points; i++) {
|
||||
int x = -1000 + i * dx;
|
||||
points[i] = div_and_round(div_and_round(k * x, 100), 10);
|
||||
}
|
||||
if (crv.type == CURVE_TYPE_CUSTOM) {
|
||||
resetCustomCurveX(points, 5+crv.points);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onCurveOneMenu(const char * result)
|
||||
{
|
||||
if (result == STR_CURVE_PRESET) {
|
||||
reusableBuffer.curveEdit.preset = 4; // 45°
|
||||
POPUP_INPUT(STR_PRESET, runPopupCurvePreset);
|
||||
}
|
||||
else if (result == STR_MIRROR) {
|
||||
CurveInfo & crv = g_model.curves[s_curveChan];
|
||||
int8_t * points = curveAddress(s_curveChan);
|
||||
for (int i=0; i<5+crv.points; i++)
|
||||
points[i] = -points[i];
|
||||
}
|
||||
else if (result == STR_CLEAR) {
|
||||
CurveInfo & crv = g_model.curves[s_curveChan];
|
||||
int8_t * points = curveAddress(s_curveChan);
|
||||
for (int i=0; i<5+crv.points; i++)
|
||||
points[i] = 0;
|
||||
if (crv.type == CURVE_TYPE_CUSTOM) {
|
||||
resetCustomCurveX(points, 5+crv.points);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MODEL_CURVE_ONE_2ND_COLUMN 130
|
||||
|
||||
enum MenuModelCurveOneItems {
|
||||
ITEM_CURVE_NAME,
|
||||
ITEM_CURVE_TYPE,
|
||||
ITEM_CURVE_POINTS,
|
||||
ITEM_CURVE_SMOOTH,
|
||||
ITEM_CURVE_COORDS1,
|
||||
ITEM_CURVE_COORDS2,
|
||||
};
|
||||
|
||||
#define IS_COORDS1_LINE_NEEDED() (crv.type==CURVE_TYPE_CUSTOM && crv.points > -3)
|
||||
|
||||
bool menuModelCurveOne(event_t event)
|
||||
{
|
||||
static uint8_t pointsOfs = 0;
|
||||
CurveData & crv = g_model.curves[s_curveChan];
|
||||
int8_t * points = curveAddress(s_curveChan);
|
||||
|
||||
SUBMENU_WITH_OPTIONS(STR_MENUCURVE, ICON_MODEL_CURVES, IS_COORDS1_LINE_NEEDED() ? 6 : 5, OPTION_MENU_NO_FOOTER, { 0, 0, 0, 0, uint8_t(5+crv.points-1), uint8_t(5+crv.points-1) });
|
||||
drawStringWithIndex(50, 3+FH, STR_CV, s_curveChan+1, MENU_TITLE_COLOR);
|
||||
lcdDrawSolidFilledRect(0, MENU_FOOTER_TOP, 250, MENU_FOOTER_HEIGHT, HEADER_BGCOLOR);
|
||||
|
||||
if (IS_COORDS1_LINE_NEEDED() && menuVerticalPosition == ITEM_CURVE_COORDS1) {
|
||||
if (menuHorizontalPosition == 0) {
|
||||
if (CURSOR_MOVED_RIGHT(event))
|
||||
menuHorizontalPosition = 1;
|
||||
else
|
||||
menuVerticalPosition -= 1;
|
||||
}
|
||||
else if (menuHorizontalPosition == 4+crv.points) {
|
||||
if (CURSOR_MOVED_RIGHT(event))
|
||||
(menuHorizontalPosition = 0, menuVerticalPosition += 1);
|
||||
else
|
||||
menuHorizontalPosition -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Curve name
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP-FH, STR_NAME);
|
||||
editName(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP-FH, crv.name, sizeof(crv.name), event, menuVerticalPosition==ITEM_CURVE_NAME);
|
||||
|
||||
// Curve type
|
||||
LcdFlags attr = (menuVerticalPosition==ITEM_CURVE_TYPE ? (s_editMode>0 ? INVERS|BLINK : INVERS) : 0);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP, "Type");
|
||||
lcdDrawTextAtIndex(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP, STR_CURVE_TYPES, crv.type, attr);
|
||||
if (attr) {
|
||||
uint8_t newType = checkIncDecModelZero(event, crv.type, CURVE_TYPE_LAST);
|
||||
if (newType != crv.type) {
|
||||
for (int i = 1; i < 4 + crv.points; i++) {
|
||||
points[i] = calcRESXto100(applyCustomCurve(calc100toRESX(-100 + i * 200 / (4 + crv.points)), s_curveChan));
|
||||
}
|
||||
if (moveCurve(s_curveChan, checkIncDec_Ret > 0 ? 3 + crv.points : -3 - crv.points)) {
|
||||
if (newType == CURVE_TYPE_CUSTOM) {
|
||||
resetCustomCurveX(points, 5 + crv.points);
|
||||
}
|
||||
crv.type = newType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Curve points count
|
||||
attr = (menuVerticalPosition==ITEM_CURVE_POINTS ? (s_editMode>0 ? INVERS|BLINK : INVERS) : 0);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + FH, STR_COUNT);
|
||||
lcdDrawNumber(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP + FH, 5+crv.points, LEFT|attr, 0, NULL, STR_PTS);
|
||||
if (attr) {
|
||||
int count = checkIncDecModel(event, crv.points, -3, 12); // 2pts - 17pts
|
||||
if (checkIncDec_Ret) {
|
||||
int newPoints[MAX_POINTS_PER_CURVE];
|
||||
newPoints[0] = points[0];
|
||||
newPoints[4+count] = points[4+crv.points];
|
||||
for (int i=1; i<4+count; i++)
|
||||
newPoints[i] = calcRESXto100(applyCustomCurve(-RESX + (i * 2 * RESX) / (4 + count), s_curveChan));
|
||||
if (moveCurve(s_curveChan, checkIncDec_Ret*(crv.type==CURVE_TYPE_CUSTOM ? 2 :1))) {
|
||||
for (int i = 0; i < 5 + count; i++) {
|
||||
points[i] = newPoints[i];
|
||||
if (crv.type == CURVE_TYPE_CUSTOM && i != 0 && i != 4 + count)
|
||||
points[5 + count + i - 1] = -100 + (i * 200) / (4 + count);
|
||||
}
|
||||
crv.points = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Curve smooth
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 2*FH, STR_SMOOTH);
|
||||
drawCheckBox(MODEL_CURVE_ONE_2ND_COLUMN, MENU_CONTENT_TOP + 2*FH, crv.smooth, menuVerticalPosition==ITEM_CURVE_SMOOTH ? INVERS : 0);
|
||||
if (menuVerticalPosition==ITEM_CURVE_SMOOTH) crv.smooth = checkIncDecModel(event, crv.smooth, 0, 1);
|
||||
|
||||
switch(event) {
|
||||
case EVT_ENTRY:
|
||||
pointsOfs = 0;
|
||||
break;
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
if (menuVerticalPosition > ITEM_CURVE_NAME) {
|
||||
killEvents(event);
|
||||
POPUP_MENU_ADD_ITEM(STR_CURVE_PRESET);
|
||||
POPUP_MENU_ADD_ITEM(STR_MIRROR);
|
||||
POPUP_MENU_ADD_ITEM(STR_CLEAR);
|
||||
POPUP_MENU_START(onCurveOneMenu);
|
||||
}
|
||||
break;
|
||||
// TODO?
|
||||
// case EVT_KEY_LONG(KEY_MENU):
|
||||
// pushMenu(menuChannelsView);
|
||||
// killEvents(event);
|
||||
}
|
||||
|
||||
drawCurve(CURVE_CENTER_X, CURVE_CENTER_Y, CURVE_SIDE_WIDTH);
|
||||
drawCurveHorizontalScale();
|
||||
if (menuVerticalPosition < ITEM_CURVE_COORDS1) drawCurveVerticalScale(CURVE_CENTER_X-CURVE_SIDE_WIDTH-15);
|
||||
|
||||
coord_t posX = 47;
|
||||
attr = (s_editMode > 0 ? INVERS|BLINK : INVERS);
|
||||
for (int i=0; i<5+crv.points; i++) {
|
||||
point_t point = getPoint(i);
|
||||
uint8_t selectionMode = 0;
|
||||
if (menuHorizontalPosition == i) {
|
||||
if (menuVerticalPosition == ITEM_CURVE_COORDS1)
|
||||
selectionMode = (IS_COORDS1_LINE_NEEDED() ? 1 : 2);
|
||||
else if (menuVerticalPosition == ITEM_CURVE_COORDS2)
|
||||
selectionMode = 2;
|
||||
}
|
||||
|
||||
int8_t x = -100 + 200*i/(5+crv.points-1);
|
||||
if (crv.type==CURVE_TYPE_CUSTOM && i>0 && i<5+crv.points-1) {
|
||||
x = points[5+crv.points+i-1];
|
||||
}
|
||||
|
||||
if (i>=pointsOfs && i<pointsOfs+5) {
|
||||
lcdDrawNumber(posX, MENU_CONTENT_TOP + 5*FH-12, i+1, TEXT_DISABLE_COLOR|RIGHT);
|
||||
lcdDrawNumber(posX, MENU_CONTENT_TOP + 6*FH-10, x, RIGHT|(selectionMode==1 ? attr : 0));
|
||||
lcdDrawNumber(posX, MENU_CONTENT_TOP + 7*FH-6, points[i], RIGHT|(selectionMode==2 ? attr : 0));
|
||||
posX += 45;
|
||||
}
|
||||
|
||||
if (selectionMode > 0) {
|
||||
lcdDrawSolidFilledRect(point.x, CURVE_CENTER_Y-CURVE_SIDE_WIDTH, 2, 2*CURVE_SIDE_WIDTH+2, CURVE_CURSOR_COLOR);
|
||||
|
||||
char text[5];
|
||||
strAppendSigned(text, points[i]);
|
||||
|
||||
if (point.x >= CURVE_CENTER_X) {
|
||||
drawCurveVerticalScale(point.x-15);
|
||||
if (points[i-1] > points[i]) {
|
||||
drawCurveCoord(point.x+1-CURVE_COORD_WIDTH, point.y, text, selectionMode==2);
|
||||
}
|
||||
else {
|
||||
drawCurveCoord(point.x+1-CURVE_COORD_WIDTH, point.y-CURVE_COORD_HEIGHT-1, text, selectionMode==2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawCurveVerticalScale(point.x+7);
|
||||
if (points[i+1] > points[i]) {
|
||||
drawCurveCoord(point.x+1, point.y, text, selectionMode==2);
|
||||
}
|
||||
else {
|
||||
drawCurveCoord(point.x+1, point.y-CURVE_COORD_HEIGHT-1, text, selectionMode==2);
|
||||
}
|
||||
}
|
||||
|
||||
drawCurvePoint(point.x-3, point.y-4, CURVE_CURSOR_COLOR);
|
||||
|
||||
strAppendSigned(text, x);
|
||||
drawCurveCoord(limit(CURVE_CENTER_X-CURVE_SIDE_WIDTH-1, point.x-CURVE_COORD_WIDTH/2, CURVE_CENTER_X+CURVE_SIDE_WIDTH-CURVE_COORD_WIDTH+1), CURVE_CENTER_Y+CURVE_SIDE_WIDTH+2, text, selectionMode==1);
|
||||
|
||||
if (s_editMode > 0) {
|
||||
if (selectionMode == 1)
|
||||
CHECK_INCDEC_MODELVAR(event, points[5+crv.points+i-1], i==1 ? -100 : points[5+crv.points+i-2], i==5+crv.points-2 ? 100 : points[5+crv.points+i]); // edit X
|
||||
else if (selectionMode == 2)
|
||||
CHECK_INCDEC_MODELVAR(event, points[i], -100, 100);
|
||||
}
|
||||
if (i < pointsOfs)
|
||||
pointsOfs = i;
|
||||
else if (i > pointsOfs+5-1)
|
||||
pointsOfs = i-5+1;
|
||||
}
|
||||
else {
|
||||
drawCurvePoint(point.x-3, point.y-4, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
lcdDrawHorizontalLine(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 6*FH - 13, SUBMENU_LINE_WIDTH, DOTTED, CURVE_AXIS_COLOR);
|
||||
lcdDrawHorizontalLine(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 7*FH - 10, SUBMENU_LINE_WIDTH, DOTTED, CURVE_AXIS_COLOR);
|
||||
drawHorizontalScrollbar(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 9*FH - 15, SUBMENU_LINE_WIDTH, pointsOfs, 5+crv.points, 5);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void editCurveRef(coord_t x, coord_t y, CurveRef & curve, event_t event, LcdFlags attr)
|
||||
{
|
||||
lcdDrawTextAtIndex(x, y, "\004DiffExpoFuncCstm", curve.type, (menuHorizontalPosition==0 ? attr : 0));
|
||||
if (attr && menuHorizontalPosition==0) {
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, curve.type, CURVE_REF_CUSTOM);
|
||||
if (checkIncDec_Ret) curve.value = 0;
|
||||
}
|
||||
switch (curve.type) {
|
||||
case CURVE_REF_DIFF:
|
||||
case CURVE_REF_EXPO:
|
||||
curve.value = GVAR_MENU_ITEM(lcdNextPos+10, y, curve.value, -100, 100, menuHorizontalPosition==1 ? LEFT|attr : LEFT, 0, event);
|
||||
break;
|
||||
case CURVE_REF_FUNC:
|
||||
lcdDrawTextAtIndex(lcdNextPos+10, y, STR_VCURVEFUNC, curve.value, (menuHorizontalPosition==1 ? attr : 0));
|
||||
if (attr && menuHorizontalPosition==1) CHECK_INCDEC_MODELVAR_ZERO(event, curve.value, CURVE_BASE-1);
|
||||
break;
|
||||
case CURVE_REF_CUSTOM:
|
||||
drawCurveName(lcdNextPos+10, y, curve.value, (menuHorizontalPosition==1 ? attr : 0));
|
||||
if (attr && menuHorizontalPosition==1) {
|
||||
if (event==EVT_KEY_LONG(KEY_ENTER) && curve.value!=0) {
|
||||
s_curveChan = (curve.value<0 ? -curve.value-1 : curve.value-1);
|
||||
pushMenu(menuModelCurveOne);
|
||||
}
|
||||
else {
|
||||
CHECK_INCDEC_MODELVAR(event, curve.value, -MAX_CURVES, MAX_CURVES);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define CURVES_NAME_POS 60
|
||||
#define CURVES_POINTS_POS 120
|
||||
|
||||
bool menuModelCurvesAll(event_t event)
|
||||
{
|
||||
SIMPLE_MENU(STR_MENUCURVES, MODEL_ICONS, menuTabModel, MENU_MODEL_CURVES, MAX_CURVES);
|
||||
|
||||
s_curveChan = menuVerticalPosition;
|
||||
|
||||
switch (event) {
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (!READ_ONLY()) {
|
||||
pushMenu(menuModelCurveOne);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES; ++i) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
uint8_t k = i + menuVerticalOffset;
|
||||
LcdFlags attr = (menuVerticalPosition == k ? INVERS : 0);
|
||||
{
|
||||
drawStringWithIndex(MENUS_MARGIN_LEFT, y, STR_CV, k+1, attr);
|
||||
CurveData & crv = g_model.curves[k];
|
||||
editName(CURVES_NAME_POS, y, crv.name, sizeof(crv.name), 0, 0);
|
||||
lcdDrawNumber(CURVES_POINTS_POS, y, 5+crv.points, LEFT, 0, NULL, STR_PTS);
|
||||
}
|
||||
}
|
||||
|
||||
drawCurve(CURVE_CENTER_X, CURVE_CENTER_Y+10, 80);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
bool menuModelFailsafe(event_t event)
|
||||
{
|
||||
uint8_t ch = 0;
|
||||
const uint8_t channelStart = g_model.moduleData[g_moduleIdx].channelsStart;
|
||||
const int lim = (g_model.extendedLimits ? (512 * LIMIT_EXT_PERCENT / 100) : 512) * 2;
|
||||
const uint8_t SLIDER_W = 128;
|
||||
const uint8_t cols = sentModuleChannels(g_moduleIdx) > 8 ? 2 : 1;
|
||||
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
event = 0;
|
||||
|
||||
if (menuVerticalPosition < sentModuleChannels(g_moduleIdx)) {
|
||||
if (s_editMode) {
|
||||
g_model.failsafeChannels[menuVerticalPosition] = channelOutputs[menuVerticalPosition+channelStart];
|
||||
s_editMode = 0;
|
||||
}
|
||||
else {
|
||||
int16_t * failsafe = &g_model.failsafeChannels[menuVerticalPosition];
|
||||
if (*failsafe < FAILSAFE_CHANNEL_HOLD)
|
||||
*failsafe = FAILSAFE_CHANNEL_HOLD;
|
||||
else if (*failsafe == FAILSAFE_CHANNEL_HOLD)
|
||||
*failsafe = FAILSAFE_CHANNEL_NOPULSE;
|
||||
else
|
||||
*failsafe = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// "Outputs => Failsafe" menu item
|
||||
setCustomFailsafe(g_moduleIdx);
|
||||
}
|
||||
|
||||
storageDirty(EE_MODEL);
|
||||
AUDIO_WARNING1();
|
||||
SEND_FAILSAFE_NOW(g_moduleIdx);
|
||||
}
|
||||
|
||||
SIMPLE_SUBMENU_WITH_OPTIONS("FAILSAFE", ICON_STATS_ANALOGS, sentModuleChannels(g_moduleIdx)+1, OPTION_MENU_NO_SCROLLBAR);
|
||||
drawStringWithIndex(50, 3+FH, "Module", g_moduleIdx+1, MENU_TITLE_COLOR);
|
||||
|
||||
for (uint8_t col=0; col < cols; col++) {
|
||||
for (uint8_t line=0; line < 8; line++) {
|
||||
coord_t x = col*(LCD_W/2);
|
||||
const coord_t y = MENU_CONTENT_TOP - FH + line*(FH+2);
|
||||
const int32_t channelValue = channelOutputs[ch+channelStart];
|
||||
int32_t failsafeValue = g_model.failsafeChannels[8*col+line];
|
||||
|
||||
// Channel name if present, number if not
|
||||
if (g_model.limitData[ch+channelStart].name[0] != '\0') {
|
||||
putsChn(x+MENUS_MARGIN_LEFT, y-3, ch+1, TINSIZE);
|
||||
lcdDrawSizedText(x+MENUS_MARGIN_LEFT, y+5, g_model.limitData[ch+channelStart].name, sizeof(g_model.limitData[ch+channelStart].name), ZCHAR|SMLSIZE);
|
||||
}
|
||||
else {
|
||||
putsChn(x+MENUS_MARGIN_LEFT, y, ch+1, 0);
|
||||
}
|
||||
|
||||
// Value
|
||||
LcdFlags flags = RIGHT;
|
||||
if (menuVerticalPosition == ch) {
|
||||
flags |= INVERS;
|
||||
if (s_editMode) {
|
||||
if (failsafeValue == FAILSAFE_CHANNEL_HOLD || failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
|
||||
s_editMode = 0;
|
||||
}
|
||||
else {
|
||||
flags |= BLINK;
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.failsafeChannels[8*col+line], -lim, +lim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
x += (LCD_W/2)-4-MENUS_MARGIN_LEFT-SLIDER_W;
|
||||
|
||||
if (failsafeValue == FAILSAFE_CHANNEL_HOLD) {
|
||||
lcdDrawText(x, y+2, STR_HOLD, flags|SMLSIZE);
|
||||
failsafeValue = 0;
|
||||
}
|
||||
else if (failsafeValue == FAILSAFE_CHANNEL_NOPULSE) {
|
||||
lcdDrawText(x, y+2, STR_NONE, flags|SMLSIZE);
|
||||
failsafeValue = 0;
|
||||
}
|
||||
else {
|
||||
#if defined(PPM_UNIT_US)
|
||||
lcdDrawNumber(x, y, PPM_CH_CENTER(ch)+failsafeValue/2, flags);
|
||||
#elif defined(PPM_UNIT_PERCENT_PREC1)
|
||||
lcdDrawNumber(x, y, calcRESXto1000(failsafeValue), PREC1|flags);
|
||||
#else
|
||||
lcdDrawNumber(x, y, calcRESXto1000(failsafeValue)/10, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Gauge
|
||||
x += 4;
|
||||
lcdDrawRect(x, y+3, SLIDER_W+1, 12);
|
||||
const coord_t lenChannel = limit((uint8_t)1, uint8_t((abs(channelValue) * SLIDER_W/2 + lim/2) / lim), uint8_t(SLIDER_W/2));
|
||||
const coord_t lenFailsafe = limit((uint8_t)1, uint8_t((abs(failsafeValue) * SLIDER_W/2 + lim/2) / lim), uint8_t(SLIDER_W/2));
|
||||
x += SLIDER_W/2;
|
||||
const coord_t xChannel = (channelValue>0) ? x : x+1-lenChannel;
|
||||
const coord_t xFailsafe = (failsafeValue>0) ? x : x+1-lenFailsafe;
|
||||
lcdDrawSolidFilledRect(xChannel, y+4, lenChannel, 5, TEXT_COLOR);
|
||||
lcdDrawSolidFilledRect(xFailsafe, y+9, lenFailsafe, 5, ALARM_COLOR);
|
||||
|
||||
if (++ch >= sentModuleChannels(g_moduleIdx)) {
|
||||
|
||||
// draw that menu at the bottom center
|
||||
flags = CENTERED | (menuVerticalPosition == ch ? INVERS : 0);
|
||||
lcdDrawSizedText(LCD_W/2, MENU_CONTENT_TOP - FH + 8*(FH+2), STR_CHANNELS2FAILSAFE, 20, flags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "opentx.h"
|
||||
|
||||
void displayFlightModes(coord_t x, coord_t y, FlightModesType value, uint8_t attr)
|
||||
{
|
||||
for (int i=0; i<MAX_FLIGHT_MODES; i++) {
|
||||
LcdFlags flags = ((menuHorizontalPosition==i && attr) ? INVERS : 0);
|
||||
flags |= ((value & (1<<i))) ? TEXT_DISABLE_COLOR : TEXT_COLOR;
|
||||
if (attr && menuHorizontalPosition < 0) flags |= INVERS;
|
||||
char s[] = " ";
|
||||
s[0] = '0' + i;
|
||||
lcdDrawText(x, y, s, flags);
|
||||
x += 12;
|
||||
}
|
||||
}
|
||||
|
||||
FlightModesType editFlightModes(coord_t x, coord_t y, event_t event, FlightModesType value, uint8_t attr)
|
||||
{
|
||||
displayFlightModes(x, y, value, attr);
|
||||
|
||||
if (attr) {
|
||||
if (s_editMode && event==EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
value ^= (1<<menuHorizontalPosition);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
enum FlightModesItems {
|
||||
ITEM_FLIGHT_MODES_NAME,
|
||||
ITEM_FLIGHT_MODES_SWITCH,
|
||||
ITEM_FLIGHT_MODES_TRIM_RUD,
|
||||
ITEM_FLIGHT_MODES_TRIM_ELE,
|
||||
ITEM_FLIGHT_MODES_TRIM_THR,
|
||||
ITEM_FLIGHT_MODES_TRIM_AIL,
|
||||
ITEM_FLIGHT_MODES_TRIM_T5,
|
||||
ITEM_FLIGHT_MODES_TRIM_T6,
|
||||
ITEM_FLIGHT_MODES_FADE_IN,
|
||||
ITEM_FLIGHT_MODES_FADE_OUT,
|
||||
ITEM_FLIGHT_MODES_COUNT,
|
||||
ITEM_FLIGHT_MODES_LAST = ITEM_FLIGHT_MODES_COUNT-1
|
||||
};
|
||||
|
||||
bool isTrimModeAvailable(int mode)
|
||||
{
|
||||
return (mode < 0 || (mode%2) == 0 || (mode/2) != menuVerticalPosition);
|
||||
}
|
||||
|
||||
#define FLIGHT_MODES_NAME_COLUMN 50
|
||||
#define FLIGHT_MODES_SWITCH_COLUMN 180
|
||||
#define FLIGHT_MODES_TRIMS_COLUMN 175
|
||||
#define FLIGHT_MODES_TRIM_WIDTH 26
|
||||
#define FLIGHT_MODES_FADEIN_COLUMN 420
|
||||
#define FLIGHT_MODES_FADEOUT_COLUMN 460
|
||||
|
||||
bool menuModelFlightModesAll(event_t event)
|
||||
{
|
||||
MENU(STR_MENUFLIGHTMODES, MODEL_ICONS, menuTabModel, MENU_MODEL_FLIGHT_MODES, MAX_FLIGHT_MODES+1, { NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, NAVIGATION_LINE_BY_LINE|ITEM_FLIGHT_MODES_LAST, 0});
|
||||
|
||||
if (menuVerticalPosition==0 && menuHorizontalPosition==ITEM_FLIGHT_MODES_SWITCH) {
|
||||
menuHorizontalPosition += CURSOR_MOVED_LEFT(event) ? -1 : +1;
|
||||
}
|
||||
|
||||
if (menuVerticalPosition<MAX_FLIGHT_MODES && menuHorizontalPosition>=0) {
|
||||
drawColumnHeader(STR_PHASES_HEADERS, NULL, menuHorizontalPosition);
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
int k = i+menuVerticalOffset;
|
||||
|
||||
if (k==MAX_FLIGHT_MODES) {
|
||||
// last line available - add the "check trims" line
|
||||
LcdFlags attr = 0;
|
||||
if (menuVerticalPosition==MAX_FLIGHT_MODES) {
|
||||
if (!trimsCheckTimer) {
|
||||
if (event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
trimsCheckTimer = 200; // 2 seconds trims cancelled
|
||||
s_editMode = 1;
|
||||
killEvents(event);
|
||||
}
|
||||
else {
|
||||
attr |= INVERS;
|
||||
s_editMode = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (event == EVT_KEY_FIRST(KEY_EXIT)) {
|
||||
trimsCheckTimer = 0;
|
||||
s_editMode = 0;
|
||||
killEvents(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
char s[32];
|
||||
sprintf(s, "Check FM%d Trims", mixerCurrentFlightMode);
|
||||
lcdDrawText(LCD_W/2, y, s, CENTERED|attr);
|
||||
return true;
|
||||
}
|
||||
|
||||
FlightModeData * p = flightModeAddress(k);
|
||||
|
||||
drawFlightMode(MENUS_MARGIN_LEFT, y, k+1, (getFlightMode()==k ? BOLD : 0) | ((menuVerticalPosition==k && menuHorizontalPosition<0) ? INVERS : 0));
|
||||
|
||||
for (uint8_t j=0; j<ITEM_FLIGHT_MODES_COUNT; j++) {
|
||||
LcdFlags attr = ((menuVerticalPosition==k && menuHorizontalPosition==j) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
|
||||
LcdFlags active = (attr && s_editMode>0) ;
|
||||
switch (j) {
|
||||
case ITEM_FLIGHT_MODES_NAME:
|
||||
editName(FLIGHT_MODES_NAME_COLUMN, y, p->name, sizeof(p->name), event, attr);
|
||||
break;
|
||||
|
||||
case ITEM_FLIGHT_MODES_SWITCH:
|
||||
if (active) CHECK_INCDEC_MODELSWITCH(event, p->swtch, SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, isSwitchAvailableInMixes);
|
||||
if (k == 0)
|
||||
lcdDrawText(FLIGHT_MODES_SWITCH_COLUMN, y, "N/A");
|
||||
else
|
||||
drawSwitch(FLIGHT_MODES_SWITCH_COLUMN, y, p->swtch, attr);
|
||||
break;
|
||||
|
||||
case ITEM_FLIGHT_MODES_TRIM_RUD:
|
||||
case ITEM_FLIGHT_MODES_TRIM_ELE:
|
||||
case ITEM_FLIGHT_MODES_TRIM_THR:
|
||||
case ITEM_FLIGHT_MODES_TRIM_AIL:
|
||||
case ITEM_FLIGHT_MODES_TRIM_T5:
|
||||
case ITEM_FLIGHT_MODES_TRIM_T6:
|
||||
{
|
||||
uint8_t t = j-ITEM_FLIGHT_MODES_TRIM_RUD;
|
||||
if (active) {
|
||||
trim_t & v = p->trim[t];
|
||||
v.mode = checkIncDec(event, v.mode==TRIM_MODE_NONE ? -1 : v.mode, -1, k==0 ? 0 : 2*MAX_FLIGHT_MODES-1, EE_MODEL, isTrimModeAvailable);
|
||||
}
|
||||
drawTrimMode(FLIGHT_MODES_TRIMS_COLUMN+j*FLIGHT_MODES_TRIM_WIDTH, y, k, t, attr);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_FLIGHT_MODES_FADE_IN:
|
||||
if (active) p->fadeIn = checkIncDec(event, p->fadeIn, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS);
|
||||
lcdDrawNumber(FLIGHT_MODES_FADEIN_COLUMN, y, (10/DELAY_STEP)*p->fadeIn, attr|PREC1|RIGHT);
|
||||
break;
|
||||
|
||||
case ITEM_FLIGHT_MODES_FADE_OUT:
|
||||
if (active) p->fadeOut = checkIncDec(event, p->fadeOut, 0, DELAY_MAX, EE_MODEL|NO_INCDEC_MARKS);
|
||||
lcdDrawNumber(FLIGHT_MODES_FADEOUT_COLUMN, y, (10/DELAY_STEP)*p->fadeOut, attr|PREC1|RIGHT);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,570 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "opentx.h"
|
||||
|
||||
#define EXPO_ONE_2ND_COLUMN 115
|
||||
|
||||
int expoFn(int x)
|
||||
{
|
||||
ExpoData * ed = expoAddress(s_currIdx);
|
||||
int16_t anas[MAX_INPUTS] = {0};
|
||||
applyExpos(anas, e_perout_mode_inactive_flight_mode, ed->srcRaw, x);
|
||||
return anas[ed->chn];
|
||||
}
|
||||
|
||||
int getExposLinesCount()
|
||||
{
|
||||
int lastch = -1;
|
||||
uint8_t count = MAX_INPUTS;
|
||||
for (int i=0; i<MAX_EXPOS; i++) {
|
||||
bool valid = EXPO_VALID(expoAddress(i));
|
||||
if (!valid)
|
||||
break;
|
||||
int ch = expoAddress(i)->chn;
|
||||
if (ch == lastch) {
|
||||
count++;
|
||||
}
|
||||
else {
|
||||
lastch = ch;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
uint8_t getExposCount()
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint8_t ch ;
|
||||
|
||||
for (int i=MAX_EXPOS-1 ; i>=0; i--) {
|
||||
ch = EXPO_VALID(expoAddress(i));
|
||||
if (ch != 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
bool reachExposLimit()
|
||||
{
|
||||
if (getExposCount() >= MAX_EXPOS) {
|
||||
POPUP_WARNING(STR_NOFREEEXPO);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void deleteExpo(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
ExpoData * expo = expoAddress(idx);
|
||||
int input = expo->chn;
|
||||
memmove(expo, expo+1, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
||||
memclear(&g_model.expoData[MAX_EXPOS-1], sizeof(ExpoData));
|
||||
if (!isInputAvailable(input)) {
|
||||
memclear(&g_model.inputNames[input], LEN_INPUT_NAME);
|
||||
}
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
// TODO avoid this global s_currCh on ARM boards ...
|
||||
int8_t s_currCh;
|
||||
void insertExpo(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
ExpoData * expo = expoAddress(idx);
|
||||
memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
||||
memclear(expo, sizeof(ExpoData));
|
||||
expo->srcRaw = (s_currCh > 4 ? MIXSRC_Rud - 1 + s_currCh : MIXSRC_Rud - 1 + channelOrder(s_currCh));
|
||||
expo->curve.type = CURVE_REF_EXPO;
|
||||
expo->mode = 3; // pos+neg
|
||||
expo->chn = s_currCh - 1;
|
||||
expo->weight = 100;
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
void copyExpo(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
ExpoData * expo = expoAddress(idx);
|
||||
memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
bool swapExpos(uint8_t & idx, uint8_t up)
|
||||
{
|
||||
ExpoData * x, * y;
|
||||
int8_t tgt_idx = (up ? idx-1 : idx+1);
|
||||
|
||||
x = expoAddress(idx);
|
||||
|
||||
if (tgt_idx < 0) {
|
||||
if (x->chn == 0)
|
||||
return false;
|
||||
x->chn--;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tgt_idx == MAX_EXPOS) {
|
||||
if (x->chn == MAX_INPUTS-1)
|
||||
return false;
|
||||
x->chn++;
|
||||
return true;
|
||||
}
|
||||
|
||||
y = expoAddress(tgt_idx);
|
||||
if (x->chn != y->chn || !EXPO_VALID(y)) {
|
||||
if (up) {
|
||||
if (x->chn>0) x->chn--;
|
||||
else return false;
|
||||
}
|
||||
else {
|
||||
if (x->chn<MAX_INPUTS-1) x->chn++;
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
pauseMixerCalculations();
|
||||
memswap(x, y, sizeof(ExpoData));
|
||||
resumeMixerCalculations();
|
||||
|
||||
idx = tgt_idx;
|
||||
return true;
|
||||
}
|
||||
|
||||
enum ExposFields {
|
||||
EXPO_FIELD_INPUT_NAME,
|
||||
EXPO_FIELD_NAME,
|
||||
EXPO_FIELD_SOURCE,
|
||||
EXPO_FIELD_SCALE,
|
||||
EXPO_FIELD_WEIGHT,
|
||||
EXPO_FIELD_OFFSET,
|
||||
EXPO_FIELD_CURVE,
|
||||
CASE_FLIGHT_MODES(EXPO_FIELD_FLIGHT_MODES)
|
||||
EXPO_FIELD_SWITCH,
|
||||
EXPO_FIELD_SIDE,
|
||||
EXPO_FIELD_TRIM,
|
||||
EXPO_FIELD_MAX
|
||||
};
|
||||
|
||||
#define CURVE_ROWS 1
|
||||
|
||||
bool menuModelExpoOne(event_t event)
|
||||
{
|
||||
ExpoData * ed = expoAddress(s_currIdx);
|
||||
|
||||
SUBMENU_WITH_OPTIONS(STR_MENUINPUTS, ICON_MODEL_INPUTS, EXPO_FIELD_MAX, OPTION_MENU_NO_FOOTER|OPTION_MENU_NO_SCROLLBAR, { 0, 0, 0, (ed->srcRaw >= MIXSRC_FIRST_TELEM ? (uint8_t)0 : (uint8_t)HIDDEN_ROW), 0, 0, CURVE_ROWS, CASE_FLIGHT_MODES((MAX_FLIGHT_MODES-1) | NAVIGATION_LINE_BY_LINE) 0 /*, ...*/});
|
||||
lcdDrawSizedText(50, 3+FH, g_model.inputNames[ed->chn], LEN_INPUT_NAME, ZCHAR|MENU_TITLE_COLOR);
|
||||
|
||||
int sub = menuVerticalPosition;
|
||||
|
||||
coord_t y = MENU_CONTENT_TOP-FH-2;
|
||||
|
||||
drawFunction(expoFn, CURVE_CENTER_X, CURVE_CENTER_Y, CURVE_SIDE_WIDTH);
|
||||
drawCurveHorizontalScale();
|
||||
drawCurveVerticalScale(CURVE_CENTER_X-CURVE_SIDE_WIDTH-15);
|
||||
|
||||
{
|
||||
char textx[5];
|
||||
char texty[5];
|
||||
int x = getValue(ed->srcRaw);
|
||||
if (ed->srcRaw >= MIXSRC_FIRST_TELEM) {
|
||||
strAppendUnsigned(textx, calcRESXto100(x));
|
||||
// TODO drawSensorCustomValue(LCD_W-8, 6*FH, ed->srcRaw - MIXSRC_FIRST_TELEM, x);
|
||||
if (ed->scale > 0) x = (x * 1024) / convertTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1, ed->scale);
|
||||
}
|
||||
else {
|
||||
strAppendSigned(textx, calcRESXto100(x));
|
||||
}
|
||||
|
||||
x = limit(-1024, x, 1024);
|
||||
int y = limit<int>(-1024, expoFn(x), 1024);
|
||||
strAppendSigned(texty, calcRESXto100(y));
|
||||
|
||||
x = divRoundClosest(x*CURVE_SIDE_WIDTH, RESX);
|
||||
y = CURVE_CENTER_Y + getCurveYCoord(expoFn, x, CURVE_SIDE_WIDTH);
|
||||
|
||||
lcdDrawSolidFilledRect(CURVE_CENTER_X+x, CURVE_CENTER_Y-CURVE_SIDE_WIDTH, 2, 2*CURVE_SIDE_WIDTH+2, CURVE_CURSOR_COLOR);
|
||||
lcdDrawSolidFilledRect(CURVE_CENTER_X-CURVE_SIDE_WIDTH-2, y-1, 2*CURVE_SIDE_WIDTH+2, 2, CURVE_CURSOR_COLOR);
|
||||
lcdDrawBitmapPattern(CURVE_CENTER_X+x-4, y-4, LBM_CURVE_POINT, CURVE_CURSOR_COLOR);
|
||||
lcdDrawBitmapPattern(CURVE_CENTER_X+x-4, y-4, LBM_CURVE_POINT_CENTER, TEXT_BGCOLOR);
|
||||
|
||||
int left = limit(CURVE_CENTER_X-CURVE_SIDE_WIDTH, CURVE_CENTER_X-CURVE_COORD_WIDTH/2+x, CURVE_CENTER_X+CURVE_SIDE_WIDTH-CURVE_COORD_WIDTH+2);
|
||||
drawCurveCoord(left, CURVE_CENTER_Y+CURVE_SIDE_WIDTH+2, textx);
|
||||
int top = limit(CURVE_CENTER_Y-CURVE_SIDE_WIDTH-1, -CURVE_COORD_HEIGHT/2+y, CURVE_CENTER_Y+CURVE_SIDE_WIDTH-CURVE_COORD_HEIGHT+1);
|
||||
drawCurveCoord(CURVE_CENTER_X-CURVE_SIDE_WIDTH-37, top, texty);
|
||||
}
|
||||
|
||||
for (uint8_t k=0; k<NUM_BODY_LINES+1; k++) {
|
||||
int i = k + menuVerticalOffset;
|
||||
for (int j=0; j<=i; ++j) {
|
||||
if (j<(int)DIM(mstate_tab) && mstate_tab[j] == HIDDEN_ROW) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
LcdFlags attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
|
||||
switch (i) {
|
||||
case EXPO_FIELD_INPUT_NAME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_INPUTNAME);
|
||||
editName(EXPO_ONE_2ND_COLUMN, y, g_model.inputNames[ed->chn], sizeof(g_model.inputNames[ed->chn]), event, attr);
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_NAME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_EXPONAME);
|
||||
editName(EXPO_ONE_2ND_COLUMN, y, ed->name, sizeof(ed->name), event, attr);
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_SOURCE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SOURCE);
|
||||
drawSource(EXPO_ONE_2ND_COLUMN, y, ed->srcRaw, menuHorizontalPosition==0 ? attr : 0);
|
||||
if (attr && menuHorizontalPosition==0)
|
||||
ed->srcRaw = checkIncDec(event, ed->srcRaw, INPUTSRC_FIRST, INPUTSRC_LAST, EE_MODEL|INCDEC_SOURCE|NO_INCDEC_MARKS, isInputSourceAvailable);
|
||||
if (ed->srcRaw >= MIXSRC_FIRST_TELEM) {
|
||||
drawSensorCustomValue(EXPO_ONE_2ND_COLUMN+75, y, (ed->srcRaw - MIXSRC_FIRST_TELEM)/3, convertTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1, ed->scale), LEFT|(menuHorizontalPosition==1?attr:0));
|
||||
if (attr && menuHorizontalPosition == 1) ed->scale = checkIncDec(event, ed->scale, 0, maxTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1), EE_MODEL);
|
||||
}
|
||||
else if (attr) {
|
||||
menuHorizontalPosition = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_SCALE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SCALE);
|
||||
drawSensorCustomValue(EXPO_ONE_2ND_COLUMN, y, (ed->srcRaw - MIXSRC_FIRST_TELEM)/3, convertTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1, ed->scale), LEFT|attr);
|
||||
if (attr) ed->scale = checkIncDec(event, ed->scale, 0, maxTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1), EE_MODEL);
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_WEIGHT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_WEIGHT);
|
||||
ed->weight = GVAR_MENU_ITEM(EXPO_ONE_2ND_COLUMN, y, ed->weight, MIN_EXPO_WEIGHT, 100, LEFT|attr, 0, event);
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_OFFSET:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_OFFSET);
|
||||
ed->offset = GVAR_MENU_ITEM(EXPO_ONE_2ND_COLUMN, y, ed->offset, -100, 100, LEFT|attr, 0, event);
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_CURVE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_CURVE);
|
||||
editCurveRef(EXPO_ONE_2ND_COLUMN, y, ed->curve, event, attr);
|
||||
break;
|
||||
|
||||
#if defined(FLIGHT_MODES)
|
||||
case EXPO_FIELD_FLIGHT_MODES:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_FLMODE);
|
||||
ed->flightModes = editFlightModes(EXPO_ONE_2ND_COLUMN, y, event, ed->flightModes, attr);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case EXPO_FIELD_SWITCH:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SWITCH);
|
||||
ed->swtch = editSwitch(EXPO_ONE_2ND_COLUMN, y, ed->swtch, attr, event);
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_SIDE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SIDE);
|
||||
ed->mode = 4 - editChoice(EXPO_ONE_2ND_COLUMN, y, STR_VCURVEFUNC, 4-ed->mode, 1, 3, attr, event);
|
||||
break;
|
||||
|
||||
case EXPO_FIELD_TRIM:
|
||||
uint8_t not_stick = (ed->srcRaw > MIXSRC_Ail);
|
||||
int8_t carryTrim = -ed->carryTrim;
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TRIM);
|
||||
lcdDrawTextAtIndex(EXPO_ONE_2ND_COLUMN, y, STR_VMIXTRIMS, (not_stick && carryTrim == 0) ? 0 : carryTrim+1, menuHorizontalPosition==0 ? attr : 0);
|
||||
if (attr) ed->carryTrim = -checkIncDecModel(event, carryTrim, not_stick ? TRIM_ON : -TRIM_OFF, -TRIM_LAST);
|
||||
break;
|
||||
}
|
||||
y += FH;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define _STR_MAX(x) "/" #x
|
||||
#define STR_MAX(x) _STR_MAX(x)
|
||||
|
||||
#define EXPO_LINE_WEIGHT_POS 125
|
||||
#define EXPO_LINE_SRC_POS 135
|
||||
#define EXPO_LINE_CURVE_POS 185
|
||||
#define EXPO_LINE_SWITCH_POS 233
|
||||
#define EXPO_LINE_SIDE_POS 275
|
||||
#define EXPO_LINE_FM_POS 295
|
||||
#define EXPO_LINE_NAME_POS 405
|
||||
#define EXPO_LINE_SELECT_POS 50
|
||||
#define EXPO_LINE_SELECT_WIDTH (LCD_W-EXPO_LINE_SELECT_POS-15)
|
||||
|
||||
void lineExpoSurround(coord_t y, LcdFlags flags=CURVE_AXIS_COLOR)
|
||||
{
|
||||
lcdDrawRect(EXPO_LINE_SELECT_POS, y-INVERT_VERT_MARGIN+1, EXPO_LINE_SELECT_WIDTH, INVERT_LINE_HEIGHT, 1, s_copyMode == COPY_MODE ? SOLID : DOTTED, flags);
|
||||
}
|
||||
|
||||
void onExposMenu(const char * result)
|
||||
{
|
||||
uint8_t chn = expoAddress(s_currIdx)->chn + 1;
|
||||
|
||||
if (result == STR_EDIT) {
|
||||
pushMenu(menuModelExpoOne);
|
||||
}
|
||||
else if (result == STR_INSERT_BEFORE || result == STR_INSERT_AFTER) {
|
||||
if (!reachExposLimit()) {
|
||||
s_currCh = chn;
|
||||
if (result == STR_INSERT_AFTER) { s_currIdx++; menuVerticalPosition++; }
|
||||
insertExpo(s_currIdx);
|
||||
pushMenu(menuModelExpoOne);
|
||||
}
|
||||
}
|
||||
else if (result == STR_COPY || result == STR_MOVE) {
|
||||
s_copyMode = (result == STR_COPY ? COPY_MODE : MOVE_MODE);
|
||||
s_copySrcIdx = s_currIdx;
|
||||
s_copySrcCh = chn;
|
||||
s_copySrcRow = menuVerticalPosition;
|
||||
}
|
||||
else if (result == STR_DELETE) {
|
||||
deleteExpo(s_currIdx);
|
||||
}
|
||||
}
|
||||
|
||||
void displayExpoInfos(coord_t y, ExpoData * ed)
|
||||
{
|
||||
drawCurveRef(EXPO_LINE_CURVE_POS, y, ed->curve);
|
||||
if (ed->swtch) {
|
||||
drawSwitch(EXPO_LINE_SWITCH_POS, y, ed->swtch);
|
||||
}
|
||||
if (ed->mode != 3) {
|
||||
lcdDrawText(EXPO_LINE_SIDE_POS, y, ed->mode == 2 ? "\176" : "\177");
|
||||
}
|
||||
}
|
||||
|
||||
void displayExpoLine(coord_t y, ExpoData * ed)
|
||||
{
|
||||
drawSource(EXPO_LINE_SRC_POS, y, ed->srcRaw);
|
||||
|
||||
displayExpoInfos(y, ed);
|
||||
displayFlightModes(EXPO_LINE_FM_POS, y, ed->flightModes, 0);
|
||||
|
||||
if (ed->name[0]) {
|
||||
lcdDrawSizedText(EXPO_LINE_NAME_POS, y+2, ed->name, sizeof(ed->name), ZCHAR|SMLSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
bool menuModelExposAll(event_t event)
|
||||
{
|
||||
int sub = menuVerticalPosition;
|
||||
|
||||
if (s_editMode > 0) {
|
||||
s_editMode = 0;
|
||||
}
|
||||
|
||||
uint8_t chn = expoAddress(s_currIdx)->chn + 1;
|
||||
|
||||
int linesCount = getExposLinesCount();
|
||||
SIMPLE_MENU(STR_MENUINPUTS, MODEL_ICONS, menuTabModel, MENU_MODEL_INPUTS, linesCount);
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
case EVT_ENTRY_UP:
|
||||
s_copyMode = 0;
|
||||
s_copyTgtOfs = 0;
|
||||
break;
|
||||
case EVT_KEY_LONG(KEY_EXIT):
|
||||
if (s_copyMode && s_copyTgtOfs == 0) {
|
||||
deleteExpo(s_currIdx);
|
||||
killEvents(event);
|
||||
event = 0;
|
||||
}
|
||||
// no break
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
if (s_copyMode) {
|
||||
if (s_copyTgtOfs) {
|
||||
// cancel the current copy / move operation
|
||||
if (s_copyMode == COPY_MODE) {
|
||||
deleteExpo(s_currIdx);
|
||||
}
|
||||
else {
|
||||
do {
|
||||
swapExpos(s_currIdx, s_copyTgtOfs > 0);
|
||||
s_copyTgtOfs += (s_copyTgtOfs < 0 ? +1 : -1);
|
||||
} while (s_copyTgtOfs != 0);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
menuVerticalPosition = s_copySrcRow;
|
||||
s_copyTgtOfs = 0;
|
||||
}
|
||||
s_copyMode = 0;
|
||||
event = 0;
|
||||
}
|
||||
break;
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if ((!s_currCh || (s_copyMode && !s_copyTgtOfs)) && !READ_ONLY()) {
|
||||
s_copyMode = (s_copyMode == COPY_MODE ? MOVE_MODE : COPY_MODE);
|
||||
s_copySrcIdx = s_currIdx;
|
||||
s_copySrcCh = chn;
|
||||
s_copySrcRow = sub;
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
killEvents(event);
|
||||
if (s_copyTgtOfs) {
|
||||
s_copyMode = 0;
|
||||
s_copyTgtOfs = 0;
|
||||
}
|
||||
else {
|
||||
if (READ_ONLY()) {
|
||||
if (!s_currCh) {
|
||||
pushMenu(menuModelExpoOne);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (s_copyMode) s_currCh = 0;
|
||||
if (s_currCh) {
|
||||
if (reachExposLimit()) break;
|
||||
insertExpo(s_currIdx);
|
||||
pushMenu(menuModelExpoOne);
|
||||
s_copyMode = 0;
|
||||
}
|
||||
else {
|
||||
event = 0;
|
||||
s_copyMode = 0;
|
||||
POPUP_MENU_ADD_ITEM(STR_EDIT);
|
||||
POPUP_MENU_ADD_ITEM(STR_INSERT_BEFORE);
|
||||
POPUP_MENU_ADD_ITEM(STR_INSERT_AFTER);
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY);
|
||||
POPUP_MENU_ADD_ITEM(STR_MOVE);
|
||||
POPUP_MENU_ADD_ITEM(STR_DELETE);
|
||||
POPUP_MENU_START(onExposMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_LEFT:
|
||||
case EVT_ROTARY_RIGHT:
|
||||
if (s_copyMode) {
|
||||
uint8_t next_ofs = ((event==EVT_ROTARY_LEFT) ? s_copyTgtOfs - 1 : s_copyTgtOfs + 1);
|
||||
|
||||
if (s_copyTgtOfs==0 && s_copyMode==COPY_MODE) {
|
||||
// insert a mix on the same channel (just above / just below)
|
||||
if (reachExposLimit()) break;
|
||||
copyExpo(s_currIdx);
|
||||
if (event==EVT_ROTARY_RIGHT) s_currIdx++;
|
||||
else if (sub-menuVerticalOffset >= 6) menuVerticalOffset++;
|
||||
}
|
||||
else if (next_ofs==0 && s_copyMode==COPY_MODE) {
|
||||
// delete the mix
|
||||
deleteExpo(s_currIdx);
|
||||
if (event==EVT_ROTARY_LEFT) s_currIdx--;
|
||||
}
|
||||
else {
|
||||
// only swap the mix with its neighbor
|
||||
if (!swapExpos(s_currIdx, event==EVT_ROTARY_LEFT)) break;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
s_copyTgtOfs = next_ofs;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
char str[6];
|
||||
strAppendUnsigned(strAppend(strAppendUnsigned(str, getExposCount()), "/"), MAX_EXPOS, 2);
|
||||
lcdDrawText(MENU_TITLE_NEXT_POS, MENU_TITLE_TOP+2, str, HEADER_COLOR);
|
||||
|
||||
sub = menuVerticalPosition;
|
||||
s_currCh = 0;
|
||||
int cur = 0;
|
||||
int i = 0;
|
||||
|
||||
for (int ch=1; ch<=MAX_INPUTS; ch++) {
|
||||
ExpoData * ed;
|
||||
coord_t y = MENU_CONTENT_TOP + (cur-menuVerticalOffset)*FH;
|
||||
if ((i<MAX_EXPOS && (ed=expoAddress(i))->chn+1 == ch && EXPO_VALID(ed))) {
|
||||
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
||||
drawSource(MENUS_MARGIN_LEFT, y, ch);
|
||||
}
|
||||
uint8_t mixCnt = 0;
|
||||
do {
|
||||
if (s_copyMode) {
|
||||
if (s_copyMode == MOVE_MODE && cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES && s_copySrcCh == ch && s_copyTgtOfs != 0 && i == (s_copySrcIdx + (s_copyTgtOfs<0))) {
|
||||
lineExpoSurround(y);
|
||||
cur++; y+=FH;
|
||||
}
|
||||
if (s_currIdx == i) {
|
||||
sub = menuVerticalPosition = cur;
|
||||
s_currCh = ch;
|
||||
}
|
||||
}
|
||||
else if (sub == cur) {
|
||||
s_currIdx = i;
|
||||
}
|
||||
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
||||
LcdFlags attr = ((s_copyMode || sub != cur) ? 0 : INVERS);
|
||||
|
||||
GVAR_MENU_ITEM(EXPO_LINE_WEIGHT_POS, y, ed->weight, MIN_EXPO_WEIGHT, 100, RIGHT | attr | (isExpoActive(i) ? BOLD : 0), 0, 0);
|
||||
displayExpoLine(y, ed);
|
||||
|
||||
if (s_copyMode) {
|
||||
if ((s_copyMode==COPY_MODE || s_copyTgtOfs == 0) && s_copySrcCh == ch && i == (s_copySrcIdx + (s_copyTgtOfs<0))) {
|
||||
/* draw a border around the raw on selection mode (copy/move) */
|
||||
lineExpoSurround(y);
|
||||
}
|
||||
if (cur == sub) {
|
||||
/* invert the raw when it's the current one */
|
||||
lineExpoSurround(y, ALARM_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
cur++; y+=FH; mixCnt++; i++; ed++;
|
||||
} while (i<MAX_EXPOS && ed->chn+1 == ch && EXPO_VALID(ed));
|
||||
if (s_copyMode == MOVE_MODE && cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES && s_copySrcCh == ch && i == (s_copySrcIdx + (s_copyTgtOfs<0))) {
|
||||
lineExpoSurround(y);
|
||||
cur++; y+=FH;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uint8_t attr = 0;
|
||||
if (sub == cur) {
|
||||
s_currIdx = i;
|
||||
s_currCh = ch;
|
||||
if (!s_copyMode) {
|
||||
attr = INVERS;
|
||||
}
|
||||
}
|
||||
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
||||
drawSource(MENUS_MARGIN_LEFT, y, ch, attr);
|
||||
if (s_copyMode == MOVE_MODE && s_copySrcCh == ch) {
|
||||
lineExpoSurround(y);
|
||||
}
|
||||
}
|
||||
cur++; y+=FH;
|
||||
}
|
||||
}
|
||||
|
||||
if (sub >= linesCount-1) menuVerticalPosition = linesCount-1;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "opentx.h"
|
||||
|
||||
enum LogicalSwitchFields {
|
||||
LS_FIELD_FUNCTION,
|
||||
LS_FIELD_V1,
|
||||
LS_FIELD_V2,
|
||||
LS_FIELD_V3,
|
||||
LS_FIELD_ANDSW,
|
||||
LS_FIELD_DURATION,
|
||||
LS_FIELD_DELAY,
|
||||
LS_FIELD_COUNT,
|
||||
LS_FIELD_LAST = LS_FIELD_COUNT-1
|
||||
};
|
||||
|
||||
#define CSW_1ST_COLUMN 50
|
||||
#define CSW_2ND_COLUMN 120
|
||||
#define CSW_3RD_COLUMN 200
|
||||
#define CSW_4TH_COLUMN 315
|
||||
#define CSW_5TH_COLUMN 375
|
||||
#define CSW_6TH_COLUMN 425
|
||||
|
||||
void putsEdgeDelayParam(coord_t x, coord_t y, LogicalSwitchData *cs, uint8_t lattr, uint8_t rattr)
|
||||
{
|
||||
lcdDrawChar(x, y, '[');
|
||||
lcdDrawNumber(lcdNextPos+2, y, lswTimerValue(cs->v2), LEFT|PREC1|lattr);
|
||||
lcdDrawChar(lcdNextPos, y, ':');
|
||||
if (cs->v3 < 0)
|
||||
lcdDrawText(lcdNextPos+3, y, "<<", rattr);
|
||||
else if (cs->v3 == 0)
|
||||
lcdDrawText(lcdNextPos+3, y, "--", rattr);
|
||||
else
|
||||
lcdDrawNumber(lcdNextPos+3, y, lswTimerValue(cs->v2+cs->v3), LEFT|PREC1|rattr);
|
||||
lcdDrawChar(lcdNextPos, y, ']');
|
||||
}
|
||||
|
||||
void onLogicalSwitchesMenu(const char * result)
|
||||
{
|
||||
LogicalSwitchData * cs = lswAddress(menuVerticalPosition);
|
||||
|
||||
if (result == STR_COPY) {
|
||||
clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH;
|
||||
clipboard.data.csw = *cs;
|
||||
}
|
||||
else if (result == STR_PASTE) {
|
||||
*cs = clipboard.data.csw;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_CLEAR) {
|
||||
memset(cs, 0, sizeof(LogicalSwitchData));
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
}
|
||||
|
||||
bool menuModelLogicalSwitches(event_t event)
|
||||
{
|
||||
INCDEC_DECLARE_VARS(EE_MODEL);
|
||||
|
||||
MENU(STR_MENULOGICALSWITCHES, MODEL_ICONS, menuTabModel, MENU_MODEL_LOGICAL_SWITCHES, MAX_LOGICAL_SWITCHES, { NAVIGATION_LINE_BY_LINE|LS_FIELD_LAST/*repeated...*/} );
|
||||
|
||||
LogicalSwitchData * cs = lswAddress(menuVerticalPosition);
|
||||
uint8_t cstate = lswFamily(cs->func);
|
||||
if ((cstate == LS_FAMILY_EDGE && menuHorizontalPosition == LS_FIELD_DELAY) ||
|
||||
(cstate != LS_FAMILY_EDGE && menuHorizontalPosition == LS_FIELD_V3)) {
|
||||
REPEAT_LAST_CURSOR_MOVE(LS_FIELD_LAST, false);
|
||||
}
|
||||
|
||||
#if defined(MENU_TOOLTIPS)
|
||||
if (menuVerticalPosition>= 0 && menuHorizontalPosition>=0) {
|
||||
drawColumnHeader(STR_LSW_HEADERS, STR_LSW_DESCRIPTIONS, menuHorizontalPosition);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (menuHorizontalPosition<0 && event==EVT_KEY_LONG(KEY_ENTER) && !READ_ONLY()) {
|
||||
killEvents(event);
|
||||
if (cs->func)
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY);
|
||||
if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH)
|
||||
POPUP_MENU_ADD_ITEM(STR_PASTE);
|
||||
if (cs->func || cs->v1 || cs->v2 || cs->delay || cs->duration || cs->andsw)
|
||||
POPUP_MENU_ADD_ITEM(STR_CLEAR);
|
||||
POPUP_MENU_START(onLogicalSwitchesMenu);
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES; ++i) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
int k = i+menuVerticalOffset;
|
||||
LcdFlags attr = (menuVerticalPosition==k ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
|
||||
LcdFlags attr1 = (menuHorizontalPosition==1 ? attr : 0);
|
||||
LcdFlags attr2 = (menuHorizontalPosition==2 ? attr : 0);
|
||||
cs = lswAddress(k);
|
||||
|
||||
// CSW name
|
||||
unsigned int sw = SWSRC_SW1+k;
|
||||
drawSwitch(MENUS_MARGIN_LEFT, y, sw, (getSwitch(sw) ? BOLD : 0) | ((menuVerticalPosition==k && CURSOR_ON_LINE()) ? INVERS : 0));
|
||||
|
||||
// CSW func
|
||||
lcdDrawTextAtIndex(CSW_1ST_COLUMN, y, STR_VCSWFUNC, cs->func, menuHorizontalPosition==0 ? attr : 0);
|
||||
|
||||
// CSW params
|
||||
cstate = lswFamily(cs->func);
|
||||
int v1_val = cs->v1;
|
||||
int16_t v1_min = 0, v1_max = MIXSRC_LAST_TELEM;
|
||||
int16_t v2_min = 0, v2_max = MIXSRC_LAST_TELEM;
|
||||
int16_t v3_min =-1, v3_max = 100;
|
||||
|
||||
if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) {
|
||||
drawSwitch(CSW_2ND_COLUMN, y, cs->v1, attr1);
|
||||
drawSwitch(CSW_3RD_COLUMN, y, cs->v2, attr2);
|
||||
v1_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v1_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
|
||||
v2_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v2_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
|
||||
INCDEC_SET_FLAG(EE_MODEL | INCDEC_SWITCH);
|
||||
INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
|
||||
}
|
||||
else if (cstate == LS_FAMILY_EDGE) {
|
||||
drawSwitch(CSW_2ND_COLUMN, y, cs->v1, attr1);
|
||||
putsEdgeDelayParam(CSW_3RD_COLUMN, y, cs, attr2, (menuHorizontalPosition==LS_FIELD_V3 ? attr : 0));
|
||||
v1_min = SWSRC_FIRST_IN_LOGICAL_SWITCHES; v1_max = SWSRC_LAST_IN_LOGICAL_SWITCHES;
|
||||
v2_min=-129; v2_max = 122;
|
||||
v3_max = 222 - cs->v2;
|
||||
if (menuHorizontalPosition == 1) {
|
||||
INCDEC_SET_FLAG(EE_MODEL | INCDEC_SWITCH);
|
||||
INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
|
||||
}
|
||||
else {
|
||||
INCDEC_SET_FLAG(EE_MODEL);
|
||||
INCDEC_ENABLE_CHECK(NULL);
|
||||
}
|
||||
}
|
||||
else if (cstate == LS_FAMILY_COMP) {
|
||||
v1_val = cs->v1;
|
||||
drawSource(CSW_2ND_COLUMN, y, v1_val, attr1);
|
||||
drawSource(CSW_3RD_COLUMN, y, cs->v2, attr2);
|
||||
INCDEC_SET_FLAG(EE_MODEL | INCDEC_SOURCE);
|
||||
INCDEC_ENABLE_CHECK(isSourceAvailable);
|
||||
}
|
||||
else if (cstate == LS_FAMILY_TIMER) {
|
||||
lcdDrawNumber(CSW_2ND_COLUMN, y, lswTimerValue(cs->v1), LEFT|PREC1|attr1);
|
||||
lcdDrawNumber(CSW_3RD_COLUMN, y, lswTimerValue(cs->v2), LEFT|PREC1|attr2);
|
||||
v1_min = v2_min = -128;
|
||||
v1_max = v2_max = 122;
|
||||
INCDEC_SET_FLAG(EE_MODEL);
|
||||
INCDEC_ENABLE_CHECK(NULL);
|
||||
}
|
||||
else {
|
||||
v1_val = cs->v1;
|
||||
drawSource(CSW_2ND_COLUMN, y, v1_val, attr1);
|
||||
if (menuHorizontalPosition == 1) {
|
||||
INCDEC_SET_FLAG(EE_MODEL | INCDEC_SOURCE);
|
||||
INCDEC_ENABLE_CHECK(isSourceAvailableInCustomSwitches);
|
||||
}
|
||||
else {
|
||||
INCDEC_SET_FLAG(EE_MODEL);
|
||||
INCDEC_ENABLE_CHECK(NULL);
|
||||
}
|
||||
LcdFlags lf = attr2 | LEFT;
|
||||
getMixSrcRange(v1_val, v2_min, v2_max, &lf);
|
||||
drawSourceCustomValue(CSW_3RD_COLUMN, y, v1_val, (v1_val <= MIXSRC_LAST_CH ? calc100toRESX(cs->v2) : cs->v2), lf);
|
||||
}
|
||||
|
||||
// CSW AND switch
|
||||
drawSwitch(CSW_4TH_COLUMN, y, cs->andsw, menuHorizontalPosition==LS_FIELD_ANDSW ? attr : 0);
|
||||
|
||||
// CSW duration
|
||||
if (cs->duration > 0)
|
||||
lcdDrawNumber(CSW_5TH_COLUMN, y, cs->duration, (menuHorizontalPosition==LS_FIELD_DURATION ? attr : 0)|PREC1|LEFT);
|
||||
else
|
||||
lcdDrawMMM(CSW_5TH_COLUMN, y, menuHorizontalPosition==LS_FIELD_DURATION ? attr : 0);
|
||||
|
||||
// CSW delay
|
||||
if (cstate == LS_FAMILY_EDGE) {
|
||||
lcdDrawText(CSW_6TH_COLUMN, y, STR_NA);
|
||||
}
|
||||
else if (cs->delay > 0) {
|
||||
lcdDrawNumber(CSW_6TH_COLUMN, y, cs->delay, (menuHorizontalPosition==LS_FIELD_DELAY ? attr : 0)|PREC1|LEFT);
|
||||
}
|
||||
else {
|
||||
lcdDrawMMM(CSW_6TH_COLUMN, y, menuHorizontalPosition==LS_FIELD_DELAY ? attr : 0);
|
||||
}
|
||||
|
||||
if (s_editMode>0 && attr) {
|
||||
switch (menuHorizontalPosition) {
|
||||
case LS_FIELD_FUNCTION:
|
||||
{
|
||||
cs->func = checkIncDec(event, cs->func, 0, LS_FUNC_MAX, EE_MODEL, isLogicalSwitchFunctionAvailable);
|
||||
uint8_t new_cstate = lswFamily(cs->func);
|
||||
if (cstate != new_cstate) {
|
||||
unsigned int save_func = cs->func;
|
||||
memset(cs, 0, sizeof(LogicalSwitchData));
|
||||
cs->func = save_func;
|
||||
if (new_cstate == LS_FAMILY_TIMER) {
|
||||
cs->v1 = cs->v2 = -119;
|
||||
}
|
||||
else if (new_cstate == LS_FAMILY_EDGE) {
|
||||
cs->v2 = -129;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case LS_FIELD_V1:
|
||||
cs->v1 = CHECK_INCDEC_PARAM(event, v1_val, v1_min, v1_max);
|
||||
break;
|
||||
case LS_FIELD_V2:
|
||||
cs->v2 = CHECK_INCDEC_PARAM(event, cs->v2, v2_min, v2_max);
|
||||
if (cstate==LS_FAMILY_OFS && cs->v1!=0 && event==EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
getvalue_t x = getValue(v1_val);
|
||||
if (v1_val <= MIXSRC_LAST_CH)
|
||||
cs->v2 = calcRESXto100(x);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
break;
|
||||
case LS_FIELD_V3:
|
||||
cs->v3 = CHECK_INCDEC_PARAM(event, cs->v3, v3_min, v3_max);
|
||||
break;
|
||||
case LS_FIELD_ANDSW:
|
||||
INCDEC_SET_FLAG(EE_MODEL | INCDEC_SWITCH);
|
||||
INCDEC_ENABLE_CHECK(isSwitchAvailableInLogicalSwitches);
|
||||
cs->andsw = CHECK_INCDEC_PARAM(event, cs->andsw, -MAX_LS_ANDSW, MAX_LS_ANDSW);
|
||||
break;
|
||||
case LS_FIELD_DURATION:
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, cs->duration, MAX_LS_DURATION);
|
||||
break;
|
||||
case LS_FIELD_DELAY:
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, cs->delay, MAX_LS_DELAY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,624 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void displayMixStatus(uint8_t channel);
|
||||
|
||||
int getMixesLinesCount()
|
||||
{
|
||||
int lastch = -1;
|
||||
uint8_t count = MAX_OUTPUT_CHANNELS;
|
||||
for (int i=0; i<MAX_MIXERS; i++) {
|
||||
bool valid = mixAddress(i)->srcRaw;
|
||||
if (!valid)
|
||||
break;
|
||||
int ch = mixAddress(i)->destCh;
|
||||
if (ch == lastch) {
|
||||
count++;
|
||||
}
|
||||
else {
|
||||
lastch = ch;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
uint8_t getMixesCount()
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint8_t ch ;
|
||||
|
||||
for (int i=MAX_MIXERS-1; i>=0; i--) {
|
||||
ch = mixAddress(i)->srcRaw;
|
||||
if (ch != 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
bool reachMixesLimit()
|
||||
{
|
||||
if (getMixesCount() >= MAX_MIXERS) {
|
||||
POPUP_WARNING(STR_NOFREEMIXER);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void deleteMix(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
MixData * mix = mixAddress(idx);
|
||||
memmove(mix, mix+1, (MAX_MIXERS-(idx+1))*sizeof(MixData));
|
||||
memclear(&g_model.mixData[MAX_MIXERS-1], sizeof(MixData));
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
void insertMix(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
MixData * mix = mixAddress(idx);
|
||||
memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData));
|
||||
memclear(mix, sizeof(MixData));
|
||||
mix->destCh = s_currCh-1;
|
||||
mix->srcRaw = s_currCh;
|
||||
if (!isSourceAvailable(mix->srcRaw)) {
|
||||
mix->srcRaw = (s_currCh > 4 ? MIXSRC_Rud - 1 + s_currCh : MIXSRC_Rud - 1 + channelOrder(s_currCh));
|
||||
while (!isSourceAvailable(mix->srcRaw)) {
|
||||
mix->srcRaw += 1;
|
||||
}
|
||||
}
|
||||
mix->weight = 100;
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
void copyMix(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
MixData * mix = mixAddress(idx);
|
||||
memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData));
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
bool swapMixes(uint8_t & idx, uint8_t up)
|
||||
{
|
||||
MixData * x, * y;
|
||||
int8_t tgt_idx = (up ? idx-1 : idx+1);
|
||||
|
||||
x = mixAddress(idx);
|
||||
|
||||
if (tgt_idx < 0) {
|
||||
if (x->destCh == 0)
|
||||
return false;
|
||||
x->destCh--;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tgt_idx == MAX_MIXERS) {
|
||||
if (x->destCh == MAX_OUTPUT_CHANNELS-1)
|
||||
return false;
|
||||
x->destCh++;
|
||||
return true;
|
||||
}
|
||||
|
||||
y = mixAddress(tgt_idx);
|
||||
uint8_t destCh = x->destCh;
|
||||
if(!y->srcRaw || destCh != y->destCh) {
|
||||
if (up) {
|
||||
if (destCh>0) x->destCh--;
|
||||
else return false;
|
||||
}
|
||||
else {
|
||||
if (destCh<MAX_OUTPUT_CHANNELS-1) x->destCh++;
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
pauseMixerCalculations();
|
||||
memswap(x, y, sizeof(MixData));
|
||||
resumeMixerCalculations();
|
||||
|
||||
idx = tgt_idx;
|
||||
return true;
|
||||
}
|
||||
|
||||
enum MixFields {
|
||||
MIX_FIELD_NAME,
|
||||
MIX_FIELD_SOURCE,
|
||||
MIX_FIELD_WEIGHT,
|
||||
MIX_FIELD_OFFSET,
|
||||
MIX_FIELD_TRIM,
|
||||
MIX_FIELD_CURVE,
|
||||
CASE_FLIGHT_MODES(MIX_FIELD_FLIGHT_MODE)
|
||||
MIX_FIELD_SWITCH,
|
||||
MIX_FIELD_WARNING,
|
||||
MIX_FIELD_MLTPX,
|
||||
MIX_FIELD_DELAY_UP,
|
||||
MIX_FIELD_DELAY_DOWN,
|
||||
MIX_FIELD_SLOW_UP,
|
||||
MIX_FIELD_SLOW_DOWN,
|
||||
MIX_FIELD_COUNT
|
||||
};
|
||||
|
||||
void gvarWeightItem(coord_t x, coord_t y, MixData *md, LcdFlags attr, event_t event)
|
||||
{
|
||||
u_int8int16_t weight;
|
||||
MD_WEIGHT_TO_UNION(md, weight);
|
||||
weight.word = GVAR_MENU_ITEM(x, y, weight.word, GV_RANGELARGE_WEIGHT_NEG, GV_RANGELARGE_WEIGHT, attr, 0, event);
|
||||
MD_UNION_TO_WEIGHT(weight, md);
|
||||
}
|
||||
|
||||
bool menuModelMixOne(event_t event)
|
||||
{
|
||||
MixData * md2 = mixAddress(s_currIdx) ;
|
||||
|
||||
SUBMENU_WITH_OPTIONS(STR_MIXER, ICON_MODEL_MIXER, MIX_FIELD_COUNT, OPTION_MENU_NO_SCROLLBAR, { 0, 0, 0, 0, 0, 1, CASE_FLIGHT_MODES((MAX_FLIGHT_MODES-1) | NAVIGATION_LINE_BY_LINE) 0 /*, ...*/ });
|
||||
putsChn(50, 3+FH, md2->destCh+1, MENU_TITLE_COLOR);
|
||||
displayMixStatus(md2->destCh);
|
||||
|
||||
// The separation line between 2 columns
|
||||
lcdDrawSolidVerticalLine(MENU_COLUMN2_X-10, DEFAULT_SCROLLBAR_Y-FH, DEFAULT_SCROLLBAR_H+5, TEXT_COLOR);
|
||||
|
||||
int8_t sub = menuVerticalPosition;
|
||||
int8_t editMode = s_editMode;
|
||||
|
||||
for (int k=0; k<2*NUM_BODY_LINES; k++) {
|
||||
coord_t y;
|
||||
if (k > NUM_BODY_LINES) {
|
||||
y = MENU_CONTENT_TOP - FH + (k-NUM_BODY_LINES)*FH;
|
||||
}
|
||||
else {
|
||||
y = MENU_CONTENT_TOP - FH + k*FH;
|
||||
}
|
||||
int8_t i = k;
|
||||
|
||||
LcdFlags attr = (sub==i ? (editMode>0 ? BLINK|INVERS : INVERS) : 0);
|
||||
switch(i) {
|
||||
case MIX_FIELD_NAME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MIXNAME);
|
||||
editName(MIXES_2ND_COLUMN, y, md2->name, sizeof(md2->name), event, attr);
|
||||
break;
|
||||
case MIX_FIELD_SOURCE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SOURCE);
|
||||
drawSource(MIXES_2ND_COLUMN, y, md2->srcRaw, attr);
|
||||
if (attr) CHECK_INCDEC_MODELSOURCE(event, md2->srcRaw, 1, MIXSRC_LAST);
|
||||
break;
|
||||
case MIX_FIELD_WEIGHT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_WEIGHT);
|
||||
gvarWeightItem(MIXES_2ND_COLUMN, y, md2, attr|LEFT, event);
|
||||
break;
|
||||
case MIX_FIELD_OFFSET:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_OFFSET);
|
||||
u_int8int16_t offset;
|
||||
MD_OFFSET_TO_UNION(md2, offset);
|
||||
offset.word = GVAR_MENU_ITEM(MIXES_2ND_COLUMN, y, offset.word, GV_RANGELARGE_OFFSET_NEG, GV_RANGELARGE_OFFSET, attr|LEFT, 0, event);
|
||||
MD_UNION_TO_OFFSET(offset, md2);
|
||||
#if 0
|
||||
drawOffsetBar(x+MIXES_2ND_COLUMN+22, y, md2);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case MIX_FIELD_TRIM:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TRIM);
|
||||
drawCheckBox(MIXES_2ND_COLUMN, y, !md2->carryTrim, attr);
|
||||
if (attr) md2->carryTrim = !checkIncDecModel(event, !md2->carryTrim, 0, 1);
|
||||
break;
|
||||
case MIX_FIELD_CURVE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_CURVE);
|
||||
editCurveRef(MIXES_2ND_COLUMN, y, md2->curve, event, attr);
|
||||
break;
|
||||
#if defined(FLIGHT_MODES)
|
||||
case MIX_FIELD_FLIGHT_MODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_FLMODE);
|
||||
md2->flightModes = editFlightModes(MIXES_2ND_COLUMN, y, event, md2->flightModes, attr);
|
||||
break;
|
||||
#endif
|
||||
case MIX_FIELD_SWITCH:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SWITCH);
|
||||
md2->swtch = editSwitch(MIXES_2ND_COLUMN, y, md2->swtch, attr, event);
|
||||
break;
|
||||
case MIX_FIELD_WARNING:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MIXWARNING);
|
||||
if (md2->mixWarn) {
|
||||
lcdDrawNumber(MIXES_2ND_COLUMN, y, md2->mixWarn, attr|LEFT);
|
||||
}
|
||||
else {
|
||||
lcdDrawText(MIXES_2ND_COLUMN, y, STR_OFF, attr);
|
||||
}
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, md2->mixWarn, 3);
|
||||
}
|
||||
break;
|
||||
case MIX_FIELD_MLTPX:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MULTPX);
|
||||
md2->mltpx = editChoice(MIXES_2ND_COLUMN, y, STR_VMLTPX, md2->mltpx, 0, 2, attr, event);
|
||||
break;
|
||||
case MIX_FIELD_DELAY_UP:
|
||||
lcdDrawText(MENU_COLUMN2_X+MENUS_MARGIN_LEFT, y, STR_DELAYUP);
|
||||
md2->delayUp = editDelay(MENU_COLUMN2_X, y, event, attr, md2->delayUp);
|
||||
break;
|
||||
case MIX_FIELD_DELAY_DOWN:
|
||||
lcdDrawText(MENU_COLUMN2_X+MENUS_MARGIN_LEFT, y, STR_DELAYDOWN);
|
||||
md2->delayDown = editDelay(MENU_COLUMN2_X, y, event, attr, md2->delayDown);
|
||||
break;
|
||||
case MIX_FIELD_SLOW_UP:
|
||||
lcdDrawText(MENU_COLUMN2_X+MENUS_MARGIN_LEFT, y, STR_SLOWUP);
|
||||
md2->speedUp = editDelay(MENU_COLUMN2_X, y, event, attr, md2->speedUp);
|
||||
break;
|
||||
case MIX_FIELD_SLOW_DOWN:
|
||||
lcdDrawText(MENU_COLUMN2_X+MENUS_MARGIN_LEFT, y, STR_SLOWDOWN);
|
||||
md2->speedDown = editDelay(MENU_COLUMN2_X, y, event, attr, md2->speedDown);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define _STR_MAX(x) "/" #x
|
||||
#define STR_MAX(x) _STR_MAX(x)
|
||||
|
||||
#define MIX_LINE_WEIGHT_POS 105
|
||||
#define MIX_LINE_SRC_POS 120
|
||||
#define MIX_LINE_CURVE_ICON 175
|
||||
#define MIX_LINE_CURVE_POS 195
|
||||
#define MIX_LINE_SWITCH_ICON 260
|
||||
#define MIX_LINE_SWITCH_POS 280
|
||||
#define MIX_LINE_DELAY_SLOW_POS 340
|
||||
#define MIX_LINE_NAME_FM_ICON 370
|
||||
#define MIX_LINE_NAME_FM_POS 390
|
||||
#define MIX_LINE_SELECT_POS 50
|
||||
#define MIX_LINE_SELECT_WIDTH (LCD_W-MIX_LINE_SELECT_POS-15)
|
||||
#define MIX_STATUS_BAR_W 130
|
||||
#define MIX_STATUS_BAR_H 13
|
||||
#define MIX_STATUS_CHAN_BAR MENUS_MARGIN_LEFT + 45
|
||||
#define MIX_STATUS_ICON_MIXER MIX_STATUS_CHAN_BAR + 140
|
||||
#define MIX_STATUS_ICON_TO MIX_STATUS_ICON_MIXER + 20
|
||||
#define MIX_STATUS_ICON_OUTPUT MIX_STATUS_ICON_TO + 35
|
||||
#define MIX_STATUS_OUT_NAME MIX_STATUS_ICON_OUTPUT + 25
|
||||
#define MIX_STATUS_OUT_BAR LCD_W - MENUS_MARGIN_LEFT - MIX_STATUS_BAR_W
|
||||
|
||||
void lineMixSurround(coord_t y, LcdFlags flags=CURVE_AXIS_COLOR)
|
||||
{
|
||||
lcdDrawRect(MIX_LINE_SELECT_POS, y-INVERT_VERT_MARGIN+1, MIX_LINE_SELECT_WIDTH, INVERT_LINE_HEIGHT, 1, s_copyMode == COPY_MODE ? SOLID : DOTTED, flags);
|
||||
}
|
||||
|
||||
void onMixesMenu(const char * result)
|
||||
{
|
||||
uint8_t chn = mixAddress(s_currIdx)->destCh + 1;
|
||||
|
||||
if (result == STR_EDIT) {
|
||||
pushMenu(menuModelMixOne);
|
||||
}
|
||||
else if (result == STR_INSERT_BEFORE || result == STR_INSERT_AFTER) {
|
||||
if (!reachMixesLimit()) {
|
||||
s_currCh = chn;
|
||||
if (result == STR_INSERT_AFTER) { s_currIdx++; menuVerticalPosition++; }
|
||||
insertMix(s_currIdx);
|
||||
pushMenu(menuModelMixOne);
|
||||
}
|
||||
}
|
||||
else if (result == STR_COPY || result == STR_MOVE) {
|
||||
s_copyMode = (result == STR_COPY ? COPY_MODE : MOVE_MODE);
|
||||
s_copySrcIdx = s_currIdx;
|
||||
s_copySrcCh = chn;
|
||||
s_copySrcRow = menuVerticalPosition;
|
||||
}
|
||||
else if (result == STR_DELETE) {
|
||||
deleteMix(s_currIdx);
|
||||
}
|
||||
}
|
||||
|
||||
void displayMixInfos(coord_t y, MixData *md)
|
||||
{
|
||||
if (md->curve.value != 0 ) lcd->drawBitmap(MIX_LINE_CURVE_ICON, y + 2, mixerSetupCurveBitmap);
|
||||
drawCurveRef(MIX_LINE_CURVE_POS, y, md->curve);
|
||||
|
||||
if (md->swtch) {
|
||||
lcd->drawBitmap(MIX_LINE_SWITCH_ICON, y + 2, mixerSetupSwitchBitmap);
|
||||
drawSwitch(MIX_LINE_SWITCH_POS, y, md->swtch);
|
||||
}
|
||||
}
|
||||
|
||||
void displayMixSmallFlightModes(coord_t x, coord_t y, FlightModesType value)
|
||||
{
|
||||
for (int i=0; i<MAX_FLIGHT_MODES; i++) {
|
||||
char s[] = " ";
|
||||
s[0] = '0' + i;
|
||||
if (value & (1<<i)) lcd->drawFilledRect(x, y+2, 8, 12 , SOLID, CURVE_AXIS_COLOR);
|
||||
lcdDrawText(x, y, s, SMLSIZE);
|
||||
x += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void displayMixLine(coord_t y, MixData *md)
|
||||
{
|
||||
if (md->name[0] && md->flightModes) {
|
||||
if (SLOW_BLINK_ON_PHASE) {
|
||||
lcd->drawBitmap(MIX_LINE_NAME_FM_ICON, y + 2, mixerSetupFlightmodeBitmap);
|
||||
displayMixSmallFlightModes(MIX_LINE_NAME_FM_POS, y + 2, md->flightModes);
|
||||
}
|
||||
else {
|
||||
lcd->drawBitmap(MIX_LINE_NAME_FM_ICON, y + 2, mixerSetupLabelBitmap);
|
||||
lcdDrawSizedText(MIX_LINE_NAME_FM_POS, y, md->name, sizeof(md->name), ZCHAR);
|
||||
}
|
||||
}
|
||||
else if (md->name[0]) {
|
||||
lcd->drawBitmap(MIX_LINE_NAME_FM_ICON, y + 2, mixerSetupLabelBitmap);
|
||||
lcdDrawSizedText(MIX_LINE_NAME_FM_POS, y, md->name, sizeof(md->name), ZCHAR);
|
||||
}
|
||||
else if (md->flightModes) {
|
||||
lcd->drawBitmap(MIX_LINE_NAME_FM_ICON, y + 2, mixerSetupFlightmodeBitmap);
|
||||
displayMixSmallFlightModes(MIX_LINE_NAME_FM_POS, y + 2, md->flightModes);
|
||||
}
|
||||
displayMixInfos(y, md);
|
||||
}
|
||||
|
||||
void displayMixStatus(uint8_t channel)
|
||||
{
|
||||
lcdDrawNumber(MENUS_MARGIN_LEFT, MENU_FOOTER_TOP, channel + 1, MENU_TITLE_COLOR, 0, "CH", NULL);
|
||||
drawSingleMixerBar(MIX_STATUS_CHAN_BAR, MENU_FOOTER_TOP + 4, MIX_STATUS_BAR_W, MIX_STATUS_BAR_H, channel);
|
||||
|
||||
lcd->drawBitmap(MIX_STATUS_ICON_MIXER, MENU_FOOTER_TOP, mixerSetupMixerBitmap);
|
||||
lcd->drawBitmap(MIX_STATUS_ICON_TO, MENU_FOOTER_TOP, mixerSetupToBitmap);
|
||||
lcd->drawBitmap(MIX_STATUS_ICON_OUTPUT, MENU_FOOTER_TOP, mixerSetupOutputBitmap);
|
||||
|
||||
if (g_model.limitData[channel].name[0] == '\0')
|
||||
lcdDrawNumber(MIX_STATUS_OUT_NAME, MENU_FOOTER_TOP, channel + 1, MENU_TITLE_COLOR, 0, "CH", NULL);
|
||||
else
|
||||
lcdDrawSizedText(MIX_STATUS_OUT_NAME, MENU_FOOTER_TOP, g_model.limitData[channel].name, sizeof(g_model.limitData[channel].name), MENU_TITLE_COLOR | LEFT | ZCHAR);
|
||||
drawSingleOutputBar(MIX_STATUS_OUT_BAR, MENU_FOOTER_TOP + 4, MIX_STATUS_BAR_W, MIX_STATUS_BAR_H, channel);
|
||||
}
|
||||
|
||||
bool menuModelMixAll(event_t event)
|
||||
{
|
||||
const BitmapBuffer * mpx_mode[] = {
|
||||
mixerSetupAddBitmap,
|
||||
mixerSetupMultiBitmap,
|
||||
mixerSetupReplaceBitmap
|
||||
};
|
||||
|
||||
|
||||
uint8_t sub = menuVerticalPosition;
|
||||
|
||||
if (s_editMode > 0) {
|
||||
s_editMode = 0;
|
||||
}
|
||||
|
||||
uint8_t chn = mixAddress(s_currIdx)->destCh + 1;
|
||||
|
||||
int linesCount = getMixesLinesCount();
|
||||
SIMPLE_MENU(STR_MIXER, MODEL_ICONS, menuTabModel, MENU_MODEL_MIXES, linesCount);
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
case EVT_ENTRY_UP:
|
||||
s_copyMode = 0;
|
||||
s_copyTgtOfs = 0;
|
||||
break;
|
||||
case EVT_KEY_LONG(KEY_EXIT):
|
||||
if (s_copyMode && s_copyTgtOfs == 0) {
|
||||
deleteMix(s_currIdx);
|
||||
killEvents(event);
|
||||
event = 0;
|
||||
}
|
||||
// no break
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
if (s_copyMode) {
|
||||
if (s_copyTgtOfs) {
|
||||
// cancel the current copy / move operation
|
||||
if (s_copyMode == COPY_MODE) {
|
||||
deleteMix(s_currIdx);
|
||||
}
|
||||
else {
|
||||
do {
|
||||
swapMixes(s_currIdx, s_copyTgtOfs > 0);
|
||||
s_copyTgtOfs += (s_copyTgtOfs < 0 ? +1 : -1);
|
||||
} while (s_copyTgtOfs != 0);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
menuVerticalPosition = s_copySrcRow;
|
||||
s_copyTgtOfs = 0;
|
||||
}
|
||||
s_copyMode = 0;
|
||||
event = 0;
|
||||
}
|
||||
break;
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if ((!s_currCh || (s_copyMode && !s_copyTgtOfs)) && !READ_ONLY()) {
|
||||
s_copyMode = (s_copyMode == COPY_MODE ? MOVE_MODE : COPY_MODE);
|
||||
s_copySrcIdx = s_currIdx;
|
||||
s_copySrcCh = chn;
|
||||
s_copySrcRow = sub;
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
killEvents(event);
|
||||
if (s_copyTgtOfs) {
|
||||
s_copyMode = 0;
|
||||
s_copyTgtOfs = 0;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
if (READ_ONLY()) {
|
||||
if (!s_currCh) {
|
||||
pushMenu(menuModelMixOne);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (s_copyMode) s_currCh = 0;
|
||||
if (s_currCh) {
|
||||
if (reachMixesLimit()) break;
|
||||
insertMix(s_currIdx);
|
||||
pushMenu(menuModelMixOne);
|
||||
s_copyMode = 0;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
event = 0;
|
||||
s_copyMode = 0;
|
||||
POPUP_MENU_ADD_ITEM(STR_EDIT);
|
||||
POPUP_MENU_ADD_ITEM(STR_INSERT_BEFORE);
|
||||
POPUP_MENU_ADD_ITEM(STR_INSERT_AFTER);
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY);
|
||||
POPUP_MENU_ADD_ITEM(STR_MOVE);
|
||||
POPUP_MENU_ADD_ITEM(STR_DELETE);
|
||||
POPUP_MENU_START(onMixesMenu);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
case EVT_ROTARY_LEFT:
|
||||
if (s_copyMode) {
|
||||
uint8_t next_ofs = (event==EVT_ROTARY_LEFT ? s_copyTgtOfs - 1 : s_copyTgtOfs + 1);
|
||||
|
||||
if (s_copyTgtOfs==0 && s_copyMode==COPY_MODE) {
|
||||
// insert a mix on the same channel (just above / just below)
|
||||
if (reachMixesLimit()) break;
|
||||
copyMix(s_currIdx);
|
||||
if (event==EVT_ROTARY_RIGHT) s_currIdx++;
|
||||
else if (sub-menuVerticalOffset >= 6) menuVerticalOffset++;
|
||||
}
|
||||
else if (next_ofs==0 && s_copyMode==COPY_MODE) {
|
||||
// delete the mix
|
||||
deleteMix(s_currIdx);
|
||||
if (event==EVT_ROTARY_LEFT) s_currIdx--;
|
||||
}
|
||||
else {
|
||||
// only swap the mix with its neighbor
|
||||
if (!swapMixes(s_currIdx, event==EVT_ROTARY_LEFT)) break;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
s_copyTgtOfs = next_ofs;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
char str[6];
|
||||
strAppendUnsigned(strAppend(strAppendUnsigned(str, getMixesCount()), "/"), MAX_MIXERS, 2);
|
||||
lcdDrawText(MENU_TITLE_NEXT_POS, MENU_TITLE_TOP+1, str, HEADER_COLOR);
|
||||
|
||||
sub = menuVerticalPosition;
|
||||
s_currCh = 0;
|
||||
int cur = 0;
|
||||
int i = 0;
|
||||
|
||||
for (int ch=1; ch<=MAX_OUTPUT_CHANNELS; ch++) {
|
||||
MixData * md;
|
||||
coord_t y = MENU_CONTENT_TOP + (cur-menuVerticalOffset)*FH;
|
||||
if (i<MAX_MIXERS && (md=mixAddress(i))->srcRaw && md->destCh+1 == ch) {
|
||||
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
||||
putsChn(MENUS_MARGIN_LEFT, y, ch, 0); // show CHx
|
||||
}
|
||||
uint8_t mixCnt = 0;
|
||||
do {
|
||||
if (s_copyMode) {
|
||||
if (s_copyMode == MOVE_MODE && cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES && s_copySrcCh == ch && s_copyTgtOfs != 0 && i == (s_copySrcIdx + (s_copyTgtOfs<0))) {
|
||||
lineMixSurround(y);
|
||||
cur++; y+=FH;
|
||||
}
|
||||
if (s_currIdx == i) {
|
||||
sub = menuVerticalPosition = cur;
|
||||
s_currCh = ch;
|
||||
}
|
||||
}
|
||||
else if (sub == cur) {
|
||||
s_currIdx = i;
|
||||
displayMixStatus(ch - 1);
|
||||
}
|
||||
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
||||
LcdFlags attr = ((s_copyMode || sub != cur) ? 0 : INVERS);
|
||||
|
||||
if (mixCnt > 0) {
|
||||
lcd->drawBitmap(10, y, mpx_mode[md->mltpx]);
|
||||
}
|
||||
|
||||
drawSource(MIX_LINE_SRC_POS, y, md->srcRaw);
|
||||
|
||||
if (mixCnt == 0 && md->mltpx == 1)
|
||||
lcdDrawText(MIX_LINE_WEIGHT_POS, y, "MULT!", RIGHT | attr | (isMixActive(i) ? BOLD : 0));
|
||||
else
|
||||
gvarWeightItem(MIX_LINE_WEIGHT_POS, y, md, RIGHT | attr | (isMixActive(i) ? BOLD : 0), event);
|
||||
|
||||
displayMixLine(y, md);
|
||||
|
||||
BitmapBuffer *delayslowbmp[] = {mixerSetupSlowBitmap, mixerSetupDelayBitmap, mixerSetupDelaySlowBitmap};
|
||||
uint8_t delayslow = 0;
|
||||
if (md->speedDown || md->speedUp)
|
||||
delayslow = 1;
|
||||
if (md->delayUp || md->delayDown)
|
||||
delayslow += 2;
|
||||
if (delayslow)
|
||||
lcd->drawBitmap(MIX_LINE_DELAY_SLOW_POS, y + 2, delayslowbmp[delayslow - 1]);
|
||||
|
||||
if (s_copyMode) {
|
||||
if ((s_copyMode==COPY_MODE || s_copyTgtOfs == 0) && s_copySrcCh == ch && i == (s_copySrcIdx + (s_copyTgtOfs<0))) {
|
||||
/* draw a border around the raw on selection mode (copy/move) */
|
||||
lineMixSurround(y);
|
||||
}
|
||||
if (cur == sub) {
|
||||
/* invert the raw when it's the current one */
|
||||
lineMixSurround(y, ALARM_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
cur++; y+=FH; mixCnt++; i++; md++;
|
||||
} while (i<MAX_MIXERS && md->srcRaw && md->destCh+1 == ch);
|
||||
if (s_copyMode == MOVE_MODE && cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES && s_copySrcCh == ch && i == (s_copySrcIdx + (s_copyTgtOfs<0))) {
|
||||
lineMixSurround(y);
|
||||
cur++; y+=FH;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uint8_t attr = 0;
|
||||
if (sub == cur) {
|
||||
s_currIdx = i;
|
||||
s_currCh = ch;
|
||||
if (!s_copyMode) {
|
||||
attr = INVERS;
|
||||
}
|
||||
}
|
||||
if (cur-menuVerticalOffset >= 0 && cur-menuVerticalOffset < NUM_BODY_LINES) {
|
||||
putsChn(MENUS_MARGIN_LEFT, y, ch, attr); // show CHx
|
||||
if (s_copyMode == MOVE_MODE && s_copySrcCh == ch) {
|
||||
lineMixSurround(y);
|
||||
}
|
||||
}
|
||||
cur++; y+=FH;
|
||||
}
|
||||
}
|
||||
|
||||
if (sub >= linesCount-1) menuVerticalPosition = linesCount-1;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include <math.h>
|
||||
|
||||
#define RECEIVER_OPTIONS_2ND_COLUMN 200
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
enum {
|
||||
MODULE_SETTINGS_OK = 0,
|
||||
MODULE_SETTINGS_DIRTY = 1,
|
||||
MODULE_SETTINGS_REBIND = 2,
|
||||
MODULE_SETTINGS_WRITING = 4,
|
||||
};
|
||||
|
||||
void onTxOptionsUpdateConfirm(const char * result)
|
||||
{
|
||||
if (result == STR_OK) {
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.dirty = MODULE_SETTINGS_WRITING;
|
||||
moduleState[g_moduleIdx].writeModuleSettings(&reusableBuffer.hardwareAndSettings.moduleSettings);
|
||||
}
|
||||
else {
|
||||
popMenu();
|
||||
}
|
||||
}
|
||||
|
||||
bool isTelemetryAvailable()
|
||||
{
|
||||
return reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].information.variant != PXX2_VARIANT_EU ||
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.txPower <= 14;
|
||||
}
|
||||
|
||||
enum {
|
||||
ITEM_MODULE_SETTINGS_EXTERNAL_ANTENNA,
|
||||
ITEM_MODULE_SETTINGS_POWER,
|
||||
ITEM_MODULE_SETTINGS_TELEMETRY,
|
||||
ITEM_MODULE_SETTINGS_COUNT
|
||||
};
|
||||
|
||||
#define IF_MODULE_OPTIONS(option, count) uint8_t(isPXX2ModuleOptionAvailable(modelId, option) ? count : HIDDEN_ROW)
|
||||
|
||||
bool isPowerAvailable(int value)
|
||||
{
|
||||
uint8_t modelId = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].information.modelID;
|
||||
uint8_t variant = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].information.variant;
|
||||
|
||||
if (modelId == PXX2_MODULE_R9M_LITE) {
|
||||
if (variant == PXX2_VARIANT_EU)
|
||||
return (value == 14 /* 25 mW with telemetry */ ||
|
||||
value == 20 /* 100 mW without telemetry */);
|
||||
else
|
||||
return value == 20; /* 100 mW */
|
||||
}
|
||||
else if (modelId == PXX2_MODULE_R9M || modelId == PXX2_MODULE_R9M_LITE_PRO) {
|
||||
if (variant == PXX2_VARIANT_EU)
|
||||
return (value == 14 /* 25 mW */ ||
|
||||
value == 23 /* 200 mW */ ||
|
||||
value == 27 /* 500 mW */);
|
||||
else
|
||||
return (value == 10 /* 10 mW */ ||
|
||||
value == 20 /* 100 mW */ ||
|
||||
value == 27 /* 500 mW */ ||
|
||||
value == 30 /* 1000 mW */);
|
||||
}
|
||||
else {
|
||||
return (value <= 20); /* 100 mW max for XJTs */
|
||||
}
|
||||
}
|
||||
|
||||
bool menuModelModuleOptions(event_t event)
|
||||
{
|
||||
if (event == EVT_ENTRY) {
|
||||
memclear(&reusableBuffer.hardwareAndSettings, sizeof(reusableBuffer.hardwareAndSettings));
|
||||
#if defined(SIMU)
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.state = PXX2_SETTINGS_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t modelId = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].information.modelID;
|
||||
// uint8_t variant = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].information.variant;
|
||||
uint8_t optionsAvailable = getPXX2ModuleOptions(modelId) & ((1 << MODULE_OPTION_EXTERNAL_ANTENNA) | (1 << MODULE_OPTION_POWER));
|
||||
|
||||
SUBMENU(STR_MODULE_OPTIONS, ICON_MODEL_SETUP, ITEM_MODULE_SETTINGS_COUNT, {
|
||||
!optionsAvailable ? (uint8_t)0 : IF_MODULE_OPTIONS(MODULE_OPTION_EXTERNAL_ANTENNA, 0),
|
||||
IF_MODULE_OPTIONS(MODULE_OPTION_POWER, 0),
|
||||
IF_MODULE_OPTIONS(MODULE_OPTION_POWER, isTelemetryAvailable() ? HIDDEN_ROW : READONLY_ROW)
|
||||
});
|
||||
|
||||
lcdDrawText(50, 3 + FH, getPXX2ModuleName(modelId), MENU_TITLE_COLOR);
|
||||
|
||||
if (reusableBuffer.hardwareAndSettings.moduleSettings.state == PXX2_HARDWARE_INFO && moduleState[g_moduleIdx].mode == MODULE_MODE_NORMAL) {
|
||||
if (!modelId)
|
||||
moduleState[g_moduleIdx].readModuleInformation(&reusableBuffer.hardwareAndSettings.modules[g_moduleIdx], PXX2_HW_INFO_TX_ID, PXX2_HW_INFO_TX_ID);
|
||||
else
|
||||
moduleState[g_moduleIdx].readModuleSettings(&reusableBuffer.hardwareAndSettings.moduleSettings);
|
||||
}
|
||||
|
||||
if (menuEvent) {
|
||||
killEvents(KEY_EXIT);
|
||||
moduleState[g_moduleIdx].mode = MODULE_MODE_NORMAL;
|
||||
if (reusableBuffer.hardwareAndSettings.moduleSettings.dirty) {
|
||||
abortPopMenu();
|
||||
POPUP_CONFIRMATION(STR_UPDATE_TX_OPTIONS, onTxOptionsUpdateConfirm);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER) && reusableBuffer.hardwareAndSettings.moduleSettings.dirty) {
|
||||
killEvents(event);
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.dirty = MODULE_SETTINGS_OK;
|
||||
moduleState[g_moduleIdx].writeModuleSettings(&reusableBuffer.hardwareAndSettings.moduleSettings);
|
||||
}
|
||||
|
||||
if (reusableBuffer.hardwareAndSettings.moduleSettings.dirty == MODULE_SETTINGS_WRITING && reusableBuffer.hardwareAndSettings.moduleSettings.state == PXX2_SETTINGS_OK) {
|
||||
popMenu();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (modelId != 0 && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) {
|
||||
menuVerticalPosition = 0;
|
||||
while (menuVerticalPosition < ITEM_MODULE_SETTINGS_COUNT && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) {
|
||||
++menuVerticalPosition;
|
||||
}
|
||||
}
|
||||
|
||||
int8_t sub = menuVerticalPosition;
|
||||
|
||||
if (reusableBuffer.hardwareAndSettings.moduleSettings.state == PXX2_SETTINGS_OK) {
|
||||
if (optionsAvailable) {
|
||||
for (uint8_t k=0; k<NUM_BODY_LINES + 1/*plus one line in submenus*/; k++) {
|
||||
coord_t y = MENU_HEADER_HEIGHT + 1 + k*FH;
|
||||
uint8_t i = k + menuVerticalOffset;
|
||||
for (int j=0; j<=i; ++j) {
|
||||
if (j<(int)DIM(mstate_tab) && mstate_tab[j] == HIDDEN_ROW) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
LcdFlags attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
|
||||
|
||||
switch (i) {
|
||||
case ITEM_MODULE_SETTINGS_EXTERNAL_ANTENNA:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_EXT_ANTENNA);
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.externalAntenna = editCheckBox(reusableBuffer.hardwareAndSettings.moduleSettings.externalAntenna, RECEIVER_OPTIONS_2ND_COLUMN, y, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.dirty = MODULE_SETTINGS_DIRTY;
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_MODULE_SETTINGS_POWER:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_POWER);
|
||||
lcdDrawNumber(RECEIVER_OPTIONS_2ND_COLUMN, y, reusableBuffer.hardwareAndSettings.moduleSettings.txPower, attr);
|
||||
lcdDrawText(lcdNextPos, y, "dBm(");
|
||||
drawPower(lcdNextPos, y, reusableBuffer.hardwareAndSettings.moduleSettings.txPower);
|
||||
lcdDrawText(lcdNextPos, y, ")");
|
||||
if (attr) {
|
||||
bool previousTelemetry = isTelemetryAvailable();
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.txPower = checkIncDec(event, reusableBuffer.hardwareAndSettings.moduleSettings.txPower, 0, 30, 0, &isPowerAvailable);
|
||||
if (checkIncDec_Ret) {
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.dirty = MODULE_SETTINGS_DIRTY;
|
||||
if (previousTelemetry != isTelemetryAvailable()) {
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.dirty |= MODULE_SETTINGS_REBIND;
|
||||
}
|
||||
}
|
||||
if (s_editMode == 0 && (reusableBuffer.hardwareAndSettings.moduleSettings.dirty & MODULE_SETTINGS_REBIND)) {
|
||||
reusableBuffer.hardwareAndSettings.moduleSettings.dirty &= ~MODULE_SETTINGS_REBIND;
|
||||
POPUP_WARNING(STR_REBIND);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_MODULE_SETTINGS_TELEMETRY:
|
||||
// only displayed in EU mode when TX power > 25mW
|
||||
lcdDrawText(RECEIVER_OPTIONS_2ND_COLUMN, y, "Telem OFF", attr | SMLSIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_NO_TX_OPTIONS);
|
||||
s_editMode = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_WAITING_FOR_TX);
|
||||
s_editMode = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,230 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
enum LimitsItems {
|
||||
ITEM_LIMITS_CH_NAME,
|
||||
ITEM_LIMITS_OFFSET,
|
||||
ITEM_LIMITS_MIN,
|
||||
ITEM_LIMITS_MAX,
|
||||
ITEM_LIMITS_DIRECTION,
|
||||
ITEM_LIMITS_CURVE,
|
||||
#if defined(PPM_CENTER_ADJUSTABLE)
|
||||
ITEM_LIMITS_PPM_CENTER,
|
||||
#endif
|
||||
#if defined(PPM_LIMITS_SYMETRICAL)
|
||||
ITEM_LIMITS_SYMETRICAL,
|
||||
#endif
|
||||
ITEM_LIMITS_COUNT,
|
||||
ITEM_LIMITS_MAXROW = ITEM_LIMITS_COUNT-1
|
||||
};
|
||||
|
||||
#define LIMITS_NAME_POS 52
|
||||
#define LIMITS_OFFSET_POS 160
|
||||
#define LIMITS_MIN_POS 220
|
||||
#define LIMITS_DIRECTION_POS 235
|
||||
#define LIMITS_MAX_POS 300
|
||||
#define LIMITS_REVERT_POS 312
|
||||
#define LIMITS_CURVE_POS 340
|
||||
#define LIMITS_PPM_CENTER_POS 440
|
||||
#define LIMITS_SYMETRICAL_POS 450
|
||||
|
||||
#define LIMITS_MIN_MAX_OFFSET 1000
|
||||
#define CONVERT_US_MIN_MAX(x) (((x)*1280)/250)
|
||||
|
||||
#if defined(PPM_UNIT_US)
|
||||
#define SET_MIN_MAX(x, val) x = ((val)*250)/128
|
||||
#define MIN_MAX_DISPLAY(x) CONVERT_US_MIN_MAX(x)
|
||||
#else
|
||||
#define MIN_MAX_DISPLAY(x) (x)
|
||||
#define SET_MIN_MAX(x, val) x = (val)
|
||||
#endif
|
||||
|
||||
void onLimitsMenu(const char *result)
|
||||
{
|
||||
uint8_t ch = menuVerticalPosition;
|
||||
|
||||
if (result == STR_RESET) {
|
||||
LimitData *ld = limitAddress(ch);
|
||||
ld->min = 0;
|
||||
ld->max = 0;
|
||||
ld->offset = 0;
|
||||
ld->ppmCenter = 0;
|
||||
ld->revert = false;
|
||||
ld->curve = 0;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_COPY_STICKS_TO_OFS) {
|
||||
copySticksToOffset(ch);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_COPY_TRIMS_TO_OFS) {
|
||||
copyTrimsToOffset(ch);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
}
|
||||
|
||||
bool menuModelLimits(event_t event)
|
||||
{
|
||||
MENU(STR_MENULIMITS, MODEL_ICONS, menuTabModel, MENU_MODEL_OUTPUTS, MAX_OUTPUT_CHANNELS+1,
|
||||
{ NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW,
|
||||
NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW,
|
||||
NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW,
|
||||
NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW, NAVIGATION_LINE_BY_LINE|ITEM_LIMITS_MAXROW,
|
||||
0 });
|
||||
|
||||
uint32_t sub = menuVerticalPosition;
|
||||
|
||||
if (sub<MAX_OUTPUT_CHANNELS && menuHorizontalPosition>=0) {
|
||||
drawColumnHeader(STR_LIMITS_HEADERS, NULL, menuHorizontalPosition);
|
||||
}
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
uint8_t k = i+menuVerticalOffset;
|
||||
|
||||
if (k==MAX_OUTPUT_CHANNELS) {
|
||||
// last line available - add the "copy trim menu" line
|
||||
uint8_t attr = (sub==MAX_OUTPUT_CHANNELS) ? INVERS : 0;
|
||||
// TODO CENTER attribute
|
||||
lcdDrawText(100, y, STR_TRIMS2OFFSETS, NO_HIGHLIGHT() ? 0 : attr);
|
||||
if (attr) {
|
||||
s_editMode = 0;
|
||||
if (event==EVT_KEY_LONG(KEY_ENTER)) {
|
||||
START_NO_HIGHLIGHT();
|
||||
killEvents(event);
|
||||
moveTrimsToOffsets(); // if highlighted and menu pressed - move trims to offsets
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
LimitData *ld = limitAddress(k);
|
||||
|
||||
int16_t v = (ld->revert) ? -LIMIT_OFS(ld) : LIMIT_OFS(ld);
|
||||
char swVal[2] = "-"; // '-', '<', '>'
|
||||
if ((channelOutputs[k] - v) > 50) swVal[0] = (ld->revert ? 127 : 126); // Switch to raw inputs? - remove trim!
|
||||
if ((channelOutputs[k] - v) < -50) swVal[0] = (ld->revert ? 126 : 127);
|
||||
lcdDrawText(LIMITS_DIRECTION_POS, y, swVal);
|
||||
|
||||
int limit = (g_model.extendedLimits ? LIMIT_EXT_MAX : 1000);
|
||||
|
||||
putsChn(MENUS_MARGIN_LEFT, y, k+1, (sub==k && menuHorizontalPosition < 0) ? INVERS : 0);
|
||||
if (sub==k && menuHorizontalPosition < 0 && event==EVT_KEY_LONG(KEY_ENTER) && !READ_ONLY()) {
|
||||
killEvents(event);
|
||||
POPUP_MENU_ADD_ITEM(STR_RESET);
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY_TRIMS_TO_OFS);
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY_STICKS_TO_OFS);
|
||||
POPUP_MENU_START(onLimitsMenu);
|
||||
}
|
||||
|
||||
for (uint8_t j=0; j<ITEM_LIMITS_COUNT; j++) {
|
||||
uint8_t attr = ((sub==k && menuHorizontalPosition==j) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
|
||||
uint8_t active = (attr && s_editMode>0) ;
|
||||
switch(j)
|
||||
{
|
||||
case ITEM_LIMITS_CH_NAME:
|
||||
editName(LIMITS_NAME_POS, y, ld->name, sizeof(ld->name), event, attr);
|
||||
break;
|
||||
|
||||
case ITEM_LIMITS_OFFSET:
|
||||
if (GV_IS_GV_VALUE(ld->offset, -1000, 1000) || (attr && event == EVT_KEY_LONG(KEY_ENTER))) {
|
||||
ld->offset = GVAR_MENU_ITEM(LIMITS_OFFSET_POS, y, ld->offset, -1000, 1000, attr|PREC1|RIGHT, 0, event);
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PPM_UNIT_US)
|
||||
lcdDrawNumber(LIMITS_OFFSET_POS, y, ((int32_t)ld->offset*128) / 25, attr|PREC1|RIGHT);
|
||||
#else
|
||||
lcdDrawNumber(LIMITS_OFFSET_POS, y, ld->offset, attr|PREC1|RIGHT);
|
||||
#endif
|
||||
if (active) {
|
||||
ld->offset = checkIncDec(event, ld->offset, -1000, 1000, EE_MODEL, NULL, stops1000);
|
||||
}
|
||||
|
||||
// TODO with the contextual menu I think
|
||||
// else if (attr && event==EVT_KEY_LONG(KEY_MENU)) {
|
||||
// copySticksToOffset(k);
|
||||
// s_editMode = 0;
|
||||
// }
|
||||
break;
|
||||
|
||||
case ITEM_LIMITS_MIN:
|
||||
if (GV_IS_GV_VALUE(ld->min, -GV_RANGELARGE, GV_RANGELARGE) || (attr && event == EVT_KEY_LONG(KEY_ENTER))) {
|
||||
ld->min = GVAR_MENU_ITEM(LIMITS_MIN_POS, y, ld->min, -LIMIT_EXT_MAX, LIMIT_EXT_MAX, attr|PREC1|RIGHT, 0, event);
|
||||
break;
|
||||
}
|
||||
lcdDrawNumber(LIMITS_MIN_POS, y, MIN_MAX_DISPLAY(ld->min-LIMITS_MIN_MAX_OFFSET), attr|PREC1|RIGHT);
|
||||
if (active) ld->min = LIMITS_MIN_MAX_OFFSET + checkIncDec(event, ld->min-LIMITS_MIN_MAX_OFFSET, -limit, 0, EE_MODEL, NULL, stops1000);
|
||||
break;
|
||||
|
||||
case ITEM_LIMITS_MAX:
|
||||
if (GV_IS_GV_VALUE(ld->max, -GV_RANGELARGE, GV_RANGELARGE) || (attr && event == EVT_KEY_LONG(KEY_ENTER))) {
|
||||
ld->max = GVAR_MENU_ITEM(LIMITS_MAX_POS, y, ld->max, -LIMIT_EXT_MAX, LIMIT_EXT_MAX, attr|PREC1|RIGHT, 0, event);
|
||||
break;
|
||||
}
|
||||
lcdDrawNumber(LIMITS_MAX_POS, y, MIN_MAX_DISPLAY(ld->max+LIMITS_MIN_MAX_OFFSET), attr|PREC1|RIGHT);
|
||||
if (active) ld->max = -LIMITS_MIN_MAX_OFFSET + checkIncDec(event, ld->max+LIMITS_MIN_MAX_OFFSET, 0, +limit, EE_MODEL, NULL, stops1000);
|
||||
break;
|
||||
|
||||
case ITEM_LIMITS_DIRECTION:
|
||||
{
|
||||
lcdDrawText(LIMITS_REVERT_POS, y, ld->revert ? "\177" : "\176", attr);
|
||||
if (active) {
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, ld->revert, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_LIMITS_CURVE:
|
||||
drawCurveName(LIMITS_CURVE_POS, y, ld->curve, attr);
|
||||
if (attr && event==EVT_KEY_LONG(KEY_ENTER) && ld->curve>0) {
|
||||
s_curveChan = (ld->curve<0 ? -ld->curve-1 : ld->curve-1);
|
||||
pushMenu(menuModelCurveOne);
|
||||
}
|
||||
if (active) {
|
||||
CHECK_INCDEC_MODELVAR(event, ld->curve, -MAX_CURVES, +MAX_CURVES);
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(PPM_CENTER_ADJUSTABLE)
|
||||
case ITEM_LIMITS_PPM_CENTER:
|
||||
lcdDrawNumber(LIMITS_PPM_CENTER_POS, y, PPM_CENTER+ld->ppmCenter, attr|RIGHT);
|
||||
if (active) {
|
||||
CHECK_INCDEC_MODELVAR(event, ld->ppmCenter, -PPM_CENTER_MAX, +PPM_CENTER_MAX);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(PPM_LIMITS_SYMETRICAL)
|
||||
case ITEM_LIMITS_SYMETRICAL:
|
||||
lcdDrawText(LIMITS_SYMETRICAL_POS, y, ld->symetrical ? "=" : "\306", attr);
|
||||
if (active) {
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, ld->symetrical, 1);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define RECEIVER_OPTIONS_2ND_COLUMN 200
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
enum {
|
||||
RECEIVER_SETTINGS_OK = 0,
|
||||
RECEIVER_SETTINGS_DIRTY = 1,
|
||||
RECEIVER_SETTINGS_WRITING = 2,
|
||||
};
|
||||
|
||||
void onRxOptionsUpdateConfirm(const char * result)
|
||||
{
|
||||
if (result == STR_OK) {
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.state = PXX2_SETTINGS_WRITE;
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_WRITING;
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.timeout = 0;
|
||||
moduleState[g_moduleIdx].mode = MODULE_MODE_RECEIVER_SETTINGS;
|
||||
}
|
||||
else {
|
||||
popMenu();
|
||||
}
|
||||
}
|
||||
|
||||
enum {
|
||||
ITEM_RECEIVER_SETTINGS_PWM_RATE,
|
||||
ITEM_RECEIVER_SETTINGS_TELEMETRY,
|
||||
ITEM_RECEIVER_SETTINGS_SPORT_FPORT,
|
||||
ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED1,
|
||||
ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED2,
|
||||
ITEM_RECEIVER_SETTINGS_PINMAP_FIRST
|
||||
};
|
||||
|
||||
|
||||
#define IF_RECEIVER_CAPABILITY(capability, count) uint8_t((reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilities & (1 << capability)) ? count : HIDDEN_ROW)
|
||||
|
||||
bool menuModelReceiverOptions(event_t event)
|
||||
{
|
||||
const int lim = (g_model.extendedLimits ? (512 * LIMIT_EXT_PERCENT / 100) : 512) * 2;
|
||||
uint8_t wbar = LCD_W / 2 - 20;
|
||||
auto outputsCount = min<uint8_t>(16, reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount);
|
||||
|
||||
if (event == EVT_ENTRY) {
|
||||
// reusableBuffer.hardwareSettings should have been cleared before calling this menu
|
||||
#if defined(SIMU)
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.state = PXX2_SETTINGS_OK;
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount = 16;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t receiverId = reusableBuffer.hardwareAndSettings.receiverSettings.receiverId;
|
||||
uint8_t receiverModelId = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.modelID;
|
||||
uint8_t receiverVariant = reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.variant;
|
||||
|
||||
SUBMENU(STR_RECEIVER_OPTIONS, ICON_MODEL_SETUP, ITEM_RECEIVER_SETTINGS_PINMAP_FIRST + outputsCount, {
|
||||
0, // PWM rate
|
||||
isModuleR9MAccess(g_moduleIdx) && receiverVariant == PXX2_VARIANT_EU && reusableBuffer.hardwareAndSettings.moduleSettings.txPower > 14 /*25mW*/ ? READONLY_ROW : (uint8_t)0, // Telemetry
|
||||
IF_RECEIVER_CAPABILITY(RECEIVER_CAPABILITY_FPORT, 0),
|
||||
uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW),
|
||||
uint8_t(reusableBuffer.hardwareAndSettings.modules[g_moduleIdx].receivers[receiverId].information.capabilityNotSupported ? READONLY_ROW : HIDDEN_ROW),
|
||||
0 // channels ...
|
||||
});
|
||||
|
||||
if (g_model.moduleData[g_moduleIdx].pxx2.receiverName[receiverId][0] != '\0')
|
||||
lcdDrawSizedText(50, 3 + FH, g_model.moduleData[g_moduleIdx].pxx2.receiverName[receiverId], effectiveLen(g_model.moduleData[g_moduleIdx].pxx2.receiverName[receiverId], PXX2_LEN_RX_NAME), MENU_TITLE_COLOR);
|
||||
else
|
||||
lcdDrawText(50, 3 + FH, "---", MENU_TITLE_COLOR);
|
||||
|
||||
if (menuEvent) {
|
||||
killEvents(KEY_EXIT);
|
||||
moduleState[g_moduleIdx].mode = MODULE_MODE_NORMAL;
|
||||
if (reusableBuffer.hardwareAndSettings.receiverSettings.dirty) {
|
||||
abortPopMenu();
|
||||
POPUP_CONFIRMATION(STR_UPDATE_RX_OPTIONS, onRxOptionsUpdateConfirm);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_HARDWARE_INFO && moduleState[g_moduleIdx].mode == MODULE_MODE_NORMAL) {
|
||||
if (!receiverModelId)
|
||||
moduleState[g_moduleIdx].readModuleInformation(&reusableBuffer.hardwareAndSettings.modules[g_moduleIdx], receiverId, receiverId);
|
||||
else if (isModuleR9MAccess(g_moduleIdx) && receiverVariant == PXX2_VARIANT_EU && !reusableBuffer.hardwareAndSettings.moduleSettings.txPower)
|
||||
moduleState[g_moduleIdx].readModuleSettings(&reusableBuffer.hardwareAndSettings.moduleSettings);
|
||||
else
|
||||
moduleState[g_moduleIdx].readReceiverSettings(&reusableBuffer.hardwareAndSettings.receiverSettings);
|
||||
}
|
||||
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER) && reusableBuffer.hardwareAndSettings.receiverSettings.dirty) {
|
||||
killEvents(event);
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_OK;
|
||||
moduleState[g_moduleIdx].writeReceiverSettings(&reusableBuffer.hardwareAndSettings.receiverSettings);
|
||||
}
|
||||
|
||||
if (reusableBuffer.hardwareAndSettings.receiverSettings.dirty == RECEIVER_SETTINGS_WRITING && reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_SETTINGS_OK) {
|
||||
popMenu();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (receiverModelId && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) {
|
||||
menuVerticalPosition = 0;
|
||||
while (menuVerticalPosition < ITEM_RECEIVER_SETTINGS_PINMAP_FIRST && mstate_tab[menuVerticalPosition] == HIDDEN_ROW) {
|
||||
++menuVerticalPosition;
|
||||
}
|
||||
}
|
||||
|
||||
int8_t sub = menuVerticalPosition;
|
||||
|
||||
if (reusableBuffer.hardwareAndSettings.receiverSettings.state == PXX2_SETTINGS_OK) {
|
||||
for (uint8_t k=0; k<NUM_BODY_LINES + 1/*plus one line in submenus*/; k++) {
|
||||
coord_t y = MENU_HEADER_HEIGHT + 1 + k*FH;
|
||||
uint8_t i = k + menuVerticalOffset;
|
||||
for (int j=0; j<=i; ++j) {
|
||||
if (j<(int)DIM(mstate_tab) && mstate_tab[j] == HIDDEN_ROW) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
LcdFlags attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
|
||||
|
||||
switch (i) {
|
||||
case ITEM_RECEIVER_SETTINGS_PWM_RATE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, isModuleR9MAccess(g_moduleIdx) ? "6.67ms PWM": "9ms PWM");
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.pwmRate = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.pwmRate, RECEIVER_OPTIONS_2ND_COLUMN, y, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY;
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_RECEIVER_SETTINGS_TELEMETRY:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TELEMETRY_DISABLED);
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.telemetryDisabled, RECEIVER_OPTIONS_2ND_COLUMN, y, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY;
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_RECEIVER_SETTINGS_SPORT_FPORT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "F.Port");
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.fport = editCheckBox(reusableBuffer.hardwareAndSettings.receiverSettings.fport, RECEIVER_OPTIONS_2ND_COLUMN, y, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY;
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED1:
|
||||
lcdDrawText(LCD_W/2, y+1, STR_MORE_OPTIONS_AVAILABLE, SMLSIZE|CENTERED);
|
||||
break;
|
||||
|
||||
case ITEM_RECEIVER_SETTINGS_CAPABILITY_NOT_SUPPORTED2:
|
||||
lcdDrawText(LCD_W/2, y+1, STR_OPENTX_UPGRADE_REQUIRED, SMLSIZE|CENTERED);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Pin
|
||||
{
|
||||
uint8_t pin = i - ITEM_RECEIVER_SETTINGS_PINMAP_FIRST;
|
||||
if (pin < reusableBuffer.hardwareAndSettings.receiverSettings.outputsCount) {
|
||||
uint8_t & mapping = reusableBuffer.hardwareAndSettings.receiverSettings.outputsMapping[pin];
|
||||
uint8_t channel = g_model.moduleData[g_moduleIdx].channelsStart + mapping;
|
||||
int32_t channelValue = channelOutputs[channel];
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_PIN);
|
||||
lcdDrawNumber(lcdNextPos + 1, y, pin + 1);
|
||||
putsChn(100, y, channel + 1, attr);
|
||||
|
||||
// Channel
|
||||
if (attr) {
|
||||
mapping = checkIncDec(event, mapping, 0, sentModuleChannels(g_moduleIdx) - 1);
|
||||
if (checkIncDec_Ret) {
|
||||
reusableBuffer.hardwareAndSettings.receiverSettings.dirty = RECEIVER_SETTINGS_DIRTY;
|
||||
}
|
||||
}
|
||||
|
||||
// Bargraph
|
||||
lcdDrawRect(RECEIVER_OPTIONS_2ND_COLUMN, y + 4, wbar + 1, 10);
|
||||
const uint8_t lenChannel = limit<uint8_t>(1, (abs(channelValue) * wbar / 2 + lim / 2) / lim, wbar / 2);
|
||||
const coord_t xChannel = (channelValue > 0) ? RECEIVER_OPTIONS_2ND_COLUMN + wbar / 2 : RECEIVER_OPTIONS_2ND_COLUMN + wbar / 2 + 1 - lenChannel;
|
||||
lcdDrawSolidFilledRect(xChannel, y + 5, lenChannel, 8, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_WAITING_FOR_RX);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,424 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define MODEL_SPECIAL_FUNC_1ST_COLUMN 60
|
||||
#define MODEL_SPECIAL_FUNC_2ND_COLUMN 120
|
||||
#define MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT (lcdNextPos + 5)
|
||||
#define MODEL_SPECIAL_FUNC_3RD_COLUMN 295
|
||||
#define MODEL_SPECIAL_FUNC_4TH_COLUMN 440
|
||||
#define MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF 450
|
||||
|
||||
void onCustomFunctionsFileSelectionMenu(const char * result)
|
||||
{
|
||||
CustomFunctionData * cf;
|
||||
uint8_t eeFlags;
|
||||
|
||||
if (menuHandlers[menuLevel] == menuModelSpecialFunctions) {
|
||||
cf = &g_model.customFn[menuVerticalPosition];
|
||||
eeFlags = EE_MODEL;
|
||||
}
|
||||
else {
|
||||
cf = &g_eeGeneral.customFn[menuVerticalPosition];
|
||||
eeFlags = EE_GENERAL;
|
||||
}
|
||||
|
||||
uint8_t func = CFN_FUNC(cf);
|
||||
|
||||
if (result == STR_UPDATE_LIST) {
|
||||
char directory[256];
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
strcpy(directory, SCRIPTS_FUNCS_PATH);
|
||||
}
|
||||
else {
|
||||
strcpy(directory, SOUNDS_PATH);
|
||||
strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
||||
}
|
||||
if (!sdListFiles(directory, func==FUNC_PLAY_SCRIPT ? SCRIPTS_EXT : SOUNDS_EXT, sizeof(cf->play.name), NULL)) {
|
||||
POPUP_WARNING(func==FUNC_PLAY_SCRIPT ? STR_NO_SCRIPTS_ON_SD : STR_NO_SOUNDS_ON_SD);
|
||||
}
|
||||
}
|
||||
else if (result != STR_EXIT) {
|
||||
// The user choosed a file in the list
|
||||
memcpy(cf->play.name, result, sizeof(cf->play.name));
|
||||
storageDirty(eeFlags);
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
LUA_LOAD_MODEL_SCRIPTS();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onCustomFunctionsMenu(const char * result)
|
||||
{
|
||||
CustomFunctionData * cfn;
|
||||
uint8_t eeFlags;
|
||||
|
||||
if (menuHandlers[menuLevel] == menuModelSpecialFunctions) {
|
||||
cfn = &g_model.customFn[menuVerticalPosition];
|
||||
eeFlags = EE_MODEL;
|
||||
}
|
||||
else {
|
||||
cfn = &g_eeGeneral.customFn[menuVerticalPosition];
|
||||
eeFlags = EE_GENERAL;
|
||||
}
|
||||
|
||||
if (result == STR_COPY) {
|
||||
clipboard.type = CLIPBOARD_TYPE_CUSTOM_FUNCTION;
|
||||
clipboard.data.cfn = *cfn;
|
||||
}
|
||||
else if (result == STR_PASTE) {
|
||||
*cfn = clipboard.data.cfn;
|
||||
storageDirty(eeFlags);
|
||||
}
|
||||
else if (result == STR_CLEAR) {
|
||||
memset(cfn, 0, sizeof(CustomFunctionData));
|
||||
storageDirty(eeFlags);
|
||||
}
|
||||
else if (result == STR_INSERT) {
|
||||
memmove(cfn+1, cfn, (MAX_SPECIAL_FUNCTIONS-menuVerticalPosition-1)*sizeof(CustomFunctionData));
|
||||
memset(cfn, 0, sizeof(CustomFunctionData));
|
||||
storageDirty(eeFlags);
|
||||
}
|
||||
else if (result == STR_DELETE) {
|
||||
memmove(cfn, cfn+1, (MAX_SPECIAL_FUNCTIONS-menuVerticalPosition-1)*sizeof(CustomFunctionData));
|
||||
memset(&g_model.customFn[MAX_SPECIAL_FUNCTIONS-1], 0, sizeof(CustomFunctionData));
|
||||
storageDirty(eeFlags);
|
||||
}
|
||||
}
|
||||
|
||||
void onAdjustGvarSourceLongEnterPress(const char * result)
|
||||
{
|
||||
CustomFunctionData * cfn = &g_model.customFn[menuVerticalPosition];
|
||||
|
||||
if (result == STR_CONSTANT) {
|
||||
CFN_GVAR_MODE(cfn) = FUNC_ADJUST_GVAR_CONSTANT;
|
||||
CFN_PARAM(cfn) = 0;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_MIXSOURCE) {
|
||||
CFN_GVAR_MODE(cfn) = FUNC_ADJUST_GVAR_SOURCE;
|
||||
CFN_PARAM(cfn) = 0;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_GLOBALVAR) {
|
||||
CFN_GVAR_MODE(cfn) = FUNC_ADJUST_GVAR_GVAR;
|
||||
CFN_PARAM(cfn) = 0;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_INCDEC) {
|
||||
CFN_GVAR_MODE(cfn) = FUNC_ADJUST_GVAR_INCDEC;
|
||||
CFN_PARAM(cfn) = 0;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result != STR_EXIT) {
|
||||
onSourceLongEnterPress(result);
|
||||
}
|
||||
}
|
||||
|
||||
enum SpecialFunctionsItems {
|
||||
ITEM_SPECIAL_FUNCTIONS_SWITCH,
|
||||
ITEM_SPECIAL_FUNCTIONS_FUNCTION,
|
||||
ITEM_SPECIAL_FUNCTIONS_PARAM,
|
||||
ITEM_SPECIAL_FUNCTIONS_VALUE,
|
||||
ITEM_SPECIAL_FUNCTIONS_ENABLE,
|
||||
ITEM_SPECIAL_FUNCTIONS_COUNT,
|
||||
ITEM_SPECIAL_FUNCTIONS_LAST = ITEM_SPECIAL_FUNCTIONS_COUNT-1
|
||||
};
|
||||
|
||||
bool menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomFunctionsContext & functionsContext)
|
||||
{
|
||||
uint8_t eeFlags = (functions == g_model.customFn) ? EE_MODEL : EE_GENERAL;
|
||||
|
||||
if (menuHorizontalPosition<0 && event==EVT_KEY_LONG(KEY_ENTER) && !READ_ONLY()) {
|
||||
killEvents(event);
|
||||
CustomFunctionData *cfn = &functions[menuVerticalPosition];
|
||||
if (!CFN_EMPTY(cfn))
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY);
|
||||
if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_FUNCTION && isAssignableFunctionAvailable(clipboard.data.cfn.func))
|
||||
POPUP_MENU_ADD_ITEM(STR_PASTE);
|
||||
if (!CFN_EMPTY(cfn) && CFN_EMPTY(&functions[MAX_SPECIAL_FUNCTIONS-1]))
|
||||
POPUP_MENU_ADD_ITEM(STR_INSERT);
|
||||
if (!CFN_EMPTY(cfn))
|
||||
POPUP_MENU_ADD_ITEM(STR_CLEAR);
|
||||
for (int i=menuVerticalPosition+1; i<MAX_SPECIAL_FUNCTIONS; i++) {
|
||||
if (!CFN_EMPTY(&functions[i])) {
|
||||
POPUP_MENU_ADD_ITEM(STR_DELETE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
POPUP_MENU_START(onCustomFunctionsMenu);
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
int k = i+menuVerticalOffset;
|
||||
|
||||
drawStringWithIndex(MENUS_MARGIN_LEFT, y, functions == g_model.customFn ? STR_SF : STR_GF, k+1, (menuVerticalPosition==k && menuHorizontalPosition<0) ? INVERS : 0);
|
||||
|
||||
CustomFunctionData * cfn = &functions[k];
|
||||
uint8_t func = CFN_FUNC(cfn);
|
||||
for (uint8_t j=0; j<ITEM_SPECIAL_FUNCTIONS_COUNT; j++) {
|
||||
LcdFlags attr = ((menuVerticalPosition==k && menuHorizontalPosition==j) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
|
||||
LcdFlags active = (attr && s_editMode>0);
|
||||
switch (j) {
|
||||
case ITEM_SPECIAL_FUNCTIONS_SWITCH:
|
||||
drawSwitch(MODEL_SPECIAL_FUNC_1ST_COLUMN, y, CFN_SWITCH(cfn), attr | ((functionsContext.activeSwitches & ((MASK_CFN_TYPE)1 << k)) ? BOLD : 0));
|
||||
if (active || AUTOSWITCH_ENTER_LONG()) {
|
||||
CHECK_INCDEC_SWITCH(event, CFN_SWITCH(cfn), SWSRC_FIRST, SWSRC_LAST, eeFlags, isSwitchAvailableInCustomFunctions);
|
||||
}
|
||||
if (func == FUNC_OVERRIDE_CHANNEL && functions != g_model.customFn) {
|
||||
func = CFN_FUNC(cfn) = func+1;
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_SPECIAL_FUNCTIONS_FUNCTION:
|
||||
if (CFN_SWITCH(cfn)) {
|
||||
if (active) {
|
||||
func = CFN_FUNC(cfn) = checkIncDec(event, CFN_FUNC(cfn), 0, FUNC_MAX-1, eeFlags, isAssignableFunctionAvailable);
|
||||
if (checkIncDec_Ret) CFN_RESET(cfn);
|
||||
}
|
||||
lcdDrawTextAtIndex(MODEL_SPECIAL_FUNC_2ND_COLUMN, y, STR_VFSWFUNC, func, attr);
|
||||
}
|
||||
else {
|
||||
j = ITEM_SPECIAL_FUNCTIONS_ENABLE; // skip other fields
|
||||
while (menuVerticalPosition==k && menuHorizontalPosition > 0) {
|
||||
REPEAT_LAST_CURSOR_MOVE(ITEM_SPECIAL_FUNCTIONS_LAST, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_SPECIAL_FUNCTIONS_PARAM:
|
||||
{
|
||||
int8_t maxParam = MAX_OUTPUT_CHANNELS-1;
|
||||
#if defined(OVERRIDE_CHANNEL_FUNCTION)
|
||||
if (func == FUNC_OVERRIDE_CHANNEL) {
|
||||
putsChn(MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT, y, CFN_CH_INDEX(cfn)+1, attr);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
if (func == FUNC_TRAINER) {
|
||||
maxParam = 4;
|
||||
drawSource(MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT, y, CFN_CH_INDEX(cfn)==0 ? 0 : MIXSRC_Rud+CFN_CH_INDEX(cfn)-1, attr);
|
||||
}
|
||||
#if defined(GVARS)
|
||||
else if (func == FUNC_ADJUST_GVAR) {
|
||||
maxParam = MAX_GVARS-1;
|
||||
drawStringWithIndex(MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT, y, STR_GV, CFN_GVAR_INDEX(cfn)+1, attr);
|
||||
if (active) CFN_GVAR_INDEX(cfn) = checkIncDec(event, CFN_GVAR_INDEX(cfn), 0, maxParam, eeFlags);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
else if (func == FUNC_SET_TIMER) {
|
||||
maxParam = TIMERS-1;
|
||||
drawStringWithIndex(MODEL_SPECIAL_FUNC_2ND_COLUMN_EXT, y, STR_TIMER, CFN_TIMER_INDEX(cfn)+1, attr);
|
||||
if (active) CFN_TIMER_INDEX(cfn) = checkIncDec(event, CFN_TIMER_INDEX(cfn), 0, maxParam, eeFlags);
|
||||
break;
|
||||
}
|
||||
else if (attr) {
|
||||
REPEAT_LAST_CURSOR_MOVE(ITEM_SPECIAL_FUNCTIONS_LAST, true);
|
||||
}
|
||||
if (active) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_CH_INDEX(cfn), maxParam);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SPECIAL_FUNCTIONS_VALUE:
|
||||
{
|
||||
INCDEC_DECLARE_VARS(eeFlags);
|
||||
int16_t val_displayed = CFN_PARAM(cfn);
|
||||
int16_t val_min = 0;
|
||||
int16_t val_max = 255;
|
||||
if (func == FUNC_RESET) {
|
||||
val_max = FUNC_RESET_PARAM_FIRST_TELEM+lastUsedTelemetryIndex();
|
||||
int param = CFN_PARAM(cfn);
|
||||
if (param < FUNC_RESET_PARAM_FIRST_TELEM) {
|
||||
lcdDrawTextAtIndex(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, STR_VFSWRESET, param, attr);
|
||||
}
|
||||
else {
|
||||
TelemetrySensor * sensor = & g_model.telemetrySensors[param-FUNC_RESET_PARAM_FIRST_TELEM];
|
||||
lcdDrawSizedText(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, sensor->label, TELEM_LABEL_LEN, attr|ZCHAR);
|
||||
}
|
||||
if (active) INCDEC_ENABLE_CHECK(functions == g_eeGeneral.customFn ? isSourceAvailableInGlobalResetSpecialFunction : isSourceAvailableInResetSpecialFunction);
|
||||
}
|
||||
#if defined(OVERRIDE_CHANNEL_FUNCTION)
|
||||
else if (func == FUNC_OVERRIDE_CHANNEL) {
|
||||
getMixSrcRange(MIXSRC_FIRST_CH, val_min, val_max);
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT);
|
||||
}
|
||||
#endif
|
||||
#if defined(DANGEROUS_MODULE_FUNCTIONS)
|
||||
else if (func >= FUNC_RANGECHECK && func <= FUNC_BIND) {
|
||||
val_max = NUM_MODULES-1;
|
||||
lcdDrawTextAtIndex(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, "\004Int.Ext.", CFN_PARAM(cfn), attr);
|
||||
}
|
||||
#endif
|
||||
else if (func == FUNC_SET_TIMER) {
|
||||
getMixSrcRange(MIXSRC_FIRST_TIMER, val_min, val_max);
|
||||
drawTimer(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT|TIMEHOUR);
|
||||
}
|
||||
else if (func == FUNC_PLAY_SOUND) {
|
||||
val_max = AU_SPECIAL_SOUND_LAST-AU_SPECIAL_SOUND_FIRST-1;
|
||||
lcdDrawTextAtIndex(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, STR_FUNCSOUNDS, val_displayed, attr);
|
||||
}
|
||||
#if defined(HAPTIC)
|
||||
else if (func == FUNC_HAPTIC) {
|
||||
val_max = 3;
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr|LEFT);
|
||||
}
|
||||
#endif
|
||||
#if defined(SDCARD)
|
||||
else if (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC || func == FUNC_PLAY_SCRIPT) {
|
||||
coord_t x = MODEL_SPECIAL_FUNC_3RD_COLUMN;
|
||||
if (ZEXIST(cfn->play.name))
|
||||
lcdDrawSizedText(x, y, cfn->play.name, sizeof(cfn->play.name), attr);
|
||||
else
|
||||
lcdDrawTextAtIndex(x, y, STR_VCSWFUNC, 0, attr);
|
||||
if (attr) s_editMode = 0;
|
||||
if (attr && event==EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
killEvents(KEY_ENTER);
|
||||
char directory[256];
|
||||
if (func==FUNC_PLAY_SCRIPT) {
|
||||
strcpy(directory, SCRIPTS_FUNCS_PATH);
|
||||
}
|
||||
else {
|
||||
strcpy(directory, SOUNDS_PATH);
|
||||
strncpy(directory+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
|
||||
}
|
||||
if (sdListFiles(directory, func==FUNC_PLAY_SCRIPT ? SCRIPTS_EXT : SOUNDS_EXT, sizeof(cfn->play.name), cfn->play.name)) {
|
||||
POPUP_MENU_START(onCustomFunctionsFileSelectionMenu);
|
||||
}
|
||||
else {
|
||||
POPUP_WARNING(func==FUNC_PLAY_SCRIPT ? STR_NO_SCRIPTS_ON_SD : STR_NO_SOUNDS_ON_SD);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (func == FUNC_PLAY_VALUE) {
|
||||
val_max = MIXSRC_LAST_TELEM;
|
||||
drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr);
|
||||
if (active) {
|
||||
INCDEC_SET_FLAG(eeFlags | INCDEC_SOURCE);
|
||||
INCDEC_ENABLE_CHECK(functions == g_eeGeneral.customFn ? isSourceAvailableInGlobalFunctions : isSourceAvailable);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (func == FUNC_VOLUME) {
|
||||
val_max = MIXSRC_LAST_CH;
|
||||
drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr);
|
||||
if (active) {
|
||||
INCDEC_SET_FLAG(eeFlags | INCDEC_SOURCE);
|
||||
INCDEC_ENABLE_CHECK(isSourceAvailable);
|
||||
}
|
||||
}
|
||||
else if (func == FUNC_LOGS) {
|
||||
if (val_displayed) {
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr|PREC1|LEFT, 0, NULL, "s");
|
||||
}
|
||||
else {
|
||||
lcdDrawMMM(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, attr);
|
||||
}
|
||||
}
|
||||
#if defined(GVARS)
|
||||
else if (func == FUNC_ADJUST_GVAR) {
|
||||
switch (CFN_GVAR_MODE(cfn)) {
|
||||
case FUNC_ADJUST_GVAR_CONSTANT:
|
||||
{
|
||||
val_displayed = (int16_t)CFN_PARAM(cfn);
|
||||
getMixSrcRange(CFN_GVAR_INDEX(cfn) + MIXSRC_FIRST_GVAR, val_min, val_max);
|
||||
drawGVarValue(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, CFN_GVAR_INDEX(cfn), val_displayed, attr|LEFT);
|
||||
break;
|
||||
}
|
||||
case FUNC_ADJUST_GVAR_SOURCE:
|
||||
val_max = MIXSRC_LAST_CH;
|
||||
drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr);
|
||||
if (active) {
|
||||
INCDEC_SET_FLAG(eeFlags | INCDEC_SOURCE);
|
||||
INCDEC_ENABLE_CHECK(isSourceAvailable);
|
||||
}
|
||||
break;
|
||||
case FUNC_ADJUST_GVAR_GVAR:
|
||||
val_max = MAX_GVARS-1;
|
||||
drawStringWithIndex(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, STR_GV, val_displayed+1, attr);
|
||||
break;
|
||||
default: // FUNC_ADJUST_GVAR_INC
|
||||
getMixSrcRange(CFN_GVAR_INDEX(cfn) + MIXSRC_FIRST_GVAR, val_min, val_max);
|
||||
getGVarIncDecRange(val_min, val_max);
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, (val_displayed < 0 ? "-= " : "+= "), attr);
|
||||
drawGVarValue(lcdNextPos, y, CFN_GVAR_INDEX(cfn), abs(val_displayed), attr|LEFT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (attr) {
|
||||
REPEAT_LAST_CURSOR_MOVE(ITEM_SPECIAL_FUNCTIONS_LAST, true);
|
||||
}
|
||||
|
||||
if (active || event==EVT_KEY_LONG(KEY_ENTER)) {
|
||||
CFN_PARAM(cfn) = CHECK_INCDEC_PARAM(event, val_displayed, val_min, val_max);
|
||||
if (func == FUNC_ADJUST_GVAR && attr && event==EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
if (CFN_GVAR_MODE(cfn) != FUNC_ADJUST_GVAR_CONSTANT)
|
||||
POPUP_MENU_ADD_ITEM(STR_CONSTANT);
|
||||
if (CFN_GVAR_MODE(cfn) != FUNC_ADJUST_GVAR_SOURCE)
|
||||
POPUP_MENU_ADD_ITEM(STR_MIXSOURCE);
|
||||
if (CFN_GVAR_MODE(cfn) != FUNC_ADJUST_GVAR_GVAR)
|
||||
POPUP_MENU_ADD_ITEM(STR_GLOBALVAR);
|
||||
if (CFN_GVAR_MODE(cfn) != FUNC_ADJUST_GVAR_INCDEC)
|
||||
POPUP_MENU_ADD_ITEM(STR_INCDEC);
|
||||
POPUP_MENU_START(onAdjustGvarSourceLongEnterPress);
|
||||
s_editMode = EDIT_MODIFY_FIELD;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SPECIAL_FUNCTIONS_ENABLE:
|
||||
if (HAS_ENABLE_PARAM(func)) {
|
||||
if (active) CFN_ACTIVE(cfn) = checkIncDec(event, CFN_ACTIVE(cfn), 0, 1, eeFlags);
|
||||
drawCheckBox(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF, y, CFN_ACTIVE(cfn), attr);
|
||||
}
|
||||
else if (HAS_REPEAT_PARAM(func)) {
|
||||
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn)==CFN_PLAY_REPEAT_NOSTART?-1:CFN_PLAY_REPEAT(cfn), -1, 60/CFN_PLAY_REPEAT_MUL, eeFlags);
|
||||
if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN+2, y, "1x", attr);
|
||||
}
|
||||
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN-1, y, "!1x", attr);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_4TH_COLUMN+12, y, CFN_PLAY_REPEAT(cfn)*CFN_PLAY_REPEAT_MUL, attr|RIGHT, 0, NULL, "s");
|
||||
}
|
||||
}
|
||||
else if (attr) {
|
||||
REPEAT_LAST_CURSOR_MOVE(ITEM_SPECIAL_FUNCTIONS_LAST, true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool menuModelSpecialFunctions(event_t event)
|
||||
{
|
||||
MENU(STR_MENUCUSTOMFUNC, MODEL_ICONS, menuTabModel, MENU_MODEL_SPECIAL_FUNCTIONS, MAX_SPECIAL_FUNCTIONS, { NAVIGATION_LINE_BY_LINE|4/*repeated*/ });
|
||||
return menuSpecialFunctions(event, g_model.customFn, modelFunctionsContext);
|
||||
}
|
||||
@@ -1,313 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
enum MenuModelTelemetryFrskyItems {
|
||||
ITEM_TELEMETRY_PROTOCOL_TYPE,
|
||||
ITEM_TELEMETRY_RSSI_LABEL,
|
||||
ITEM_TELEMETRY_RSSI_SOURCE,
|
||||
ITEM_TELEMETRY_RSSI_ALARM1,
|
||||
ITEM_TELEMETRY_RSSI_ALARM2,
|
||||
ITEM_TELEMETRY_DISABLE_ALARMS,
|
||||
ITEM_TELEMETRY_SENSORS_LABEL,
|
||||
ITEM_TELEMETRY_SENSOR_FIRST,
|
||||
ITEM_TELEMETRY_SENSOR_LAST = ITEM_TELEMETRY_SENSOR_FIRST + MAX_TELEMETRY_SENSORS - 1,
|
||||
ITEM_TELEMETRY_DISCOVER_SENSORS,
|
||||
ITEM_TELEMETRY_NEW_SENSOR,
|
||||
ITEM_TELEMETRY_DELETE_ALL_SENSORS,
|
||||
ITEM_TELEMETRY_IGNORE_SENSOR_INSTANCE,
|
||||
#if defined(VARIO)
|
||||
ITEM_TELEMETRY_VARIO_LABEL,
|
||||
ITEM_TELEMETRY_VARIO_SOURCE,
|
||||
ITEM_TELEMETRY_VARIO_RANGE,
|
||||
ITEM_TELEMETRY_VARIO_CENTER,
|
||||
#endif
|
||||
ITEM_TELEMETRY_MAX
|
||||
};
|
||||
|
||||
#define TELEM_COL2 200
|
||||
#define TELEM_COL3 275
|
||||
#define TELEM_COL4 350
|
||||
#define TELEM_COL5 425
|
||||
|
||||
#define RSSI_ROWS LABEL(RSSI), 0, 0, 0, 0,
|
||||
#define SENSOR_ROWS(x) (isTelemetryFieldAvailable(x) ? (uint8_t)0 : HIDDEN_ROW)
|
||||
#define SENSORS_ROWS LABEL(Sensors), SENSOR_ROWS(0), SENSOR_ROWS(1), SENSOR_ROWS(2), SENSOR_ROWS(3), SENSOR_ROWS(4), SENSOR_ROWS(5), SENSOR_ROWS(6), SENSOR_ROWS(7), SENSOR_ROWS(8), SENSOR_ROWS(9), SENSOR_ROWS(10), SENSOR_ROWS(11), SENSOR_ROWS(12), SENSOR_ROWS(13), SENSOR_ROWS(14), SENSOR_ROWS(15), SENSOR_ROWS(16), SENSOR_ROWS(17), SENSOR_ROWS(18), SENSOR_ROWS(19), SENSOR_ROWS(20), SENSOR_ROWS(21), SENSOR_ROWS(22), SENSOR_ROWS(23), SENSOR_ROWS(24), SENSOR_ROWS(25), SENSOR_ROWS(26), SENSOR_ROWS(27), SENSOR_ROWS(28), SENSOR_ROWS(29), SENSOR_ROWS(30), \
|
||||
SENSOR_ROWS(31), SENSOR_ROWS(32), SENSOR_ROWS(33), SENSOR_ROWS(34), SENSOR_ROWS(35), SENSOR_ROWS(36), SENSOR_ROWS(37), SENSOR_ROWS(38), SENSOR_ROWS(39), SENSOR_ROWS(40),SENSOR_ROWS(41), SENSOR_ROWS(42), SENSOR_ROWS(43), SENSOR_ROWS(44), SENSOR_ROWS(45), SENSOR_ROWS(46), SENSOR_ROWS(47), SENSOR_ROWS(48), SENSOR_ROWS(49), SENSOR_ROWS(50),SENSOR_ROWS(51), SENSOR_ROWS(52), SENSOR_ROWS(53), SENSOR_ROWS(54), SENSOR_ROWS(55), SENSOR_ROWS(56), SENSOR_ROWS(57), SENSOR_ROWS(58), SENSOR_ROWS(59), 0, 0, 0, 0,
|
||||
#if defined(VARIO)
|
||||
#define VARIO_ROWS LABEL(Vario), 0, 1, 2,
|
||||
#else
|
||||
#define VARIO_ROWS
|
||||
#endif
|
||||
#define TELEMETRY_TYPE_ROWS (!IS_INTERNAL_MODULE_ENABLED() && g_model.moduleData[EXTERNAL_MODULE].type == MODULE_TYPE_PPM) ? (uint8_t)0 : HIDDEN_ROW,
|
||||
|
||||
void onSensorMenu(const char * result)
|
||||
{
|
||||
uint8_t index = menuVerticalPosition - ITEM_TELEMETRY_SENSOR_FIRST;
|
||||
|
||||
if (index < MAX_TELEMETRY_SENSORS) {
|
||||
if (result == STR_EDIT) {
|
||||
pushMenu(menuModelSensor);
|
||||
}
|
||||
else if (result == STR_DELETE) {
|
||||
delTelemetryIndex(index);
|
||||
index += 1;
|
||||
if (index<MAX_TELEMETRY_SENSORS && isTelemetryFieldAvailable(index))
|
||||
menuVerticalPosition += 1;
|
||||
else
|
||||
menuVerticalPosition = ITEM_TELEMETRY_NEW_SENSOR;
|
||||
}
|
||||
else if (result == STR_COPY) {
|
||||
int newIndex = availableTelemetryIndex();
|
||||
|
||||
if (newIndex >= 0) {
|
||||
TelemetrySensor & sourceSensor = g_model.telemetrySensors[index];
|
||||
TelemetrySensor & newSensor = g_model.telemetrySensors[newIndex];
|
||||
newSensor = sourceSensor;
|
||||
TelemetryItem & sourceItem = telemetryItems[index];
|
||||
TelemetryItem & newItem = telemetryItems[newIndex];
|
||||
newItem = sourceItem;
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else {
|
||||
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onDeleteAllSensorsConfirm(const char * result)
|
||||
{
|
||||
if (result == STR_OK) {
|
||||
for (int i=0; i<MAX_TELEMETRY_SENSORS; i++) {
|
||||
delTelemetryIndex(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool menuModelTelemetry(event_t event)
|
||||
{
|
||||
MENU(STR_MENUTELEMETRY, MODEL_ICONS, menuTabModel, MENU_MODEL_TELEMETRY, ITEM_TELEMETRY_MAX, { TELEMETRY_TYPE_ROWS RSSI_ROWS SENSORS_ROWS VARIO_ROWS });
|
||||
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
int k = i + menuVerticalOffset;
|
||||
for (int j=0; j<=k; j++) {
|
||||
if (mstate_tab[j] == HIDDEN_ROW)
|
||||
k++;
|
||||
}
|
||||
|
||||
LcdFlags blink = ((s_editMode>0) ? BLINK|INVERS : INVERS);
|
||||
LcdFlags attr = (menuVerticalPosition == k ? blink : 0);
|
||||
|
||||
if (k >= ITEM_TELEMETRY_SENSOR_FIRST && k <= ITEM_TELEMETRY_SENSOR_LAST) {
|
||||
int index = k - ITEM_TELEMETRY_SENSOR_FIRST;
|
||||
lcdDrawNumber(MENUS_MARGIN_LEFT+INDENT_WIDTH, y, index+1, LEFT|attr, 0, NULL, ":");
|
||||
lcdDrawSizedText(60, y, g_model.telemetrySensors[index].label, TELEM_LABEL_LEN, ZCHAR);
|
||||
TelemetryItem & telemetryItem = telemetryItems[index];
|
||||
if (telemetryItem.isFresh()) {
|
||||
lcdDrawText(130, y, "*");
|
||||
}
|
||||
if (telemetryItem.isAvailable()) {
|
||||
LcdFlags color = telemetryItem.isOld() ? ALARM_COLOR : TEXT_COLOR;
|
||||
drawSensorCustomValue(TELEM_COL2, y, index, getValue(MIXSRC_FIRST_TELEM+3*index), LEFT|color);
|
||||
}
|
||||
else {
|
||||
lcdDrawText(TELEM_COL2, y, "---"); // TODO shortcut
|
||||
}
|
||||
TelemetrySensor * sensor = & g_model.telemetrySensors[index];
|
||||
#if defined(MULTIMODULE)
|
||||
if (IS_SPEKTRUM_PROTOCOL()) {
|
||||
// Spektrum does not (yet?) really support multiple sensor of the same type. But a lot of
|
||||
// different sensor display the same information (e.g. voltage, capacity). Show the id
|
||||
// of the sensor in the overview to ease figuring out what sensors belong together
|
||||
lcdDrawHexNumber(TELEM_COL5, y, sensor->id, LEFT);
|
||||
} else
|
||||
#endif
|
||||
if (sensor->type == TELEM_TYPE_CUSTOM && !g_model.ignoreSensorIds) {
|
||||
lcdDrawNumber(TELEM_COL5, y, sensor->instance, LEFT);
|
||||
}
|
||||
if (attr) {
|
||||
s_editMode = 0;
|
||||
s_currIdx = index;
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
POPUP_MENU_ADD_ITEM(STR_EDIT);
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY);
|
||||
POPUP_MENU_ADD_ITEM(STR_DELETE);
|
||||
POPUP_MENU_START(onSensorMenu);
|
||||
}
|
||||
else if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
pushMenu(menuModelSensor);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
switch (k) {
|
||||
case ITEM_TELEMETRY_PROTOCOL_TYPE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TELEMETRY_TYPE);
|
||||
lcdDrawTextAtIndex(TELEM_COL2, y, STR_TELEMETRY_PROTOCOLS, g_model.telemetryProtocol, attr);
|
||||
g_model.telemetryProtocol = checkIncDec(event, g_model.telemetryProtocol, PROTOCOL_TELEMETRY_FIRST, PROTOCOL_TELEMETRY_LAST, EE_MODEL, isTelemetryProtocolAvailable);
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_SENSORS_LABEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TELEMETRY_SENSORS);
|
||||
lcdDrawText(TELEM_COL2, y, STR_VALUE, 0);
|
||||
if (!g_model.ignoreSensorIds && !IS_SPEKTRUM_PROTOCOL()) {
|
||||
lcdDrawText(TELEM_COL5, y, STR_ID, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_DISCOVER_SENSORS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT+INDENT_WIDTH, y, allowNewSensors ? STR_STOP_DISCOVER_SENSORS : STR_DISCOVER_SENSORS, attr);
|
||||
if (attr && event==EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
allowNewSensors = !allowNewSensors;
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_NEW_SENSOR:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT+INDENT_WIDTH, y, NO_INDENT(STR_TELEMETRY_NEWSENSOR), attr);
|
||||
if (attr && event==EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
int res = availableTelemetryIndex();
|
||||
if (res >= 0) {
|
||||
s_currIdx = res;
|
||||
pushMenu(menuModelSensor);
|
||||
}
|
||||
else {
|
||||
POPUP_WARNING(STR_TELEMETRYFULL);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_DELETE_ALL_SENSORS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT+INDENT_WIDTH, y, STR_DELETE_ALL_SENSORS, attr);
|
||||
if (attr)
|
||||
s_editMode = 0;
|
||||
if (attr && event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
killEvents(KEY_ENTER);
|
||||
POPUP_CONFIRMATION(STR_CONFIRMDELETE, onDeleteAllSensorsConfirm);
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_IGNORE_SENSOR_INSTANCE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_IGNORE_INSTANCE);
|
||||
g_model.ignoreSensorIds = editCheckBox(g_model.ignoreSensorIds, TELEM_COL2, y, attr, event);
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_RSSI_LABEL:
|
||||
#if defined(MULTIMODULE)
|
||||
if (!IS_INTERNAL_MODULE_ON() &&
|
||||
g_model.moduleData[EXTERNAL_MODULE].type == MODULE_TYPE_MULTIMODULE &&
|
||||
g_model.moduleData[EXTERNAL_MODULE].getMultiProtocol(false) == MODULE_SUBTYPE_MULTI_FS_AFHDS2A)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "RSNR");
|
||||
else
|
||||
#endif
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "RSSI");
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_RSSI_SOURCE: {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + INDENT_WIDTH, y, STR_SOURCE);
|
||||
drawSource(TELEM_COL2, y, g_model.rssiSource ? MIXSRC_FIRST_TELEM + 3 * (g_model.rssiSource - 1) : 0, attr);
|
||||
if (g_model.rssiSource) {
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[g_model.rssiSource - 1];
|
||||
lcdDrawText(lcdNextPos, y, " ", attr);
|
||||
drawReceiverName(lcdNextPos, y, sensor->frskyInstance.rxIndex >> 2, sensor->frskyInstance.rxIndex & 0x03, attr);
|
||||
}
|
||||
if (attr) {
|
||||
g_model.rssiSource = checkIncDec(event, g_model.rssiSource, 0, MAX_TELEMETRY_SENSORS, EE_MODEL | NO_INCDEC_MARKS, isRssiSensorAvailable);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_TELEMETRY_RSSI_ALARM1:
|
||||
case ITEM_TELEMETRY_RSSI_ALARM2: {
|
||||
bool warning = (k==ITEM_TELEMETRY_RSSI_ALARM1);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, (warning ? STR_LOWALARM : STR_CRITICALALARM));
|
||||
lcdDrawNumber(TELEM_COL2, y, warning? g_model.rssiAlarms.getWarningRssi() : g_model.rssiAlarms.getCriticalRssi(), LEFT|attr, 3);
|
||||
|
||||
if (attr && s_editMode>0) {
|
||||
if (warning)
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.rssiAlarms.warning, -30, 30);
|
||||
else
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.rssiAlarms.critical, -30, 30);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ITEM_TELEMETRY_DISABLE_ALARMS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_DISABLE_ALARM);
|
||||
g_model.rssiAlarms.disabled = editCheckBox(g_model.rssiAlarms.disabled, TELEM_COL3, y, attr, event);
|
||||
break;
|
||||
#if defined(VARIO)
|
||||
case ITEM_TELEMETRY_VARIO_LABEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_VARIO);
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_VARIO_SOURCE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, INDENT TR_SOURCE);
|
||||
drawSource(TELEM_COL2, y, g_model.varioData.source ? MIXSRC_FIRST_TELEM+3*(g_model.varioData.source-1) : 0, attr);
|
||||
if (attr) {
|
||||
g_model.varioData.source = checkIncDec(event, g_model.varioData.source, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable);
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_VARIO_RANGE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_RANGE);
|
||||
lcdDrawNumber(TELEM_COL2, y, -10+g_model.varioData.min, (menuHorizontalPosition==0 ? attr : 0)|LEFT);
|
||||
lcdDrawNumber(TELEM_COL3, y, 10+g_model.varioData.max, (menuHorizontalPosition==1 ? attr : 0)|LEFT);
|
||||
if (attr && s_editMode>0) {
|
||||
switch (menuHorizontalPosition) {
|
||||
case 0:
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.varioData.min, -7, 7);
|
||||
break;
|
||||
case 1:
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.varioData.max, -7, 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_TELEMETRY_VARIO_CENTER:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_CENTER);
|
||||
lcdDrawNumber(TELEM_COL2, y, -5+g_model.varioData.centerMin, (menuHorizontalPosition==0 ? attr : 0)|PREC1|LEFT);
|
||||
lcdDrawNumber(TELEM_COL3, y, 5+g_model.varioData.centerMax, (menuHorizontalPosition==1 ? attr : 0)|PREC1|LEFT);
|
||||
lcdDrawTextAtIndex(TELEM_COL4, y, STR_VVARIOCENTER, g_model.varioData.centerSilent, (menuHorizontalPosition==2 ? attr : 0));
|
||||
if (attr && s_editMode>0) {
|
||||
switch (menuHorizontalPosition) {
|
||||
case 0:
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.varioData.centerMin, -16, 5+min<int8_t>(10, g_model.varioData.centerMax+5));
|
||||
break;
|
||||
case 1:
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.varioData.centerMax, -5+max<int8_t>(-10, g_model.varioData.centerMin-5), +15);
|
||||
break;
|
||||
case 2:
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.varioData.centerSilent, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,295 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
enum SensorFields {
|
||||
SENSOR_FIELD_NAME,
|
||||
SENSOR_FIELD_TYPE,
|
||||
SENSOR_FIELD_ID,
|
||||
SENSOR_FIELD_FORMULA=SENSOR_FIELD_ID,
|
||||
SENSOR_FIELD_UNIT,
|
||||
SENSOR_FIELD_PRECISION,
|
||||
SENSOR_FIELD_PARAM1,
|
||||
SENSOR_FIELD_PARAM2,
|
||||
SENSOR_FIELD_PARAM3,
|
||||
SENSOR_FIELD_PARAM4,
|
||||
SENSOR_FIELD_AUTOOFFSET,
|
||||
SENSOR_FIELD_ONLYPOSITIVE,
|
||||
SENSOR_FIELD_FILTER,
|
||||
SENSOR_FIELD_PERSISTENT,
|
||||
SENSOR_FIELD_LOGS,
|
||||
SENSOR_FIELD_MAX
|
||||
};
|
||||
|
||||
#define SENSOR_2ND_COLUMN 140
|
||||
#define SENSOR_3RD_COLUMN 280
|
||||
|
||||
#define SENSOR_UNIT_ROWS ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
||||
#define SENSOR_PREC_ROWS (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT ? (uint8_t)0 : HIDDEN_ROW)
|
||||
#define SENSOR_PARAM1_ROWS (sensor->unit >= UNIT_FIRST_VIRTUAL ? HIDDEN_ROW : (uint8_t)0)
|
||||
#define SENSOR_PARAM2_ROWS (sensor->unit == UNIT_GPS || sensor->unit == UNIT_DATETIME || sensor->unit == UNIT_CELLS || (sensor->type==TELEM_TYPE_CALCULATED && (sensor->formula==TELEM_FORMULA_CONSUMPTION || sensor->formula==TELEM_FORMULA_TOTALIZE)) ? HIDDEN_ROW : (uint8_t)0)
|
||||
#define SENSOR_PARAM3_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW
|
||||
#define SENSOR_PARAM4_ROWS (sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY) ? (uint8_t)0 : HIDDEN_ROW
|
||||
#define SENSOR_AUTOOFFSET_ROWS (sensor->unit != UNIT_RPMS && sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
||||
#define SENSOR_ONLYPOS_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
||||
#define SENSOR_FILTER_ROWS (sensor->isConfigurable() ? (uint8_t)0 : HIDDEN_ROW)
|
||||
#define SENSOR_PERSISTENT_ROWS (sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : HIDDEN_ROW)
|
||||
|
||||
bool menuModelSensor(event_t event)
|
||||
{
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[s_currIdx];
|
||||
|
||||
SUBMENU("SENSOR", ICON_MODEL_TELEMETRY, SENSOR_FIELD_MAX, { 0, 0, sensor->type == TELEM_TYPE_CALCULATED ? (uint8_t)0 : (uint8_t)1, SENSOR_UNIT_ROWS, SENSOR_PREC_ROWS, SENSOR_PARAM1_ROWS, SENSOR_PARAM2_ROWS, SENSOR_PARAM3_ROWS, SENSOR_PARAM4_ROWS, SENSOR_AUTOOFFSET_ROWS, SENSOR_ONLYPOS_ROWS, SENSOR_FILTER_ROWS, SENSOR_PERSISTENT_ROWS, 0 });
|
||||
lcdDrawNumber(lcdNextPos, 3, s_currIdx+1, MENU_TITLE_COLOR|LEFT);
|
||||
drawSensorCustomValue(50, 3 + FH, s_currIdx, getValue(MIXSRC_FIRST_TELEM+3*s_currIdx), MENU_TITLE_COLOR|LEFT);
|
||||
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES + 1/*plus one line in submenus*/; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP - FH - 2 + i*FH;
|
||||
int k = i + menuVerticalOffset;
|
||||
|
||||
for (int j=0; j<k; j++) {
|
||||
if (mstate_tab[j+1] == HIDDEN_ROW) {
|
||||
if (++k >= (int)DIM(mstate_tab)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LcdFlags attr = (menuVerticalPosition==k ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
|
||||
|
||||
switch (k) {
|
||||
case SENSOR_FIELD_NAME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_NAME);
|
||||
editName(SENSOR_2ND_COLUMN, y, sensor->label, TELEM_LABEL_LEN, event, attr);
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_TYPE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, NO_INDENT(STR_TYPE));
|
||||
sensor->type = editChoice(SENSOR_2ND_COLUMN, y, STR_VSENSORTYPES, sensor->type, 0, 1, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
sensor->instance = 0;
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
sensor->param = 0;
|
||||
sensor->filter = 0;
|
||||
sensor->autoOffset = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_ID:
|
||||
if (sensor->type == TELEM_TYPE_CUSTOM) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_ID);
|
||||
lcdDrawHexNumber(SENSOR_2ND_COLUMN, y, sensor->id, LEFT|(menuHorizontalPosition==0 ? attr : 0));
|
||||
lcdDrawNumber(SENSOR_3RD_COLUMN, y, sensor->instance, LEFT|(menuHorizontalPosition==1 ? attr : 0));
|
||||
if (attr) {
|
||||
switch (menuHorizontalPosition) {
|
||||
case 0:
|
||||
sensor->id = checkIncDec(event, sensor->id, 0x0000, 0xffff, INCDEC_REP10|NO_INCDEC_MARKS);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, sensor->instance, 0xff);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_FORMULA);
|
||||
sensor->formula = editChoice(SENSOR_2ND_COLUMN, y, STR_VFORMULAS, sensor->formula, 0, TELEM_FORMULA_LAST, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
sensor->param = 0;
|
||||
if (sensor->formula == TELEM_FORMULA_CELL) {
|
||||
sensor->unit = UNIT_VOLTS;
|
||||
sensor->prec = 2;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
||||
sensor->unit = UNIT_DIST;
|
||||
sensor->prec = 0;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
|
||||
sensor->unit = UNIT_MAH;
|
||||
sensor->prec = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_UNIT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_UNIT);
|
||||
lcdDrawTextAtIndex(SENSOR_2ND_COLUMN, y, STR_VTELEMUNIT, sensor->unit, attr);
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELVAR_ZERO(event, sensor->unit, UNIT_MAX);
|
||||
if (checkIncDec_Ret) {
|
||||
if (sensor->unit == UNIT_FAHRENHEIT) {
|
||||
sensor->prec = 0;
|
||||
}
|
||||
telemetryItems[s_currIdx].clear();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_PRECISION:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_PRECISION);
|
||||
sensor->prec = editChoice(SENSOR_2ND_COLUMN, y, STR_VPREC, sensor->prec, 0, 2, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
telemetryItems[s_currIdx].clear();
|
||||
}
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_PARAM1:
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
if (sensor->formula == TELEM_FORMULA_CELL) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_CELLSENSOR);
|
||||
drawSource(SENSOR_2ND_COLUMN, y, sensor->cell.source ? MIXSRC_FIRST_TELEM+3*(sensor->cell.source-1) : 0, attr);
|
||||
if (attr) {
|
||||
sensor->cell.source = checkIncDec(event, sensor->cell.source, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isCellsSensor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_GPSSENSOR);
|
||||
drawSource(SENSOR_2ND_COLUMN, y, sensor->dist.gps ? MIXSRC_FIRST_TELEM+3*(sensor->dist.gps-1) : 0, attr);
|
||||
if (attr) {
|
||||
sensor->dist.gps = checkIncDec(event, sensor->dist.gps, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isGPSSensor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_CURRENTSENSOR);
|
||||
drawSource(SENSOR_2ND_COLUMN, y, sensor->consumption.source ? MIXSRC_FIRST_TELEM+3*(sensor->consumption.source-1) : 0, attr);
|
||||
if (attr) {
|
||||
sensor->consumption.source = checkIncDec(event, sensor->consumption.source, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable);
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_TOTALIZE) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SOURCE);
|
||||
drawSource(SENSOR_2ND_COLUMN, y, sensor->consumption.source ? MIXSRC_FIRST_TELEM+3*(sensor->consumption.source-1) : 0, attr);
|
||||
if (attr) {
|
||||
sensor->consumption.source = checkIncDec(event, sensor->consumption.source, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sensor->unit == UNIT_RPMS) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, NO_INDENT(STR_BLADES));
|
||||
if (attr) sensor->custom.ratio = checkIncDec(event, sensor->custom.ratio, 1, 30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
||||
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.ratio, LEFT|attr);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_RATIO);
|
||||
if (attr) sensor->custom.ratio = checkIncDec(event, sensor->custom.ratio, 0, 30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
||||
if (sensor->custom.ratio == 0)
|
||||
lcdDrawText(SENSOR_2ND_COLUMN, y, "-", attr);
|
||||
else
|
||||
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.ratio, LEFT|attr|PREC1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// no break
|
||||
|
||||
case SENSOR_FIELD_PARAM2:
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
if (sensor->formula == TELEM_FORMULA_CELL) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_CELLINDEX);
|
||||
sensor->cell.index = editChoice(SENSOR_2ND_COLUMN, y, STR_VCELLINDEX, sensor->cell.index, 0, 8, attr, event);
|
||||
break;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_ALTSENSOR);
|
||||
drawSource(SENSOR_2ND_COLUMN, y, sensor->dist.alt ? MIXSRC_FIRST_TELEM+3*(sensor->dist.alt-1) : 0, attr);
|
||||
if (attr) {
|
||||
sensor->dist.alt = checkIncDec(event, sensor->dist.alt, 0, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isAltSensor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (sensor->unit == UNIT_RPMS) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MULTIPLIER);
|
||||
if (attr) sensor->custom.offset = checkIncDec(event, sensor->custom.offset, 1, 30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
||||
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.offset, LEFT|attr);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_OFFSET);
|
||||
if (attr) sensor->custom.offset = checkIncDec(event, sensor->custom.offset, -30000, +30000, EE_MODEL|NO_INCDEC_MARKS|INCDEC_REP10);
|
||||
if (sensor->prec > 0) attr |= (sensor->prec == 2 ? PREC2 : PREC1);
|
||||
lcdDrawNumber(SENSOR_2ND_COLUMN, y, sensor->custom.offset, LEFT|attr);
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
|
||||
case SENSOR_FIELD_PARAM3:
|
||||
// no break
|
||||
|
||||
case SENSOR_FIELD_PARAM4:
|
||||
{
|
||||
drawStringWithIndex(MENUS_MARGIN_LEFT, y, STR_SOURCE, k-SENSOR_FIELD_PARAM1+1);
|
||||
int8_t * source = &sensor->calc.sources[k-SENSOR_FIELD_PARAM1];
|
||||
if (attr) {
|
||||
*source = checkIncDec(event, *source, -MAX_TELEMETRY_SENSORS, MAX_TELEMETRY_SENSORS, EE_MODEL|NO_INCDEC_MARKS, isSensorAvailable);
|
||||
}
|
||||
if (*source < 0) {
|
||||
lcdDrawText(SENSOR_2ND_COLUMN, y, "-", attr);
|
||||
drawSource(SENSOR_2ND_COLUMN+5, y, MIXSRC_FIRST_TELEM+3*(-1-*source), attr);
|
||||
}
|
||||
else {
|
||||
drawSource(SENSOR_2ND_COLUMN, y, *source ? MIXSRC_FIRST_TELEM+3*(*source-1) : 0, attr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SENSOR_FIELD_AUTOOFFSET:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_AUTOOFFSET);
|
||||
sensor->autoOffset = editCheckBox(sensor->autoOffset, SENSOR_2ND_COLUMN, y, attr, event);
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_ONLYPOSITIVE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_ONLYPOSITIVE);
|
||||
sensor->onlyPositive = editCheckBox(sensor->onlyPositive, SENSOR_2ND_COLUMN, y, attr, event);
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_FILTER:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_FILTER);
|
||||
sensor->filter = editCheckBox(sensor->filter, SENSOR_2ND_COLUMN, y, attr, event);
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_PERSISTENT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, NO_INDENT(STR_PERSISTENT));
|
||||
sensor->persistent = editCheckBox(sensor->persistent, SENSOR_2ND_COLUMN, y, attr, event);
|
||||
if (checkIncDec_Ret && !sensor->persistent) {
|
||||
sensor->persistentValue = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case SENSOR_FIELD_LOGS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_LOGS);
|
||||
sensor->logs = editCheckBox(sensor->logs, SENSOR_2ND_COLUMN, y, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
logsClose();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
const char *warningText = nullptr;
|
||||
const char *warningInfoText;
|
||||
uint8_t warningInfoLength;
|
||||
uint8_t warningType;
|
||||
uint8_t warningResult = 0;
|
||||
uint8_t warningInfoFlags = ZCHAR;
|
||||
PopupFunc popupFunc = nullptr;
|
||||
const char *popupMenuItems[POPUP_MENU_MAX_LINES];
|
||||
uint8_t popupMenuSelectedItem = 0;
|
||||
uint16_t popupMenuItemsCount = 0;
|
||||
uint16_t popupMenuOffset = 0;
|
||||
uint8_t popupMenuOffsetType = MENU_OFFSET_INTERNAL;
|
||||
void (*popupMenuHandler)(const char * result);
|
||||
|
||||
void drawAlertBox(const char * title, const char * text, const char * action)
|
||||
{
|
||||
theme->drawMessageBox(title, text, action, WARNING_TYPE_ALERT);
|
||||
}
|
||||
|
||||
void showAlertBox(const char * title, const char * text, const char * action, uint8_t sound)
|
||||
{
|
||||
drawAlertBox(title, text, action);
|
||||
AUDIO_ERROR_MESSAGE(sound);
|
||||
lcdRefresh();
|
||||
lcdSetContrast();
|
||||
waitKeysReleased();
|
||||
backlightOn();
|
||||
checkBacklight();
|
||||
}
|
||||
|
||||
void showMessageBox(const char * title)
|
||||
{
|
||||
// drawMessageBox();
|
||||
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y, title, WARNING_LINE_LEN, DBLSIZE|WARNING_COLOR);
|
||||
lcdRefresh();
|
||||
}
|
||||
|
||||
void drawPopupBackgroundAndBorder(coord_t x, coord_t y, coord_t w, coord_t h)
|
||||
{
|
||||
lcdDrawSolidFilledRect(x + 1, y + 1, w - 2, h - 2, TEXT_BGCOLOR);
|
||||
lcdDrawSolidRect(x, y, w, h, 1, ALARM_COLOR);
|
||||
}
|
||||
|
||||
void runPopupWarning(event_t event)
|
||||
{
|
||||
warningResult = false;
|
||||
|
||||
const char * action;
|
||||
switch (warningType) {
|
||||
case WARNING_TYPE_INFO:
|
||||
action = STR_OK;
|
||||
break;
|
||||
case WARNING_TYPE_ASTERISK:
|
||||
case WARNING_TYPE_WAIT:
|
||||
action = STR_EXIT;
|
||||
break;
|
||||
default:
|
||||
action = STR_POPUPS_ENTER_EXIT;
|
||||
break;
|
||||
}
|
||||
|
||||
theme->drawMessageBox(warningText, warningInfoText, action, warningType);
|
||||
|
||||
switch (event) {
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (warningType == WARNING_TYPE_ASTERISK)
|
||||
// key ignored, the user has to press [EXIT]
|
||||
break;
|
||||
|
||||
if (warningType == WARNING_TYPE_CONFIRM) {
|
||||
warningType = WARNING_TYPE_ASTERISK;
|
||||
warningText = nullptr;
|
||||
if (popupMenuHandler)
|
||||
popupMenuHandler(STR_OK);
|
||||
else
|
||||
warningResult = true;
|
||||
break;
|
||||
}
|
||||
// no break
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
if (warningType == WARNING_TYPE_CONFIRM) {
|
||||
if (popupMenuHandler)
|
||||
popupMenuHandler(STR_EXIT);
|
||||
}
|
||||
warningText = nullptr;
|
||||
warningType = WARNING_TYPE_ASTERISK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const char * runPopupMenu(event_t event)
|
||||
{
|
||||
const char * result = nullptr;
|
||||
|
||||
uint8_t display_count = min<unsigned int>(popupMenuItemsCount, MENU_MAX_DISPLAY_LINES);
|
||||
|
||||
switch (event) {
|
||||
case EVT_ROTARY_LEFT:
|
||||
if (popupMenuSelectedItem > 0) {
|
||||
popupMenuSelectedItem--;
|
||||
}
|
||||
else if (popupMenuOffset > 0) {
|
||||
popupMenuOffset--;
|
||||
result = STR_UPDATE_LIST;
|
||||
}
|
||||
else {
|
||||
popupMenuSelectedItem = min<uint8_t>(display_count, MENU_MAX_DISPLAY_LINES) - 1;
|
||||
if (popupMenuItemsCount > MENU_MAX_DISPLAY_LINES) {
|
||||
popupMenuOffset = popupMenuItemsCount - MENU_MAX_DISPLAY_LINES;
|
||||
result = STR_UPDATE_LIST;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
if (popupMenuSelectedItem < display_count - 1 && popupMenuOffset + popupMenuSelectedItem + 1 < popupMenuItemsCount) {
|
||||
popupMenuSelectedItem++;
|
||||
}
|
||||
else if (popupMenuItemsCount > popupMenuOffset + display_count) {
|
||||
popupMenuOffset++;
|
||||
result = STR_UPDATE_LIST;
|
||||
}
|
||||
else {
|
||||
popupMenuSelectedItem = 0;
|
||||
if (popupMenuOffset) {
|
||||
popupMenuOffset = 0;
|
||||
result = STR_UPDATE_LIST;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
result = popupMenuItems[popupMenuSelectedItem + (popupMenuOffsetType == MENU_OFFSET_INTERNAL ? popupMenuOffset : 0)];
|
||||
popupMenuItemsCount = 0;
|
||||
popupMenuSelectedItem = 0;
|
||||
popupMenuOffset = 0;
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
result = STR_EXIT;
|
||||
popupMenuItemsCount = 0;
|
||||
popupMenuSelectedItem = 0;
|
||||
popupMenuOffset = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
int y = (LCD_H - (display_count*(FH+1))) / 2;
|
||||
|
||||
drawPopupBackgroundAndBorder(MENU_X, y, MENU_W, display_count * (FH+1) + 2);
|
||||
|
||||
for (uint8_t i=0; i<display_count; i++) {
|
||||
if (i == popupMenuSelectedItem) {
|
||||
lcdDrawSolidFilledRect(MENU_X+1, i*(FH+1) + y + 1, MENU_W-2, FH+1, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawText(MENU_X+6, i*(FH+1) + y + 2, popupMenuItems[i+(popupMenuOffsetType == MENU_OFFSET_INTERNAL ? popupMenuOffset : 0)], TEXT_INVERTED_COLOR);
|
||||
}
|
||||
else {
|
||||
lcdDrawText(MENU_X+6, i*(FH+1) + y + 2, popupMenuItems[i+(popupMenuOffsetType == MENU_OFFSET_INTERNAL ? popupMenuOffset : 0)], 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (popupMenuItemsCount > display_count) {
|
||||
drawVerticalScrollbar(MENU_X+MENU_W-1, y+1, MENU_MAX_DISPLAY_LINES * (FH+1), popupMenuOffset, popupMenuItemsCount, MENU_MAX_DISPLAY_LINES);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define XPOT_DELTA 10
|
||||
#define XPOT_DELAY 5 /* cycles */
|
||||
#define STICKS_WIDTH 90
|
||||
#define STICKS_Y 60
|
||||
#define STICK_LEFT_X 25
|
||||
#define STICK_RIGHT_X (LCD_W-STICK_LEFT_X-STICKS_WIDTH)
|
||||
#define STICK_PANEL_WIDTH 68
|
||||
|
||||
void drawStick(coord_t x, coord_t y, const BitmapBuffer * background, int16_t xval, int16_t yval)
|
||||
{
|
||||
lcd->drawBitmap(x, y, calibStickBackground);
|
||||
lcd->drawBitmap(x + 2 + STICK_PANEL_WIDTH/2 + STICK_PANEL_WIDTH/2 * xval/RESX, y + 2 + STICK_PANEL_WIDTH/2 - STICK_PANEL_WIDTH/2 * yval/RESX, calibStick);
|
||||
}
|
||||
|
||||
void drawSticks()
|
||||
{
|
||||
int16_t calibStickVert = calibratedAnalogs[CONVERT_MODE(1)];
|
||||
if (g_model.throttleReversed && CONVERT_MODE(1) == THR_STICK)
|
||||
calibStickVert = -calibStickVert;
|
||||
drawStick(STICK_LEFT_X, STICKS_Y, calibStickBackground, calibratedAnalogs[CONVERT_MODE(0)], calibStickVert);
|
||||
|
||||
calibStickVert = calibratedAnalogs[CONVERT_MODE(2)];
|
||||
if (g_model.throttleReversed && CONVERT_MODE(2) == THR_STICK)
|
||||
calibStickVert = -calibStickVert;
|
||||
drawStick(STICK_RIGHT_X, STICKS_Y, calibStickBackground, calibratedAnalogs[CONVERT_MODE(3)], calibStickVert);
|
||||
}
|
||||
|
||||
void drawPots()
|
||||
{
|
||||
// The pots which are displayed in the main view
|
||||
extern void drawMainPots();
|
||||
drawMainPots();
|
||||
|
||||
#if defined(PCBX12S)
|
||||
// The 2 main front sliders
|
||||
drawVerticalSlider(125, 120, 120, calibratedAnalogs[CALIBRATED_SLIDER_FRONT_LEFT], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
drawVerticalSlider(LCD_W-125-12, 120, 120, calibratedAnalogs[CALIBRATED_SLIDER_FRONT_RIGHT], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PCBX12S)
|
||||
void drawMouse()
|
||||
{
|
||||
drawStick(STICK_LEFT_X, STICKS_Y+100, calibTrackpBackground, calibratedAnalogs[CALIBRATED_MOUSE1], calibratedAnalogs[CALIBRATED_MOUSE2]);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool menuCommonCalib(event_t event)
|
||||
{
|
||||
drawMenuTemplate(NULL, ICON_RADIO_CALIBRATION, NULL, OPTION_MENU_NO_FOOTER);
|
||||
|
||||
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_MOUSE_ANALOGS; i++) { // get low and high vals for sticks and trims
|
||||
int16_t vt = i<TX_VOLTAGE ? anaIn(i) : anaIn(i+1);
|
||||
reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]);
|
||||
reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]);
|
||||
if (i >= POT1 && i <= POT_LAST) {
|
||||
if (IS_POT_WITHOUT_DETENT(i)) {
|
||||
reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2;
|
||||
}
|
||||
uint8_t idx = i - POT1;
|
||||
int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount;
|
||||
if (IS_POT_MULTIPOS(i) && count <= XPOTS_MULTIPOS_COUNT) {
|
||||
// use raw analog value for multipos calibraton, anaIn() already has multipos decoded value
|
||||
vt = getAnalogValue(i) >> 1;
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 0 || vt < reusableBuffer.calib.xpotsCalib[idx].lastPosition - XPOT_DELTA || vt > reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) {
|
||||
reusableBuffer.calib.xpotsCalib[idx].lastPosition = vt;
|
||||
reusableBuffer.calib.xpotsCalib[idx].lastCount = 1;
|
||||
}
|
||||
else {
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].lastCount < 255) {
|
||||
reusableBuffer.calib.xpotsCalib[idx].lastCount++;
|
||||
}
|
||||
}
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].lastCount == XPOT_DELAY) {
|
||||
int16_t position = reusableBuffer.calib.xpotsCalib[idx].lastPosition;
|
||||
bool found = false;
|
||||
for (int j=0; j<count; j++) {
|
||||
int16_t step = reusableBuffer.calib.xpotsCalib[idx].steps[j];
|
||||
if (position >= step-XPOT_DELTA && position <= step+XPOT_DELTA) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (count < XPOTS_MULTIPOS_COUNT) {
|
||||
reusableBuffer.calib.xpotsCalib[idx].steps[count] = position;
|
||||
}
|
||||
reusableBuffer.calib.xpotsCalib[idx].stepsCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
menuCalibrationState = CALIB_START;
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_ENTER):
|
||||
killEvents(event);
|
||||
menuCalibrationState++;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (menuCalibrationState) {
|
||||
case CALIB_START:
|
||||
// START CALIBRATION
|
||||
if (!READ_ONLY()) {
|
||||
lcdDrawText(50, 3, STR_MENUCALIBRATION, MENU_TITLE_COLOR);
|
||||
lcdDrawText(50, 3+FH, STR_MENUTOSTART, MENU_TITLE_COLOR);
|
||||
}
|
||||
break;
|
||||
|
||||
case CALIB_SET_MIDPOINT:
|
||||
// SET MIDPOINT
|
||||
lcdDrawText(50, 3, STR_MENUCALIBRATION, MENU_TITLE_COLOR);
|
||||
lcdDrawText(50, 3+FH, STR_SETMIDPOINT, MENU_TITLE_COLOR);
|
||||
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_MOUSE_ANALOGS; i++) {
|
||||
reusableBuffer.calib.loVals[i] = 15000;
|
||||
reusableBuffer.calib.hiVals[i] = -15000;
|
||||
reusableBuffer.calib.midVals[i] = i < TX_VOLTAGE ? anaIn(i) : anaIn(i+1);
|
||||
if (i < NUM_XPOTS) {
|
||||
reusableBuffer.calib.xpotsCalib[i].stepsCount = 0;
|
||||
reusableBuffer.calib.xpotsCalib[i].lastCount = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CALIB_MOVE_STICKS:
|
||||
// MOVE STICKS/POTS
|
||||
lcdDrawText(50, 3, STR_MENUCALIBRATION, MENU_TITLE_COLOR);
|
||||
lcdDrawText(50, 3+FH, STR_MOVESTICKSPOTS, MENU_TITLE_COLOR);
|
||||
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_MOUSE_ANALOGS; i++) {
|
||||
if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i]) > 50) {
|
||||
g_eeGeneral.calib[i].mid = reusableBuffer.calib.midVals[i];
|
||||
int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i];
|
||||
g_eeGeneral.calib[i].spanNeg = v - v/STICK_TOLERANCE;
|
||||
v = reusableBuffer.calib.hiVals[i] - reusableBuffer.calib.midVals[i];
|
||||
g_eeGeneral.calib[i].spanPos = v - v/STICK_TOLERANCE;
|
||||
}
|
||||
}
|
||||
for (int i=POT1; i<=POT_LAST; i++) {
|
||||
int idx = i - POT1;
|
||||
int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount;
|
||||
if (IS_POT_MULTIPOS(i)) {
|
||||
if (count > 1 && count <= XPOTS_MULTIPOS_COUNT) {
|
||||
for (int j=0; j<count; j++) {
|
||||
for (int k=j+1; k<count; k++) {
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].steps[k] < reusableBuffer.calib.xpotsCalib[idx].steps[j]) {
|
||||
SWAP(reusableBuffer.calib.xpotsCalib[idx].steps[j], reusableBuffer.calib.xpotsCalib[idx].steps[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i];
|
||||
calib->count = count - 1;
|
||||
for (int j=0; j<calib->count; j++) {
|
||||
calib->steps[j] = (reusableBuffer.calib.xpotsCalib[idx].steps[j+1] + reusableBuffer.calib.xpotsCalib[idx].steps[j]) >> 5;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// g_eeGeneral.potsConfig &= ~(0x03<<(2*idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CALIB_STORE:
|
||||
g_eeGeneral.chkSum = evalChkSum();
|
||||
storageDirty(EE_GENERAL);
|
||||
menuCalibrationState = CALIB_FINISHED;
|
||||
break;
|
||||
|
||||
default:
|
||||
menuCalibrationState = CALIB_START;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (calibHorus) {
|
||||
lcd->drawBitmap((LCD_W-calibHorus->getWidth())/2, LCD_H-20-calibHorus->getHeight(), calibHorus);
|
||||
}
|
||||
|
||||
drawSticks();
|
||||
drawPots();
|
||||
|
||||
#if defined(PCBX12S)
|
||||
drawMouse();
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool menuRadioCalibration(event_t event)
|
||||
{
|
||||
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) TRACE("Menu %s displayed ...", STR_MENUCALIBRATION);
|
||||
if (menuCalibrationState == CALIB_FINISHED || (menuCalibrationState == CALIB_START && event == EVT_KEY_FIRST(KEY_EXIT))) {
|
||||
menuCalibrationState = CALIB_START;
|
||||
killEvents(event);
|
||||
popMenu();
|
||||
return false;
|
||||
}
|
||||
if (!check_submenu_simple(event, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
menuVerticalPosition = -1;
|
||||
|
||||
return menuCommonCalib(READ_ONLY() ? 0 : event);
|
||||
}
|
||||
|
||||
bool menuFirstCalib(event_t event)
|
||||
{
|
||||
if (event == EVT_KEY_FIRST(KEY_EXIT) || menuCalibrationState == CALIB_FINISHED) {
|
||||
menuCalibrationState = CALIB_START;
|
||||
chainMenu(menuMainView);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return menuCommonCalib(event);
|
||||
}
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
enum MenuRadioHardwareItems {
|
||||
ITEM_RADIO_HARDWARE_CALIBRATION,
|
||||
ITEM_RADIO_HARDWARE_LABEL_STICKS,
|
||||
ITEM_RADIO_HARDWARE_STICK1,
|
||||
ITEM_RADIO_HARDWARE_STICK2,
|
||||
ITEM_RADIO_HARDWARE_STICK3,
|
||||
ITEM_RADIO_HARDWARE_STICK4,
|
||||
ITEM_RADIO_HARDWARE_LABEL_POTS,
|
||||
ITEM_RADIO_HARDWARE_POT1,
|
||||
ITEM_RADIO_HARDWARE_POT2,
|
||||
ITEM_RADIO_HARDWARE_POT3,
|
||||
#if defined(PCBX10)
|
||||
ITEM_RADIO_HARDWARE_EXT1,
|
||||
ITEM_RADIO_HARDWARE_EXT2,
|
||||
#endif
|
||||
ITEM_RADIO_HARDWARE_LS,
|
||||
ITEM_RADIO_HARDWARE_RS,
|
||||
#if defined(PCBX12S)
|
||||
ITEM_RADIO_HARDWARE_LS2,
|
||||
ITEM_RADIO_HARDWARE_RS2,
|
||||
#endif
|
||||
ITEM_RADIO_HARDWARE_LABEL_SWITCHES,
|
||||
ITEM_RADIO_HARDWARE_SA,
|
||||
ITEM_RADIO_HARDWARE_SB,
|
||||
ITEM_RADIO_HARDWARE_SC,
|
||||
ITEM_RADIO_HARDWARE_SD,
|
||||
ITEM_RADIO_HARDWARE_SE,
|
||||
ITEM_RADIO_HARDWARE_SF,
|
||||
ITEM_RADIO_HARDWARE_SG,
|
||||
ITEM_RADIO_HARDWARE_SH,
|
||||
ITEM_RADIO_HARDWARE_SI, // Gimbal switch left
|
||||
ITEM_RADIO_HARDWARE_SJ, // Gimbal switch right
|
||||
ITEM_RADIO_HARDWARE_BATTERY_CALIB,
|
||||
ITEM_RADIO_HARDWARE_RTC_BATTERY,
|
||||
ITEM_RADIO_HARDWARE_SERIAL_BAUDRATE,
|
||||
ITEM_RADIO_HARDWARE_BLUETOOTH_MODE,
|
||||
ITEM_RADIO_HARDWARE_BLUETOOTH_PAIRING_CODE,
|
||||
ITEM_RADIO_HARDWARE_BLUETOOTH_NAME,
|
||||
#if defined(AUX_SERIAL)
|
||||
ITEM_RADIO_HARDWARE_AUX_SERIAL_MODE,
|
||||
#endif
|
||||
ITEM_RADIO_HARDWARE_JITTER_FILTER,
|
||||
ITEM_RADIO_HARDWARE_MAX
|
||||
};
|
||||
|
||||
#define HW_SETTINGS_COLUMN 150
|
||||
|
||||
|
||||
#define POTS_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1
|
||||
#define SWITCHES_ROWS NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1, NAVIGATION_LINE_BY_LINE|1
|
||||
|
||||
#define BLUETOOTH_ROWS 0, uint8_t(g_eeGeneral.bluetoothMode != BLUETOOTH_TELEMETRY ? HIDDEN_ROW : -1), uint8_t(g_eeGeneral.bluetoothMode == BLUETOOTH_OFF ? -1 : 0)
|
||||
|
||||
// TODO should be moved to the HAL
|
||||
#define SWITCH_TYPE_MAX(sw) ((MIXSRC_SF-MIXSRC_FIRST_SWITCH == sw || MIXSRC_SH-MIXSRC_FIRST_SWITCH == sw || MIXSRC_SI-MIXSRC_FIRST_SWITCH == sw || MIXSRC_SJ-MIXSRC_FIRST_SWITCH == sw) ? SWITCH_2POS : SWITCH_3POS)
|
||||
|
||||
bool menuRadioHardware(event_t event)
|
||||
{
|
||||
MENU(STR_HARDWARE, RADIO_ICONS, menuTabGeneral, MENU_RADIO_HARDWARE, ITEM_RADIO_HARDWARE_MAX, {
|
||||
0 /* calibration button */,
|
||||
|
||||
LABEL(Sticks),
|
||||
0 /* stick 1 */,
|
||||
0 /* stick 2 */,
|
||||
0 /* stick 3 */,
|
||||
0 /* stick 4 */,
|
||||
|
||||
LABEL(Pots),
|
||||
POTS_ROWS,
|
||||
|
||||
LABEL(Switches),
|
||||
SWITCHES_ROWS,
|
||||
|
||||
0, /* battery */
|
||||
READONLY_ROW, /* RTC */
|
||||
|
||||
0, /* max baudrate */
|
||||
|
||||
BLUETOOTH_ROWS,
|
||||
|
||||
0, /* aux serial mode */
|
||||
0, /* ADC filter */
|
||||
});
|
||||
|
||||
uint8_t sub = menuVerticalPosition;
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES; ++i) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
int k = i + menuVerticalOffset;
|
||||
for (int j=0; j<=k; j++) {
|
||||
if (mstate_tab[j] == HIDDEN_ROW)
|
||||
k++;
|
||||
}
|
||||
LcdFlags attr = (sub == k ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
|
||||
switch (k) {
|
||||
case ITEM_RADIO_HARDWARE_CALIBRATION:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "Calibration", attr);
|
||||
if (attr && s_editMode>0) {
|
||||
pushMenu(menuRadioCalibration);
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_LABEL_STICKS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_STICKS);
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_STICK1:
|
||||
case ITEM_RADIO_HARDWARE_STICK2:
|
||||
case ITEM_RADIO_HARDWARE_STICK3:
|
||||
case ITEM_RADIO_HARDWARE_STICK4:
|
||||
editStickHardwareSettings(HW_SETTINGS_COLUMN, y, k - ITEM_RADIO_HARDWARE_STICK1, event, attr);
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_LS:
|
||||
case ITEM_RADIO_HARDWARE_RS:
|
||||
#if defined(PCBX12S)
|
||||
case ITEM_RADIO_HARDWARE_LS2:
|
||||
case ITEM_RADIO_HARDWARE_RS2:
|
||||
#endif
|
||||
{
|
||||
int idx = k - ITEM_RADIO_HARDWARE_LS;
|
||||
uint8_t mask = (0x01 << idx);
|
||||
lcdDrawTextAtIndex(INDENT_WIDTH, y, STR_VSRCRAW, NUM_STICKS+NUM_POTS+idx+1, menuHorizontalPosition < 0 ? attr : 0);
|
||||
if (ZEXIST(g_eeGeneral.anaNames[NUM_STICKS+NUM_POTS+idx]) || (attr && menuHorizontalPosition == 0))
|
||||
editName(HW_SETTINGS_COLUMN, y, g_eeGeneral.anaNames[NUM_STICKS+NUM_POTS+idx], LEN_ANA_NAME, event, attr && menuHorizontalPosition == 0);
|
||||
else
|
||||
lcdDrawMMM(HW_SETTINGS_COLUMN, y, 0);
|
||||
uint8_t potType = (g_eeGeneral.slidersConfig & mask) >> idx;
|
||||
potType = editChoice(HW_SETTINGS_COLUMN+50, y, STR_SLIDERTYPES, potType, SLIDER_NONE, SLIDER_WITH_DETENT, menuHorizontalPosition == 1 ? attr : 0, event);
|
||||
g_eeGeneral.slidersConfig &= ~mask;
|
||||
g_eeGeneral.slidersConfig |= (potType << idx);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_RADIO_HARDWARE_LABEL_POTS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_POTS);
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_POT1:
|
||||
case ITEM_RADIO_HARDWARE_POT2:
|
||||
case ITEM_RADIO_HARDWARE_POT3:
|
||||
#if defined(PCBX10)
|
||||
case ITEM_RADIO_HARDWARE_EXT1:
|
||||
case ITEM_RADIO_HARDWARE_EXT2:
|
||||
#endif
|
||||
{
|
||||
int index = k - ITEM_RADIO_HARDWARE_POT1;
|
||||
lcdDrawTextAtIndex(INDENT_WIDTH, y, STR_VSRCRAW, NUM_STICKS+index+1, menuHorizontalPosition < 0 ? attr : 0);
|
||||
if (ZEXIST(g_eeGeneral.anaNames[NUM_STICKS+index]) || (attr && menuHorizontalPosition == 0))
|
||||
editName(HW_SETTINGS_COLUMN, y, g_eeGeneral.anaNames[NUM_STICKS+index], LEN_ANA_NAME, event, attr && menuHorizontalPosition == 0);
|
||||
else
|
||||
lcdDrawMMM(HW_SETTINGS_COLUMN, y, 0);
|
||||
uint32_t potType = bfGet<uint32_t>(g_eeGeneral.potsConfig, 2*(index), 2);
|
||||
potType = editChoice(HW_SETTINGS_COLUMN+50, y, STR_POTTYPES, potType, POT_NONE, POT_WITHOUT_DETENT, menuHorizontalPosition == 1 ? attr : 0, event);
|
||||
g_eeGeneral.potsConfig = bfSet<uint32_t>(g_eeGeneral.potsConfig, potType, 2*index, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_RADIO_HARDWARE_LABEL_SWITCHES:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SWITCHES);
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_SA:
|
||||
case ITEM_RADIO_HARDWARE_SB:
|
||||
case ITEM_RADIO_HARDWARE_SC:
|
||||
case ITEM_RADIO_HARDWARE_SD:
|
||||
case ITEM_RADIO_HARDWARE_SE:
|
||||
case ITEM_RADIO_HARDWARE_SF:
|
||||
case ITEM_RADIO_HARDWARE_SG:
|
||||
case ITEM_RADIO_HARDWARE_SH:
|
||||
case ITEM_RADIO_HARDWARE_SI:
|
||||
case ITEM_RADIO_HARDWARE_SJ:
|
||||
{
|
||||
int index = k - ITEM_RADIO_HARDWARE_SA;
|
||||
int config = SWITCH_CONFIG(index);
|
||||
lcdDrawTextAtIndex(INDENT_WIDTH, y, STR_VSRCRAW, MIXSRC_FIRST_SWITCH-MIXSRC_Rud+index+1, menuHorizontalPosition < 0 ? attr : 0);
|
||||
if (ZEXIST(g_eeGeneral.switchNames[index]) || (attr && menuHorizontalPosition == 0))
|
||||
editName(HW_SETTINGS_COLUMN, y, g_eeGeneral.switchNames[index], LEN_SWITCH_NAME, event, menuHorizontalPosition == 0 ? attr : 0);
|
||||
else
|
||||
lcdDrawMMM(HW_SETTINGS_COLUMN, y, 0);
|
||||
config = editChoice(HW_SETTINGS_COLUMN+50, y, STR_SWTYPES, config, SWITCH_NONE, SWITCH_TYPE_MAX(index), menuHorizontalPosition == 1 ? attr : 0, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
g_eeGeneral.switchConfig = bfSet<swconfig_t>(g_eeGeneral.switchConfig, config, 2*index, 2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_RADIO_HARDWARE_BATTERY_CALIB:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BATT_CALIB);
|
||||
lcdDrawNumber(HW_SETTINGS_COLUMN+50, y, getBatteryVoltage(), attr|PREC2, 0, NULL, "V");
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.txVoltageCalibration, -127, 127);
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_RTC_BATTERY:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_RTC_BATT);
|
||||
lcdDrawNumber(HW_SETTINGS_COLUMN+50, y, getRTCBatteryVoltage(), attr|PREC2, 0, NULL, "V");
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_SERIAL_BAUDRATE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MAXBAUDRATE);
|
||||
lcdDrawNumber(HW_SETTINGS_COLUMN+50, y, CROSSFIRE_BAUDRATES[g_eeGeneral.telemetryBaudrate], attr|LEFT);
|
||||
if (attr) {
|
||||
g_eeGeneral.telemetryBaudrate = DIM(CROSSFIRE_BAUDRATES) - 1 - checkIncDecModel(event, DIM(CROSSFIRE_BAUDRATES) - 1 - g_eeGeneral.telemetryBaudrate, 0, DIM(CROSSFIRE_BAUDRATES) - 1);
|
||||
if (checkIncDec_Ret && IS_EXTERNAL_MODULE_ON()) {
|
||||
pauseMixerCalculations();
|
||||
pausePulses();
|
||||
EXTERNAL_MODULE_OFF();
|
||||
RTOS_WAIT_MS(20); // 20ms so that the pulses interrupt will reinit the frame rate
|
||||
telemetryProtocol = 255; // force telemetry port + module reinitialization
|
||||
EXTERNAL_MODULE_ON();
|
||||
resumePulses();
|
||||
resumeMixerCalculations();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_BLUETOOTH_MODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BLUETOOTH);
|
||||
g_eeGeneral.bluetoothMode = editChoice(HW_SETTINGS_COLUMN+50, y, STR_BLUETOOTH_MODES, g_eeGeneral.bluetoothMode, BLUETOOTH_OFF, BLUETOOTH_TRAINER, attr, event);
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_BLUETOOTH_PAIRING_CODE:
|
||||
lcdDrawText(INDENT_WIDTH, y, STR_BLUETOOTH_PIN_CODE);
|
||||
lcdDrawText(HW_SETTINGS_COLUMN+50, y, "000000", 0);
|
||||
break;
|
||||
|
||||
case ITEM_RADIO_HARDWARE_BLUETOOTH_NAME:
|
||||
lcdDrawText(INDENT_WIDTH, y, STR_NAME);
|
||||
editName(HW_SETTINGS_COLUMN+50, y, g_eeGeneral.bluetoothName, LEN_BLUETOOTH_NAME, event, attr);
|
||||
break;
|
||||
|
||||
#if defined(AUX_SERIAL)
|
||||
case ITEM_RADIO_HARDWARE_AUX_SERIAL_MODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_AUX_SERIAL_MODE);
|
||||
g_eeGeneral.auxSerialMode = editChoice(HW_SETTINGS_COLUMN+50, y, STR_AUX_SERIAL_MODES, g_eeGeneral.auxSerialMode, 0, UART_MODE_MAX, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
auxSerialInit(g_eeGeneral.auxSerialMode, modelTelemetryProtocol());
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_RADIO_HARDWARE_JITTER_FILTER:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_JITTER_FILTER);
|
||||
uint8_t b = 1-g_eeGeneral.jitterFilter;
|
||||
g_eeGeneral.jitterFilter = 1 - editCheckBox(b, HW_SETTINGS_COLUMN+50, y, attr, event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
enum PowerMeterFields {
|
||||
POWER_METER_FREQ_RANGE,
|
||||
POWER_METER_ATTENUATOR,
|
||||
POWER_METER_MAX,
|
||||
POWER_METER_POWER,
|
||||
POWER_METER_PEAK,
|
||||
POWER_METER_FIELDS_MAX
|
||||
};
|
||||
|
||||
constexpr coord_t POWER_METER_2ND_COLUMN = 100;
|
||||
|
||||
bool menuRadioPowerMeter(event_t event)
|
||||
{
|
||||
SUBMENU(STR_MENU_POWER_METER, ICON_RADIO_SPECTRUM_ANALYSER, POWER_METER_FIELDS_MAX-1, {0, 0, READONLY_ROW, READONLY_ROW, READONLY_ROW});
|
||||
|
||||
if (TELEMETRY_STREAMING()) {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_TURN_OFF_RECEIVER);
|
||||
if (event == EVT_KEY_FIRST(KEY_EXIT)) {
|
||||
killEvents(event);
|
||||
popMenu();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (menuEvent) {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_STOPPING);
|
||||
lcdRefresh();
|
||||
moduleState[g_moduleIdx].readModuleInformation(&reusableBuffer.moduleSetup.pxx2.moduleInformation, PXX2_HW_INFO_TX_ID, PXX2_HW_INFO_TX_ID);
|
||||
/* wait 1s to resume normal operation before leaving */
|
||||
watchdogSuspend(1000);
|
||||
RTOS_WAIT_MS(1000);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (moduleState[g_moduleIdx].mode != MODULE_MODE_POWER_METER) {
|
||||
memclear(&reusableBuffer.powerMeter, sizeof(reusableBuffer.powerMeter));
|
||||
reusableBuffer.powerMeter.freq = 2400000000;
|
||||
reusableBuffer.powerMeter.attn = 4;
|
||||
reusableBuffer.powerMeter.dirty = true;
|
||||
moduleState[g_moduleIdx].mode = MODULE_MODE_POWER_METER;
|
||||
}
|
||||
|
||||
// The warning
|
||||
if (reusableBuffer.powerMeter.attn != 0) {
|
||||
lcdDrawCenteredText(MENU_BODY_TOP, STR_POWERMETER_ATTN_NEEDED, BOLD | INVERS);
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i<POWER_METER_FIELDS_MAX; i++) {
|
||||
LcdFlags attr = (menuVerticalPosition == i ? (s_editMode > 0 ? INVERS | BLINK : INVERS) : 0);
|
||||
coord_t y = MENU_BODY_TOP + 2 * FH + i * FH;
|
||||
|
||||
switch (i) {
|
||||
case POWER_METER_FREQ_RANGE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_POWERMETER_FREQ);
|
||||
lcdDrawNumber(POWER_METER_2ND_COLUMN, y, reusableBuffer.powerMeter.freq / 1000000, LEFT | attr);
|
||||
lcdDrawText(lcdNextPos, y, " MHz band");
|
||||
if (attr) {
|
||||
reusableBuffer.powerMeter.freq = checkIncDec(event, reusableBuffer.powerMeter.freq == 900000000, 0, 1) ? 900000000 : 2400000000;
|
||||
if (checkIncDec_Ret) {
|
||||
reusableBuffer.powerMeter.power = 0;
|
||||
reusableBuffer.powerMeter.peak = 0;
|
||||
reusableBuffer.powerMeter.dirty = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case POWER_METER_ATTENUATOR:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_POWERMETER_ATTN);
|
||||
lcdDrawNumber(POWER_METER_2ND_COLUMN, y, -10 * reusableBuffer.powerMeter.attn, LEFT | attr);
|
||||
lcdDrawText(lcdNextPos, y, " dB");
|
||||
if (attr) {
|
||||
reusableBuffer.powerMeter.attn = checkIncDec(event, reusableBuffer.powerMeter.attn, 0, 5, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case POWER_METER_MAX:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MAX);
|
||||
lcdDrawNumber(POWER_METER_2ND_COLUMN, y, -10 + 10 * reusableBuffer.powerMeter.attn);
|
||||
lcdDrawText(lcdNextPos + 3, y, "dBm/ ");
|
||||
drawPower(lcdNextPos + 3, y, -10 + 10 * reusableBuffer.powerMeter.attn, 0);
|
||||
if (attr) {
|
||||
reusableBuffer.powerMeter.attn = checkIncDec(event, reusableBuffer.powerMeter.attn, 0, 5, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case POWER_METER_POWER:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_POWERMETER_POWER);
|
||||
if (reusableBuffer.powerMeter.power) {
|
||||
lcdDrawNumber(POWER_METER_2ND_COLUMN, y, reusableBuffer.powerMeter.power + reusableBuffer.powerMeter.attn * 1000, LEFT | PREC2);
|
||||
lcdDrawText(lcdNextPos, y, "dBm");
|
||||
}
|
||||
break;
|
||||
|
||||
case POWER_METER_PEAK:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_POWERMETER_PEAK);
|
||||
if (reusableBuffer.powerMeter.peak) {
|
||||
lcdDrawNumber(POWER_METER_2ND_COLUMN, y, reusableBuffer.powerMeter.peak + reusableBuffer.powerMeter.attn * 1000, LEFT | PREC2);
|
||||
lcdDrawText(lcdNextPos, y, "dBm");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,434 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <io/frsky_firmware_update.h>
|
||||
#include "opentx.h"
|
||||
#include "storage/modelslist.h"
|
||||
|
||||
#define REFRESH_FILES() do { reusableBuffer.sdManager.offset = 65535; currentBitmapIndex = -1; } while (0)
|
||||
#define NODE_TYPE(fname) fname[SD_SCREEN_FILE_LENGTH+1]
|
||||
#define IS_DIRECTORY(fname) ((bool)(!NODE_TYPE(fname)))
|
||||
#define IS_FILE(fname) ((bool)(NODE_TYPE(fname)))
|
||||
|
||||
int currentBitmapIndex = 0;
|
||||
BitmapBuffer * currentBitmap = NULL;
|
||||
|
||||
bool menuRadioSdManagerInfo(event_t event)
|
||||
{
|
||||
SIMPLE_SUBMENU(STR_SD_INFO_TITLE, ICON_RADIO_SD_MANAGER, 1);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 2*FH, STR_SD_TYPE);
|
||||
lcdDrawText(100, 2*FH, SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 3*FH, STR_SD_SIZE);
|
||||
lcdDrawNumber(100, 3*FH, sdGetSize(), LEFT, 0, NULL, "M");
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 4*FH, STR_SD_SECTORS);
|
||||
#if defined(SD_GET_FREE_BLOCKNR)
|
||||
lcdDrawNumber(100, 4*FH, SD_GET_FREE_BLOCKNR()/1000, LEFT, 0, NULL, "/");
|
||||
lcdDrawNumber(150, 4*FH, sdGetNoSectors()/1000, LEFT);
|
||||
#else
|
||||
lcdDrawNumber(100, 4*FH, sdGetNoSectors()/1000, LEFT, 0, NULL, "k");
|
||||
#endif
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 5*FH, STR_SD_SPEED);
|
||||
lcdDrawNumber(100, 5*FH, SD_GET_SPEED()/1000, LEFT, 0, NULL, "kb/s");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool isFilenameGreater(bool isfile, const char * fn, const char * line)
|
||||
{
|
||||
return (isfile && IS_DIRECTORY(line)) || (isfile==IS_FILE(line) && strcasecmp(fn, line) > 0);
|
||||
}
|
||||
|
||||
inline bool isFilenameLower(bool isfile, const char * fn, const char * line)
|
||||
{
|
||||
return (!isfile && IS_FILE(line)) || (isfile==IS_FILE(line) && strcasecmp(fn, line) < 0);
|
||||
}
|
||||
|
||||
void getSelectionFullPath(char * lfn)
|
||||
{
|
||||
f_getcwd(lfn, _MAX_LFN);
|
||||
strcat(lfn, "/");
|
||||
strcat(lfn, reusableBuffer.sdManager.lines[menuVerticalPosition - menuVerticalOffset]);
|
||||
}
|
||||
|
||||
void onSdManagerMenu(const char * result)
|
||||
{
|
||||
TCHAR lfn[_MAX_LFN+1];
|
||||
|
||||
// TODO possible buffer overflows here!
|
||||
|
||||
uint8_t index = menuVerticalPosition-menuVerticalOffset;
|
||||
char *line = reusableBuffer.sdManager.lines[index];
|
||||
|
||||
if (result == STR_SD_INFO) {
|
||||
pushMenu(menuRadioSdManagerInfo);
|
||||
}
|
||||
else if (result == STR_SD_FORMAT) {
|
||||
POPUP_CONFIRMATION(STR_CONFIRM_FORMAT);
|
||||
}
|
||||
else if (result == STR_COPY_FILE) {
|
||||
clipboard.type = CLIPBOARD_TYPE_SD_FILE;
|
||||
f_getcwd(clipboard.data.sd.directory, CLIPBOARD_PATH_LEN);
|
||||
strncpy(clipboard.data.sd.filename, line, CLIPBOARD_PATH_LEN-1);
|
||||
}
|
||||
else if (result == STR_PASTE) {
|
||||
f_getcwd(lfn, _MAX_LFN);
|
||||
// if destination is dir, copy into that dir
|
||||
if (IS_DIRECTORY(line)) {
|
||||
strcat(lfn, "/");
|
||||
strcat(lfn, line);
|
||||
}
|
||||
if (strcmp(clipboard.data.sd.directory, lfn)) { // prevent copying to the same directory
|
||||
POPUP_WARNING(sdCopyFile(clipboard.data.sd.filename, clipboard.data.sd.directory, clipboard.data.sd.filename, lfn));
|
||||
REFRESH_FILES();
|
||||
}
|
||||
}
|
||||
else if (result == STR_RENAME_FILE) {
|
||||
memcpy(reusableBuffer.sdManager.originalName, line, sizeof(reusableBuffer.sdManager.originalName));
|
||||
uint8_t fnlen = 0, extlen = 0;
|
||||
getFileExtension(line, 0, LEN_FILE_EXTENSION_MAX, &fnlen, &extlen);
|
||||
// write spaces to allow extending the length of a filename
|
||||
memset(line + fnlen - extlen, ' ', SD_SCREEN_FILE_LENGTH - fnlen + extlen);
|
||||
line[SD_SCREEN_FILE_LENGTH-extlen] = '\0';
|
||||
s_editMode = EDIT_MODIFY_STRING;
|
||||
editNameCursorPos = 0;
|
||||
}
|
||||
else if (result == STR_DELETE_FILE) {
|
||||
getSelectionFullPath(lfn);
|
||||
f_unlink(lfn);
|
||||
menuVerticalOffset = 0;
|
||||
menuVerticalPosition = 0;
|
||||
REFRESH_FILES();
|
||||
}
|
||||
else if (result == STR_PLAY_FILE) {
|
||||
getSelectionFullPath(lfn);
|
||||
audioQueue.stopAll();
|
||||
audioQueue.playFile(lfn, 0, ID_PLAY_FROM_SD_MANAGER);
|
||||
}
|
||||
else if (result == STR_ASSIGN_BITMAP) {
|
||||
memcpy(g_model.header.bitmap, line, sizeof(g_model.header.bitmap));
|
||||
if(modelslist.getCurrentModel())
|
||||
modelslist.getCurrentModel()->resetBuffer();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_ASSIGN_SPLASH) {
|
||||
f_getcwd(lfn, _MAX_LFN);
|
||||
sdCopyFile(line, lfn, SPLASH_FILE, BITMAPS_PATH);
|
||||
}
|
||||
else if (result == STR_VIEW_TEXT) {
|
||||
getSelectionFullPath(lfn);
|
||||
pushMenuTextView(lfn);
|
||||
}
|
||||
else if (result == STR_FLASH_INTERNAL_MODULE) {
|
||||
getSelectionFullPath(lfn);
|
||||
FrskyDeviceFirmwareUpdate device(INTERNAL_MODULE);
|
||||
device.flashFirmware(lfn);
|
||||
}
|
||||
else if (result == STR_FLASH_EXTERNAL_MODULE) {
|
||||
getSelectionFullPath(lfn);
|
||||
FrskyDeviceFirmwareUpdate device(EXTERNAL_MODULE);
|
||||
device.flashFirmware(lfn);
|
||||
}
|
||||
else if (result == STR_FLASH_EXTERNAL_DEVICE) {
|
||||
getSelectionFullPath(lfn);
|
||||
FrskyDeviceFirmwareUpdate device(SPORT_MODULE);
|
||||
device.flashFirmware(lfn);
|
||||
}
|
||||
#if defined(LUA)
|
||||
else if (result == STR_EXECUTE_FILE) {
|
||||
getSelectionFullPath(lfn);
|
||||
luaExec(lfn);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool menuRadioSdManager(event_t _event)
|
||||
{
|
||||
if (warningResult) {
|
||||
warningResult = 0;
|
||||
showMessageBox(STR_FORMATTING);
|
||||
logsClose();
|
||||
audioQueue.stopSD();
|
||||
if(sdCardFormat()) {
|
||||
f_chdir("/");
|
||||
REFRESH_FILES();
|
||||
}
|
||||
}
|
||||
|
||||
event_t event = (EVT_KEY_MASK(_event) == KEY_ENTER ? 0 : _event);
|
||||
SIMPLE_MENU(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, RADIO_ICONS, menuTabGeneral, MENU_RADIO_SD_MANAGER, reusableBuffer.sdManager.count);
|
||||
|
||||
int index = menuVerticalPosition-menuVerticalOffset;
|
||||
|
||||
switch(_event) {
|
||||
case EVT_ENTRY:
|
||||
f_chdir(ROOT_PATH);
|
||||
REFRESH_FILES();
|
||||
break;
|
||||
|
||||
#if 0
|
||||
// TODO: Implement it
|
||||
case EVT_KEY_LONG(KEY_MENU):
|
||||
if (!READ_ONLY() && s_editMode == 0) {
|
||||
killEvents(_event);
|
||||
POPUP_MENU_ADD_ITEM(STR_SD_INFO);
|
||||
POPUP_MENU_ADD_ITEM(STR_SD_FORMAT);
|
||||
POPUP_MENU_START(onSdManagerMenu);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
REFRESH_FILES();
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (s_editMode > 0) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
if (IS_DIRECTORY(reusableBuffer.sdManager.lines[index])) {
|
||||
f_chdir(reusableBuffer.sdManager.lines[index]);
|
||||
menuVerticalOffset = 0;
|
||||
menuVerticalPosition = 1;
|
||||
index = 1;
|
||||
REFRESH_FILES();
|
||||
killEvents(_event);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// no break
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
if (s_editMode == 0) {
|
||||
killEvents(_event);
|
||||
char * line = reusableBuffer.sdManager.lines[index];
|
||||
if (!strcmp(line, "..")) {
|
||||
break; // no menu for parent dir
|
||||
}
|
||||
const char * ext = getFileExtension(line);
|
||||
if (ext) {
|
||||
if (!strcasecmp(ext, SOUNDS_EXT)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_PLAY_FILE);
|
||||
}
|
||||
else if (isExtensionMatching(ext, BITMAPS_EXT)) {
|
||||
TCHAR lfn[_MAX_LFN+1];
|
||||
f_getcwd(lfn, _MAX_LFN);
|
||||
if (!READ_ONLY() && unsigned(strlen(ext)+ext-line) <= sizeof(g_model.header.bitmap) && !strcmp(lfn, BITMAPS_PATH)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_ASSIGN_BITMAP);
|
||||
}
|
||||
if (!strcmp(ext, PNG_EXT)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_ASSIGN_SPLASH);
|
||||
}
|
||||
}
|
||||
else if (!READ_ONLY() && !strcasecmp(ext, SPORT_FIRMWARE_EXT)) {
|
||||
if (HAS_SPORT_UPDATE_CONNECTOR())
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_EXTERNAL_DEVICE);
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_INTERNAL_MODULE);
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_EXTERNAL_MODULE);
|
||||
}
|
||||
else if (!READ_ONLY() && !strcasecmp(ext, UPDATE_FIRMWARE_EXT)) {
|
||||
FrSkyFirmwareInformation information;
|
||||
if (readFirmwareInformation(line, information) == nullptr) {
|
||||
if (information.productFamily == FIRMWARE_FAMILY_INTERNAL_MODULE)
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_INTERNAL_MODULE);
|
||||
if (information.productFamily == FIRMWARE_FAMILY_EXTERNAL_MODULE)
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_EXTERNAL_MODULE);
|
||||
if (HAS_SPORT_UPDATE_CONNECTOR() && (information.productFamily == FIRMWARE_FAMILY_RECEIVER || information.productFamily == FIRMWARE_FAMILY_SENSOR))
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_EXTERNAL_DEVICE);
|
||||
#if defined(PXX2)
|
||||
if (information.productFamily == FIRMWARE_FAMILY_RECEIVER)
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_RECEIVER_OTA);
|
||||
#endif
|
||||
#if defined(BLUETOOTH)
|
||||
if (information.productFamily == FIRMWARE_FAMILY_BLUETOOTH_CHIP)
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_BLUETOOTH_MODULE);
|
||||
#endif
|
||||
#if defined(HARDWARE_POWER_MANAGEMENT_UNIT)
|
||||
if (information.productFamily == FIRMWARE_FAMILY_POWER_MANAGEMENT_UNIT)
|
||||
POPUP_MENU_ADD_ITEM(STR_FLASH_POWER_MANAGEMENT_UNIT);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (isExtensionMatching(ext, SCRIPTS_EXT)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_EXECUTE_FILE);
|
||||
}
|
||||
if (isExtensionMatching(ext, TEXT_EXT) || isExtensionMatching(ext, SCRIPTS_EXT)) {
|
||||
POPUP_MENU_ADD_ITEM(STR_VIEW_TEXT);
|
||||
}
|
||||
}
|
||||
if (!READ_ONLY()) {
|
||||
if (IS_FILE(line))
|
||||
POPUP_MENU_ADD_ITEM(STR_COPY_FILE);
|
||||
if (clipboard.type == CLIPBOARD_TYPE_SD_FILE)
|
||||
POPUP_MENU_ADD_ITEM(STR_PASTE);
|
||||
POPUP_MENU_ADD_ITEM(STR_RENAME_FILE);
|
||||
if (IS_FILE(line))
|
||||
POPUP_MENU_ADD_ITEM(STR_DELETE_FILE);
|
||||
}
|
||||
POPUP_MENU_START(onSdManagerMenu);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (reusableBuffer.sdManager.offset != menuVerticalOffset) {
|
||||
FILINFO fno;
|
||||
DIR dir;
|
||||
|
||||
if (menuVerticalOffset == 0) {
|
||||
reusableBuffer.sdManager.offset = 0;
|
||||
memset(reusableBuffer.sdManager.lines, 0, sizeof(reusableBuffer.sdManager.lines));
|
||||
}
|
||||
else if (menuVerticalOffset == reusableBuffer.sdManager.count-NUM_BODY_LINES) {
|
||||
reusableBuffer.sdManager.offset = menuVerticalOffset;
|
||||
memset(reusableBuffer.sdManager.lines, 0, sizeof(reusableBuffer.sdManager.lines));
|
||||
}
|
||||
else if (menuVerticalOffset > reusableBuffer.sdManager.offset) {
|
||||
memmove(reusableBuffer.sdManager.lines[0], reusableBuffer.sdManager.lines[1], (NUM_BODY_LINES-1)*sizeof(reusableBuffer.sdManager.lines[0]));
|
||||
memset(reusableBuffer.sdManager.lines[NUM_BODY_LINES-1], 0xff, SD_SCREEN_FILE_LENGTH);
|
||||
NODE_TYPE(reusableBuffer.sdManager.lines[NUM_BODY_LINES-1]) = 1;
|
||||
}
|
||||
else {
|
||||
memmove(reusableBuffer.sdManager.lines[1], reusableBuffer.sdManager.lines[0], (NUM_BODY_LINES-1)*sizeof(reusableBuffer.sdManager.lines[0]));
|
||||
memset(reusableBuffer.sdManager.lines[0], 0, sizeof(reusableBuffer.sdManager.lines[0]));
|
||||
}
|
||||
|
||||
reusableBuffer.sdManager.count = 0;
|
||||
|
||||
FRESULT res = f_opendir(&dir, "."); // Open the directory
|
||||
if (res == FR_OK) {
|
||||
bool firstTime = true;
|
||||
for (;;) {
|
||||
res = sdReadDir(&dir, &fno, firstTime);
|
||||
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
|
||||
if (strlen(fno.fname) > SD_SCREEN_FILE_LENGTH) continue;
|
||||
if (fno.fattrib & AM_HID) continue; /* Ignore Windows hidden files */
|
||||
if (fno.fname[0] == '.' && fno.fname[1] != '.') continue; /* Ignore UNIX hidden files, but not .. */
|
||||
|
||||
reusableBuffer.sdManager.count++;
|
||||
|
||||
bool isfile = !(fno.fattrib & AM_DIR);
|
||||
|
||||
if (menuVerticalOffset == 0) {
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
||||
char * line = reusableBuffer.sdManager.lines[i];
|
||||
if (line[0] == '\0' || isFilenameLower(isfile, fno.fname, line)) {
|
||||
if (i < NUM_BODY_LINES-1) memmove(reusableBuffer.sdManager.lines[i+1], line, sizeof(reusableBuffer.sdManager.lines[i]) * (NUM_BODY_LINES-1-i));
|
||||
memset(line, 0, sizeof(reusableBuffer.sdManager.lines[0]));
|
||||
strcpy(line, fno.fname);
|
||||
NODE_TYPE(line) = isfile;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (reusableBuffer.sdManager.offset == menuVerticalOffset) {
|
||||
for (int8_t i=NUM_BODY_LINES-1; i>=0; i--) {
|
||||
char *line = reusableBuffer.sdManager.lines[i];
|
||||
if (line[0] == '\0' || isFilenameGreater(isfile, fno.fname, line)) {
|
||||
if (i > 0) memmove(reusableBuffer.sdManager.lines[0], reusableBuffer.sdManager.lines[1], sizeof(reusableBuffer.sdManager.lines[0]) * i);
|
||||
memset(line, 0, sizeof(reusableBuffer.sdManager.lines[0]));
|
||||
strcpy(line, fno.fname);
|
||||
NODE_TYPE(line) = isfile;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (menuVerticalOffset > reusableBuffer.sdManager.offset) {
|
||||
if (isFilenameGreater(isfile, fno.fname, reusableBuffer.sdManager.lines[NUM_BODY_LINES-2]) && isFilenameLower(isfile, fno.fname, reusableBuffer.sdManager.lines[NUM_BODY_LINES-1])) {
|
||||
memset(reusableBuffer.sdManager.lines[NUM_BODY_LINES-1], 0, sizeof(reusableBuffer.sdManager.lines[0]));
|
||||
strcpy(reusableBuffer.sdManager.lines[NUM_BODY_LINES-1], fno.fname);
|
||||
NODE_TYPE(reusableBuffer.sdManager.lines[NUM_BODY_LINES-1]) = isfile;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isFilenameLower(isfile, fno.fname, reusableBuffer.sdManager.lines[1]) && isFilenameGreater(isfile, fno.fname, reusableBuffer.sdManager.lines[0])) {
|
||||
memset(reusableBuffer.sdManager.lines[0], 0, sizeof(reusableBuffer.sdManager.lines[0]));
|
||||
strcpy(reusableBuffer.sdManager.lines[0], fno.fname);
|
||||
NODE_TYPE(reusableBuffer.sdManager.lines[0]) = isfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
f_closedir(&dir);
|
||||
}
|
||||
}
|
||||
|
||||
reusableBuffer.sdManager.offset = menuVerticalOffset;
|
||||
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
LcdFlags attr = (index == i ? INVERS : 0);
|
||||
if (reusableBuffer.sdManager.lines[i][0]) {
|
||||
if (s_editMode == EDIT_MODIFY_STRING && attr) {
|
||||
uint8_t extlen, efflen;
|
||||
const char * ext = getFileExtension(reusableBuffer.sdManager.originalName, 0, 0, NULL, &extlen);
|
||||
editName(MENUS_MARGIN_LEFT, y, reusableBuffer.sdManager.lines[i], SD_SCREEN_FILE_LENGTH - extlen, _event, attr, 0);
|
||||
efflen = effectiveLen(reusableBuffer.sdManager.lines[i], SD_SCREEN_FILE_LENGTH - extlen);
|
||||
if (s_editMode == 0) {
|
||||
if (ext) {
|
||||
strAppend(&reusableBuffer.sdManager.lines[i][efflen], ext);
|
||||
}
|
||||
else {
|
||||
reusableBuffer.sdManager.lines[i][efflen] = 0;
|
||||
}
|
||||
f_rename(reusableBuffer.sdManager.originalName, reusableBuffer.sdManager.lines[i]);
|
||||
REFRESH_FILES();
|
||||
}
|
||||
}
|
||||
else if (IS_DIRECTORY(reusableBuffer.sdManager.lines[i])) {
|
||||
char s[sizeof(reusableBuffer.sdManager.lines[0])+2];
|
||||
char * ptr = s;
|
||||
*ptr++ = '[';
|
||||
ptr = strAppend(ptr, reusableBuffer.sdManager.lines[i]);
|
||||
*ptr++ = ']';
|
||||
*ptr = '\0';
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, s, attr);
|
||||
}
|
||||
else {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, reusableBuffer.sdManager.lines[i], attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const char * ext = getFileExtension(reusableBuffer.sdManager.lines[index]);
|
||||
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
|
||||
if (currentBitmapIndex != menuVerticalPosition) {
|
||||
currentBitmapIndex = menuVerticalPosition;
|
||||
delete currentBitmap;
|
||||
currentBitmap = BitmapBuffer::load(reusableBuffer.sdManager.lines[index]);
|
||||
}
|
||||
if (currentBitmap) {
|
||||
uint16_t height = currentBitmap->getHeight();
|
||||
uint16_t width = currentBitmap->getWidth();
|
||||
if (height > MENU_BODY_HEIGHT-10) {
|
||||
height = MENU_BODY_HEIGHT - 10;
|
||||
}
|
||||
if (width > LCD_W/2) {
|
||||
width = LCD_W/2;
|
||||
}
|
||||
lcd->drawScaledBitmap(currentBitmap, LCD_W / 2 - 20 + LCD_W/4 - width/2, MENU_BODY_TOP + MENU_BODY_HEIGHT/2 - height/2, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,525 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define LANGUAGE_PACKS_DEFINITION
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define RADIO_SETUP_2ND_COLUMN 235
|
||||
|
||||
int8_t editSlider(coord_t x, coord_t y, event_t event, int8_t value, int8_t min, int8_t max, LcdFlags attr)
|
||||
{
|
||||
drawHorizontalSlider(x, y, 100, value, min, max, 0, OPTION_SLIDER_DBL_COLOR|attr);
|
||||
return editChoice(x, y, NULL, value, min, max, attr, event);
|
||||
}
|
||||
|
||||
#define SLIDER_5POS(val) val = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, val, -2, +2, attr)
|
||||
|
||||
enum menuRadioSetupItems {
|
||||
ITEM_SETUP_DATE,
|
||||
ITEM_SETUP_TIME,
|
||||
ITEM_SETUP_BATT_RANGE,
|
||||
ITEM_SETUP_SOUND_LABEL,
|
||||
ITEM_SETUP_BEEP_MODE,
|
||||
ITEM_SETUP_GENERAL_VOLUME,
|
||||
ITEM_SETUP_BEEP_VOLUME,
|
||||
ITEM_SETUP_BEEP_LENGTH,
|
||||
ITEM_SETUP_SPEAKER_PITCH,
|
||||
ITEM_SETUP_WAV_VOLUME,
|
||||
ITEM_SETUP_BACKGROUND_VOLUME,
|
||||
CASE_VARIO(ITEM_SETUP_VARIO_LABEL)
|
||||
CASE_VARIO(ITEM_SETUP_VARIO_VOLUME)
|
||||
CASE_VARIO(ITEM_SETUP_VARIO_PITCH)
|
||||
CASE_VARIO(ITEM_SETUP_VARIO_RANGE)
|
||||
CASE_VARIO(ITEM_SETUP_VARIO_REPEAT)
|
||||
CASE_HAPTIC(ITEM_SETUP_HAPTIC_LABEL)
|
||||
CASE_HAPTIC(ITEM_SETUP_HAPTIC_MODE)
|
||||
CASE_HAPTIC(ITEM_SETUP_HAPTIC_LENGTH)
|
||||
CASE_HAPTIC(ITEM_SETUP_HAPTIC_STRENGTH)
|
||||
// ITEM_SETUP_CONTRAST,
|
||||
ITEM_SETUP_ALARMS_LABEL,
|
||||
ITEM_SETUP_BATTERY_WARNING,
|
||||
ITEM_SETUP_INACTIVITY_ALARM,
|
||||
// ITEM_SETUP_MEMORY_WARNING,
|
||||
ITEM_SETUP_ALARM_WARNING,
|
||||
ITEM_SETUP_RSSI_POWEROFF_ALARM,
|
||||
ITEM_SETUP_BACKLIGHT_LABEL,
|
||||
ITEM_SETUP_BACKLIGHT_MODE,
|
||||
ITEM_SETUP_BACKLIGHT_DELAY,
|
||||
ITEM_SETUP_BRIGHTNESS,
|
||||
ITEM_SETUP_DIM_LEVEL,
|
||||
ITEM_SETUP_FLASH_BEEP,
|
||||
CASE_PWR_BUTTON_PRESS(ITEM_SETUP_PWR_OFF_SPEED)
|
||||
#if defined(PXX2)
|
||||
ITEM_RADIO_SETUP_OWNER_ID,
|
||||
#endif
|
||||
CASE_GPS(ITEM_SETUP_LABEL_GPS)
|
||||
CASE_GPS(ITEM_SETUP_TIMEZONE)
|
||||
CASE_GPS(ITEM_SETUP_ADJUST_RTC)
|
||||
CASE_GPS(ITEM_SETUP_GPSFORMAT)
|
||||
CASE_PXX1(ITEM_SETUP_COUNTRYCODE)
|
||||
ITEM_SETUP_LANGUAGE,
|
||||
ITEM_SETUP_IMPERIAL,
|
||||
IF_FAI_CHOICE(ITEM_SETUP_FAI)
|
||||
ITEM_SETUP_SWITCHES_DELAY,
|
||||
ITEM_SETUP_USB_MODE,
|
||||
ITEM_SETUP_RX_CHANNEL_ORD,
|
||||
ITEM_SETUP_STICK_MODE,
|
||||
ITEM_SETUP_MAX
|
||||
};
|
||||
|
||||
bool menuRadioSetup(event_t event)
|
||||
{
|
||||
#if defined(RTCLOCK)
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
|
||||
if ((menuVerticalPosition==ITEM_SETUP_DATE || menuVerticalPosition==ITEM_SETUP_TIME) &&
|
||||
(s_editMode>0) &&
|
||||
(event==EVT_KEY_FIRST(KEY_ENTER) || event==EVT_KEY_BREAK(KEY_ENTER) || event==EVT_KEY_LONG(KEY_ENTER) || event==EVT_KEY_FIRST(KEY_EXIT))) {
|
||||
// set the date and time into RTC chip
|
||||
rtcSetTime(&t);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FAI_CHOICE)
|
||||
#define FAI_CHOICE_ROW (g_eeGeneral.fai ? (uint8_t)-1 : (uint8_t)0),
|
||||
|
||||
if (warningResult) {
|
||||
warningResult = 0;
|
||||
g_eeGeneral.fai = true;
|
||||
storageDirty(EE_GENERAL);
|
||||
}
|
||||
#else
|
||||
#define FAI_CHOICE_ROW
|
||||
#endif
|
||||
|
||||
MENU(STR_MENURADIOSETUP, RADIO_ICONS, menuTabGeneral, MENU_RADIO_SETUP, ITEM_SETUP_MAX, {
|
||||
2|NAVIGATION_LINE_BY_LINE, 2|NAVIGATION_LINE_BY_LINE, 1|NAVIGATION_LINE_BY_LINE, // Date Time Bat range
|
||||
LABEL(SOUND), 0, 0, 0, 0, 0, 0, 0,
|
||||
CASE_VARIO(LABEL(VARIO)) CASE_VARIO(0) CASE_VARIO(0) CASE_VARIO(0) CASE_VARIO(0)
|
||||
CASE_HAPTIC(LABEL(HAPTIC)) CASE_HAPTIC(0) CASE_HAPTIC(0) CASE_HAPTIC(0)
|
||||
LABEL(ALARMS), 0, 0, 0, 0,
|
||||
LABEL(BACKLIGHT), 0, 0, 0, 0, 0,
|
||||
CASE_PWR_BUTTON_PRESS(0)
|
||||
CASE_PXX2(0) // owner registration ID
|
||||
CASE_GPS(LABEL(GPS))
|
||||
CASE_GPS(0) // timezone
|
||||
CASE_GPS(0) // adjust RTC
|
||||
CASE_GPS(0) // GPS format
|
||||
CASE_PXX1(0) // country code
|
||||
0, // voice language
|
||||
0, // imperial
|
||||
FAI_CHOICE_ROW
|
||||
0, // switches delay
|
||||
0, // USB mode
|
||||
0, // RX channels order
|
||||
0, // sticks mode
|
||||
1 /*to force edit mode*/
|
||||
}); // Units - Fai choice - Play delay - USB mode - Chan order - Mode (1 to 4)
|
||||
|
||||
if (event == EVT_ENTRY) {
|
||||
reusableBuffer.generalSettings.stickMode = g_eeGeneral.stickMode;
|
||||
}
|
||||
|
||||
int sub = menuVerticalPosition;
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
int k = i + menuVerticalOffset;
|
||||
LcdFlags blink = ((s_editMode>0) ? BLINK|INVERS : INVERS);
|
||||
LcdFlags attr = (sub == k ? blink : 0);
|
||||
|
||||
switch(k) {
|
||||
case ITEM_SETUP_DATE:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_DATE);
|
||||
LcdFlags flags = 0;
|
||||
if (attr && menuHorizontalPosition < 0) {
|
||||
flags |= INVERS;
|
||||
}
|
||||
for (uint8_t j=0; j<3; j++) {
|
||||
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
||||
switch (j) {
|
||||
case 0:
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, t.tm_year+TM_YEAR_BASE, flags|rowattr);
|
||||
if (rowattr && s_editMode>0) t.tm_year = checkIncDec(event, t.tm_year, 112, 200, 0);
|
||||
lcdDrawText(lcdNextPos+3, y, "-", flags);
|
||||
break;
|
||||
case 1:
|
||||
lcdDrawNumber(lcdNextPos+3, y, t.tm_mon+1, flags|rowattr|LEADING0, 2);
|
||||
if (rowattr && s_editMode>0) t.tm_mon = checkIncDec(event, t.tm_mon, 0, 11, 0);
|
||||
lcdDrawText(lcdNextPos+3, y, "-", flags);
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
int16_t year = TM_YEAR_BASE + t.tm_year;
|
||||
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
||||
static const uint8_t dmon[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
dlim += dmon[t.tm_mon];
|
||||
lcdDrawNumber(lcdNextPos+3, y, t.tm_mday, flags|rowattr|LEADING0, 2);
|
||||
if (rowattr && s_editMode>0) t.tm_mday = checkIncDec(event, t.tm_mday, 1, dlim, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (attr && checkIncDec_Ret) {
|
||||
g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SETUP_TIME:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TIME);
|
||||
LcdFlags flags = 0;
|
||||
if (attr && menuHorizontalPosition < 0) {
|
||||
flags |= INVERS;
|
||||
}
|
||||
for (uint8_t j=0; j<3; j++) {
|
||||
uint8_t rowattr = (menuHorizontalPosition==j ? attr : 0);
|
||||
switch (j) {
|
||||
case 0:
|
||||
if (rowattr && s_editMode>0) t.tm_hour = checkIncDec(event, t.tm_hour, 0, 23, 0);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, t.tm_hour, flags|rowattr|LEADING0, 2);
|
||||
lcdDrawText(lcdNextPos+3, y, ":", flags);
|
||||
break;
|
||||
case 1:
|
||||
if (rowattr && s_editMode>0) t.tm_min = checkIncDec(event, t.tm_min, 0, 59, 0);
|
||||
lcdDrawNumber(lcdNextPos+3, y, t.tm_min, flags|rowattr|LEADING0, 2);
|
||||
lcdDrawText(lcdNextPos+3, y, ":", flags);
|
||||
break;
|
||||
case 2:
|
||||
if (rowattr && s_editMode>0) t.tm_sec = checkIncDec(event, t.tm_sec, 0, 59, 0);
|
||||
lcdDrawNumber(lcdNextPos+3, y, t.tm_sec, flags|rowattr|LEADING0, 2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (attr && checkIncDec_Ret)
|
||||
g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SETUP_BATT_RANGE:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BATTERY_RANGE);
|
||||
LcdFlags flags = 0;
|
||||
if (attr && menuHorizontalPosition < 0) {
|
||||
flags |= INVERS;
|
||||
}
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, 90+g_eeGeneral.vBatMin, flags|(menuHorizontalPosition==0 ? attr : 0)|PREC1|LEFT);
|
||||
lcdDrawText(lcdNextPos+3, y, "-", flags);
|
||||
lcdDrawNumber(lcdNextPos+3, y, 120+g_eeGeneral.vBatMax, flags|(menuHorizontalPosition>0 ? attr : 0)|PREC1|LEFT);
|
||||
lcdDrawText(lcdNextPos+1, y, "V", flags);
|
||||
if (attr && s_editMode>0) {
|
||||
if (menuHorizontalPosition==0)
|
||||
CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatMin, -50, g_eeGeneral.vBatMax+29); // min=4.0V
|
||||
else
|
||||
CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatMax, g_eeGeneral.vBatMin-29, +40); // max=16.0V
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SETUP_SOUND_LABEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SOUND_LABEL);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BEEP_MODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SPEAKER);
|
||||
g_eeGeneral.beepMode = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_VBEEPMODE, g_eeGeneral.beepMode, -2, 1, attr, event);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_GENERAL_VOLUME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SPEAKER_VOLUME);
|
||||
g_eeGeneral.speakerVolume = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, g_eeGeneral.speakerVolume, -VOLUME_LEVEL_DEF, VOLUME_LEVEL_MAX-VOLUME_LEVEL_DEF, attr);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BEEP_VOLUME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BEEP_VOLUME);
|
||||
g_eeGeneral.beepVolume = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, g_eeGeneral.beepVolume, -2, +2, attr);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_WAV_VOLUME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_WAV_VOLUME);
|
||||
g_eeGeneral.wavVolume = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, g_eeGeneral.wavVolume, -2, +2, attr);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BACKGROUND_VOLUME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BG_VOLUME);
|
||||
g_eeGeneral.backgroundVolume = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, g_eeGeneral.backgroundVolume, -2, +2, attr);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BEEP_LENGTH:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BEEP_LENGTH);
|
||||
SLIDER_5POS(g_eeGeneral.beepLength);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_SPEAKER_PITCH:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SPKRPITCH);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.speakerPitch*15, attr|LEFT, 0, "+", "Hz");
|
||||
if (attr) {
|
||||
CHECK_INCDEC_GENVAR(event, g_eeGeneral.speakerPitch, 0, 20);
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(VARIO)
|
||||
case ITEM_SETUP_VARIO_LABEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_VARIO);
|
||||
break;
|
||||
case ITEM_SETUP_VARIO_VOLUME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, TR_SPEAKER_VOLUME);
|
||||
g_eeGeneral.varioVolume = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, g_eeGeneral.varioVolume, -2, +2, attr);
|
||||
break;
|
||||
case ITEM_SETUP_VARIO_PITCH:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_PITCH_AT_ZERO);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, VARIO_FREQUENCY_ZERO+(g_eeGeneral.varioPitch*10), attr|LEFT, 0, NULL, "Hz");
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.varioPitch, -40, 40);
|
||||
break;
|
||||
case ITEM_SETUP_VARIO_RANGE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_PITCH_AT_MAX);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, VARIO_FREQUENCY_ZERO+(g_eeGeneral.varioPitch*10)+VARIO_FREQUENCY_RANGE+(g_eeGeneral.varioRange*10), attr|LEFT, 0, NULL, "Hz");
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.varioRange, -80, 80);
|
||||
break;
|
||||
case ITEM_SETUP_VARIO_REPEAT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_REPEAT_AT_ZERO);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, VARIO_REPEAT_ZERO+(g_eeGeneral.varioRepeat*10), attr|LEFT, 0, NULL, STR_MS);
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.varioRepeat, -30, 50);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(HAPTIC)
|
||||
case ITEM_SETUP_HAPTIC_LABEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_HAPTIC_LABEL);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_HAPTIC_MODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MODE);
|
||||
g_eeGeneral.hapticMode = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_VBEEPMODE, g_eeGeneral.hapticMode, -2, 1, attr, event);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_HAPTIC_LENGTH:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_LENGTH);
|
||||
SLIDER_5POS(g_eeGeneral.hapticLength);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_HAPTIC_STRENGTH:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_HAPTICSTRENGTH);
|
||||
SLIDER_5POS(g_eeGeneral.hapticStrength);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
case ITEM_SETUP_CONTRAST:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_CONTRAST);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.contrast, attr|LEFT);
|
||||
if (attr) {
|
||||
CHECK_INCDEC_GENVAR(event, g_eeGeneral.contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
|
||||
lcdSetContrast();
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_SETUP_ALARMS_LABEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_ALARMS_LABEL);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BATTERY_WARNING:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BATTERYWARNING);
|
||||
drawValueWithUnit(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.vBatWarn, UNIT_VOLTS, attr|PREC1|LEFT);
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatWarn, 40, 120); //4-12V
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_ALARM_WARNING:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_ALARMWARNING);
|
||||
uint8_t b = 1 - g_eeGeneral.disableAlarmWarning;
|
||||
g_eeGeneral.disableAlarmWarning = 1 - editCheckBox(b, RADIO_SETUP_2ND_COLUMN, y, attr, event);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SETUP_RSSI_POWEROFF_ALARM:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_RSSISHUTDOWNALARM);
|
||||
uint8_t b = 1 - g_eeGeneral.disableRssiPoweroffAlarm;
|
||||
g_eeGeneral.disableRssiPoweroffAlarm = 1 - editCheckBox(b, RADIO_SETUP_2ND_COLUMN, y, attr, event);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SETUP_INACTIVITY_ALARM:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y,STR_INACTIVITYALARM);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.inactivityTimer, attr|LEFT, 0, NULL, "m");
|
||||
if (attr) g_eeGeneral.inactivityTimer = checkIncDec(event, g_eeGeneral.inactivityTimer, 0, 250, EE_GENERAL); //0..250minutes
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BACKLIGHT_LABEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BACKLIGHT_LABEL);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BACKLIGHT_MODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MODE);
|
||||
g_eeGeneral.backlightMode = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_VBLMODE, g_eeGeneral.backlightMode, e_backlight_mode_off, e_backlight_mode_on, attr, event);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_FLASH_BEEP:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_ALARM);
|
||||
g_eeGeneral.alarmsFlash = editCheckBox(g_eeGeneral.alarmsFlash, RADIO_SETUP_2ND_COLUMN, y, attr, event ) ;
|
||||
break;
|
||||
|
||||
#if defined(PXX2)
|
||||
case ITEM_RADIO_SETUP_OWNER_ID:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_OWNER_ID);
|
||||
editName(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID, event, attr);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_SETUP_BACKLIGHT_DELAY:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BLDELAY);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.lightAutoOff*5, attr|LEFT, 0, NULL, "s");
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.lightAutoOff, 0, 600/5);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_BRIGHTNESS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BLONBRIGHTNESS);
|
||||
g_eeGeneral.backlightBright = BACKLIGHT_LEVEL_MAX - editSlider(RADIO_SETUP_2ND_COLUMN, y, event, BACKLIGHT_LEVEL_MAX - g_eeGeneral.backlightBright, BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX, attr);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_DIM_LEVEL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_BLOFFBRIGHTNESS);
|
||||
g_eeGeneral.blOffBright = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, g_eeGeneral.blOffBright, BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX, attr);
|
||||
break;
|
||||
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
case ITEM_SETUP_PWR_OFF_SPEED:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_PWR_OFF_SPEED);
|
||||
g_eeGeneral.pwrOffSpeed = editSlider(RADIO_SETUP_2ND_COLUMN, y, event, g_eeGeneral.pwrOffSpeed, -1, 2, attr);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_SETUP_LABEL_GPS:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_GPS);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_TIMEZONE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TIMEZONE);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.timezone, attr|LEFT);
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.timezone, -12, 12);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_ADJUST_RTC:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_ADJUST_RTC);
|
||||
g_eeGeneral.adjustRTC = editCheckBox(g_eeGeneral.adjustRTC, RADIO_SETUP_2ND_COLUMN, y, attr, event ) ;
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_GPSFORMAT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_GPSCOORD);
|
||||
g_eeGeneral.gpsFormat = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_GPSFORMAT, g_eeGeneral.gpsFormat, 0, 1, attr, event);
|
||||
break;
|
||||
|
||||
#if defined(PXX1)
|
||||
case ITEM_SETUP_COUNTRYCODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_COUNTRYCODE);
|
||||
g_eeGeneral.countryCode = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_COUNTRYCODES, g_eeGeneral.countryCode, 0, 2, attr, event);
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ITEM_SETUP_LANGUAGE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_VOICELANG);
|
||||
lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, currentLanguagePack->name, attr);
|
||||
if (attr) {
|
||||
currentLanguagePackIdx = checkIncDec(event, currentLanguagePackIdx, 0, DIM(languagePacks)-2, EE_GENERAL);
|
||||
if (checkIncDec_Ret) {
|
||||
currentLanguagePack = languagePacks[currentLanguagePackIdx];
|
||||
strncpy(g_eeGeneral.ttsLanguage, currentLanguagePack->id, 2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_IMPERIAL:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_UNITSSYSTEM);
|
||||
g_eeGeneral.imperial = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_VUNITSSYSTEM, g_eeGeneral.imperial, 0, 1, attr, event);
|
||||
break;
|
||||
|
||||
#if defined(FAI_CHOICE)
|
||||
case ITEM_SETUP_FAI:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "FAI Mode");
|
||||
if (g_eeGeneral.fai) {
|
||||
lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, "Locked in FAI Mode");
|
||||
}
|
||||
else {
|
||||
g_eeGeneral.fai = editCheckBox(g_eeGeneral.fai, RADIO_SETUP_2ND_COLUMN, y, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
g_eeGeneral.fai = false;
|
||||
POPUP_CONFIRMATION("FAI mode?");
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
case ITEM_SETUP_SWITCHES_DELAY:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SWITCHES_DELAY);
|
||||
lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, 10*SWITCHES_DELAY(), attr|LEFT, 0, NULL, STR_MS);
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.switchesDelay, -15, 100-15);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_USB_MODE:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_USBMODE);
|
||||
g_eeGeneral.USBMode = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_USBMODES, g_eeGeneral.USBMode, USB_UNSELECTED_MODE, USB_MAX_MODE, attr, event);
|
||||
break;
|
||||
|
||||
case ITEM_SETUP_RX_CHANNEL_ORD:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_RXCHANNELORD); // RAET->AETR
|
||||
char s[5];
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
s[i] = STR_RETA123[channelOrder(i+1)];
|
||||
}
|
||||
s[4] = '\0';
|
||||
lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, s, attr);
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.templateSetup, 0, 23);
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SETUP_STICK_MODE:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MODE);
|
||||
char s[2] = " ";
|
||||
s[0] = '1'+reusableBuffer.generalSettings.stickMode;
|
||||
lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, s, attr);
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
drawSource(RADIO_SETUP_2ND_COLUMN + 40 + 50*i, y, MIXSRC_Rud + *(modn12x3 + 4*reusableBuffer.generalSettings.stickMode + i));
|
||||
}
|
||||
if (attr && s_editMode>0) {
|
||||
CHECK_INCDEC_GENVAR(event, reusableBuffer.generalSettings.stickMode, 0, 3);
|
||||
}
|
||||
else if (reusableBuffer.generalSettings.stickMode != g_eeGeneral.stickMode) {
|
||||
pausePulses();
|
||||
g_eeGeneral.stickMode = reusableBuffer.generalSettings.stickMode;
|
||||
checkThrottleStick();
|
||||
resumePulses();
|
||||
waitKeysReleased();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
enum SpectrumFields {
|
||||
SPECTRUM_FREQUENCY,
|
||||
SPECTRUM_SPAN,
|
||||
SPECTRUM_FIELDS_MAX
|
||||
};
|
||||
|
||||
bool menuRadioSpectrumAnalyser(event_t event)
|
||||
{
|
||||
SUBMENU(STR_MENU_SPECTRUM_ANALYSER, ICON_RADIO_SPECTRUM_ANALYSER, 1, {1});
|
||||
|
||||
if (menuEvent) {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_STOPPING);
|
||||
lcdRefresh();
|
||||
moduleState[g_moduleIdx].readModuleInformation(&reusableBuffer.moduleSetup.pxx2.moduleInformation, PXX2_HW_INFO_TX_ID, PXX2_HW_INFO_TX_ID);
|
||||
/* wait 1s to resume normal operation before leaving */
|
||||
watchdogSuspend(1000);
|
||||
RTOS_WAIT_MS(1000);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (moduleState[g_moduleIdx].mode != MODULE_MODE_SPECTRUM_ANALYSER) {
|
||||
if (TELEMETRY_STREAMING()) {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_TURN_OFF_RECEIVER);
|
||||
if (event == EVT_KEY_FIRST(KEY_EXIT)) {
|
||||
killEvents(event);
|
||||
popMenu();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
memclear(&reusableBuffer.spectrumAnalyser, sizeof(reusableBuffer.spectrumAnalyser));
|
||||
|
||||
if (isModuleR9MAccess(g_moduleIdx)) {
|
||||
reusableBuffer.spectrumAnalyser.spanDefault = 20;
|
||||
reusableBuffer.spectrumAnalyser.spanMax = 40;
|
||||
reusableBuffer.spectrumAnalyser.freqDefault = 890;
|
||||
reusableBuffer.spectrumAnalyser.freqMin = 850;
|
||||
reusableBuffer.spectrumAnalyser.freqMax = 930;
|
||||
}
|
||||
else {
|
||||
reusableBuffer.spectrumAnalyser.spanDefault = 40; // 40MHz
|
||||
reusableBuffer.spectrumAnalyser.spanMax = 80;
|
||||
reusableBuffer.spectrumAnalyser.freqDefault = 2440; // 2440MHz
|
||||
reusableBuffer.spectrumAnalyser.freqMin = 2400;
|
||||
reusableBuffer.spectrumAnalyser.freqMax = 2485;
|
||||
}
|
||||
|
||||
reusableBuffer.spectrumAnalyser.span = reusableBuffer.spectrumAnalyser.spanDefault * 1000000;
|
||||
reusableBuffer.spectrumAnalyser.freq = reusableBuffer.spectrumAnalyser.freqDefault * 1000000;
|
||||
reusableBuffer.spectrumAnalyser.step = reusableBuffer.spectrumAnalyser.span / LCD_W;
|
||||
reusableBuffer.spectrumAnalyser.dirty = true;
|
||||
moduleState[g_moduleIdx].mode = MODULE_MODE_SPECTRUM_ANALYSER;
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i<SPECTRUM_FIELDS_MAX; i++) {
|
||||
LcdFlags attr = (menuHorizontalPosition == i ? (s_editMode>0 ? INVERS|BLINK : INVERS) : 0);
|
||||
|
||||
switch (i) {
|
||||
case SPECTRUM_FREQUENCY: {
|
||||
uint16_t frequency = reusableBuffer.spectrumAnalyser.freq / 1000000;
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_FOOTER_TOP, "F:", TEXT_INVERTED_COLOR);
|
||||
lcdDrawNumber(lcdNextPos + 2, MENU_FOOTER_TOP, frequency, attr | TEXT_INVERTED_COLOR);
|
||||
lcdDrawText(lcdNextPos + 2, MENU_FOOTER_TOP, "MHz", TEXT_INVERTED_COLOR);
|
||||
if (attr) {
|
||||
reusableBuffer.spectrumAnalyser.freq = uint32_t(checkIncDec(event, frequency, reusableBuffer.spectrumAnalyser.freqMin, reusableBuffer.spectrumAnalyser.freqMax, 0)) * 1000000;
|
||||
if (checkIncDec_Ret) {
|
||||
reusableBuffer.spectrumAnalyser.dirty = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SPECTRUM_SPAN:
|
||||
uint8_t span = reusableBuffer.spectrumAnalyser.span / 1000000;
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + 100, MENU_FOOTER_TOP, "S:", TEXT_INVERTED_COLOR);
|
||||
lcdDrawNumber(lcdNextPos + 2, MENU_FOOTER_TOP, reusableBuffer.spectrumAnalyser.span/1000000, attr | TEXT_INVERTED_COLOR);
|
||||
lcdDrawText(lcdNextPos + 2, MENU_FOOTER_TOP, "MHz", TEXT_INVERTED_COLOR);
|
||||
if (attr) {
|
||||
reusableBuffer.spectrumAnalyser.span = checkIncDec(event, span, 1, reusableBuffer.spectrumAnalyser.spanMax, 0) * 1000000;
|
||||
if (checkIncDec_Ret) {
|
||||
reusableBuffer.spectrumAnalyser.step = reusableBuffer.spectrumAnalyser.span / LCD_W;
|
||||
reusableBuffer.spectrumAnalyser.dirty = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t frequency = ((reusableBuffer.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2) / 10000000) * 10000000 + 10000000; ; frequency += 10000000) {
|
||||
int offset = frequency - (reusableBuffer.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2);
|
||||
int x = offset / reusableBuffer.spectrumAnalyser.step;
|
||||
if (x >= LCD_W - 1)
|
||||
break;
|
||||
lcdDrawVerticalLine(x, MENU_HEADER_HEIGHT, LCD_H - MENU_HEADER_HEIGHT - MENU_FOOTER_HEIGHT, STASHED, CURVE_AXIS_COLOR);
|
||||
}
|
||||
|
||||
for (uint8_t power = 20; ; power += 20) {
|
||||
int y = MENU_FOOTER_TOP - 1 - limit<int>(0, power << 1, LCD_H - MENU_HEADER_HEIGHT - MENU_FOOTER_HEIGHT);
|
||||
if (y <= MENU_HEADER_HEIGHT)
|
||||
break;
|
||||
lcdDrawHorizontalLine(0, y, LCD_W, STASHED, CURVE_AXIS_COLOR);
|
||||
}
|
||||
|
||||
coord_t peak_y = LCD_H;
|
||||
coord_t peak_x = 0;
|
||||
|
||||
coord_t prev_yv = (coord_t)-1;
|
||||
for (coord_t xv=0; xv<LCD_W; xv++) {
|
||||
coord_t yv = MENU_FOOTER_TOP - 1 - limit<int>(0, reusableBuffer.spectrumAnalyser.bars[xv] << 1, LCD_H - MENU_HEADER_HEIGHT - MENU_FOOTER_HEIGHT);
|
||||
if (prev_yv != (coord_t)-1) {
|
||||
if (yv < peak_y) {
|
||||
peak_x = xv;
|
||||
peak_y = yv;
|
||||
}
|
||||
if (prev_yv < yv) {
|
||||
for (int y=prev_yv; y<=yv; y+=1) {
|
||||
lcdDrawPoint(xv, y, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int y=yv; y<=prev_yv; y+=1) {
|
||||
lcdDrawPoint(xv, y, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
prev_yv = yv;
|
||||
}
|
||||
|
||||
prev_yv = (coord_t)-1;
|
||||
for (coord_t xv=0; xv<LCD_W; xv++) {
|
||||
coord_t yv = MENU_FOOTER_TOP - 1 - limit<int>(0, reusableBuffer.spectrumAnalyser.max[xv] << 1, LCD_H - MENU_HEADER_HEIGHT - MENU_FOOTER_HEIGHT);
|
||||
if (prev_yv != (coord_t)-1) {
|
||||
if (prev_yv < yv) {
|
||||
for (int y=prev_yv; y<=yv; y+=1) {
|
||||
lcdDrawPoint(xv, y, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int y=yv; y<=prev_yv; y+=1) {
|
||||
lcdDrawPoint(xv, y, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
prev_yv = yv;
|
||||
}
|
||||
|
||||
coord_t y = max<coord_t>(MENU_HEADER_HEIGHT + 1, peak_y - FH);
|
||||
lcdDrawNumber(limit<coord_t>(20, peak_x, LCD_W - 20), y, ((reusableBuffer.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2) + peak_x * (reusableBuffer.spectrumAnalyser.span / LCD_W)) / 1000000, TINSIZE | CENTERED);
|
||||
lcdDrawText(lcdNextPos, y, "M", TINSIZE);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include "opentx.h"
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
bool addRadioTool(uint8_t index, const char * label)
|
||||
{
|
||||
int8_t sub = menuVerticalPosition - HEADER_LINE;
|
||||
LcdFlags attr = (sub == index ? INVERS : 0);
|
||||
coord_t y = MENU_CONTENT_TOP + index * FH;
|
||||
lcdDrawNumber(MENUS_MARGIN_LEFT, y, index + 1, LEADING0|LEFT, 2);
|
||||
lcdDrawText(30, y, label, (sub == index ? INVERS : 0));
|
||||
if (attr && s_editMode > 0) {
|
||||
s_editMode = 0;
|
||||
killAllEvents();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void addRadioModuleTool(uint8_t index, const char * label, bool (* tool)(event_t), uint8_t module)
|
||||
{
|
||||
if (addRadioTool(index, label)) {
|
||||
g_moduleIdx = module;
|
||||
pushMenu(tool);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(LUA)
|
||||
void addRadioScriptTool(uint8_t index, const char * path)
|
||||
{
|
||||
char toolName[TOOL_NAME_MAXLEN + 1];
|
||||
const char * label;
|
||||
char * ext = (char *)getFileExtension(path);
|
||||
if (readToolName(toolName, path)) {
|
||||
label = toolName;
|
||||
}
|
||||
else {
|
||||
*ext = '\0';
|
||||
label = getBasename(path);
|
||||
}
|
||||
|
||||
if (addRadioTool(index, label)) {
|
||||
f_chdir("/SCRIPTS/TOOLS/");
|
||||
*ext = '.';
|
||||
luaExec(path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool menuRadioTools(event_t event)
|
||||
{
|
||||
if (event == EVT_ENTRY || event == EVT_ENTRY_UP) {
|
||||
memclear(&reusableBuffer.radioTools, sizeof(reusableBuffer.radioTools));
|
||||
#if defined(PXX2)
|
||||
for (uint8_t module = 0; module < NUM_MODULES; module++) {
|
||||
if (isModulePXX2(module) && (module == INTERNAL_MODULE ? IS_INTERNAL_MODULE_ON() : IS_EXTERNAL_MODULE_ON())) {
|
||||
moduleState[module].readModuleInformation(&reusableBuffer.radioTools.modules[module], PXX2_HW_INFO_TX_ID, PXX2_HW_INFO_TX_ID);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
SIMPLE_MENU(STR_MENUTOOLS, RADIO_ICONS, menuTabGeneral, MENU_RADIO_TOOLS, HEADER_LINE + reusableBuffer.radioTools.linesCount);
|
||||
|
||||
uint8_t index = 0;
|
||||
|
||||
#if defined(PXX2)
|
||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER))
|
||||
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_INT, menuRadioSpectrumAnalyser, INTERNAL_MODULE);
|
||||
|
||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER))
|
||||
addRadioModuleTool(index++, STR_POWER_METER_INT, menuRadioPowerMeter, INTERNAL_MODULE);
|
||||
|
||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER))
|
||||
addRadioModuleTool(index++, STR_SPECTRUM_ANALYSER_EXT, menuRadioSpectrumAnalyser, EXTERNAL_MODULE);
|
||||
|
||||
if (isPXX2ModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER))
|
||||
addRadioModuleTool(index++, STR_POWER_METER_EXT, menuRadioPowerMeter, EXTERNAL_MODULE);
|
||||
#endif
|
||||
|
||||
#if defined(LUA)
|
||||
FILINFO fno;
|
||||
DIR dir;
|
||||
|
||||
#if defined(CROSSFIRE)
|
||||
if(isFileAvailable(SCRIPTS_TOOLS_PATH "/CROSSFIRE/crossfire.lua"))
|
||||
addRadioScriptTool(index++, SCRIPTS_TOOLS_PATH "/CROSSFIRE/crossfire.lua");
|
||||
#endif
|
||||
|
||||
FRESULT res = f_opendir(&dir, SCRIPTS_TOOLS_PATH);
|
||||
if (res == FR_OK) {
|
||||
for (;;) {
|
||||
TCHAR path[_MAX_LFN+1] = SCRIPTS_TOOLS_PATH "/";
|
||||
res = f_readdir(&dir, &fno); /* Read a directory item */
|
||||
if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */
|
||||
if (fno.fattrib & AM_DIR) continue; /* Skip subfolders */
|
||||
if (fno.fattrib & AM_HID) continue; /* Skip hidden files */
|
||||
if (fno.fattrib & AM_SYS) continue; /* Skip system files */
|
||||
|
||||
strcat(path, fno.fname);
|
||||
if (isRadioScriptTool(fno.fname))
|
||||
addRadioScriptTool(index++, path);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (index == 0) {
|
||||
lcdDrawCenteredText(LCD_H/2, STR_NO_TOOLS);
|
||||
}
|
||||
|
||||
reusableBuffer.radioTools.linesCount = index;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define TRAINER_COLUMN_WIDTH 60
|
||||
#define TRAINER_COLUMN_1 MENUS_MARGIN_LEFT+100
|
||||
#define TRAINER_COLUMN_2 TRAINER_COLUMN_1+TRAINER_COLUMN_WIDTH
|
||||
#define TRAINER_COLUMN_3 TRAINER_COLUMN_2+TRAINER_COLUMN_WIDTH
|
||||
|
||||
bool menuRadioTrainer(event_t event)
|
||||
{
|
||||
uint8_t y;
|
||||
bool slave = SLAVE_MODE();
|
||||
|
||||
MENU(STR_MENUTRAINER, RADIO_ICONS, menuTabGeneral, MENU_RADIO_TRAINER, (slave ? 0 : 6), { NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, NAVIGATION_LINE_BY_LINE|2, 0, 0});
|
||||
|
||||
if (slave) {
|
||||
lcdDrawText(LCD_W/2, 5*FH, STR_SLAVE, CENTERED|TEXT_COLOR);
|
||||
return true;
|
||||
}
|
||||
|
||||
LcdFlags attr;
|
||||
LcdFlags blink = ((s_editMode>0) ? BLINK|INVERS : INVERS);
|
||||
|
||||
/* lcdDrawText(TRAINER_COLUMN_1, MENU_HEADER_HEIGHT+1, "Mode", HEADER_COLOR);
|
||||
lcdDrawText(TRAINER_COLUMN_2, MENU_HEADER_HEIGHT+1, "Weight", HEADER_COLOR);
|
||||
lcdDrawText(TRAINER_COLUMN_3, MENU_HEADER_HEIGHT+1, "Source", HEADER_COLOR);
|
||||
*/
|
||||
|
||||
y = MENU_CONTENT_TOP;
|
||||
|
||||
for (uint8_t i=0; i<NUM_STICKS; i++) {
|
||||
uint8_t chan = channelOrder(i+1);
|
||||
TrainerMix * td = &g_eeGeneral.trainer.mix[chan-1];
|
||||
|
||||
drawSource(MENUS_MARGIN_LEFT, y, MIXSRC_Rud-1+chan, ((menuVerticalPosition==i && CURSOR_ON_LINE()) ? INVERS : 0));
|
||||
|
||||
for (int j=0; j<3; j++) {
|
||||
|
||||
attr = ((menuVerticalPosition==i && menuHorizontalPosition==j) ? blink : 0);
|
||||
|
||||
switch (j) {
|
||||
case 0:
|
||||
lcdDrawTextAtIndex(TRAINER_COLUMN_1, y, STR_TRNMODE, td->mode, attr);
|
||||
if (attr&BLINK) CHECK_INCDEC_GENVAR(event, td->mode, 0, 2);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
lcdDrawNumber(TRAINER_COLUMN_2, y, td->studWeight, LEFT|attr, 0, NULL, "%");
|
||||
if (attr&BLINK) CHECK_INCDEC_GENVAR(event, td->studWeight, -125, 125);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
lcdDrawTextAtIndex(TRAINER_COLUMN_3, y, STR_TRNCHN, td->srcChn, attr);
|
||||
if (attr&BLINK) CHECK_INCDEC_GENVAR(event, td->srcChn, 0, 3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
y += FH;
|
||||
}
|
||||
|
||||
attr = (menuVerticalPosition==4) ? blink : 0;
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 5*FH, STR_MULTIPLIER);
|
||||
lcdDrawNumber(TRAINER_COLUMN_1, MENU_CONTENT_TOP + 5*FH, g_eeGeneral.PPM_Multiplier+10, LEFT|attr|PREC1);
|
||||
if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.PPM_Multiplier, -10, 40);
|
||||
|
||||
attr = (menuVerticalPosition==5) ? INVERS : 0;
|
||||
if (attr) s_editMode = 0;
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 6*FH, STR_CAL, attr);
|
||||
for (int i=0; i<4; i++) {
|
||||
#if defined (PPM_UNIT_PERCENT_PREC1)
|
||||
lcdDrawNumber(TRAINER_COLUMN_1+i*TRAINER_COLUMN_WIDTH, MENU_CONTENT_TOP + 6*FH, (ppmInput[i]-g_eeGeneral.trainer.calib[i])*2, LEFT|PREC1);
|
||||
#else
|
||||
lcdDrawNumber(TRAINER_COLUMN_1+i*TRAINER_COLUMN_WIDTH, MENU_CONTENT_TOP + 6*FH, (ppmInput[i]-g_eeGeneral.trainer.calib[i])/5, LEFT);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (attr) {
|
||||
if (event==EVT_KEY_LONG(KEY_ENTER)){
|
||||
memcpy(g_eeGeneral.trainer.calib, ppmInput, sizeof(g_eeGeneral.trainer.calib));
|
||||
storageDirty(EE_GENERAL);
|
||||
AUDIO_WARNING1();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,228 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "options.h"
|
||||
|
||||
#if defined(PXX2)
|
||||
constexpr coord_t COLUMN2_X = 200;
|
||||
|
||||
void drawPXX2Version(coord_t x, coord_t y, PXX2Version version)
|
||||
{
|
||||
if (version.major == 0xFF && version.minor == 0x0F && version.revision == 0x0F) {
|
||||
lcdDrawText(x, y, "---");
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(x, y, 1 + version.major, LEFT);
|
||||
lcdDrawChar(lcdNextPos, y, '.');
|
||||
lcdDrawNumber(lcdNextPos, y, version.minor, LEFT);
|
||||
lcdDrawChar(lcdNextPos, y, '.');
|
||||
lcdDrawNumber(lcdNextPos, y, version.revision, LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
void drawPXX2FullVersion(coord_t x, coord_t y, PXX2Version hwVersion, PXX2Version swVersion)
|
||||
{
|
||||
drawPXX2Version(x, y, hwVersion);
|
||||
lcdDrawText(lcdNextPos, y, "/");
|
||||
drawPXX2Version(lcdNextPos, y, swVersion);
|
||||
}
|
||||
|
||||
bool menuRadioModulesVersion(event_t event)
|
||||
{
|
||||
if (menuEvent) {
|
||||
moduleState[INTERNAL_MODULE].mode = MODULE_MODE_NORMAL;
|
||||
moduleState[EXTERNAL_MODULE].mode = MODULE_MODE_NORMAL;
|
||||
return false;
|
||||
}
|
||||
|
||||
drawMenuTemplate(STR_MENU_MODULES_RX_VERSION, 0, RADIO_ICONS, OPTION_MENU_TITLE_BAR);
|
||||
|
||||
if (event == EVT_ENTRY) {
|
||||
memclear(&reusableBuffer.hardwareAndSettings.modules, sizeof(reusableBuffer.hardwareAndSettings.modules));
|
||||
}
|
||||
|
||||
if (event == EVT_ENTRY || get_tmr10ms() >= reusableBuffer.hardwareAndSettings.updateTime) {
|
||||
if (isModulePXX2(INTERNAL_MODULE) && IS_INTERNAL_MODULE_ON()) {
|
||||
moduleState[INTERNAL_MODULE].readModuleInformation(&reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE], PXX2_HW_INFO_TX_ID, PXX2_MAX_RECEIVERS_PER_MODULE - 1);
|
||||
}
|
||||
|
||||
if (isModulePXX2(EXTERNAL_MODULE) && IS_EXTERNAL_MODULE_ON()) {
|
||||
moduleState[EXTERNAL_MODULE].readModuleInformation(&reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE], PXX2_HW_INFO_TX_ID, PXX2_MAX_RECEIVERS_PER_MODULE - 1);
|
||||
}
|
||||
|
||||
reusableBuffer.hardwareAndSettings.updateTime = get_tmr10ms() + 1000 /* 10s*/;
|
||||
}
|
||||
|
||||
coord_t y = MENU_BODY_TOP - menuVerticalOffset * FH;
|
||||
|
||||
for (uint8_t module=0; module<NUM_MODULES; module++) {
|
||||
// Label
|
||||
if (y >= MENU_BODY_TOP && y < MENU_FOOTER_TOP) {
|
||||
if (module == INTERNAL_MODULE)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_INTERNAL_MODULE);
|
||||
else if (module == EXTERNAL_MODULE)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_EXTERNAL_MODULE);
|
||||
}
|
||||
y += FH;
|
||||
|
||||
// Module model
|
||||
if (y >= MENU_BODY_TOP && y < MENU_FOOTER_TOP) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + INDENT_WIDTH, y, STR_MODULE);
|
||||
if (module == INTERNAL_MODULE) {
|
||||
if (!IS_INTERNAL_MODULE_ON()) {
|
||||
lcdDrawText(COLUMN2_X, y, STR_OFF);
|
||||
y += FH;
|
||||
continue;
|
||||
}
|
||||
if (!isModulePXX2(INTERNAL_MODULE)) {
|
||||
lcdDrawText(COLUMN2_X, y, STR_NO_INFORMATION);
|
||||
y += FH;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (module == EXTERNAL_MODULE) {
|
||||
if (!IS_EXTERNAL_MODULE_ON()) {
|
||||
lcdDrawText(COLUMN2_X, y, STR_OFF);
|
||||
y += FH;
|
||||
continue;
|
||||
}
|
||||
if (!isModulePXX2(EXTERNAL_MODULE)) {
|
||||
lcdDrawText(COLUMN2_X, y, STR_NO_INFORMATION);
|
||||
y += FH;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
uint8_t modelId = reusableBuffer.hardwareAndSettings.modules[module].information.modelID;
|
||||
lcdDrawText(COLUMN2_X, y, getPXX2ModuleName(modelId));
|
||||
}
|
||||
y += FH;
|
||||
|
||||
// Module version
|
||||
if (y >= MENU_BODY_TOP && y < MENU_FOOTER_TOP) {
|
||||
if (reusableBuffer.hardwareAndSettings.modules[module].information.modelID) {
|
||||
drawPXX2FullVersion(COLUMN2_X, y, reusableBuffer.hardwareAndSettings.modules[module].information.hwVersion, reusableBuffer.hardwareAndSettings.modules[module].information.swVersion);
|
||||
static const char * variants[] = {"FCC", "EU", "FLEX"};
|
||||
uint8_t variant = reusableBuffer.hardwareAndSettings.modules[module].information.variant - 1;
|
||||
if (variant < DIM(variants)) {
|
||||
lcdDrawText(lcdNextPos + 1, y, variants[variant]);
|
||||
}
|
||||
}
|
||||
}
|
||||
y += FH;
|
||||
|
||||
for (uint8_t receiver=0; receiver<PXX2_MAX_RECEIVERS_PER_MODULE; receiver++) {
|
||||
if (reusableBuffer.hardwareAndSettings.modules[module].receivers[receiver].information.modelID && reusableBuffer.hardwareAndSettings.modules[module].receivers[receiver].timestamp < get_tmr10ms() + 2000) {
|
||||
// Receiver model
|
||||
if (y >= MENU_BODY_TOP && y < MENU_FOOTER_TOP) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + INDENT_WIDTH, y, STR_RECEIVER);
|
||||
lcdDrawNumber(lcdNextPos + 2, y, receiver + 1);
|
||||
uint8_t modelId = reusableBuffer.hardwareAndSettings.modules[module].receivers[receiver].information.modelID;
|
||||
lcdDrawText(COLUMN2_X, y, getPXX2ReceiverName(modelId));
|
||||
}
|
||||
y += FH;
|
||||
|
||||
// Receiver version
|
||||
if (y >= MENU_BODY_TOP && y < MENU_FOOTER_TOP) {
|
||||
drawPXX2FullVersion(COLUMN2_X, y, reusableBuffer.hardwareAndSettings.modules[module].receivers[receiver].information.hwVersion, reusableBuffer.hardwareAndSettings.modules[module].receivers[receiver].information.swVersion);
|
||||
}
|
||||
y += FH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t lines = (y - (FH + 1)) / FH + menuVerticalOffset;
|
||||
if (lines > NUM_BODY_LINES) {
|
||||
drawVerticalScrollbar(LCD_W-1, FH, LCD_H-FH, menuVerticalOffset, lines, NUM_BODY_LINES);
|
||||
}
|
||||
|
||||
switch(event) {
|
||||
case EVT_ROTARY_LEFT:
|
||||
if (lines > NUM_BODY_LINES) {
|
||||
if (menuVerticalOffset-- == 0)
|
||||
menuVerticalOffset = lines - 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
if (lines > NUM_BODY_LINES) {
|
||||
if (++menuVerticalOffset + NUM_BODY_LINES > lines)
|
||||
menuVerticalOffset = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
if (menuVerticalOffset != 0)
|
||||
menuVerticalOffset = 0;
|
||||
else
|
||||
popMenu();
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool menuRadioVersion(event_t event)
|
||||
{
|
||||
char id[27];
|
||||
getCPUUniqueID(id);
|
||||
|
||||
SIMPLE_MENU(STR_MENUVERSION, RADIO_ICONS, menuTabGeneral, MENU_RADIO_VERSION, 1);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP, vers_stamp);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + FH, date_stamp);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 2*FH, time_stamp);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 3*FH, eeprom_stamp);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + 4*FH, "UID:");
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + 64, MENU_CONTENT_TOP + 4*FH, id);
|
||||
|
||||
coord_t y = MENU_CONTENT_TOP + 5*FH;
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "OPTS:");
|
||||
lcdNextPos = MENUS_MARGIN_LEFT + 64;
|
||||
|
||||
for (uint8_t i=0; options[i]; i++) {
|
||||
const char * option = options[i];
|
||||
coord_t width = getTextWidth(option);
|
||||
|
||||
if ((lcdNextPos + 5 + width) > LCD_W) {
|
||||
lcdDrawText(lcdNextPos, y, ",");
|
||||
lcdNextPos = MENUS_MARGIN_LEFT;
|
||||
y += FH;
|
||||
}
|
||||
if (i > 0 && lcdNextPos !=MENUS_MARGIN_LEFT) {
|
||||
lcdDrawText(lcdNextPos, y, ", ");
|
||||
}
|
||||
lcdDrawText(lcdNextPos, y, option);
|
||||
}
|
||||
|
||||
#if defined(PXX2)
|
||||
y += FH + FH / 2;
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, BUTTON(TR_MODULES_RX_VERSION), menuVerticalPosition == 0 ? INVERS : 0);
|
||||
y += FH;
|
||||
if (menuVerticalPosition == 0 && event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
s_editMode = EDIT_SELECT_FIELD;
|
||||
pushMenu(menuRadioModulesVersion);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
class DarkblueTheme: public Theme
|
||||
{
|
||||
public:
|
||||
DarkblueTheme():
|
||||
Theme("Darkblue")
|
||||
{
|
||||
}
|
||||
|
||||
void loadColors() const
|
||||
{
|
||||
lcdColorTable[TEXT_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[TEXT_BGCOLOR_INDEX] = RGB(10, 78, 121);
|
||||
lcdColorTable[TEXT_INVERTED_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = RGB(32, 34, 42);
|
||||
lcdColorTable[TEXT_STATUSBAR_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[LINE_COLOR_INDEX] = GREY;
|
||||
lcdColorTable[SCROLLBOX_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[MENU_TITLE_BGCOLOR_INDEX] = DARKGREY;
|
||||
lcdColorTable[MENU_TITLE_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[MENU_TITLE_DISABLE_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[HEADER_COLOR_INDEX] = RGB(32, 34, 42);
|
||||
lcdColorTable[ALARM_COLOR_INDEX] = RGB(32, 34, 42);
|
||||
lcdColorTable[WARNING_COLOR_INDEX] = YELLOW;
|
||||
lcdColorTable[TEXT_DISABLE_COLOR_INDEX] = GREY;
|
||||
lcdColorTable[CURVE_AXIS_COLOR_INDEX] = LIGHTGREY;
|
||||
lcdColorTable[CURVE_COLOR_INDEX] = RGB(32, 34, 42);
|
||||
lcdColorTable[CURVE_CURSOR_COLOR_INDEX] = RGB(32, 34, 42);
|
||||
lcdColorTable[TITLE_BGCOLOR_INDEX] = RGB(32, 34, 42);
|
||||
lcdColorTable[TRIM_BGCOLOR_INDEX] = RGB(32, 34, 42);
|
||||
lcdColorTable[TRIM_SHADOW_COLOR_INDEX] = RGB(100, 100, 100);
|
||||
lcdColorTable[MAINVIEW_PANES_COLOR_INDEX] = GREY;
|
||||
lcdColorTable[MAINVIEW_GRAPHICS_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[HEADER_BGCOLOR_INDEX] = BLACK;
|
||||
lcdColorTable[HEADER_ICON_BGCOLOR_INDEX] = BLACK;
|
||||
lcdColorTable[HEADER_CURRENT_BGCOLOR_INDEX] = RGB(10, 78, 121);
|
||||
lcdColorTable[OVERLAY_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[BARGRAPH1_COLOR_INDEX] = RGB(15, 150, 250);
|
||||
lcdColorTable[BARGRAPH2_COLOR_INDEX] = RGB(167, 167, 167);
|
||||
lcdColorTable[BARGRAPH_BGCOLOR_INDEX] = RGB(97, 97, 102);
|
||||
}
|
||||
|
||||
void loadMenuIcon(uint8_t index, const char * filename) const
|
||||
{
|
||||
BitmapBuffer * mask = BitmapBuffer::loadMask(getThemePath(filename));
|
||||
if (mask) {
|
||||
menuIconNormal[index] = new BitmapBuffer(BMP_RGB565, mask->getWidth(), mask->getHeight());
|
||||
if (menuIconNormal[index]) {
|
||||
menuIconNormal[index]->clear(HEADER_BGCOLOR);
|
||||
menuIconNormal[index]->drawMask(0, 0, mask, HEADER_CURRENT_BGCOLOR);
|
||||
}
|
||||
menuIconSelected[index] = new BitmapBuffer(BMP_RGB565, mask->getWidth(), mask->getHeight());
|
||||
if (menuIconSelected[index]) {
|
||||
menuIconSelected[index]->clear(HEADER_BGCOLOR);
|
||||
menuIconSelected[index]->drawMask(0, 0, mask, MENU_TITLE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadMenusIcons() const
|
||||
{
|
||||
loadMenuIcon(ICON_OPENTX, "mask_opentx.png");
|
||||
loadMenuIcon(ICON_RADIO, "mask_menu_radio.png");
|
||||
loadMenuIcon(ICON_RADIO_SETUP, "mask_radio_setup.png");
|
||||
loadMenuIcon(ICON_RADIO_SD_MANAGER, "mask_radio_sd_browser.png");
|
||||
loadMenuIcon(ICON_RADIO_TOOLS, "mask_radio_tools.png");
|
||||
loadMenuIcon(ICON_RADIO_SPECTRUM_ANALYSER, "/mask_radio_spectrum_analyser.png");
|
||||
loadMenuIcon(ICON_RADIO_GLOBAL_FUNCTIONS, "mask_radio_global_functions.png");
|
||||
loadMenuIcon(ICON_RADIO_TRAINER, "mask_radio_trainer.png");
|
||||
loadMenuIcon(ICON_RADIO_HARDWARE, "mask_radio_hardware.png");
|
||||
loadMenuIcon(ICON_RADIO_VERSION, "mask_radio_version.png");
|
||||
loadMenuIcon(ICON_MODEL, "mask_menu_model.png");
|
||||
loadMenuIcon(ICON_MODEL_SETUP, "mask_model_setup.png");
|
||||
loadMenuIcon(ICON_MODEL_HELI, "mask_model_heli.png");
|
||||
loadMenuIcon(ICON_MODEL_FLIGHT_MODES, "mask_model_flight_modes.png");
|
||||
loadMenuIcon(ICON_MODEL_INPUTS, "mask_model_inputs.png");
|
||||
loadMenuIcon(ICON_MODEL_MIXER, "mask_model_mixer.png");
|
||||
loadMenuIcon(ICON_MODEL_OUTPUTS, "mask_model_outputs.png");
|
||||
loadMenuIcon(ICON_MODEL_CURVES, "mask_model_curves.png");
|
||||
loadMenuIcon(ICON_MODEL_GVARS, "mask_model_gvars.png");
|
||||
loadMenuIcon(ICON_MODEL_LOGICAL_SWITCHES, "mask_model_logical_switches.png");
|
||||
loadMenuIcon(ICON_MODEL_SPECIAL_FUNCTIONS, "mask_model_special_functions.png");
|
||||
loadMenuIcon(ICON_MODEL_LUA_SCRIPTS, "mask_model_lua_scripts.png");
|
||||
loadMenuIcon(ICON_MODEL_TELEMETRY, "mask_model_telemetry.png");
|
||||
loadMenuIcon(ICON_STATS, "mask_menu_stats.png");
|
||||
loadMenuIcon(ICON_STATS_THROTTLE_GRAPH, "mask_stats_throttle_graph.png");
|
||||
loadMenuIcon(ICON_STATS_TIMERS, "mask_stats_timers.png");
|
||||
loadMenuIcon(ICON_STATS_ANALOGS, "mask_stats_analogs.png");
|
||||
loadMenuIcon(ICON_STATS_DEBUG, "mask_stats_debug.png");
|
||||
loadMenuIcon(ICON_THEME, "mask_menu_theme.png");
|
||||
loadMenuIcon(ICON_THEME_SETUP, "mask_theme_setup.png");
|
||||
loadMenuIcon(ICON_THEME_VIEW1, "mask_theme_view1.png");
|
||||
loadMenuIcon(ICON_THEME_VIEW2, "mask_theme_view2.png");
|
||||
loadMenuIcon(ICON_THEME_VIEW3, "mask_theme_view3.png");
|
||||
loadMenuIcon(ICON_THEME_VIEW4, "mask_theme_view4.png");
|
||||
loadMenuIcon(ICON_THEME_VIEW5, "mask_theme_view5.png");
|
||||
loadMenuIcon(ICON_THEME_ADD_VIEW, "mask_theme_add_view.png");
|
||||
loadMenuIcon(ICON_MONITOR, "mask_monitor.png");
|
||||
loadMenuIcon(ICON_MONITOR_CHANNELS1, "mask_monitor_channels1.png");
|
||||
loadMenuIcon(ICON_MONITOR_CHANNELS2, "mask_monitor_channels2.png");
|
||||
loadMenuIcon(ICON_MONITOR_CHANNELS3, "mask_monitor_channels3.png");
|
||||
loadMenuIcon(ICON_MONITOR_CHANNELS4, "mask_monitor_channels4.png");
|
||||
loadMenuIcon(ICON_MONITOR_LOGICAL_SWITCHES, "/mask_monitor_logsw.png");
|
||||
}
|
||||
|
||||
void loadThemeBitmaps() const
|
||||
{
|
||||
// Calibration screen
|
||||
delete calibStick;
|
||||
calibStick = BitmapBuffer::load(getThemePath("stick_pointer.png"));
|
||||
|
||||
delete calibStickBackground;
|
||||
calibStickBackground = BitmapBuffer::load(getThemePath("stick_background.png"));
|
||||
|
||||
delete calibTrackpBackground;
|
||||
calibTrackpBackground = BitmapBuffer::load(getThemePath("trackp_background.png"));
|
||||
|
||||
delete calibHorus;
|
||||
#if defined(PCBX10)
|
||||
if (STICKS_PWM_ENABLED())
|
||||
calibHorus = BitmapBuffer::load(getThemePath("X10S.bmp"));
|
||||
else
|
||||
calibHorus = BitmapBuffer::load(getThemePath("X10.bmp"));
|
||||
#else
|
||||
calibHorus = BitmapBuffer::load(getThemePath("horus.bmp"));
|
||||
#endif
|
||||
|
||||
// Channels monitor screen
|
||||
delete chanMonLockedBitmap;
|
||||
chanMonLockedBitmap = BitmapBuffer::loadMaskOnBackground("mask_monitor_lockch.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete chanMonInvertedBitmap;
|
||||
chanMonInvertedBitmap = BitmapBuffer::loadMaskOnBackground("mask_monitor_inver.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
// Model Selection screen
|
||||
delete modelselIconBitmap;
|
||||
modelselIconBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_iconback.png", TITLE_BGCOLOR, TEXT_BGCOLOR);
|
||||
if (modelselIconBitmap) {
|
||||
BitmapBuffer * bitmap = BitmapBuffer::load(getThemePath("modelsel/icon_default.png"));
|
||||
modelselIconBitmap->drawBitmap(20, 8, bitmap);
|
||||
delete bitmap;
|
||||
}
|
||||
|
||||
delete modelselSdFreeBitmap;
|
||||
modelselSdFreeBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_sdfree.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete modelselModelQtyBitmap;
|
||||
modelselModelQtyBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_modelqty.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete modelselModelNameBitmap;
|
||||
modelselModelNameBitmap = BitmapBuffer::loadMaskOnBackground("modelsel/mask_modelname.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete modelselModelMoveBackground;
|
||||
modelselModelMoveBackground = BitmapBuffer::loadMask(getThemePath("modelsel/mask_moveback.png"));
|
||||
|
||||
delete modelselModelMoveIcon;
|
||||
modelselModelMoveIcon = BitmapBuffer::loadMask(getThemePath("modelsel/mask_moveico.png"));
|
||||
|
||||
delete modelselWizardBackground;
|
||||
modelselWizardBackground = BitmapBuffer::load(getThemePath("wizard/background.png"));
|
||||
|
||||
|
||||
// Mixer setup screen
|
||||
delete mixerSetupMixerBitmap;
|
||||
mixerSetupMixerBitmap = BitmapBuffer::loadMaskOnBackground("mask_sbar_mixer.png", MENU_TITLE_COLOR, HEADER_BGCOLOR);
|
||||
|
||||
delete mixerSetupToBitmap;
|
||||
mixerSetupToBitmap = BitmapBuffer::loadMaskOnBackground("mask_sbar_to.png", TEXT_BGCOLOR, HEADER_BGCOLOR);
|
||||
|
||||
delete mixerSetupOutputBitmap;
|
||||
mixerSetupOutputBitmap = BitmapBuffer::loadMaskOnBackground("mask_sbar_output.png", MENU_TITLE_COLOR, HEADER_BGCOLOR);
|
||||
|
||||
delete mixerSetupAddBitmap;
|
||||
mixerSetupAddBitmap = BitmapBuffer::loadMaskOnBackground("mask_mplex_add.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupMultiBitmap;
|
||||
mixerSetupMultiBitmap = BitmapBuffer::loadMaskOnBackground("mask_mplex_multi.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupReplaceBitmap;
|
||||
mixerSetupReplaceBitmap = BitmapBuffer::loadMaskOnBackground("mask_mplex_replace.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupLabelBitmap;
|
||||
mixerSetupLabelBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_label.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupCurveBitmap;
|
||||
mixerSetupCurveBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_curve.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupSwitchBitmap;
|
||||
mixerSetupSwitchBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_switch.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupSlowBitmap;
|
||||
mixerSetupSlowBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_slow.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupDelayBitmap;
|
||||
mixerSetupDelayBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_delay.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupDelaySlowBitmap;
|
||||
mixerSetupDelaySlowBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_delayslow.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
|
||||
delete mixerSetupFlightmodeBitmap;
|
||||
mixerSetupFlightmodeBitmap = BitmapBuffer::loadMaskOnBackground("mask_textline_fm.png", TEXT_COLOR, TEXT_BGCOLOR);
|
||||
}
|
||||
|
||||
virtual void load() const
|
||||
{
|
||||
loadColors();
|
||||
loadMenusIcons();
|
||||
loadThemeBitmaps();
|
||||
loadFontCache();
|
||||
}
|
||||
|
||||
void drawTopbarBackground(uint8_t icon) const
|
||||
{
|
||||
lcdDrawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
lcdDrawSolidFilledRect(0, 0, 41, MENU_HEADER_HEIGHT, HEADER_ICON_BGCOLOR);
|
||||
|
||||
if (icon == ICON_OPENTX) {
|
||||
static BitmapBuffer * thumb = BitmapBuffer::load(getFilePath("topmenu_opentx.bmp"));
|
||||
lcd->drawBitmap(5, 7, thumb);
|
||||
}
|
||||
else {
|
||||
lcd->drawBitmap(5, 7, menuIconSelected[icon]);
|
||||
}
|
||||
|
||||
drawTopbarDatetime();
|
||||
}
|
||||
|
||||
virtual void drawMenuIcon(uint8_t index, uint8_t position, bool selected) const
|
||||
{
|
||||
lcd->drawBitmap(50+position*MENU_ICONS_SPACING, 7, selected ? menuIconSelected[index] : menuIconNormal[index]);
|
||||
}
|
||||
|
||||
protected:
|
||||
static BitmapBuffer * menuIconNormal[MENUS_ICONS_COUNT];
|
||||
static BitmapBuffer * menuIconSelected[MENUS_ICONS_COUNT];
|
||||
};
|
||||
|
||||
BitmapBuffer * DarkblueTheme::menuIconNormal[MENUS_ICONS_COUNT] = { NULL };
|
||||
BitmapBuffer * DarkblueTheme::menuIconSelected[MENUS_ICONS_COUNT] = { NULL };
|
||||
|
||||
const DarkblueTheme darkblueTheme;
|
||||
@@ -1,240 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define TRIM_LH_X 10
|
||||
#define TRIM_LV_X 24
|
||||
#define TRIM_RV_X (LCD_W-35)
|
||||
#define TRIM_RH_X (LCD_W-175)
|
||||
#define TRIM_V_Y 55
|
||||
#define TRIM_H_Y (LCD_H-37)
|
||||
#define TRIM_LEN 80
|
||||
#define POTS_LINE_Y (LCD_H-20)
|
||||
|
||||
Layout * customScreens[MAX_CUSTOM_SCREENS] = { 0, 0, 0, 0, 0 };
|
||||
Topbar * topbar;
|
||||
|
||||
void drawMainPots()
|
||||
{
|
||||
// The 3 pots
|
||||
drawHorizontalSlider(TRIM_LH_X, POTS_LINE_Y, 160, calibratedAnalogs[CALIBRATED_POT1], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
if (IS_POT_MULTIPOS(POT2))
|
||||
drawHorizontalSlider(LCD_W/2-20, POTS_LINE_Y, XPOTS_MULTIPOS_COUNT*5, 1 + (potsPos[1] & 0x0f), 1, XPOTS_MULTIPOS_COUNT + 1, XPOTS_MULTIPOS_COUNT, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_NUMBER_BUTTON);
|
||||
else
|
||||
drawHorizontalSlider(LCD_W/2-40, POTS_LINE_Y, 80, calibratedAnalogs[CALIBRATED_POT2], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
drawHorizontalSlider(TRIM_RH_X, POTS_LINE_Y, 160, calibratedAnalogs[CALIBRATED_POT3], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
|
||||
// The 2 rear sliders
|
||||
drawVerticalSlider(6, TRIM_V_Y, 160, calibratedAnalogs[CALIBRATED_SLIDER_REAR_LEFT], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
drawVerticalSlider(LCD_W-18, TRIM_V_Y, 160, calibratedAnalogs[CALIBRATED_SLIDER_REAR_RIGHT], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
}
|
||||
|
||||
void drawTrims(uint8_t flightMode)
|
||||
{
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
static const coord_t x[4] = { TRIM_LH_X, TRIM_LV_X, TRIM_RV_X, TRIM_RH_X };
|
||||
static uint8_t vert[4] = {0, 1, 1, 0};
|
||||
unsigned int stickIndex = CONVERT_MODE(i);
|
||||
coord_t xm = x[stickIndex];
|
||||
int32_t trim = getTrimValue(flightMode, i);
|
||||
|
||||
|
||||
if(getRawTrimValue(flightMode, i).mode == TRIM_MODE_NONE)
|
||||
continue;
|
||||
|
||||
if (vert[i]) {
|
||||
if (g_model.extendedTrims == 1) {
|
||||
drawVerticalSlider(xm, TRIM_V_Y, 160, trim, TRIM_EXTENDED_MIN, TRIM_EXTENDED_MAX, 0, OPTION_SLIDER_EMPTY_BAR|OPTION_SLIDER_TRIM_BUTTON);
|
||||
}
|
||||
else {
|
||||
drawVerticalSlider(xm, TRIM_V_Y, 160, trim, TRIM_MIN, TRIM_MAX, 0, OPTION_SLIDER_EMPTY_BAR|OPTION_SLIDER_TRIM_BUTTON);
|
||||
}
|
||||
if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) {
|
||||
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
|
||||
uint16_t y = TRIM_V_Y + TRIM_LEN + (trim<0 ? -TRIM_LEN/2 : TRIM_LEN/2);
|
||||
lcdDrawNumber(xm+2, y, trim, TINSIZE | CENTERED | VERTICAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (g_model.extendedTrims == 1) {
|
||||
drawHorizontalSlider(xm, TRIM_H_Y, 160, trim, TRIM_EXTENDED_MIN, TRIM_EXTENDED_MAX, 0, OPTION_SLIDER_EMPTY_BAR|OPTION_SLIDER_TRIM_BUTTON);
|
||||
}
|
||||
else {
|
||||
drawHorizontalSlider(xm, TRIM_H_Y, 160, trim, TRIM_MIN, TRIM_MAX, 0, OPTION_SLIDER_EMPTY_BAR|OPTION_SLIDER_TRIM_BUTTON);
|
||||
}
|
||||
if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) {
|
||||
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
|
||||
uint16_t x = xm + TRIM_LEN + (trim>0 ? -TRIM_LEN/2 : TRIM_LEN/2);
|
||||
lcdDrawNumber(x, TRIM_H_Y+2, trim, TINSIZE | CENTERED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onMainViewMenu(const char *result)
|
||||
{
|
||||
if (result == STR_MODEL_SELECT) {
|
||||
chainMenu(menuModelSelect);
|
||||
}
|
||||
else if (result == STR_RESET_TIMER1) {
|
||||
timerReset(0);
|
||||
}
|
||||
else if (result == STR_RESET_TIMER2) {
|
||||
timerReset(1);
|
||||
}
|
||||
else if (result == STR_RESET_TIMER3) {
|
||||
timerReset(2);
|
||||
}
|
||||
else if (result == STR_VIEW_NOTES) {
|
||||
pushModelNotes();
|
||||
}
|
||||
else if (result == STR_RESET_SUBMENU) {
|
||||
POPUP_MENU_ADD_ITEM(STR_RESET_FLIGHT);
|
||||
POPUP_MENU_ADD_ITEM(STR_RESET_TIMER1);
|
||||
POPUP_MENU_ADD_ITEM(STR_RESET_TIMER2);
|
||||
POPUP_MENU_ADD_ITEM(STR_RESET_TIMER3);
|
||||
POPUP_MENU_ADD_ITEM(STR_RESET_TELEMETRY);
|
||||
}
|
||||
else if (result == STR_RESET_TELEMETRY) {
|
||||
telemetryReset();
|
||||
}
|
||||
else if (result == STR_RESET_FLIGHT) {
|
||||
flightReset();
|
||||
}
|
||||
else if (result == STR_STATISTICS) {
|
||||
pushMenu(menuTabStats[0]);
|
||||
}
|
||||
else if (result == STR_SETUP_SCREENS) {
|
||||
pushMenu(menuTabScreensSetup[1]);
|
||||
}
|
||||
else if (result == STR_ABOUT_US) {
|
||||
chainMenu(menuAboutView);
|
||||
}
|
||||
else if (result == STR_MONITOR_SCREENS) {
|
||||
pushMenu(menuTabMonitors[lastMonitorPage]);
|
||||
}
|
||||
}
|
||||
|
||||
int getMainViewsCount()
|
||||
{
|
||||
for (int index=1; index<MAX_CUSTOM_SCREENS; index++) {
|
||||
if (!customScreens[index]) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return MAX_CUSTOM_SCREENS;
|
||||
}
|
||||
|
||||
bool menuMainView(event_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
killEvents(KEY_EXIT);
|
||||
killEvents(KEY_UP);
|
||||
killEvents(KEY_DOWN);
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
killEvents(event);
|
||||
POPUP_MENU_ADD_ITEM(STR_MODEL_SELECT);
|
||||
if (modelHasNotes()) {
|
||||
POPUP_MENU_ADD_ITEM(STR_VIEW_NOTES);
|
||||
}
|
||||
POPUP_MENU_ADD_ITEM(STR_MONITOR_SCREENS);
|
||||
POPUP_MENU_ADD_ITEM(STR_RESET_SUBMENU);
|
||||
POPUP_MENU_ADD_ITEM(STR_STATISTICS);
|
||||
POPUP_MENU_ADD_ITEM(STR_ABOUT_US);
|
||||
POPUP_MENU_START(onMainViewMenu);
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_MODEL):
|
||||
killEvents(event);
|
||||
pushMenu(menuTabModel[0]);
|
||||
return false;
|
||||
|
||||
case EVT_KEY_LONG(KEY_RADIO):
|
||||
killEvents(event);
|
||||
pushMenu(menuTabGeneral[0]);
|
||||
return false;
|
||||
|
||||
case EVT_KEY_LONG(KEY_TELEM):
|
||||
killEvents(event);
|
||||
pushMenu(menuTabScreensSetup[1]);
|
||||
return false;
|
||||
|
||||
#if defined(PCBX12S)
|
||||
case EVT_KEY_FIRST(KEY_PGDN):
|
||||
#elif defined(PCBX10)
|
||||
case EVT_KEY_BREAK(KEY_PGDN):
|
||||
#endif
|
||||
storageDirty(EE_MODEL);
|
||||
g_model.view = circularIncDec(g_model.view, +1, 0, getMainViewsCount()-1);
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_PGUP):
|
||||
#if defined(PCBX10)
|
||||
case EVT_KEY_LONG(KEY_PGDN):
|
||||
#endif
|
||||
killEvents(event);
|
||||
storageDirty(EE_MODEL);
|
||||
g_model.view = circularIncDec(g_model.view, -1, 0, getMainViewsCount()-1);
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
#if defined(GVARS)
|
||||
if (gvarDisplayTimer > 0) {
|
||||
gvarDisplayTimer = 0;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (g_model.view >= getMainViewsCount()) {
|
||||
g_model.view = 0;
|
||||
}
|
||||
|
||||
for (uint8_t i=0; i<MAX_CUSTOM_SCREENS; i++) {
|
||||
if (customScreens[i]) {
|
||||
if (i == g_model.view)
|
||||
customScreens[i]->refresh();
|
||||
else
|
||||
customScreens[i]->background();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool menuMainViewChannelsMonitor(event_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
chainMenu(menuMainView);
|
||||
event = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return menuChannelsView(event);
|
||||
}
|
||||
#endif
|
||||
@@ -1,12 +1,17 @@
|
||||
include(gui/${GUI_DIR}/CMakeLists.txt)
|
||||
include_directories(gui gui/${GUI_DIR})
|
||||
|
||||
if(NOT GUI_DIR STREQUAL colorlcd)
|
||||
set(SRC
|
||||
${SRC}
|
||||
gui/navigation/common.cpp
|
||||
gui/navigation/navigation_${NAVIGATION_TYPE}.cpp
|
||||
)
|
||||
string(TOUPPER ${NAVIGATION_TYPE} NAVIGATION_TYPE)
|
||||
add_definitions(-DNAVIGATION_${NAVIGATION_TYPE})
|
||||
endif()
|
||||
|
||||
set(SRC
|
||||
${SRC}
|
||||
gui/navigation/common.cpp
|
||||
gui/navigation/navigation_${NAVIGATION_TYPE}.cpp
|
||||
gui/screenshot.cpp
|
||||
)
|
||||
|
||||
string(TOUPPER ${NAVIGATION_TYPE} NAVIGATION_TYPE)
|
||||
add_definitions(-DNAVIGATION_${NAVIGATION_TYPE})
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
include_directories(
|
||||
${RADIO_SRC_DIRECTORY}/gui/colorlcd
|
||||
${RADIO_SRC_DIRECTORY}/gui/colorlcd/layouts
|
||||
${RADIO_SRC_DIRECTORY}/fonts/truetype
|
||||
)
|
||||
|
||||
file(GLOB THEMES_SRC RELATIVE ${RADIO_SRC_DIRECTORY}/gui/colorlcd ${RADIO_SRC_DIRECTORY}/gui/colorlcd/themes/*.cpp)
|
||||
file(GLOB LAYOUTS_SRC RELATIVE ${RADIO_SRC_DIRECTORY}/gui/colorlcd ${RADIO_SRC_DIRECTORY}/gui/colorlcd/layouts/*.cpp)
|
||||
file(GLOB WIDGETS_SRC RELATIVE ${RADIO_SRC_DIRECTORY}/gui/colorlcd ${RADIO_SRC_DIRECTORY}/gui/colorlcd/widgets/*.cpp)
|
||||
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
lcd.cpp
|
||||
splash.cpp
|
||||
fonts.cpp
|
||||
curves.cpp
|
||||
bitmaps.cpp
|
||||
|
||||
theme.cpp
|
||||
# topbar.cpp
|
||||
# layout.cpp
|
||||
# widget.cpp
|
||||
${THEMES_SRC}
|
||||
# ${LAYOUTS_SRC}
|
||||
# ${WIDGETS_SRC}
|
||||
rle.cpp
|
||||
# popups.cpp
|
||||
draw_functions.cpp
|
||||
# menus.cpp
|
||||
menu_model.cpp
|
||||
# model_select.cpp
|
||||
model_setup.cpp
|
||||
model_flightmodes.cpp
|
||||
model_inputs.cpp
|
||||
model_mixes.cpp
|
||||
model_outputs.cpp
|
||||
model_curves.cpp
|
||||
model_gvars.cpp
|
||||
model_logical_switches.cpp
|
||||
special_functions.cpp
|
||||
model_telemetry.cpp
|
||||
menu_radio.cpp
|
||||
radio_setup.cpp
|
||||
radio_sdmanager.cpp
|
||||
radio_tools.cpp
|
||||
radio_trainer.cpp
|
||||
radio_version.cpp
|
||||
radio_hardware.cpp
|
||||
radio_calibration.cpp
|
||||
view_main.cpp
|
||||
# view_statistics.cpp
|
||||
)
|
||||
|
||||
macro(add_gui_src src)
|
||||
set(GUI_SRC
|
||||
${GUI_SRC}
|
||||
${src}
|
||||
)
|
||||
endmacro(add_gui_src)
|
||||
|
||||
if(HELI)
|
||||
add_gui_src(model_heli.cpp)
|
||||
endif()
|
||||
|
||||
if(PXX2 OR LUA)
|
||||
add_gui_src(radio_tools.cpp)
|
||||
endif()
|
||||
|
||||
if(PXX2)
|
||||
add_gui_src(radio_spectrum_analyser.cpp)
|
||||
endif()
|
||||
|
||||
if(LUA STREQUAL YES)
|
||||
# TODO set(SRC ${SRC} lua/widgets.cpp)
|
||||
# TODO set(GUI_SRC ${GUI_SRC} model_custom_scripts.cpp)
|
||||
endif()
|
||||
|
||||
# gui/${GUI_DIR}/modelslist.cpp
|
||||
|
||||
set(SRC
|
||||
${SRC}
|
||||
stubs.cpp
|
||||
)
|
||||
|
||||
# includes libopenui
|
||||
include(gui/libopenui/CMakeLists.txt)
|
||||
include_directories(gui/libopenui)
|
||||
add_definitions(-DLIBOPENUI)
|
||||
foreach(LIBOPENUI_FILE ${LIBOPENUI_SRC})
|
||||
set(SRC ${SRC} gui/libopenui/${LIBOPENUI_FILE})
|
||||
endforeach()
|
||||
@@ -183,7 +183,7 @@ const uint8_t LBM_SWIPE_RIGHT[] = {
|
||||
BitmapBuffer * calibStick = NULL;
|
||||
BitmapBuffer * calibStickBackground = NULL;
|
||||
BitmapBuffer * calibTrackpBackground = NULL;
|
||||
BitmapBuffer * calibHorus = NULL;
|
||||
BitmapBuffer * calibRadioPict = NULL;
|
||||
BitmapBuffer * modelselIconBitmap = NULL;
|
||||
BitmapBuffer * modelselSdFreeBitmap = NULL;
|
||||
BitmapBuffer * modelselModelQtyBitmap = NULL;
|
||||
@@ -201,8 +201,10 @@ BitmapBuffer * mixerSetupMultiBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupReplaceBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupLabelBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupCurveBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupSwitchBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupSwitchIcon = NULL;
|
||||
BitmapBuffer * mixerSetupDelayBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupSlowBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupDelaySlowBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupFlightmodeIcon = NULL;
|
||||
BitmapBuffer * mixerSetupFlightmodeBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupSwitchBitmap = NULL;
|
||||
@@ -83,7 +83,7 @@ extern BitmapBuffer * modelselWizardBackground;
|
||||
extern BitmapBuffer * calibStick;
|
||||
extern BitmapBuffer * calibStickBackground;
|
||||
extern BitmapBuffer * calibTrackpBackground;
|
||||
extern BitmapBuffer * calibHorus;
|
||||
extern BitmapBuffer * calibRadioPict;
|
||||
|
||||
// Channels monitor bitmaps
|
||||
extern BitmapBuffer * chanMonLockedBitmap;
|
||||
@@ -97,11 +97,13 @@ extern BitmapBuffer * mixerSetupAddBitmap;
|
||||
extern BitmapBuffer * mixerSetupMultiBitmap;
|
||||
extern BitmapBuffer * mixerSetupReplaceBitmap;
|
||||
extern BitmapBuffer * mixerSetupLabelBitmap;
|
||||
extern BitmapBuffer * mixerSetupFlightmodeBitmap;
|
||||
extern BitmapBuffer * mixerSetupFlightmodeIcon;
|
||||
extern BitmapBuffer * mixerSetupCurveBitmap;
|
||||
extern BitmapBuffer * mixerSetupSwitchBitmap;
|
||||
extern BitmapBuffer * mixerSetupSwitchIcon;
|
||||
extern BitmapBuffer * mixerSetupDelayBitmap;
|
||||
extern BitmapBuffer * mixerSetupSlowBitmap;
|
||||
extern BitmapBuffer * mixerSetupDelaySlowBitmap;
|
||||
extern BitmapBuffer * mixerSetupFlightmodeBitmap;
|
||||
extern BitmapBuffer * mixerSetupSwitchBitmap;
|
||||
|
||||
#endif // _BITMAPS_H_
|
||||
@@ -32,6 +32,7 @@
|
||||
#define BLACK RGB(0, 0, 0)
|
||||
#define YELLOW RGB(0xF0, 0xD0, 0x10)
|
||||
#define BLUE RGB(0x30, 0xA0, 0xE0)
|
||||
#define DARKBLUE RGB(0, 0x35, 0x67)
|
||||
#define GREY RGB(96, 96, 96)
|
||||
#define DARKGREY RGB(64, 64, 64)
|
||||
#define LIGHTGREY RGB(180, 180, 180)
|
||||
@@ -79,7 +80,7 @@ enum LcdColorIndex
|
||||
|
||||
extern uint16_t lcdColorTable[LCD_COLOR_COUNT];
|
||||
|
||||
#define COLOR(index) ((index) << 16)
|
||||
#define COLOR(index) LcdFlags((index) << 16)
|
||||
#define COLOR_IDX(att) uint8_t((att) >> 16)
|
||||
|
||||
#define TEXT_COLOR COLOR(TEXT_COLOR_INDEX)
|
||||
@@ -105,7 +106,7 @@ extern uint16_t lcdColorTable[LCD_COLOR_COUNT];
|
||||
#define TRIM_SHADOW_COLOR COLOR(TRIM_SHADOW_COLOR_INDEX)
|
||||
#define HEADER_BGCOLOR COLOR(HEADER_BGCOLOR_INDEX)
|
||||
#define HEADER_ICON_BGCOLOR COLOR(HEADER_ICON_BGCOLOR_INDEX)
|
||||
#define HEADER_CURRENT_BGCOLOR COLOR(HEADER_CURRENT_BGCOLOR_INDEX)
|
||||
constexpr LcdFlags HEADER_CURRENT_BGCOLOR = COLOR(HEADER_CURRENT_BGCOLOR_INDEX);
|
||||
#define MAINVIEW_PANES_COLOR COLOR(MAINVIEW_PANES_COLOR_INDEX)
|
||||
#define MAINVIEW_GRAPHICS_COLOR COLOR(MAINVIEW_GRAPHICS_COLOR_INDEX)
|
||||
#define OVERLAY_COLOR COLOR(OVERLAY_COLOR_INDEX)
|
||||
@@ -33,37 +33,6 @@ void drawColumnHeader(const char * const * headers, const char * const * descrip
|
||||
}
|
||||
}
|
||||
|
||||
static const uint8_t __alpha_button_on[] __ALIGNED(4) = {
|
||||
#include "alpha_button_on.lbm"
|
||||
};
|
||||
Bitmap ALPHA_BUTTON_ON(BMP_ARGB4444, (const uint16_t*)__alpha_button_on);
|
||||
|
||||
static const uint8_t __alpha_button_off[] __ALIGNED(4) = {
|
||||
#include "alpha_button_off.lbm"
|
||||
};
|
||||
Bitmap ALPHA_BUTTON_OFF(BMP_ARGB4444, (const uint16_t*)__alpha_button_off);
|
||||
|
||||
void drawButton(coord_t x, coord_t y, const char * label, LcdFlags attr)
|
||||
{
|
||||
int width = getTextWidth(label, 0, 0);
|
||||
int padding = 0;
|
||||
if (attr & (BUTTON_OFF|BUTTON_ON)) {
|
||||
padding = 5;
|
||||
}
|
||||
if (attr & INVERS) {
|
||||
lcdDrawSolidFilledRect(x, y, padding+width+16+padding, 19, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawText(x+padding+8, y, label, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
else {
|
||||
lcdDrawText(x+padding+8, y, label, TEXT_COLOR);
|
||||
}
|
||||
lcdDrawSolidRect(x-1, y-1, padding+width+18+padding, 21, 1, TEXT_COLOR);
|
||||
if (attr & BUTTON_OFF)
|
||||
lcd->drawBitmap(x-6, y+3, &ALPHA_BUTTON_OFF);
|
||||
else if (attr & BUTTON_ON)
|
||||
lcd->drawBitmap(x-6, y+3, &ALPHA_BUTTON_ON);
|
||||
}
|
||||
|
||||
void drawCheckBox(coord_t x, coord_t y, uint8_t value, LcdFlags attr)
|
||||
{
|
||||
if (attr) {
|
||||
@@ -96,92 +65,6 @@ void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uin
|
||||
}
|
||||
}
|
||||
|
||||
void drawHorizontalScrollbar(coord_t x, coord_t y, coord_t w, uint16_t offset, uint16_t count, uint8_t visible)
|
||||
{
|
||||
if (visible < count) {
|
||||
lcdDrawSolidHorizontalLine(x, y, w, LINE_COLOR);
|
||||
coord_t xofs = (w*offset + count/2) / count;
|
||||
coord_t xhgt = (w*visible + count/2) / count;
|
||||
if (xhgt + xofs > w)
|
||||
xhgt = w - xofs;
|
||||
lcdDrawSolidFilledRect(x+xofs, y-1, xhgt, 3, SCROLLBOX_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawProgressScreen(const char * title, const char * message, int num, int den)
|
||||
{
|
||||
lcdClear();
|
||||
lcdSetColor(WHITE);
|
||||
if (message) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, LCD_H-42, message, CUSTOM_COLOR);
|
||||
}
|
||||
lcdDrawRect(MENUS_MARGIN_LEFT, LCD_H-22, LCD_W-2*MENUS_MARGIN_LEFT, 15, 1, SOLID, CUSTOM_COLOR);
|
||||
lcdSetColor(RED);
|
||||
if (num > 0 && den > 0) {
|
||||
int width = ((LCD_W-2*MENUS_MARGIN_LEFT-4) * num) / den;
|
||||
lcdDrawSolidFilledRect(MENUS_MARGIN_LEFT+2, LCD_H-20, width, 11, CUSTOM_COLOR);
|
||||
}
|
||||
lcdRefresh();
|
||||
}
|
||||
|
||||
void drawShadow(coord_t x, coord_t y, coord_t w, coord_t h)
|
||||
{
|
||||
lcdDrawSolidVerticalLine(x+w, y+1, h, TEXT_COLOR);
|
||||
lcdDrawSolidHorizontalLine(x+1, y+h, w, TEXT_COLOR);
|
||||
lcdDrawSolidVerticalLine(x+w+1, y+2, h, LINE_COLOR);
|
||||
lcdDrawSolidHorizontalLine(x+2, y+h+1, w, LINE_COLOR);
|
||||
}
|
||||
|
||||
void drawMenuTemplate(const char * title, uint8_t icon, const uint8_t * icons, uint32_t options)
|
||||
{
|
||||
coord_t bodyTop, bodyBottom;
|
||||
|
||||
theme->drawTopbarBackground(icons ? icons[0] : icon);
|
||||
|
||||
// Menu title bar
|
||||
if (options & OPTION_MENU_TITLE_BAR) {
|
||||
linesDisplayed = NUM_BODY_LINES;
|
||||
bodyTop = MENU_BODY_TOP;
|
||||
lcdDrawSolidFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR);
|
||||
lcdDrawSolidFilledRect(0, MENU_TITLE_TOP, LCD_W, MENU_TITLE_HEIGHT, TITLE_BGCOLOR);
|
||||
if (title) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP+1, title, MENU_TITLE_COLOR);
|
||||
}
|
||||
if (icons) {
|
||||
for (int i=0; i<menuPageCount; i++) {
|
||||
if (menuPageIndex != i) {
|
||||
theme->drawMenuIcon(icons[i+1], i, false);
|
||||
}
|
||||
}
|
||||
theme->drawMenuIcon(icons[menuPageIndex+1], menuPageIndex, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
linesDisplayed = NUM_BODY_LINES + 1;
|
||||
bodyTop = MENU_HEADER_HEIGHT;
|
||||
if (title) {
|
||||
lcdDrawText(50, 3, title, MENU_TITLE_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
// Footer
|
||||
if (options & OPTION_MENU_NO_FOOTER) {
|
||||
bodyBottom = LCD_H;
|
||||
}
|
||||
else {
|
||||
bodyBottom = MENU_FOOTER_TOP;
|
||||
lcdDrawSolidFilledRect(0, MENU_FOOTER_TOP, LCD_W, MENU_FOOTER_HEIGHT, HEADER_BGCOLOR);
|
||||
}
|
||||
|
||||
// Body
|
||||
lcdDrawSolidFilledRect(0, bodyTop, LCD_W, bodyBottom-bodyTop, TEXT_BGCOLOR);
|
||||
|
||||
// Scrollbar
|
||||
if (!(options & OPTION_MENU_NO_SCROLLBAR) && linesCount>linesDisplayed) {
|
||||
drawVerticalScrollbar(DEFAULT_SCROLLBAR_X, bodyTop+3, bodyBottom-bodyTop-6, menuVerticalOffset, linesCount, linesDisplayed);
|
||||
}
|
||||
}
|
||||
|
||||
void drawTrimSquare(coord_t x, coord_t y)
|
||||
{
|
||||
lcdDrawSolidFilledRect(x-2, y, 15, 15, TRIM_BGCOLOR);
|
||||
@@ -306,21 +189,13 @@ void drawHorizontalSlider(coord_t x, coord_t y, int len, int val, int min, int m
|
||||
}
|
||||
}
|
||||
|
||||
void drawSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options)
|
||||
{
|
||||
if (options & OPTION_SLIDER_VERTICAL)
|
||||
drawVerticalSlider(x, y, len, val, min, max, steps, options);
|
||||
else
|
||||
drawHorizontalSlider(x, y, len, val, min, max, steps, options);
|
||||
}
|
||||
|
||||
#if defined(GVARS)
|
||||
bool noZero(int val)
|
||||
{
|
||||
return val != 0;
|
||||
}
|
||||
|
||||
void drawGVarValue(coord_t x, coord_t y, uint8_t gvar, gvar_t value, LcdFlags flags)
|
||||
void drawGVarValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t gvar, gvar_t value, LcdFlags flags)
|
||||
{
|
||||
uint8_t prec = g_model.gvars[gvar].prec;
|
||||
if (prec > 0) {
|
||||
@@ -371,22 +246,24 @@ int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int
|
||||
return value;
|
||||
}
|
||||
#else
|
||||
int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int16_t max, LcdFlags attr, event_t event)
|
||||
void drawValueOrGVar(BitmapBuffer * dc, coord_t x, coord_t y, gvar_t value, LcdFlags flags)
|
||||
{
|
||||
if (attr & INVERS) value = checkIncDec(event, value, min, max, EE_MODEL);
|
||||
lcdDrawNumber(x, y, value, attr, 0, NULL, "%");
|
||||
return value;
|
||||
drawNumber(dc, x, y, value, flags, 0, nullptr, "%");
|
||||
}
|
||||
#endif
|
||||
|
||||
void drawSleepBitmap()
|
||||
{
|
||||
lcd->setOffset(0, 0);
|
||||
lcd->clearClippingRect();
|
||||
lcd->clear();
|
||||
|
||||
const BitmapBuffer * bitmap = BitmapBuffer::load(getThemePath("sleep.bmp"));
|
||||
if (bitmap) {
|
||||
lcd->drawBitmap((LCD_W-bitmap->getWidth())/2, (LCD_H-bitmap->getHeight())/2, bitmap);
|
||||
delete bitmap;
|
||||
}
|
||||
|
||||
lcdRefresh();
|
||||
}
|
||||
|
||||
@@ -395,13 +272,13 @@ void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char
|
||||
{
|
||||
if (totalDuration == 0)
|
||||
return;
|
||||
|
||||
|
||||
static uint32_t lastDuration = 0xffffffff;
|
||||
static const BitmapBuffer * shutdown = BitmapBuffer::load(getThemePath("shutdown.bmp"));
|
||||
|
||||
if (shutdown) {
|
||||
if (duration < lastDuration) {
|
||||
theme->drawBackground();
|
||||
theme->drawBackground(lcd);
|
||||
lcd->drawBitmap((LCD_W-shutdown->getWidth())/2, (LCD_H-shutdown->getHeight())/2, shutdown);
|
||||
lcdStoreBackupBuffer();
|
||||
}
|
||||
@@ -428,20 +305,300 @@ void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char
|
||||
lastDuration = duration;
|
||||
}
|
||||
|
||||
void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverIdx, LcdFlags flags)
|
||||
void drawCurveRef(BitmapBuffer * dc, coord_t x, coord_t y, const CurveRef & curve, LcdFlags flags)
|
||||
{
|
||||
if (isModulePXX2(moduleIdx)) {
|
||||
if (g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx][0] != '\0')
|
||||
lcdDrawSizedText(x, y, g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx], effectiveLen(g_model.moduleData[moduleIdx].pxx2.receiverName[receiverIdx], PXX2_LEN_RX_NAME), flags);
|
||||
else
|
||||
lcdDrawText(x, y, "---", flags);
|
||||
}
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
else if (moduleIdx == INTERNAL_MODULE) {
|
||||
lcdDrawText(x, y, "Internal", flags);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
lcdDrawText(x, y, "External", flags);
|
||||
if (curve.value != 0) {
|
||||
switch (curve.type) {
|
||||
case CURVE_REF_DIFF:
|
||||
dc->drawText(x, y, "D", flags);
|
||||
drawValueOrGVar(dc, lcdNextPos + 1, y + 2, curve.value, LEFT|SMLSIZE|flags);
|
||||
break;
|
||||
|
||||
case CURVE_REF_EXPO:
|
||||
dc->drawText(x, y, "E", flags);
|
||||
drawValueOrGVar(dc, lcdNextPos + 1, y + 2, curve.value, LEFT|SMLSIZE|flags);
|
||||
break;
|
||||
|
||||
case CURVE_REF_FUNC:
|
||||
drawTextAtIndex(dc, x, y, STR_VCURVEFUNC, curve.value, flags);
|
||||
break;
|
||||
|
||||
case CURVE_REF_CUSTOM:
|
||||
dc->drawText(x, y, getCurveString(curve.value), flags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att)
|
||||
{
|
||||
uint8_t length = STR_VSRCRAW[0];
|
||||
lcdDrawSizedText(x, y, STR_VSRCRAW+2+length*(idx+1), length-1, att);
|
||||
}
|
||||
|
||||
void putsModelName(coord_t x, coord_t y, char * name, uint8_t id, LcdFlags att)
|
||||
{
|
||||
uint8_t len = sizeof(g_model.header.name);
|
||||
while (len>0 && !name[len-1]) --len;
|
||||
if (len==0) {
|
||||
drawStringWithIndex(x, y, STR_MODEL, id+1, att|LEADING0);
|
||||
}
|
||||
else {
|
||||
lcdDrawSizedText(x, y, name, sizeof(g_model.header.name), ZCHAR|att);
|
||||
}
|
||||
}
|
||||
|
||||
void drawCurveName(coord_t x, coord_t y, int8_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[8];
|
||||
getCurveString(s, idx);
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void drawSource(BitmapBuffer * dc, coord_t x, coord_t y, mixsrc_t idx, LcdFlags flags)
|
||||
{
|
||||
char s[16];
|
||||
getSourceString(s, idx);
|
||||
dc->drawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void drawSwitch(BitmapBuffer * dc, coord_t x, coord_t y, int32_t idx, LcdFlags flags)
|
||||
{
|
||||
dc->drawText(x, y, getSwitchPositionName(idx), flags);
|
||||
}
|
||||
|
||||
void drawTrimMode(BitmapBuffer * dc, 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;
|
||||
unsigned int p = mode >> 1;
|
||||
|
||||
if (mode == TRIM_MODE_NONE) {
|
||||
dc->drawText(x, y, "--", att);
|
||||
}
|
||||
else {
|
||||
char s[2];
|
||||
s[0] = (mode % 2 == 0) ? ':' : '+';
|
||||
s[1] = '0'+p;
|
||||
dc->drawSizedText(x, y, s, 2, att);
|
||||
}
|
||||
}
|
||||
|
||||
void drawDate(BitmapBuffer * dc, coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags att)
|
||||
{
|
||||
// TODO
|
||||
if (att & DBLSIZE) {
|
||||
x -= 42;
|
||||
att &= ~FONTSIZE_MASK;
|
||||
lcdDrawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos-1, y, telemetryItem.datetime.month, att|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos-1, y, telemetryItem.datetime.year-2000, att|LEFT);
|
||||
y += FH;
|
||||
lcdDrawNumber(x, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(x, y, telemetryItem.datetime.day, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.month, att|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos-1, y, '-', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.year-2000, att|LEFT);
|
||||
lcdDrawNumber(lcdNextPos+11, y, telemetryItem.datetime.hour, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.min, att|LEADING0|LEFT, 2);
|
||||
lcdDrawChar(lcdNextPos, y, ':', att);
|
||||
lcdDrawNumber(lcdNextPos, y, telemetryItem.datetime.sec, att|LEADING0|LEFT, 2);
|
||||
}
|
||||
}
|
||||
|
||||
void drawGPSCoord(coord_t x, coord_t y, int32_t value, const char * direction, LcdFlags flags, bool seconds=true)
|
||||
{
|
||||
char s[32];
|
||||
uint32_t absvalue = abs(value);
|
||||
char * tmp = strAppendUnsigned(s, absvalue / 1000000);
|
||||
*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';
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void drawGPSPosition(coord_t x, coord_t y, int32_t longitude, int32_t latitude, LcdFlags flags)
|
||||
{
|
||||
if (flags & EXPANDED) {
|
||||
drawGPSCoord(x, y, latitude, "NS", flags, true);
|
||||
drawGPSCoord(x, y + FH, longitude, "EW", flags, true);
|
||||
}
|
||||
else {
|
||||
drawGPSCoord(x, y, latitude, "NS", flags, false);
|
||||
drawGPSCoord(lcdNextPos+5, y, longitude, "EW", flags, false);
|
||||
}
|
||||
}
|
||||
|
||||
void drawGPSSensorValue(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags)
|
||||
{
|
||||
drawGPSPosition(x, y, telemetryItem.gps.longitude, telemetryItem.gps.latitude, flags);
|
||||
}
|
||||
|
||||
|
||||
void drawSensorCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t sensor, int32_t value, LcdFlags flags)
|
||||
{
|
||||
if (sensor >= MAX_TELEMETRY_SENSORS) {
|
||||
// Lua luaLcdDrawChannel() can call us with a bad value
|
||||
return;
|
||||
}
|
||||
|
||||
TelemetryItem & telemetryItem = telemetryItems[sensor];
|
||||
TelemetrySensor & telemetrySensor = g_model.telemetrySensors[sensor];
|
||||
|
||||
if (telemetrySensor.unit == UNIT_DATETIME) {
|
||||
drawDate(dc, x, y, telemetryItem, flags);
|
||||
}
|
||||
else if (telemetrySensor.unit == UNIT_GPS) {
|
||||
drawGPSSensorValue(x, y, telemetryItem, flags);
|
||||
}
|
||||
else 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 (value == 0) {
|
||||
lcdDrawText(x, y, "OK", flags);
|
||||
}
|
||||
else {
|
||||
for (uint8_t i=0; i<16; i++) {
|
||||
if (value & (1 << i)) {
|
||||
char s[] = "CH__ KO";
|
||||
strAppendUnsigned(&s[2], i+1, 2);
|
||||
dc->drawText(x, flags & DBLSIZE ? y+1 : y, s, flags & ~DBLSIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (value == 0) {
|
||||
dc->drawText(x, flags & DBLSIZE ? y+1 : y, "Rx OK", flags & ~DBLSIZE);
|
||||
}
|
||||
else {
|
||||
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 (value & (1<<i)) {
|
||||
dc->drawText(x, flags & DBLSIZE ? y+1 : y, RXS_STATUS[i], flags & ~DBLSIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (telemetrySensor.unit == UNIT_TEXT) {
|
||||
dc->drawSizedText(x, flags & DBLSIZE ? y+1 : y, telemetryItem.text, sizeof(telemetryItem.text), flags & ~DBLSIZE);
|
||||
}
|
||||
else {
|
||||
if (telemetrySensor.prec > 0) {
|
||||
flags |= (telemetrySensor.prec==1 ? PREC1 : PREC2);
|
||||
}
|
||||
drawValueWithUnit(dc, x, y, value, telemetrySensor.unit == UNIT_CELLS ? UNIT_VOLTS : telemetrySensor.unit, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void drawSourceCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, source_t source, int32_t value, LcdFlags flags)
|
||||
{
|
||||
if (source >= MIXSRC_FIRST_TELEM) {
|
||||
source = (source-MIXSRC_FIRST_TELEM) / 3;
|
||||
drawSensorCustomValue(dc, y, source, value, flags);
|
||||
}
|
||||
else if (source >= MIXSRC_FIRST_TIMER || source == MIXSRC_TX_TIME) {
|
||||
if (value < 0) flags |= BLINK|INVERS;
|
||||
// TODO drawTimer(dc, x, y, value, flags);
|
||||
}
|
||||
else if (source == MIXSRC_TX_VOLTAGE) {
|
||||
lcdDrawNumber(x, y, value, flags|PREC1);
|
||||
}
|
||||
#if defined(INTERNAL_GPS)
|
||||
else if (source == MIXSRC_TX_GPS) {
|
||||
if (gpsData.fix) {
|
||||
drawGPSPosition(x, y, gpsData.longitude, gpsData.latitude, flags);
|
||||
}
|
||||
else {
|
||||
lcdDrawText(x, y, "sats: ", flags);
|
||||
lcdDrawNumber(lcdNextPos, y, gpsData.numSat, flags);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(GVARS)
|
||||
else if (source >= MIXSRC_FIRST_GVAR && source <= MIXSRC_LAST_GVAR) {
|
||||
drawGVarValue(x, y, source - MIXSRC_FIRST_GVAR, value, flags);
|
||||
}
|
||||
#endif
|
||||
else if (source < MIXSRC_FIRST_CH) {
|
||||
lcdDrawNumber(x, y, calcRESXto100(value), flags);
|
||||
}
|
||||
else if (source <= MIXSRC_LAST_CH) {
|
||||
#if defined(PPM_UNIT_PERCENT_PREC1)
|
||||
lcdDrawNumber(x, y, calcRESXto1000(value), flags|PREC1);
|
||||
#else
|
||||
lcdDrawNumber(x, y, calcRESXto100(value), flags);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(x, y, value, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void drawValueWithUnit(BitmapBuffer * dc, coord_t x, coord_t y, int val, uint8_t unit, LcdFlags flags)
|
||||
{
|
||||
// convertUnit(val, unit);
|
||||
drawNumber(dc, x, y, val, flags & (~NO_UNIT));
|
||||
if (!(flags & NO_UNIT) && unit != UNIT_RAW) {
|
||||
drawTextAtIndex(dc, lcdNextPos/*+1*/, y, STR_VTELEMUNIT, unit, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void drawHexNumber(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t val, LcdFlags flags)
|
||||
{
|
||||
for (int i=12; i>=0; i-=4) {
|
||||
char c = (val >> i) & 0xf;
|
||||
c = c>9 ? c+'A'-10 : c+'0';
|
||||
dc->drawSizedText(x, y, &c, 1, flags);
|
||||
x = lcdNextPos;
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,14 @@
|
||||
#define _DRAW_FUNCTIONS_H_
|
||||
|
||||
#include "opentx.h"
|
||||
#include "common/colorlcd/draw_functions.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define OPTION_MENU_NO_FOOTER 0x01
|
||||
#define OPTION_MENU_TITLE_BAR 0x02
|
||||
#define OPTION_MENU_NO_SCROLLBAR 0x04
|
||||
|
||||
#define OPTION_SLIDER_INVERS INVERS
|
||||
#define OPTION_SLIDER_BLINK BLINK
|
||||
#define OPTION_SLIDER_VERTICAL 0x04
|
||||
#define OPTION_SLIDER_EMPTY_BAR 0x08
|
||||
#define OPTION_SLIDER_DBL_COLOR 0x10
|
||||
@@ -39,43 +41,34 @@
|
||||
|
||||
void drawStatusText(const char * text);
|
||||
void drawColumnHeader(const char * const * headers, const char * const * descriptions, uint8_t index);
|
||||
void drawTopbarDatetime();
|
||||
|
||||
#define BUTTON_ON 0x10
|
||||
#define BUTTON_OFF 0x20
|
||||
void drawButton(coord_t x, coord_t y, const char * label, LcdFlags attr);
|
||||
void drawCheckBox(coord_t x, coord_t y, uint8_t value, LcdFlags attr);
|
||||
void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible);
|
||||
void drawHorizontalScrollbar(coord_t x, coord_t y, coord_t w, uint16_t offset, uint16_t count, uint8_t visible);
|
||||
void drawProgressScreen(const char * title, const char * message, int num, int den);
|
||||
void drawShadow(coord_t x, coord_t y, coord_t w, coord_t h);
|
||||
void drawTrimSquare(coord_t x, coord_t y);
|
||||
void drawHorizontalTrimPosition(coord_t x, coord_t y, int16_t dir);
|
||||
void drawVerticalTrimPosition(coord_t x, coord_t y, int16_t dir);
|
||||
void drawVerticalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
|
||||
void drawHorizontalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
|
||||
void drawSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options);
|
||||
#define drawStatusLine(...)
|
||||
|
||||
void drawGVarValue(coord_t x, coord_t y, uint8_t gvar, gvar_t value, LcdFlags flags);
|
||||
|
||||
#if defined(GVARS)
|
||||
int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int16_t max, LcdFlags attr, uint8_t editflags, event_t event);
|
||||
#else
|
||||
int16_t editGVarFieldValue(coord_t x, coord_t y, int16_t value, int16_t min, int16_t max, LcdFlags attr, event_t event);
|
||||
#endif
|
||||
void drawValueOrGVar(BitmapBuffer * dc, coord_t x, coord_t y, gvar_t gvar, LcdFlags flags = 0);
|
||||
void drawGVarValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t gvar, gvar_t value, LcdFlags flags = 0);
|
||||
void drawSourceCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, source_t source, int32_t value, LcdFlags flags);
|
||||
void drawSensorCustomValue(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t sensor, int32_t value, LcdFlags flags=0);
|
||||
void drawDate(BitmapBuffer * dc, coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags = 0);
|
||||
void drawValueWithUnit(BitmapBuffer * dc, coord_t x, coord_t y, int val, uint8_t unit, LcdFlags flags = 0);
|
||||
void drawHexNumber(BitmapBuffer * dc, coord_t x, coord_t y, uint32_t val, LcdFlags flags = 0);
|
||||
inline void drawChn(BitmapBuffer * dc, coord_t x, coord_t y, uint8_t idx, LcdFlags flags)
|
||||
{
|
||||
drawSource(dc, x, y, MIXSRC_CH1 + idx - 1, flags);
|
||||
}
|
||||
|
||||
// Screen templates
|
||||
void drawMenuTemplate(const char * title, uint8_t icon, const uint8_t * icons=nullptr, uint32_t options=0);
|
||||
void drawSplash();
|
||||
void drawSleepBitmap();
|
||||
void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char * message);
|
||||
void drawShutdownAnimation(uint32_t index, const char * message);
|
||||
|
||||
// Main view standard widgets
|
||||
void drawTopBar();
|
||||
void drawMainPots();
|
||||
void drawTrims(uint8_t flightMode);
|
||||
|
||||
void drawReceiverName(coord_t x, coord_t y, uint8_t moduleIdx, uint8_t receiverIdx, LcdFlags flags);
|
||||
|
||||
#endif // _DRAW_FUNCTIONS_H_
|
||||
@@ -21,66 +21,88 @@
|
||||
#include "opentx.h"
|
||||
#include "rle.h"
|
||||
|
||||
#if !defined(BOOT)
|
||||
const uint16_t font_tinsize_specs[] = {
|
||||
#include "font_tinsize.specs"
|
||||
#include "font_9.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_tinsize[] = {
|
||||
#include "font_tinsize.lbm"
|
||||
#include "font_9.lbm"
|
||||
};
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
const uint16_t font_smlsize_specs[] = {
|
||||
#include "font_smlsize.specs"
|
||||
#include "font_15.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_smlsize[] = {
|
||||
#include "font_smlsize.lbm"
|
||||
#include "font_15.lbm"
|
||||
};
|
||||
#endif
|
||||
|
||||
const uint16_t font_stdsize_specs[] = {
|
||||
#include "font_stdsize.specs"
|
||||
#include "font_17.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_stdsize[] = {
|
||||
#include "font_stdsize.lbm"
|
||||
};
|
||||
|
||||
#if !defined(BOOT)
|
||||
const uint16_t font_midsize_specs[] = {
|
||||
#include "font_midsize.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_midsize[] = {
|
||||
#include "font_midsize.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_dblsize_specs[] = {
|
||||
#include "font_dblsize.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_dblsize[] = {
|
||||
#include "font_dblsize.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_xxlsize_specs[] = {
|
||||
#include "font_xxlsize.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_xxlsize[] = {
|
||||
#include "font_xxlsize.lbm"
|
||||
#include "font_17.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_stdsizebold_specs[] = {
|
||||
#include "font_stdsizebold.specs"
|
||||
#include "font_bold17.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_stdsizebold[] = {
|
||||
#include "font_stdsizebold.lbm"
|
||||
#include "font_bold17.lbm"
|
||||
};
|
||||
#else
|
||||
const uint16_t font_smlsize_specs[] = {
|
||||
#include "font_13.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_smlsize[] = {
|
||||
#include "font_13.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_stdsize_specs[] = {
|
||||
#include "font_16.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_stdsize[] = {
|
||||
#include "font_16.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_stdsizebold_specs[] = {
|
||||
#include "font_bold16.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_stdsizebold[] = {
|
||||
#include "font_bold16.lbm"
|
||||
};
|
||||
#endif
|
||||
|
||||
const uint16_t font_midsize_specs[] = {
|
||||
#include "font_24.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_midsize[] = {
|
||||
#include "font_24.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_dblsize_specs[] = {
|
||||
#include "font_32.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_dblsize[] = {
|
||||
#include "font_32.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_xxlsize_specs[] = {
|
||||
#include "font_64.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_xxlsize[] = {
|
||||
#include "font_64.lbm"
|
||||
};
|
||||
|
||||
#if !defined(BOOT)
|
||||
const uint16_t * const fontspecsTable[16] = {
|
||||
font_stdsize_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsize_specs, font_stdsize_specs,
|
||||
@@ -91,37 +113,12 @@ const uint8_t * fontsTable[16] = {
|
||||
font_stdsize, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsize, font_stdsize,
|
||||
font_stdsizebold, font_tinsize, font_smlsize, font_midsize, font_dblsize, font_xxlsize, font_stdsize, font_stdsize
|
||||
};
|
||||
|
||||
#else
|
||||
const uint16_t * const fontspecsTable[1] = { font_stdsize_specs };
|
||||
const uint8_t * fontsTable[1] = { font_stdsize };
|
||||
#endif
|
||||
|
||||
BitmapBuffer * fontCache[2] = { NULL, NULL };
|
||||
|
||||
BitmapBuffer * createFontCache(const uint8_t * font, LcdFlags fg, LcdFlags bg)
|
||||
{
|
||||
coord_t width = *((uint16_t *)font);
|
||||
coord_t height = *(((uint16_t *)font)+1);
|
||||
|
||||
BitmapBuffer * buffer = new BitmapBuffer(BMP_RGB565, width, height);
|
||||
if (buffer) {
|
||||
buffer->clear(bg);
|
||||
buffer->drawBitmapPattern(0, 0, font, fg);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void loadFontCache()
|
||||
{
|
||||
delete fontCache[0];
|
||||
delete fontCache[1];
|
||||
fontCache[0] = createFontCache(fontsTable[0], TEXT_COLOR, TEXT_BGCOLOR);
|
||||
fontCache[1] = createFontCache(fontsTable[0], TEXT_INVERTED_COLOR, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t* decompressFont(const uint8_t* font)
|
||||
uint8_t * decompressFont(const uint8_t * font)
|
||||
{
|
||||
uint16_t width = *((uint16_t *)font);
|
||||
uint16_t height = *(((uint16_t *)font)+1);
|
||||
@@ -24,54 +24,11 @@
|
||||
#include "gui_common.h"
|
||||
#include "lcd.h"
|
||||
#include "menus.h"
|
||||
#include "popups.h"
|
||||
#include "draw_functions.h"
|
||||
#include "bitmaps.h"
|
||||
#include "theme.h"
|
||||
|
||||
#define HEADER_LINE 0
|
||||
|
||||
#define MENU_TOOLTIPS
|
||||
#define MENU_HEADER_HEIGHT 45
|
||||
#define MENU_TITLE_TOP 48
|
||||
#define MENU_TITLE_HEIGHT 21
|
||||
#define MENU_BODY_TOP (MENU_TITLE_TOP+MENU_TITLE_HEIGHT)
|
||||
#define MENU_CONTENT_TOP (MENU_BODY_TOP+1)
|
||||
#define MENU_FOOTER_HEIGHT 21
|
||||
#define MENU_FOOTER_TOP (LCD_H-MENU_FOOTER_HEIGHT)
|
||||
#define MENU_BODY_HEIGHT (MENU_FOOTER_TOP-MENU_BODY_TOP)
|
||||
#define MENUS_MARGIN_LEFT 6
|
||||
|
||||
#define DEFAULT_SCROLLBAR_X LCD_W-10
|
||||
#define DEFAULT_SCROLLBAR_Y MENU_CONTENT_TOP
|
||||
#define DEFAULT_SCROLLBAR_H (MENU_FOOTER_TOP - DEFAULT_SCROLLBAR_Y - 6)
|
||||
|
||||
#define FH 20
|
||||
#define NUM_BODY_LINES (MENU_BODY_HEIGHT / FH)
|
||||
|
||||
#define INVERT_HORZ_MARGIN 2
|
||||
#define INVERT_VERT_MARGIN 1
|
||||
#define INVERT_LINE_HEIGHT 20
|
||||
|
||||
#define CURVE_SIDE_WIDTH 100
|
||||
#define CURVE_CENTER_X (LCD_W-CURVE_SIDE_WIDTH-7)
|
||||
#define CURVE_CENTER_Y 151
|
||||
#define CURVE_COORD_WIDTH 36
|
||||
#define CURVE_COORD_HEIGHT 17
|
||||
|
||||
#define DATETIME_SEPARATOR_X (LCD_W-53)
|
||||
#define DATETIME_LINE1 9
|
||||
#define DATETIME_LINE2 23
|
||||
#define DATETIME_MIDDLE (LCD_W+DATETIME_SEPARATOR_X+4)/2
|
||||
|
||||
#define MENU_TITLE_NEXT_POS (lcdNextPos + 10)
|
||||
|
||||
#if defined(HELI) && defined(GVARS) && defined(LUA_MODEL_SCRIPTS)
|
||||
#define MENU_ICONS_SPACING 31
|
||||
#else
|
||||
#define MENU_ICONS_SPACING 33
|
||||
#endif
|
||||
|
||||
#define SUBMENU_LINE_WIDTH 230
|
||||
#include "libopenui_config.h"
|
||||
|
||||
#define LOAD_MODEL_BITMAP()
|
||||
|
||||
@@ -89,7 +46,6 @@ void drawCurveVerticalScale(int x);
|
||||
void drawCurveHorizontalScale();
|
||||
void drawCurveCoord(int x, int y, const char * text, bool active=false);
|
||||
void drawCurvePoint(int x, int y, LcdFlags color);
|
||||
void drawPower(coord_t x, coord_t y, int8_t dBm, LcdFlags att = 0);
|
||||
|
||||
extern Layout * customScreens[MAX_CUSTOM_SCREENS];
|
||||
extern Topbar * topbar;
|
||||
|
Before Width: | Height: | Size: 169 B After Width: | Height: | Size: 169 B |
|
Before Width: | Height: | Size: 233 B After Width: | Height: | Size: 233 B |
|
Before Width: | Height: | Size: 178 B After Width: | Height: | Size: 178 B |
|
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 212 B After Width: | Height: | Size: 212 B |
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include "opentx.h"
|
||||
#include "strhelpers.h"
|
||||
|
||||
#if defined(SIMU)
|
||||
display_t displayBuf[DISPLAY_BUFFER_SIZE];
|
||||
#endif
|
||||
|
||||
uint16_t lcdColorTable[LCD_COLOR_COUNT];
|
||||
|
||||
coord_t lcdNextPos;
|
||||
|
||||
uint8_t getMappedChar(uint8_t c)
|
||||
{
|
||||
uint8_t result;
|
||||
if (c == 0)
|
||||
result = 0;
|
||||
#if defined(TRANSLATIONS_FR)
|
||||
else if (c >= 0x80 && c <= 0x84) {
|
||||
result = 115 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_DE)
|
||||
else if (c >= 0x80 && c <= 0x86) {
|
||||
result = 120 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_CZ)
|
||||
else if (c >= 0x80 && c <= 0x80+29) {
|
||||
result = 127 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_ES)
|
||||
else if (c >= 0x80 && c <= 0x81) {
|
||||
result = 157 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_FI)
|
||||
else if (c >= 0x80 && c <= 0x85) {
|
||||
result = 159 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_IT)
|
||||
else if (c >= 0x80 && c <= 0x81) {
|
||||
result = 165 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_PL)
|
||||
else if (c >= 0x80 && c <= 0x80+17) {
|
||||
result = 167 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_PT)
|
||||
else if (c >= 0x80 && c <= 0x80+21) {
|
||||
result = 185 + c - 0x80;
|
||||
}
|
||||
#elif defined(TRANSLATIONS_SE)
|
||||
else if (c >= 0x80 && c <= 0x85) {
|
||||
result = 207 + c - 0x80;
|
||||
}
|
||||
#endif
|
||||
else if (c < 0xC0)
|
||||
result = c - 0x20;
|
||||
else
|
||||
result = c - 0xC0 + 96;
|
||||
// TRACE("getMappedChar '%c' (%d) = %d", c, c, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
int getFontPatternWidth(const uint16_t * spec, uint8_t index)
|
||||
{
|
||||
return spec[index + 2] - spec[index + 1];
|
||||
}
|
||||
|
||||
int getCharWidth(uint8_t c, const uint16_t * spec)
|
||||
{
|
||||
return getFontPatternWidth(spec, getMappedChar(c));
|
||||
}
|
||||
|
||||
void lcdPutFontPattern(coord_t x, coord_t y, const uint8_t * font, const uint16_t * spec, int index, LcdFlags flags)
|
||||
{
|
||||
coord_t offset = spec[index + 1];
|
||||
coord_t width = spec[index + 2] - offset;
|
||||
if (width > 0)
|
||||
lcdDrawBitmapPattern(x, y, font, flags, offset, width);
|
||||
lcdNextPos = x + width;
|
||||
}
|
||||
|
||||
void lcdDrawChar(coord_t x, coord_t y, char c, LcdFlags flags)
|
||||
{
|
||||
uint32_t fontindex = FONTINDEX(flags);
|
||||
const unsigned char * font = fontsTable[fontindex];
|
||||
const uint16_t * fontspecs = fontspecsTable[fontindex];
|
||||
lcdPutFontPattern(x, y, font, fontspecs, getMappedChar(c), flags);
|
||||
}
|
||||
|
||||
uint8_t getFontHeight(LcdFlags flags)
|
||||
{
|
||||
uint32_t fontindex = FONTINDEX(flags);
|
||||
return fontspecsTable[fontindex][0];
|
||||
}
|
||||
|
||||
int getTextWidth(const char * s, int len, LcdFlags flags)
|
||||
{
|
||||
const uint16_t * specs = fontspecsTable[FONTINDEX(flags)];
|
||||
|
||||
int result = 0;
|
||||
for (int i=0; len==0 || i<len; ++i) {
|
||||
|
||||
#if !defined(BOOT)
|
||||
char c = (flags & ZCHAR) ? zchar2char(*s) : *s;
|
||||
#else
|
||||
char c = *s;
|
||||
#endif
|
||||
if (c == '\0')
|
||||
break;
|
||||
result += getCharWidth(c, specs);
|
||||
++s;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void lcdDrawTextAtIndex(coord_t x, coord_t y, const char * s, uint8_t idx, LcdFlags flags)
|
||||
{
|
||||
uint8_t length;
|
||||
length = *(s++);
|
||||
lcdDrawSizedText(x, y, s+length*idx, length, flags & ~ZCHAR);
|
||||
}
|
||||
|
||||
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t len, const char * prefix, const char * 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;
|
||||
int mode = MODE(flags);
|
||||
bool neg = false;
|
||||
if (val < 0) {
|
||||
val = -val;
|
||||
neg = true;
|
||||
}
|
||||
do {
|
||||
*--s = '0' + (val % 10);
|
||||
++idx;
|
||||
val /= 10;
|
||||
if (mode!=0 && idx==mode) {
|
||||
mode = 0;
|
||||
*--s = '.';
|
||||
if (val==0)
|
||||
*--s = '0';
|
||||
}
|
||||
} while (val!=0 || mode>0 || (mode==MODE(LEADING0) && idx<len));
|
||||
if (neg) *--s = '-';
|
||||
|
||||
// TODO needs check on all string lengths ...
|
||||
if (prefix) {
|
||||
int len = strlen(prefix);
|
||||
if (len <= 16) {
|
||||
s -= len;
|
||||
strncpy(s, prefix, len);
|
||||
}
|
||||
}
|
||||
if (suffix) {
|
||||
strncpy(&str[32], suffix, 16);
|
||||
}
|
||||
flags &= ~LEADING0;
|
||||
lcdDrawText(x, y, s, flags);
|
||||
}
|
||||
|
||||
void lcdSetContrast()
|
||||
{
|
||||
lcdSetRefVolt(g_eeGeneral.contrast);
|
||||
}
|
||||
|
||||
#if defined(SIMU)
|
||||
BitmapBuffer _lcd(BMP_RGB565, LCD_W, LCD_H, displayBuf);
|
||||
BitmapBuffer * lcd = &_lcd;
|
||||
|
||||
void DMAFillRect(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color)
|
||||
{
|
||||
#if defined(PCBX10) && !defined(SIMU)
|
||||
x = destw - (x + w);
|
||||
y = desth - (y + h);
|
||||
#endif
|
||||
|
||||
for (int i=0; i<h; i++) {
|
||||
for (int j=0; j<w; j++) {
|
||||
dest[(y+i)*destw+x+j] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DMACopyBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
#if defined(PCBX10) && !defined(SIMU)
|
||||
x = destw - (x + w);
|
||||
y = desth - (y + h);
|
||||
srcx = srcw - (srcx + w);
|
||||
srcy = srch - (srcy + h);
|
||||
#endif
|
||||
|
||||
for (int i=0; i<h; i++) {
|
||||
memcpy(dest+(y+i)*destw+x, src+(srcy+i)*srcw+srcx, 2*w);
|
||||
}
|
||||
}
|
||||
|
||||
void DMACopyAlphaBitmap(uint16_t * dest, uint16_t destw, uint16_t desth, uint16_t x, uint16_t y, const uint16_t * src, uint16_t srcw, uint16_t srch, uint16_t srcx, uint16_t srcy, uint16_t w, uint16_t h)
|
||||
{
|
||||
#if defined(PCBX10) && !defined(SIMU)
|
||||
x = destw - (x + w);
|
||||
y = desth - (y + h);
|
||||
srcx = srcw - (srcx + w);
|
||||
srcy = srch - (srcy + h);
|
||||
#endif
|
||||
|
||||
for (coord_t line=0; line<h; line++) {
|
||||
uint16_t * p = dest + (y+line)*destw + x;
|
||||
const uint16_t * q = src + (srcy+line)*srcw + srcx;
|
||||
for (coord_t col=0; col<w; col++) {
|
||||
uint8_t alpha = *q >> 12;
|
||||
uint8_t red = ((((*q >> 8) & 0x0f) << 1) * alpha + (*p >> 11) * (0x0f-alpha)) / 0x0f;
|
||||
uint8_t green = ((((*q >> 4) & 0x0f) << 2) * alpha + ((*p >> 5) & 0x3f) * (0x0f-alpha)) / 0x0f;
|
||||
uint8_t blue = ((((*q >> 0) & 0x0f) << 1) * alpha + ((*p >> 0) & 0x1f) * (0x0f-alpha)) / 0x0f;
|
||||
*p = (red << 11) + (green << 5) + (blue << 0);
|
||||
p++; q++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DMABitmapConvert(uint16_t * dest, const uint8_t * src, uint16_t w, uint16_t h, uint32_t format)
|
||||
{
|
||||
if (format == DMA2D_ARGB4444) {
|
||||
for (int row = 0; row < h; ++row) {
|
||||
for (int col = 0; col < w; ++col) {
|
||||
*dest = ARGB(src[0], src[1], src[2], src[3]);
|
||||
++dest;
|
||||
src += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int row = 0; row < h; ++row) {
|
||||
for(int col = 0; col < w; ++col) {
|
||||
*dest = RGB(src[1], src[2], src[3]);
|
||||
++dest;
|
||||
src += 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -56,47 +56,10 @@
|
||||
/* telemetry flags */
|
||||
#define NO_UNIT 0x40
|
||||
|
||||
enum FontSizeIndex {
|
||||
STDSIZE_INDEX,
|
||||
TINSIZE_INDEX,
|
||||
SMLSIZE_INDEX,
|
||||
MIDSIZE_INDEX,
|
||||
DBLSIZE_INDEX,
|
||||
XXLSIZE_INDEX,
|
||||
SPARE6_INDEX,
|
||||
SPARE7_INDEX,
|
||||
STDSIZE_BOLD_INDEX,
|
||||
SPARE9_INDEX,
|
||||
SPAREa_INDEX,
|
||||
SPAREb_INDEX,
|
||||
SPAREc_INDEX,
|
||||
SPAREd_INDEX,
|
||||
SPAREe_INDEX,
|
||||
SPAREf_INDEX,
|
||||
};
|
||||
|
||||
#define STDSIZE (STDSIZE_INDEX << 8)
|
||||
#define TINSIZE (TINSIZE_INDEX << 8)
|
||||
#define SMLSIZE (SMLSIZE_INDEX << 8)
|
||||
#define MIDSIZE (MIDSIZE_INDEX << 8)
|
||||
#define DBLSIZE (DBLSIZE_INDEX << 8)
|
||||
#define XXLSIZE (XXLSIZE_INDEX << 8)
|
||||
#define BOLD (STDSIZE_BOLD_INDEX << 8)
|
||||
#define FONTSIZE_MASK 0x0f00
|
||||
|
||||
#if !defined(BOOT)
|
||||
#define FONTSIZE(flags) ((flags) & FONTSIZE_MASK)
|
||||
#define FONTINDEX(flags) (FONTSIZE(flags) >> 8)
|
||||
#else
|
||||
#define FONTSIZE(flags) STDSIZE
|
||||
#define FONTINDEX(flags) STDSIZE_INDEX
|
||||
#endif
|
||||
|
||||
#define TIMEBLINK 0x1000
|
||||
#define TIMEHOUR 0x2000
|
||||
#define EXPANDED 0x2000
|
||||
#define VERTICAL 0x4000
|
||||
#define NO_FONTCACHE 0x8000
|
||||
|
||||
#include "colors.h"
|
||||
|
||||
@@ -113,6 +76,8 @@ extern display_t displayBuf[DISPLAY_BUFFER_SIZE];
|
||||
#define ASSERT_IN_DISPLAY(p) assert((p) >= displayBuf && (p) < DISPLAY_END)
|
||||
|
||||
extern coord_t lcdNextPos;
|
||||
void lcdNextLayer();
|
||||
|
||||
|
||||
void lcdDrawChar(coord_t x, coord_t y, char c, LcdFlags flags=0);
|
||||
|
||||
@@ -138,25 +103,8 @@ inline void lcdDrawSizedText(coord_t x, coord_t y, const char * s, uint8_t len,
|
||||
lcd->drawSizedText(x, y, s, len, attr);
|
||||
}
|
||||
|
||||
void lcdDrawHexNumber(coord_t x, coord_t y, uint32_t val, LcdFlags mode=0);
|
||||
void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags=0, uint8_t len=0, const char * prefix=NULL, const char * suffix=NULL);
|
||||
|
||||
#if !defined(BOOT)
|
||||
void drawRtcTime(coord_t x, coord_t y, LcdFlags att=0);
|
||||
void drawTimer(coord_t x, coord_t y, int32_t tme, LcdFlags att=0);
|
||||
|
||||
void putsModelName(coord_t x, coord_t y, char *name, uint8_t id, LcdFlags att);
|
||||
void putsStickName(coord_t x, coord_t y, uint8_t idx, LcdFlags att=0);
|
||||
void drawSwitch(coord_t x, coord_t y, swsrc_t swtch, LcdFlags flags=0);
|
||||
void drawSource(coord_t x, coord_t y, mixsrc_t idx, LcdFlags att=0);
|
||||
void drawCurveName(coord_t x, coord_t y, int8_t idx, LcdFlags att=0);
|
||||
void drawTimerMode(coord_t x, coord_t y, swsrc_t mode, LcdFlags att=0);
|
||||
void drawTrimMode(coord_t x, coord_t y, uint8_t phase, uint8_t idx, LcdFlags att);
|
||||
|
||||
#define putsChn(x, y, idx, att) drawSource(x, y, MIXSRC_CH1+idx-1, att)
|
||||
void putsChnLetter(coord_t x, coord_t y, uint8_t idx, LcdFlags attr);
|
||||
#endif // !BOOT
|
||||
|
||||
#define SOLID 0xff
|
||||
#define DOTTED 0x55
|
||||
#define STASHED 0x33
|
||||
@@ -252,6 +200,7 @@ inline int getBitmapHeight(const uint8_t * bmp)
|
||||
}
|
||||
|
||||
uint8_t getMappedChar(uint8_t c);
|
||||
int getCharWidth(uint8_t c, const uint16_t * spec);
|
||||
uint8_t getFontHeight(LcdFlags flags);
|
||||
int getTextWidth(const char * s, int len=0, LcdFlags flags=0);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "menu_model.h"
|
||||
#include "model_setup.h"
|
||||
#include "model_heli.h"
|
||||
#include "model_flightmodes.h"
|
||||
#include "model_mixes.h"
|
||||
#include "model_inputs.h"
|
||||
#include "model_outputs.h"
|
||||
#include "model_curves.h"
|
||||
#include "model_logical_switches.h"
|
||||
#include "special_functions.h"
|
||||
#include "model_telemetry.h"
|
||||
|
||||
ModelMenu::ModelMenu():
|
||||
TabsGroup(ICON_MODEL)
|
||||
{
|
||||
addTab(new ModelSetupPage());
|
||||
#if defined(HELI)
|
||||
addTab(new ModelHeliPage());
|
||||
#endif
|
||||
addTab(new ModelFlightModesPage());
|
||||
addTab(new ModelInputsPage());
|
||||
addTab(new ModelMixesPage());
|
||||
addTab(new ModelOutputsPage());
|
||||
addTab(new ModelCurvesPage());
|
||||
addTab(new ModelLogicalSwitchesPage());
|
||||
addTab(new SpecialFunctionsPage(g_model.customFn));
|
||||
addTab(new ModelTelemetryPage());
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MENU_MODEL_H_
|
||||
#define _MENU_MODEL_H_
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelMenu: public TabsGroup {
|
||||
public:
|
||||
ModelMenu();
|
||||
};
|
||||
|
||||
#endif // _MENU_MODEL_H_
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "menu_radio.h"
|
||||
#include "radio_setup.h"
|
||||
#include "radio_sdmanager.h"
|
||||
#include "radio_tools.h"
|
||||
#include "special_functions.h"
|
||||
#include "radio_calibration.h"
|
||||
#include "radio_trainer.h"
|
||||
#include "radio_version.h"
|
||||
#include "radio_hardware.h"
|
||||
#include "myeeprom.h"
|
||||
|
||||
RadioMenu::RadioMenu():
|
||||
TabsGroup(ICON_RADIO)
|
||||
{
|
||||
addTab(new RadioSetupPage());
|
||||
addTab(new RadioSdManagerPage());
|
||||
addTab(new RadioToolsPage());
|
||||
addTab(new SpecialFunctionsPage(g_eeGeneral.customFn));
|
||||
addTab(new RadioTrainerPage());
|
||||
addTab(new RadioHardwarePage());
|
||||
addTab(new RadioVersionPage());
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MENU_RADIO_H_
|
||||
#define _MENU_RADIO_H_
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class RadioMenu: public TabsGroup {
|
||||
public:
|
||||
RadioMenu();
|
||||
};
|
||||
|
||||
#endif // _MENU_RADIO_H_
|
||||
@@ -0,0 +1,359 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MENUS_H_
|
||||
#define _MENUS_H_
|
||||
|
||||
#include "keys.h"
|
||||
|
||||
#define MIXES_2ND_COLUMN 140
|
||||
|
||||
extern int menuVerticalPosition;
|
||||
extern int menuHorizontalPosition;
|
||||
extern int menuVerticalOffset;
|
||||
extern uint8_t menuCalibrationState;
|
||||
|
||||
// Temporary no highlight
|
||||
extern uint8_t noHighlightCounter;
|
||||
#define NO_HIGHLIGHT() (noHighlightCounter > 0)
|
||||
#define START_NO_HIGHLIGHT() do { noHighlightCounter = 25; } while(0)
|
||||
|
||||
typedef bool (*MenuHandlerFunc)(event_t event);
|
||||
|
||||
extern MenuHandlerFunc menuHandlers[5];
|
||||
extern uint8_t menuVerticalPositions[4];
|
||||
extern uint8_t menuLevel;
|
||||
extern event_t menuEvent;
|
||||
|
||||
void chainMenu(MenuHandlerFunc newMenu);
|
||||
void pushMenu(MenuHandlerFunc newMenu);
|
||||
void popMenu();
|
||||
void abortPopMenu();
|
||||
|
||||
inline bool isModelMenuDisplayed()
|
||||
{
|
||||
return menuVerticalPositions[0] == 0;
|
||||
}
|
||||
|
||||
enum MenuIcons {
|
||||
ICON_OPENTX,
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
ICON_NEXT,
|
||||
ICON_BACK,
|
||||
#endif
|
||||
ICON_RADIO,
|
||||
ICON_RADIO_SETUP,
|
||||
ICON_RADIO_SD_MANAGER,
|
||||
ICON_RADIO_TOOLS,
|
||||
ICON_RADIO_SPECTRUM_ANALYSER,
|
||||
ICON_RADIO_GLOBAL_FUNCTIONS,
|
||||
ICON_RADIO_TRAINER,
|
||||
ICON_RADIO_HARDWARE,
|
||||
ICON_RADIO_CALIBRATION,
|
||||
ICON_RADIO_VERSION,
|
||||
ICON_MODEL,
|
||||
ICON_MODEL_SETUP,
|
||||
ICON_MODEL_HELI,
|
||||
ICON_MODEL_FLIGHT_MODES,
|
||||
ICON_MODEL_INPUTS,
|
||||
ICON_MODEL_MIXER,
|
||||
ICON_MODEL_OUTPUTS,
|
||||
ICON_MODEL_CURVES,
|
||||
ICON_MODEL_GVARS,
|
||||
ICON_MODEL_LOGICAL_SWITCHES,
|
||||
ICON_MODEL_SPECIAL_FUNCTIONS,
|
||||
ICON_MODEL_LUA_SCRIPTS,
|
||||
ICON_MODEL_TELEMETRY,
|
||||
ICON_THEME,
|
||||
ICON_THEME_SETUP,
|
||||
ICON_THEME_VIEW1,
|
||||
ICON_THEME_VIEW2,
|
||||
ICON_THEME_VIEW3,
|
||||
ICON_THEME_VIEW4,
|
||||
ICON_THEME_VIEW5,
|
||||
ICON_THEME_ADD_VIEW,
|
||||
ICON_STATS,
|
||||
ICON_STATS_THROTTLE_GRAPH,
|
||||
ICON_STATS_TIMERS,
|
||||
ICON_STATS_ANALOGS,
|
||||
ICON_STATS_DEBUG,
|
||||
ICON_MONITOR,
|
||||
ICON_MONITOR_CHANNELS1,
|
||||
ICON_MONITOR_CHANNELS2,
|
||||
ICON_MONITOR_CHANNELS3,
|
||||
ICON_MONITOR_CHANNELS4,
|
||||
ICON_MONITOR_LOGICAL_SWITCHES,
|
||||
MENUS_ICONS_COUNT
|
||||
};
|
||||
|
||||
enum EnumTabModel {
|
||||
MENU_MODEL_SETUP,
|
||||
CASE_HELI(MENU_MODEL_HELI)
|
||||
CASE_FLIGHT_MODES(MENU_MODEL_FLIGHT_MODES)
|
||||
MENU_MODEL_INPUTS,
|
||||
MENU_MODEL_MIXES,
|
||||
MENU_MODEL_OUTPUTS,
|
||||
MENU_MODEL_CURVES,
|
||||
CASE_GVARS(MENU_MODEL_GVARS)
|
||||
MENU_MODEL_LOGICAL_SWITCHES,
|
||||
MENU_MODEL_SPECIAL_FUNCTIONS,
|
||||
#if defined(LUA_MODEL_SCRIPTS)
|
||||
MENU_MODEL_CUSTOM_SCRIPTS,
|
||||
#endif
|
||||
MENU_MODEL_TELEMETRY,
|
||||
MENU_MODEL_PAGES_COUNT
|
||||
};
|
||||
|
||||
const uint8_t MODEL_ICONS[MENU_MODEL_PAGES_COUNT + 1] = {
|
||||
ICON_MODEL,
|
||||
ICON_MODEL_SETUP,
|
||||
CASE_HELI(ICON_MODEL_HELI)
|
||||
CASE_FLIGHT_MODES(ICON_MODEL_FLIGHT_MODES)
|
||||
ICON_MODEL_INPUTS,
|
||||
ICON_MODEL_MIXER,
|
||||
ICON_MODEL_OUTPUTS,
|
||||
ICON_MODEL_CURVES,
|
||||
CASE_GVARS(ICON_MODEL_GVARS)
|
||||
ICON_MODEL_LOGICAL_SWITCHES,
|
||||
ICON_MODEL_SPECIAL_FUNCTIONS,
|
||||
#if defined(LUA_MODEL_SCRIPTS)
|
||||
ICON_MODEL_LUA_SCRIPTS,
|
||||
#endif
|
||||
ICON_MODEL_TELEMETRY
|
||||
};
|
||||
|
||||
const uint8_t STATS_ICONS[] = {
|
||||
ICON_STATS,
|
||||
ICON_STATS_THROTTLE_GRAPH,
|
||||
ICON_STATS_DEBUG,
|
||||
ICON_STATS_ANALOGS,
|
||||
#if defined(DEBUG_TRACE_BUFFER)
|
||||
ICON_STATS_TIMERS
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8_t MONITOR_ICONS[] = {
|
||||
ICON_MONITOR,
|
||||
ICON_MONITOR_CHANNELS1,
|
||||
ICON_MONITOR_CHANNELS2,
|
||||
ICON_MONITOR_CHANNELS3,
|
||||
ICON_MONITOR_CHANNELS4,
|
||||
ICON_MONITOR_LOGICAL_SWITCHES
|
||||
};
|
||||
|
||||
bool menuModelSetup(event_t event);
|
||||
bool menuModelFailsafe(event_t event);
|
||||
bool menuModelHeli(event_t event);
|
||||
bool menuModelFlightModesAll(event_t event);
|
||||
bool menuModelExposAll(event_t event);
|
||||
bool menuModelMixAll(event_t event);
|
||||
bool menuModelLimits(event_t event);
|
||||
bool menuModelCurvesAll(event_t event);
|
||||
bool menuModelCurveOne(event_t event);
|
||||
bool menuModelGVars(event_t event);
|
||||
bool menuModelLogicalSwitches(event_t event);
|
||||
bool menuModelSpecialFunctions(event_t event);
|
||||
bool menuModelCustomScripts(event_t event);
|
||||
bool menuModelTelemetryFrsky(event_t event);
|
||||
bool menuModelSensor(event_t event);
|
||||
bool menuModelExpoOne(event_t event);
|
||||
|
||||
extern const MenuHandlerFunc menuTabModel[MENU_MODEL_PAGES_COUNT];
|
||||
|
||||
enum EnumTabRadio {
|
||||
MENU_RADIO_SETUP,
|
||||
MENU_RADIO_SD_MANAGER,
|
||||
MENU_RADIO_TOOLS,
|
||||
MENU_RADIO_SPECIAL_FUNCTIONS,
|
||||
MENU_RADIO_TRAINER,
|
||||
MENU_RADIO_HARDWARE,
|
||||
MENU_RADIO_VERSION,
|
||||
MENU_RADIO_PAGES_COUNT
|
||||
};
|
||||
|
||||
const uint8_t RADIO_ICONS[MENU_RADIO_PAGES_COUNT + 1] = {
|
||||
ICON_RADIO,
|
||||
ICON_RADIO_SETUP,
|
||||
ICON_RADIO_SD_MANAGER,
|
||||
ICON_RADIO_TOOLS,
|
||||
ICON_RADIO_GLOBAL_FUNCTIONS,
|
||||
ICON_RADIO_TRAINER,
|
||||
ICON_RADIO_HARDWARE,
|
||||
ICON_RADIO_VERSION
|
||||
};
|
||||
|
||||
bool menuRadioSetup(event_t event);
|
||||
bool menuRadioSdManager(event_t event);
|
||||
bool menuRadioTools(event_t event);
|
||||
bool menuRadioSpecialFunctions(event_t event);
|
||||
bool menuRadioTrainer(event_t event);
|
||||
bool menuRadioVersion(event_t event);
|
||||
bool menuRadioHardware(event_t event);
|
||||
bool menuRadioCalibration(event_t event);
|
||||
|
||||
extern const MenuHandlerFunc menuTabGeneral[MENU_RADIO_PAGES_COUNT];
|
||||
|
||||
enum MenuRadioIndexes
|
||||
{
|
||||
e_StatsGraph,
|
||||
e_StatsDebug,
|
||||
e_StatsAnalogs,
|
||||
#if defined(DEBUG_TRACE_BUFFER)
|
||||
e_StatsTraces,
|
||||
#endif
|
||||
};
|
||||
|
||||
bool menuStatsGraph(event_t event);
|
||||
bool menuStatsDebug(event_t event);
|
||||
bool menuStatsAnalogs(event_t event);
|
||||
bool menuStatsTraces(event_t event);
|
||||
|
||||
enum EnumTabMonitors
|
||||
{
|
||||
e_MonChannelsFirst,
|
||||
e_MonChannels1 = e_MonChannelsFirst,
|
||||
e_MonChannels2,
|
||||
e_MonChannels3,
|
||||
e_MonChannels4,
|
||||
e_MonLogicalSwitches,
|
||||
e_MonTabChannelsPagesCount
|
||||
};
|
||||
|
||||
extern const MenuHandlerFunc menuTabMonitors[e_MonTabChannelsPagesCount];
|
||||
extern uint8_t lastMonitorPage;
|
||||
extern void drawSingleMixerBar(coord_t, coord_t, coord_t, coord_t, uint8_t);
|
||||
extern void drawSingleOutputBar(coord_t, coord_t, coord_t, coord_t, uint8_t);
|
||||
|
||||
extern const MenuHandlerFunc menuTabScreensSetup[1+MAX_CUSTOM_SCREENS] ;
|
||||
|
||||
bool menuFirstCalib(event_t event);
|
||||
bool menuMainView(event_t event);
|
||||
bool menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomFunctionsContext & functionsContext);
|
||||
bool menuModelSelect(event_t event);
|
||||
bool menuAboutView(event_t event);
|
||||
bool menuMainViewChannelsMonitor(event_t event);
|
||||
bool menuTextView(event_t event);
|
||||
bool menuScreensTheme(event_t event);
|
||||
bool menuRadioSpectrumAnalyser(event_t event);
|
||||
bool menuRadioPowerMeter(event_t event);
|
||||
|
||||
extern int8_t checkIncDec_Ret; // global helper vars
|
||||
|
||||
#define EDIT_SELECT_FIELD 0
|
||||
#define EDIT_MODIFY_FIELD 1
|
||||
#define EDIT_MODIFY_STRING 2
|
||||
extern int8_t s_editMode; // global editmode
|
||||
|
||||
// checkIncDec flags
|
||||
#define EE_GENERAL 0x01
|
||||
#define EE_MODEL 0x02
|
||||
#define NO_INCDEC_MARKS 0x04
|
||||
#define INCDEC_SWITCH 0x08
|
||||
#define INCDEC_SOURCE 0x10
|
||||
#define INCDEC_REP10 0x40
|
||||
#define NO_DBLKEYS 0x80
|
||||
|
||||
// mawrow special values
|
||||
//#define READONLY_ROW ((uint8_t)-1)
|
||||
//#define TITLE_ROW READONLY_ROW
|
||||
//#define ORPHAN_ROW ((uint8_t)-2)
|
||||
//#define HIDDEN_ROW ((uint8_t)-3)
|
||||
//#define NAVIGATION_LINE_BY_LINE 0x40
|
||||
//#define CURSOR_ON_LINE() (menuHorizontalPosition<0)
|
||||
|
||||
extern uint8_t s_curveChan;
|
||||
|
||||
extern const char * warningText;
|
||||
extern const char * warningInfoText;
|
||||
extern uint8_t warningInfoLength;
|
||||
extern uint8_t warningResult;
|
||||
extern uint8_t warningType;
|
||||
|
||||
#define COPY_MODE 1
|
||||
#define MOVE_MODE 2
|
||||
extern uint8_t s_copyMode;
|
||||
extern int8_t s_copySrcRow;
|
||||
extern int8_t s_copyTgtOfs;
|
||||
extern uint8_t s_currIdx;
|
||||
extern int8_t s_currCh;
|
||||
extern uint8_t s_copySrcIdx;
|
||||
extern uint8_t s_copySrcCh;
|
||||
|
||||
uint8_t getExposCount();
|
||||
void deleteExpo(uint8_t idx);
|
||||
void insertExpo(uint8_t idx, uint8_t input);
|
||||
|
||||
uint8_t getMixesCount();
|
||||
void deleteMix(uint8_t idx);
|
||||
void insertMix(uint8_t idx);
|
||||
void copyMix(uint8_t source, uint8_t dest, int8_t ch);
|
||||
|
||||
#define MENU_X 80
|
||||
#define MENU_W LCD_W-(2*MENU_X)
|
||||
#define POPUP_X 120
|
||||
#define POPUP_Y 70
|
||||
#define WARNING_LINE_LEN 32
|
||||
#define WARNING_LINE_X (POPUP_X+66)
|
||||
#define WARNING_LINE_Y (POPUP_Y+9)
|
||||
|
||||
void copySelection(char * dst, const char * src, uint8_t size);
|
||||
|
||||
void showMessageBox(const char * title);
|
||||
void runPopupWarning(event_t event);
|
||||
|
||||
extern void (* popupFunc)(event_t event);
|
||||
extern uint8_t warningInfoFlags;
|
||||
|
||||
#define DISPLAY_WARNING(evt) (*popupFunc)(evt)
|
||||
#define POPUP_WARNING(s) (warningType = WARNING_TYPE_ASTERISK, warningText = s, warningInfoText = 0, popupFunc = runPopupWarning)
|
||||
#define POPUP_INPUT(s, func) (warningText = s, popupFunc = func)
|
||||
#define SET_WARNING_INFO(info, len, flags) (warningInfoText = info, warningInfoLength = len, warningInfoFlags = flags)
|
||||
|
||||
#define POPUP_MENU_START(func) do { popupMenuHandler = (func); AUDIO_KEY_PRESS(); } while(0)
|
||||
#define POPUP_MENU_MAX_LINES 12
|
||||
#define MENU_MAX_DISPLAY_LINES 9
|
||||
#define MENU_LINE_LENGTH (LEN_MODEL_NAME+12)
|
||||
|
||||
extern const char * popupMenuItems[POPUP_MENU_MAX_LINES];
|
||||
extern uint16_t popupMenuItemsCount;
|
||||
extern uint16_t popupMenuOffset;
|
||||
enum {
|
||||
MENU_OFFSET_INTERNAL,
|
||||
MENU_OFFSET_EXTERNAL
|
||||
};
|
||||
extern uint8_t popupMenuOffsetType;
|
||||
extern uint8_t popupMenuSelectedItem;
|
||||
const char * runPopupMenu(event_t event);
|
||||
extern void (*popupMenuHandler)(const char * result);
|
||||
|
||||
#define TEXT_FILENAME_MAXLEN 40
|
||||
extern char s_text_file[TEXT_FILENAME_MAXLEN];
|
||||
void pushMenuTextView(const char * filename);
|
||||
void pushModelNotes();
|
||||
void readModelNotes();
|
||||
|
||||
typedef int (*FnFuncP) (int x);
|
||||
void drawFunction(FnFuncP fn, int x, int y, int width);
|
||||
|
||||
void onSourceLongEnterPress(const char *result);
|
||||
|
||||
uint8_t switchToMix(uint8_t source);
|
||||
|
||||
#endif // _MENUS_H_
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_curves.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
bool isCurveFilled(uint8_t index)
|
||||
{
|
||||
CurveInfo &curve = g_model.curves[index];
|
||||
int8_t * points = curveAddress(index);
|
||||
for (int i = 0; i < 5 + curve.points; i++) {
|
||||
if (points[i] != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class CurveEditWindow : public Page {
|
||||
public:
|
||||
explicit CurveEditWindow(uint8_t index):
|
||||
Page(ICON_MODEL_CURVES),
|
||||
index(index)
|
||||
{
|
||||
buildBody(&body);
|
||||
buildHeader(&header);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t index;
|
||||
CurveEdit * curveEdit = nullptr;
|
||||
|
||||
void buildHeader(Window * window)
|
||||
{
|
||||
new StaticText(window, {70, 4, LCD_W - 100, 20}, STR_MENUCURVE, MENU_TITLE_COLOR);
|
||||
char s[16];
|
||||
strAppendStringWithIndex(s, STR_CV, index + 1);
|
||||
new StaticText(window, {70, 28, LCD_W - 100, 20}, s, MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void buildBody(Window * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.setMarginLeft(20);
|
||||
grid.setMarginRight(20);
|
||||
grid.setLabelWidth(100);
|
||||
grid.spacer(20);
|
||||
|
||||
CurveInfo & curve = g_model.curves[index];
|
||||
int8_t * points = curveAddress(index);
|
||||
|
||||
// Curve editor
|
||||
curveEdit = new CurveEdit(window, { 20, grid.getWindowHeight(), LCD_W - 40, LCD_W - 40}, index);
|
||||
grid.spacer(curveEdit->height() + 15);
|
||||
|
||||
// Name
|
||||
new StaticText(window, grid.getLabelSlot(), STR_NAME);
|
||||
new TextEdit(window, grid.getFieldSlot(), curve.name, sizeof(curve.name));
|
||||
grid.nextLine();
|
||||
|
||||
// Type
|
||||
new StaticText(window, grid.getLabelSlot(), STR_TYPE);
|
||||
new Choice(window, grid.getFieldSlot(2, 0), STR_CURVE_TYPES, 0, 1, GET_DEFAULT(g_model.curves[index].type),
|
||||
[=](int32_t newValue) {
|
||||
CurveInfo &curve = g_model.curves[index];
|
||||
if (newValue != curve.type) {
|
||||
for (int i = 1; i < 4 + curve.points; i++) {
|
||||
points[i] = calcRESXto100(applyCustomCurve(calc100toRESX(-100 + i * 200 / (4 + curve.points)), index));
|
||||
}
|
||||
if (moveCurve(index, newValue == CURVE_TYPE_CUSTOM ? 3 + curve.points : -3 - curve.points)) {
|
||||
if (newValue == CURVE_TYPE_CUSTOM) {
|
||||
resetCustomCurveX(points, 5 + curve.points);
|
||||
}
|
||||
curve.type = newValue;
|
||||
}
|
||||
SET_DIRTY();
|
||||
curveEdit->update();
|
||||
}
|
||||
});
|
||||
|
||||
// Points count
|
||||
auto edit = new NumberEdit(window, grid.getFieldSlot(2, 1), 2, 17, GET_DEFAULT(g_model.curves[index].points + 5),
|
||||
[=](int32_t newValue) {
|
||||
newValue -= 5;
|
||||
CurveInfo &curve = g_model.curves[index];
|
||||
int newPoints[MAX_POINTS_PER_CURVE];
|
||||
newPoints[0] = points[0];
|
||||
newPoints[4 + newValue] = points[4 + curve.points];
|
||||
for (int i = 1; i < 4 + newValue; i++)
|
||||
newPoints[i] = calcRESXto100(applyCustomCurve(-RESX + (i * 2 * RESX) / (4 + newValue), index));
|
||||
if (moveCurve(index, (newValue - curve.points) * (curve.type == CURVE_TYPE_CUSTOM ? 2 : 1))) {
|
||||
for (int i = 0; i < 5 + newValue; i++) {
|
||||
points[i] = newPoints[i];
|
||||
if (curve.type == CURVE_TYPE_CUSTOM && i != 0 && i != 4 + newValue)
|
||||
points[5 + newValue + i - 1] = -100 + (i * 200) / (4 + newValue);
|
||||
}
|
||||
curve.points = newValue;
|
||||
SET_DIRTY();
|
||||
curveEdit->update();
|
||||
}
|
||||
});
|
||||
edit->setSuffix(STR_PTS);
|
||||
grid.nextLine();
|
||||
|
||||
// Smooth
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SMOOTH);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_DEFAULT(g_model.curves[index].smooth),
|
||||
[=](int32_t newValue) {
|
||||
g_model.curves[index].smooth = newValue;
|
||||
SET_DIRTY();
|
||||
curveEdit->update();
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
class CurveButton : public Button {
|
||||
public:
|
||||
CurveButton(Window * parent, const rect_t &rect, uint8_t index) :
|
||||
Button(parent, rect),
|
||||
index(index)
|
||||
{
|
||||
if (isCurveFilled(index)) {
|
||||
setHeight(130);
|
||||
new Curve(this, {5, 5, 120, 120},
|
||||
[=](int x) -> int {
|
||||
return applyCustomCurve(x, index);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
// bounding rect
|
||||
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
|
||||
|
||||
// curve characteristics
|
||||
if (isCurveFilled(index)) {
|
||||
CurveInfo &curve = g_model.curves[index];
|
||||
drawNumber(dc, 130, 5, 5 + curve.points, LEFT, 0, nullptr, STR_PTS);
|
||||
drawTextAtIndex(dc, 130, 25, STR_CURVE_TYPES, curve.type);
|
||||
if (curve.smooth)
|
||||
dc->drawText(130, 45, "Smooth");
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t index;
|
||||
};
|
||||
|
||||
ModelCurvesPage::ModelCurvesPage() :
|
||||
PageTab(STR_MENUCURVES, ICON_MODEL_CURVES)
|
||||
{
|
||||
}
|
||||
|
||||
void ModelCurvesPage::rebuild(FormWindow * window, int8_t focusIndex)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window, focusIndex);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
void ModelCurvesPage::editCurve(FormWindow * window, uint8_t curve)
|
||||
{
|
||||
Window * editWindow = new CurveEditWindow(curve);
|
||||
editWindow->setCloseHandler([=]() {
|
||||
rebuild(window, curve);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelCurvesPage::build(FormWindow * window, int8_t focusIndex)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(66);
|
||||
|
||||
for (uint8_t index = 0; index < MAX_CURVES; index++) {
|
||||
CurveInfo &curve = g_model.curves[index];
|
||||
int8_t * points = curveAddress(index);
|
||||
|
||||
// Curve label
|
||||
new StaticText(window, grid.getLabelSlot(), getCurveString(1 + index), BUTTON_BACKGROUND | CENTERED);
|
||||
|
||||
// Curve drawing
|
||||
Button * button = new CurveButton(window, grid.getFieldSlot(), index);
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
editCurve(window, index);
|
||||
});
|
||||
menu->addLine(STR_CURVE_PRESET, [=]() {
|
||||
Menu * menu = new Menu();
|
||||
for (int angle = -45; angle <= 45; angle += 15) {
|
||||
char label[16];
|
||||
strAppend(strAppendSigned(label, angle), "@");
|
||||
menu->addLine(label, [=]() {
|
||||
int dx = 2000 / (5 + curve.points - 1);
|
||||
for (uint8_t i = 0; i < 5 + curve.points; i++) {
|
||||
int x = -1000 + i * dx;
|
||||
points[i] = div_and_round(angle * x, 450);
|
||||
}
|
||||
if (curve.type == CURVE_TYPE_CUSTOM) {
|
||||
resetCustomCurveX(points, 5 + curve.points);
|
||||
}
|
||||
storageDirty(EE_MODEL);
|
||||
rebuild(window, index);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (isCurveFilled(index)) {
|
||||
menu->addLine(STR_MIRROR, [=]() {
|
||||
for (int i = 0; i < 5 + curve.points; i++)
|
||||
points[i] = -points[i];
|
||||
storageDirty(EE_MODEL);
|
||||
button->invalidate();
|
||||
});
|
||||
menu->addLine(STR_CLEAR, [=]() {
|
||||
for (int i = 0; i < 5 + curve.points; i++)
|
||||
points[i] = 0;
|
||||
if (curve.type == CURVE_TYPE_CUSTOM)
|
||||
resetCustomCurveX(points, 5 + curve.points);
|
||||
storageDirty(EE_MODEL);
|
||||
rebuild(window, index);
|
||||
});
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
if (focusIndex == index) {
|
||||
button->setFocus();
|
||||
}
|
||||
|
||||
grid.spacer(button->height() + 5);
|
||||
}
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setLastField();
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _MODEL_CURVES_H_
|
||||
#define _MODEL_CURVES_H_
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelCurvesPage: public PageTab {
|
||||
public:
|
||||
ModelCurvesPage();
|
||||
|
||||
virtual void build(FormWindow * window) override
|
||||
{
|
||||
build(window, -1);
|
||||
}
|
||||
|
||||
protected:
|
||||
void build(FormWindow * window, int8_t focusIndex);
|
||||
void rebuild(FormWindow * window, int8_t focusIndex);
|
||||
void editCurve(FormWindow * window, uint8_t curve);
|
||||
};
|
||||
|
||||
#endif // _MODEL_CURVES_H_
|
||||
@@ -29,7 +29,7 @@ void onModelCustomScriptMenu(const char *result)
|
||||
POPUP_WARNING(STR_NO_SCRIPTS_ON_SD);
|
||||
}
|
||||
}
|
||||
else if (result != STR_EXIT) {
|
||||
else {
|
||||
// The user choosed a lua file in the list
|
||||
copySelection(sd.file, result, sizeof(sd.file));
|
||||
memset(sd.inputs, 0, sizeof(sd.inputs));
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_flightmodes.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
ModelFlightModesPage::ModelFlightModesPage():
|
||||
PageTab(STR_MENUFLIGHTMODES, ICON_MODEL_FLIGHT_MODES)
|
||||
{
|
||||
}
|
||||
|
||||
bool isTrimModeAvailable(int mode)
|
||||
{
|
||||
return (mode < 0 || (mode%2) == 0 || (mode/2) != 0); //ToDo menuVerticalPosition
|
||||
}
|
||||
|
||||
class FlightModeGroup: public FormGroup
|
||||
{
|
||||
public:
|
||||
FlightModeGroup(Window * parent, uint8_t index, const rect_t & rect) :
|
||||
FormGroup(parent, rect),
|
||||
index(index)
|
||||
{
|
||||
}
|
||||
|
||||
void checkEvents()
|
||||
{
|
||||
FormGroup::checkEvents();
|
||||
bool newActive = (getFlightMode() == index);
|
||||
if (newActive != active) {
|
||||
active = newActive;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
if (index == getFlightMode()) {
|
||||
dc->drawSolidFilledRect(0, 0, width(), height(), WARNING_COLOR);
|
||||
}
|
||||
FormGroup::paint(dc);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t index;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
void ModelFlightModesPage::build(FormWindow * window)
|
||||
{
|
||||
coord_t y = 2;
|
||||
|
||||
for (int i = 0; i < MAX_FLIGHT_MODES; i++) {
|
||||
auto group = new FlightModeGroup(window, i, { 2, y, LCD_W - 10, 0 });
|
||||
if (i == 0) {
|
||||
window->setFirstField(group);
|
||||
}
|
||||
|
||||
FormGridLayout grid;
|
||||
grid.setMarginRight(15);
|
||||
grid.spacer();
|
||||
grid.setLabelWidth(140);
|
||||
|
||||
char label[16];
|
||||
getFlightModeString(label, i+1);
|
||||
new Subtitle(group, grid.getLabelSlot(), label);
|
||||
grid.nextLine();
|
||||
|
||||
// Flight mode name
|
||||
new StaticText(group, grid.getLabelSlot(true), STR_NAME);
|
||||
auto nameEdit = new TextEdit(group, grid.getFieldSlot(), g_model.flightModeData[i].name, LEN_FLIGHT_MODE_NAME);
|
||||
group->setFirstField(nameEdit);
|
||||
grid.nextLine();
|
||||
|
||||
// Flight mode switch
|
||||
if (i > 0) {
|
||||
new StaticText(group, grid.getLabelSlot(true), STR_SWITCH);
|
||||
new SwitchChoice(group, grid.getFieldSlot(), SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, GET_SET_DEFAULT(g_model.flightModeData[i].swtch));
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Flight mode trims
|
||||
new StaticText(group, grid.getLabelSlot(true), STR_TRIMS);
|
||||
|
||||
const char * STR_VTRIMS_MODES = "\002"
|
||||
"--"
|
||||
"=0"
|
||||
"+0"
|
||||
"=1"
|
||||
"+1"
|
||||
"=2"
|
||||
"+2"
|
||||
"=3"
|
||||
"+3"
|
||||
"=4"
|
||||
"+4"
|
||||
"=5"
|
||||
"+5"
|
||||
"=6"
|
||||
"+6"
|
||||
"=7"
|
||||
"+7"
|
||||
"=8"
|
||||
"+8";
|
||||
for (int t=0; t<NUM_TRIMS; t++) {
|
||||
// TODO isTrimModeAvailable to avoid +{{CURRENT}}
|
||||
new Choice(group, grid.getFieldSlot(NUM_TRIMS, t), STR_VTRIMS_MODES, -1, 2*MAX_FLIGHT_MODES-1,
|
||||
GET_DEFAULT(g_model.flightModeData[i].trim[t].mode==TRIM_MODE_NONE ? -1 : g_model.flightModeData[i].trim[t].mode),
|
||||
SET_DEFAULT(g_model.flightModeData[i].trim[t].mode),
|
||||
STDSIZE);
|
||||
}
|
||||
grid.nextLine();
|
||||
|
||||
// Flight mode fade in / out
|
||||
new StaticText(group, grid.getLabelSlot(true), "Fade in/out");
|
||||
auto edit = new NumberEdit(group, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
|
||||
GET_DEFAULT(g_model.flightModeData[i].fadeIn * (10 / DELAY_STEP)),
|
||||
SET_VALUE(g_model.flightModeData[i].fadeIn, newValue / (10 / DELAY_STEP)),
|
||||
PREC1);
|
||||
edit->setStep(10 / DELAY_STEP);
|
||||
edit = new NumberEdit(group, grid.getFieldSlot(2, 1), 0, DELAY_MAX,
|
||||
GET_DEFAULT(g_model.flightModeData[i].fadeOut * (10 / DELAY_STEP)),
|
||||
SET_VALUE(g_model.flightModeData[i].fadeOut, newValue / (10 / DELAY_STEP)),
|
||||
PREC1);
|
||||
edit->setStep(10 / DELAY_STEP);
|
||||
grid.nextLine();
|
||||
|
||||
group->setLastField(FormField::getCurrentField());
|
||||
|
||||
grid.spacer();
|
||||
coord_t height = grid.getWindowHeight();
|
||||
group->setHeight(height);
|
||||
y += height + 2;
|
||||
}
|
||||
|
||||
char label[32];
|
||||
sprintf(label, "Check FM Trims");
|
||||
// TODO rather use a centered slot?
|
||||
// TODO dynamic text with FM index for the button text
|
||||
auto button = new TextButton(window, { 60, y + 5, LCD_W - 120, PAGE_LINE_HEIGHT }, label,
|
||||
[&]() -> uint8_t {
|
||||
if (trimsCheckTimer)
|
||||
trimsCheckTimer = 0;
|
||||
else
|
||||
trimsCheckTimer = 200; // 2 seconds trims cancelled
|
||||
return trimsCheckTimer;
|
||||
});
|
||||
|
||||
window->setInnerHeight(y + 40);
|
||||
window->setLastField(button);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelFlightModesPage: public PageTab {
|
||||
public:
|
||||
ModelFlightModesPage();
|
||||
|
||||
void build(FormWindow * window);
|
||||
};
|
||||
@@ -20,31 +20,32 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#if 0
|
||||
void editGVarValue(coord_t x, coord_t y, event_t event, uint8_t gvar, uint8_t flightMode, LcdFlags flags)
|
||||
{
|
||||
FlightModeData * fm = &g_model.flightModeData[flightMode];
|
||||
gvar_t * v = &fm->gvars[gvar];
|
||||
gvar_t & v = fm->gvars[gvar];
|
||||
int16_t vmin, vmax;
|
||||
if (*v > GVAR_MAX) {
|
||||
uint8_t fm = *v - GVAR_MAX - 1;
|
||||
if (v > GVAR_MAX) {
|
||||
uint8_t fm = v - GVAR_MAX - 1;
|
||||
if (fm >= flightMode) fm++;
|
||||
drawFlightMode(x, y, fm + 1, flags&(~LEFT));
|
||||
vmin = GVAR_MAX + 1;
|
||||
vmax = GVAR_MAX + MAX_FLIGHT_MODES - 1;
|
||||
}
|
||||
else {
|
||||
drawGVarValue(x, y, gvar, *v, flags);
|
||||
drawGVarValue(x, y, gvar, v, flags);
|
||||
vmin = GVAR_MIN + g_model.gvars[gvar].min;
|
||||
vmax = GVAR_MAX - g_model.gvars[gvar].max;
|
||||
}
|
||||
|
||||
if (flags & INVERS) {
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER) && flightMode > 0) {
|
||||
*v = (*v > GVAR_MAX ? 0 : GVAR_MAX+1);
|
||||
v = (v > GVAR_MAX ? 0 : GVAR_MAX+1);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (s_editMode > 0) {
|
||||
*v = checkIncDec(event, *v, vmin, vmax, EE_MODEL);
|
||||
v = checkIncDec(event, v, vmin, vmax, EE_MODEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +102,7 @@ bool menuModelGVarOne(event_t event)
|
||||
break;
|
||||
|
||||
default:
|
||||
drawStringWithIndex(MENUS_MARGIN_LEFT, y, STR_FM, k-GVAR_FIELD_FM0);
|
||||
drawStringWithIndex(MENUS_MARGIN_LEFT, y, STR_FP, k-GVAR_FIELD_FM0);
|
||||
editGVarValue(MIXES_2ND_COLUMN, y, event, s_currIdx, k-GVAR_FIELD_FM0, LEFT|attr);
|
||||
break;
|
||||
}
|
||||
@@ -182,3 +183,4 @@ bool menuModelGVars(event_t event)
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_heli.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
ModelHeliPage::ModelHeliPage():
|
||||
PageTab(STR_MENUHELISETUP, ICON_MODEL_HELI)
|
||||
{
|
||||
}
|
||||
|
||||
void ModelHeliPage::build(FormWindow * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
|
||||
// Swash type
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SWASHTYPE);
|
||||
auto first = new Choice(window, grid.getFieldSlot(), STR_VSWASHTYPE, 0, SWASH_TYPE_MAX, GET_SET_DEFAULT(g_model.swashR.type));
|
||||
grid.nextLine();
|
||||
|
||||
// Swash ring
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SWASHRING);
|
||||
new NumberEdit(window, grid.getFieldSlot(), 0, 100, GET_SET_DEFAULT(g_model.swashR.value));
|
||||
grid.nextLine();
|
||||
|
||||
// Elevator source
|
||||
new StaticText(window, grid.getLabelSlot(), STR_ELEVATOR);
|
||||
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.elevatorSource));
|
||||
grid.nextLine();
|
||||
|
||||
// Elevator weight
|
||||
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT);
|
||||
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.elevatorWeight));
|
||||
grid.nextLine();
|
||||
|
||||
// Aileron source
|
||||
new StaticText(window, grid.getLabelSlot(), STR_AILERON);
|
||||
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.aileronWeight));
|
||||
grid.nextLine();
|
||||
|
||||
// Aileron weight
|
||||
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT);
|
||||
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.aileronWeight));
|
||||
grid.nextLine();
|
||||
|
||||
// Collective source
|
||||
new StaticText(window, grid.getLabelSlot(), STR_COLLECTIVE);
|
||||
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(g_model.swashR.collectiveSource));
|
||||
grid.nextLine();
|
||||
|
||||
// Collective weight
|
||||
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT);
|
||||
auto last = new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(g_model.swashR.collectiveWeight));
|
||||
FormField::link(last, first);
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelHeliPage: public PageTab {
|
||||
public:
|
||||
ModelHeliPage();
|
||||
|
||||
void build(FormWindow * window);
|
||||
};
|
||||
@@ -0,0 +1,518 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_inputs.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
#define PASTE_BEFORE -2
|
||||
#define PASTE_AFTER -1
|
||||
|
||||
uint8_t getExposCount()
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint8_t ch ;
|
||||
|
||||
for (int i=MAX_EXPOS-1 ; i>=0; i--) {
|
||||
ch = EXPO_VALID(expoAddress(i));
|
||||
if (ch != 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
bool reachExposLimit()
|
||||
{
|
||||
if (getExposCount() >= MAX_EXPOS) {
|
||||
POPUP_WARNING(STR_NOFREEEXPO);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void copyExpo(uint8_t source, uint8_t dest, int8_t input)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
ExpoData sourceExpo;
|
||||
memcpy(&sourceExpo, expoAddress(source), sizeof(ExpoData));
|
||||
ExpoData * expo = expoAddress(dest);
|
||||
|
||||
if(input == PASTE_AFTER) {
|
||||
memmove(expo+2, expo+1, (MAX_EXPOS-(source+1))*sizeof(ExpoData));
|
||||
memcpy(expo+1, &sourceExpo, sizeof(ExpoData));
|
||||
(expo+1)->chn = (expo)->chn;
|
||||
}
|
||||
else if(input == PASTE_BEFORE) {
|
||||
memmove(expo+1, expo, (MAX_EXPOS-(source+1))*sizeof(ExpoData));
|
||||
memcpy(expo, &sourceExpo, sizeof(ExpoData));
|
||||
expo->chn = (expo+1)->chn;
|
||||
}
|
||||
else {
|
||||
memmove(expo+1, expo, (MAX_EXPOS-(source+1))*sizeof(ExpoData));
|
||||
memcpy(expo, &sourceExpo, sizeof(ExpoData));
|
||||
expo->chn = input;
|
||||
}
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
void deleteExpo(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
ExpoData * expo = expoAddress(idx);
|
||||
int input = expo->chn;
|
||||
memmove(expo, expo+1, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
||||
memclear(&g_model.expoData[MAX_EXPOS-1], sizeof(ExpoData));
|
||||
if (!isInputAvailable(input)) {
|
||||
memclear(&g_model.inputNames[input], LEN_INPUT_NAME);
|
||||
}
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
class InputEditWindow: public Page {
|
||||
public:
|
||||
InputEditWindow(int8_t input, uint8_t index):
|
||||
Page(ICON_MODEL_INPUTS),
|
||||
input(input),
|
||||
index(index),
|
||||
preview(this, {LCD_W - 158, 0, 158, 158},
|
||||
[=](int x) -> int {
|
||||
ExpoData * line = expoAddress(index);
|
||||
int16_t anas[MAX_INPUTS] = {0};
|
||||
applyExpos(anas, e_perout_mode_inactive_flight_mode, line->srcRaw, x);
|
||||
return anas[line->chn];
|
||||
},
|
||||
[=]() -> int {
|
||||
return getValue(expoAddress(index)->srcRaw);
|
||||
})
|
||||
{
|
||||
buildBody(&body);
|
||||
buildHeader(&header);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t input;
|
||||
uint8_t index;
|
||||
Curve preview;
|
||||
Choice * trimChoice = nullptr;
|
||||
Window * updateCurvesWindow = nullptr;
|
||||
Choice * curveTypeChoice = nullptr;
|
||||
|
||||
void buildHeader(Window * window) {
|
||||
new StaticText(window, { 50, 0, 100, 20 }, STR_MENUINPUTS, MENU_TITLE_COLOR);
|
||||
new StaticText(window, { 50, FH+2, 100, 20 }, getSourceString(MIXSRC_FIRST_INPUT + input), MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void updateCurves() {
|
||||
FormGridLayout grid;
|
||||
grid.setLabelWidth(120);
|
||||
|
||||
updateCurvesWindow->clear();
|
||||
|
||||
ExpoData * line = expoAddress(index) ;
|
||||
|
||||
new StaticText(updateCurvesWindow, grid.getLabelSlot(), STR_CURVE);
|
||||
curveTypeChoice = new Choice(updateCurvesWindow, grid.getFieldSlot(2, 0), "\004DiffExpoFuncCstm", 0, CURVE_REF_CUSTOM,
|
||||
GET_DEFAULT(line->curve.type),
|
||||
[=](int32_t newValue) {
|
||||
line->curve.type = newValue;
|
||||
line->curve.value = 0;
|
||||
SET_DIRTY();
|
||||
updateCurves();
|
||||
curveTypeChoice->setFocus();
|
||||
});
|
||||
|
||||
switch (line->curve.type) {
|
||||
case CURVE_REF_DIFF:
|
||||
case CURVE_REF_EXPO: {
|
||||
// TODO GVAR
|
||||
NumberEdit * edit = new NumberEdit(updateCurvesWindow, grid.getFieldSlot(2, 1), -100, 100,
|
||||
GET_SET_DEFAULT(line->curve.value));
|
||||
edit->setSuffix("%");
|
||||
break;
|
||||
}
|
||||
case CURVE_REF_FUNC:
|
||||
new Choice(updateCurvesWindow, grid.getFieldSlot(2, 1), STR_VCURVEFUNC, 0, CURVE_BASE-1, GET_SET_DEFAULT(line->curve.value));
|
||||
break;
|
||||
case CURVE_REF_CUSTOM:
|
||||
#warning "TODO Custom Curve Choice"
|
||||
// new CustomCurveChoice(updateCurvesWindow, grid.getFieldSlot(2, 1), -MAX_CURVES, MAX_CURVES, GET_SET_DEFAULT(line->curve.value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void buildBody(FormWindow * window)
|
||||
{
|
||||
NumberEdit * edit;
|
||||
|
||||
FormGridLayout grid;
|
||||
grid.setLabelWidth(120);
|
||||
grid.spacer(PAGE_PADDING);
|
||||
|
||||
ExpoData * line = expoAddress(index) ;
|
||||
|
||||
grid.setMarginRight(163);
|
||||
|
||||
// Input Name
|
||||
new StaticText(window, grid.getLabelSlot(), STR_INPUTNAME);
|
||||
auto name = new TextEdit(window, grid.getFieldSlot(), g_model.inputNames[line->chn], sizeof(g_model.inputNames[line->chn]));
|
||||
window->setFirstField(name);
|
||||
grid.nextLine();
|
||||
|
||||
// Switch
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SWITCH);
|
||||
new SwitchChoice(window, grid.getFieldSlot(), SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, GET_SET_DEFAULT(line->swtch));
|
||||
grid.nextLine();
|
||||
|
||||
// Side
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SIDE);
|
||||
new Choice(window, grid.getFieldSlot(), STR_VCURVEFUNC, 1, 3,
|
||||
[=]() -> int16_t {
|
||||
return 4 - line->mode;
|
||||
},
|
||||
[=](int16_t newValue) {
|
||||
line->mode = 4 - newValue;
|
||||
SET_DIRTY();
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// Name
|
||||
new StaticText(window, grid.getLabelSlot(), STR_EXPONAME);
|
||||
new TextEdit(window, grid.getFieldSlot(), line->name, sizeof(line->name));
|
||||
grid.nextLine();
|
||||
|
||||
// Source
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SOURCE);
|
||||
new SourceChoice(window, grid.getFieldSlot(), INPUTSRC_FIRST, INPUTSRC_LAST,
|
||||
GET_DEFAULT(line->srcRaw),
|
||||
[=] (int32_t newValue) {
|
||||
line->srcRaw = newValue;
|
||||
if (line->srcRaw > MIXSRC_Ail && line->carryTrim == TRIM_ON) {
|
||||
line->carryTrim = TRIM_OFF;
|
||||
trimChoice->invalidate();
|
||||
}
|
||||
SET_DIRTY();
|
||||
}
|
||||
);
|
||||
/* TODO telemetry current value
|
||||
if (ed->srcRaw >= MIXSRC_FIRST_TELEM) {
|
||||
drawSensorCustomValue(EXPO_ONE_2ND_COLUMN+75, y, (ed->srcRaw - MIXSRC_FIRST_TELEM)/3, convertTelemValue(ed->srcRaw - MIXSRC_FIRST_TELEM + 1, ed->scale), LEFT|(menuHorizontalPosition==1?attr:0));
|
||||
} */
|
||||
grid.nextLine();
|
||||
|
||||
// Scale
|
||||
// TODO only displayed when source is telemetry + unfinished
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SCALE);
|
||||
new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(line->scale));
|
||||
grid.nextLine();
|
||||
|
||||
// Weight
|
||||
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT);
|
||||
// TODO GVAR ?
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(line->weight));
|
||||
edit->setSuffix("%");
|
||||
grid.nextLine();
|
||||
|
||||
// Offset
|
||||
new StaticText(window, grid.getLabelSlot(), STR_OFFSET);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(line->offset));
|
||||
edit->setSuffix("%");
|
||||
grid.nextLine();
|
||||
|
||||
// Trim
|
||||
new StaticText(window, grid.getLabelSlot(), STR_TRIM);
|
||||
trimChoice = new Choice(window, grid.getFieldSlot(), STR_VMIXTRIMS, -TRIM_OFF, -TRIM_LAST,
|
||||
GET_VALUE(-line->carryTrim),
|
||||
SET_VALUE(line->carryTrim, -newValue));
|
||||
trimChoice->setAvailableHandler([=](int value) {
|
||||
return value != TRIM_ON || line->srcRaw <= MIXSRC_Ail;
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// grid.setMarginRight(10);
|
||||
|
||||
// Curve
|
||||
updateCurvesWindow = new Window(window, { 0, grid.getWindowHeight(), LCD_W - 162, 0 });
|
||||
updateCurves();
|
||||
grid.addWindow(updateCurvesWindow);
|
||||
|
||||
// Flight modes
|
||||
new StaticText(window, grid.getLabelSlot(), STR_FLMODE);
|
||||
TextButton * flightmode = nullptr;
|
||||
for (uint8_t i=0; i<MAX_FLIGHT_MODES; i++) {
|
||||
char fm[2] = { char('0' + i), '\0'};
|
||||
if (i > 0 && (i % 4) == 0)
|
||||
grid.nextLine();
|
||||
flightmode = new TextButton(window, grid.getFieldSlot(4, i % 4), fm,
|
||||
[=]() -> uint8_t {
|
||||
BFBIT_FLIP(line->flightModes, bfBit<uint32_t>(i));
|
||||
SET_DIRTY();
|
||||
return !(bfSingleBitGet(line->flightModes, i));
|
||||
},
|
||||
bfSingleBitGet(line->flightModes, i) ? 0 : BUTTON_CHECKED);
|
||||
}
|
||||
grid.nextLine();
|
||||
window->setLastField(flightmode);
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
};
|
||||
|
||||
void CommonInputOrMixButton::checkEvents()
|
||||
{
|
||||
if (active != isActive()) {
|
||||
invalidate();
|
||||
active = !active;
|
||||
}
|
||||
|
||||
Button::checkEvents();
|
||||
}
|
||||
|
||||
void CommonInputOrMixButton::drawFlightModes(BitmapBuffer *dc, FlightModesType value)
|
||||
{
|
||||
dc->drawBitmap(146, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupFlightmodeBitmap);
|
||||
coord_t x = 166;
|
||||
for (int i = 0; i < MAX_FLIGHT_MODES; i++) {
|
||||
char s[] = " ";
|
||||
s[0] = '0' + i;
|
||||
if (value & (1 << i)) {
|
||||
dc->drawText(x, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, s, SMLSIZE | TEXT_DISABLE_COLOR);
|
||||
}
|
||||
else {
|
||||
dc->drawSolidFilledRect(x, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, 8, 3, SCROLLBOX_COLOR);
|
||||
dc->drawText(x, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, s, SMLSIZE);
|
||||
}
|
||||
x += 8;
|
||||
}
|
||||
}
|
||||
|
||||
void CommonInputOrMixButton::paint(BitmapBuffer * dc)
|
||||
{
|
||||
if (active)
|
||||
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, WARNING_COLOR);
|
||||
paintBody(dc);
|
||||
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
|
||||
}
|
||||
|
||||
class InputLineButton : public CommonInputOrMixButton {
|
||||
public:
|
||||
InputLineButton(Window * parent, const rect_t & rect, uint8_t index):
|
||||
CommonInputOrMixButton(parent, rect, index)
|
||||
{
|
||||
const ExpoData & line = g_model.expoData[index];
|
||||
if (line.swtch || line.curve.value != 0 || line.flightModes) {
|
||||
setHeight(getHeight() + 20);
|
||||
}
|
||||
}
|
||||
|
||||
bool isActive() override
|
||||
{
|
||||
return isExpoActive(index);
|
||||
}
|
||||
|
||||
void paintBody(BitmapBuffer * dc) override
|
||||
{
|
||||
const ExpoData & line = g_model.expoData[index];
|
||||
|
||||
// first line ...
|
||||
drawValueOrGVar(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, line.weight);
|
||||
drawSource(dc, 60, FIELD_PADDING_TOP, line.srcRaw);
|
||||
|
||||
if (line.name[0]) {
|
||||
dc->drawBitmap(146, 2 + FIELD_PADDING_TOP, mixerSetupLabelBitmap);
|
||||
dc->drawSizedText(166, FIELD_PADDING_TOP, line.name, sizeof(line.name), ZCHAR);
|
||||
}
|
||||
|
||||
// second line ...
|
||||
if (line.swtch) {
|
||||
dc->drawMask(3, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupSwitchIcon, TEXT_COLOR);
|
||||
drawSwitch(dc, 21, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, line.swtch);
|
||||
}
|
||||
|
||||
if (line.curve.value != 0 ) {
|
||||
dc->drawBitmap(60, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupCurveBitmap);
|
||||
drawCurveRef(dc, 80, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, line.curve);
|
||||
}
|
||||
|
||||
if (line.flightModes) {
|
||||
drawFlightModes(dc, line.flightModes);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ModelInputsPage::ModelInputsPage():
|
||||
PageTab(STR_MENUINPUTS, ICON_MODEL_INPUTS)
|
||||
{
|
||||
}
|
||||
|
||||
void ModelInputsPage::rebuild(FormWindow * window, int8_t focusIndex)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window, focusIndex);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
void ModelInputsPage::editInput(FormWindow * window, uint8_t input, uint8_t index)
|
||||
{
|
||||
Window * editWindow = new InputEditWindow(input, index);
|
||||
editWindow->setCloseHandler([=]() {
|
||||
rebuild(window, index);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelInputsPage::build(FormWindow * window, int8_t focusIndex)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(66);
|
||||
|
||||
Window::clearFocus();
|
||||
|
||||
int inputIndex = 0;
|
||||
ExpoData * line = g_model.expoData;
|
||||
for (uint8_t input=0; input<MAX_INPUTS; input++) {
|
||||
if (inputIndex < MAX_EXPOS && line->chn == input && EXPO_VALID(line)) {
|
||||
new StaticText(window, grid.getLabelSlot(), getSourceString(MIXSRC_FIRST_INPUT + input), BUTTON_BACKGROUND | CENTERED);
|
||||
while (inputIndex < MAX_EXPOS && line->chn == input && EXPO_VALID(line)) {
|
||||
Button * button = new InputLineButton(window, grid.getFieldSlot(), inputIndex);
|
||||
if (focusIndex == inputIndex)
|
||||
button->setFocus();
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
button->bringToTop();
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
editInput(window, input, inputIndex);
|
||||
});
|
||||
if (!reachExposLimit()) {
|
||||
menu->addLine(STR_INSERT_BEFORE, [=]() {
|
||||
insertExpo(inputIndex, input);
|
||||
editInput(window, input, inputIndex);
|
||||
});
|
||||
menu->addLine(STR_INSERT_AFTER, [=]() {
|
||||
insertExpo(inputIndex + 1, input);
|
||||
editInput(window, input, inputIndex + 1);
|
||||
});
|
||||
menu->addLine(STR_COPY, [=]() {
|
||||
s_copyMode = COPY_MODE;
|
||||
s_copySrcIdx = inputIndex;
|
||||
});
|
||||
if (s_copyMode != 0) {
|
||||
menu->addLine(STR_PASTE_BEFORE, [=]() {
|
||||
copyExpo(s_copySrcIdx, inputIndex, PASTE_BEFORE);
|
||||
if (s_copyMode == MOVE_MODE) {
|
||||
deleteExpo((s_copySrcIdx > inputIndex) ? s_copySrcIdx+1 : s_copySrcIdx);
|
||||
s_copyMode = 0;
|
||||
}
|
||||
rebuild(window, inputIndex);
|
||||
});
|
||||
menu->addLine(STR_PASTE_AFTER, [=]() {
|
||||
copyExpo(s_copySrcIdx, inputIndex, PASTE_AFTER);
|
||||
if (s_copyMode == MOVE_MODE) {
|
||||
deleteExpo((s_copySrcIdx > inputIndex) ? s_copySrcIdx+1 : s_copySrcIdx);
|
||||
s_copyMode = 0;
|
||||
}
|
||||
rebuild(window, inputIndex+1);
|
||||
});
|
||||
}
|
||||
}
|
||||
menu->addLine(STR_MOVE, [=]() {
|
||||
s_copyMode = MOVE_MODE;
|
||||
s_copySrcIdx = inputIndex;
|
||||
});
|
||||
menu->addLine(STR_DELETE, [=]() {
|
||||
deleteExpo(inputIndex);
|
||||
rebuild(window, -1);
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
|
||||
grid.spacer(button->height() - 2);
|
||||
|
||||
++inputIndex;
|
||||
++line;
|
||||
}
|
||||
|
||||
grid.spacer(7);
|
||||
}
|
||||
else {
|
||||
auto button = new TextButton(window, grid.getLabelSlot(), getSourceString(MIXSRC_FIRST_INPUT + input));
|
||||
if (focusIndex == inputIndex)
|
||||
button->setFocus();
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
button->bringToTop();
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
insertExpo(inputIndex, input);
|
||||
editInput(window, input, inputIndex);
|
||||
return 0;
|
||||
});
|
||||
if (!reachExposLimit()) {
|
||||
if (s_copyMode != 0) {
|
||||
menu->addLine(STR_PASTE, [=]() {
|
||||
copyExpo(s_copySrcIdx, inputIndex, input);
|
||||
if(s_copyMode == MOVE_MODE) {
|
||||
deleteExpo((s_copySrcIdx >= inputIndex) ? s_copySrcIdx+1 : s_copySrcIdx);
|
||||
s_copyMode = 0;
|
||||
}
|
||||
rebuild(window, -1);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
grid.spacer(button->height() + 5);
|
||||
}
|
||||
}
|
||||
|
||||
Window * focus = Window::getFocus();
|
||||
if (focus) {
|
||||
focus->bringToTop();
|
||||
}
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setLastField();
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
|
||||
// TODO port: avoid global s_currCh on ARM boards (as done here)...
|
||||
int8_t s_currCh;
|
||||
uint8_t s_copyMode;
|
||||
int8_t s_copySrcRow;
|
||||
|
||||
void insertExpo(uint8_t idx, uint8_t input)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
ExpoData * expo = expoAddress(idx);
|
||||
memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData));
|
||||
memclear(expo, sizeof(ExpoData));
|
||||
expo->srcRaw = (input >= 4 ? MIXSRC_Rud + input : MIXSRC_Rud + channelOrder(input + 1) - 1);
|
||||
expo->curve.type = CURVE_REF_EXPO;
|
||||
expo->mode = 3; // pos+neg
|
||||
expo->chn = input;
|
||||
expo->weight = 100;
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MODEL_INPUTS_H
|
||||
#define _MODEL_INPUTS_H
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelInputsPage: public PageTab {
|
||||
public:
|
||||
ModelInputsPage();
|
||||
|
||||
void build(FormWindow * window) override
|
||||
{
|
||||
build(window, 0);
|
||||
}
|
||||
|
||||
protected:
|
||||
void build(FormWindow * window, int8_t focusIndex);
|
||||
void rebuild(FormWindow * window, int8_t focusIndex);
|
||||
void editInput(FormWindow * window, uint8_t channel, uint8_t index);
|
||||
uint8_t s_copySrcIdx;
|
||||
};
|
||||
|
||||
class CommonInputOrMixButton : public Button {
|
||||
public:
|
||||
CommonInputOrMixButton(Window * parent, const rect_t & rect, uint8_t index):
|
||||
Button(parent, rect),
|
||||
index(index)
|
||||
{
|
||||
setFocusHandler([=]() {
|
||||
bringToTop();
|
||||
});
|
||||
}
|
||||
|
||||
virtual bool isActive() = 0;
|
||||
|
||||
void checkEvents() override;
|
||||
|
||||
void drawFlightModes(BitmapBuffer *dc, FlightModesType value);
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
virtual void paintBody(BitmapBuffer * dc) = 0;
|
||||
|
||||
protected:
|
||||
uint8_t index;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
|
||||
#endif //_MODEL_INPUTS_H
|
||||
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_logical_switches.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
void putsEdgeDelayParam(coord_t x, coord_t y, LogicalSwitchData * ls)
|
||||
{
|
||||
lcdDrawChar(x, y, '[');
|
||||
lcdDrawNumber(lcdNextPos+2, y, lswTimerValue(ls->v2), LEFT|PREC1);
|
||||
lcdDrawChar(lcdNextPos, y, ':');
|
||||
if (ls->v3 < 0)
|
||||
lcdDrawText(lcdNextPos+3, y, "<<");
|
||||
else if (ls->v3 == 0)
|
||||
lcdDrawText(lcdNextPos+3, y, "--");
|
||||
else
|
||||
lcdDrawNumber(lcdNextPos+3, y, lswTimerValue(ls->v2+ls->v3), LEFT|PREC1);
|
||||
lcdDrawChar(lcdNextPos, y, ']');
|
||||
}
|
||||
|
||||
class LogicalSwitchEditWindow: public Page {
|
||||
public:
|
||||
LogicalSwitchEditWindow(uint8_t ls):
|
||||
Page(ICON_MODEL_LOGICAL_SWITCHES),
|
||||
ls(ls)
|
||||
{
|
||||
buildBody(&body);
|
||||
buildHeader(&header);
|
||||
}
|
||||
|
||||
bool isActive() {
|
||||
return getSwitch(SWSRC_FIRST_LOGICAL_SWITCH+ls);
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
if (active != isActive()) {
|
||||
headerSwitchName->setFlags(isActive() ? BOLD|WARNING_COLOR : MENU_TITLE_COLOR);
|
||||
active = !active;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t ls;
|
||||
bool active = false;
|
||||
Window * logicalSwitchOneWindow = nullptr;
|
||||
StaticText * headerSwitchName = nullptr;
|
||||
NumberEdit * v2Edit = nullptr;
|
||||
|
||||
void updateLogicalSwitchOneWindow()
|
||||
{
|
||||
FormGridLayout grid;
|
||||
logicalSwitchOneWindow->clear();
|
||||
|
||||
LogicalSwitchData * cs = lswAddress(ls);
|
||||
uint8_t cstate = lswFamily(cs->func);
|
||||
|
||||
if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) {
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V1);
|
||||
auto choice = new SwitchChoice(logicalSwitchOneWindow, grid.getFieldSlot(), SWSRC_FIRST_IN_LOGICAL_SWITCHES, SWSRC_LAST_IN_LOGICAL_SWITCHES, GET_SET_DEFAULT(cs->v1));
|
||||
choice->setAvailableHandler(isSwitchAvailableInLogicalSwitches);
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V2);
|
||||
choice = new SwitchChoice(logicalSwitchOneWindow, grid.getFieldSlot(), SWSRC_FIRST_IN_LOGICAL_SWITCHES, SWSRC_LAST_IN_LOGICAL_SWITCHES, GET_SET_DEFAULT(cs->v2));
|
||||
choice->setAvailableHandler(isSwitchAvailableInLogicalSwitches);
|
||||
grid.nextLine();
|
||||
}
|
||||
else if (cstate == LS_FAMILY_EDGE) {
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V1);
|
||||
auto choice = new SwitchChoice(logicalSwitchOneWindow, grid.getFieldSlot(), SWSRC_FIRST_IN_LOGICAL_SWITCHES, SWSRC_LAST_IN_LOGICAL_SWITCHES, GET_SET_DEFAULT(cs->v1));
|
||||
choice->setAvailableHandler(isSwitchAvailableInLogicalSwitches);
|
||||
grid.nextLine();
|
||||
|
||||
auto edit1 = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(2, 0), -129, 122, GET_DEFAULT(cs->v2));
|
||||
auto edit2 = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(2, 1), -1, 222 - cs->v2, GET_SET_DEFAULT(cs->v3));
|
||||
edit1->setSetValueHandler([=](int32_t newValue) {
|
||||
cs->v2 = newValue;
|
||||
cs->v3 = min<uint8_t>(cs->v3, 222 - cs->v2);
|
||||
SET_DIRTY();
|
||||
edit2->setMax(222 - cs->v2);
|
||||
edit2->invalidate();
|
||||
});
|
||||
edit1->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, 2, 2, lswTimerValue(value), flags | PREC1);
|
||||
});
|
||||
edit2->setDisplayHandler([=](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
if (value < 0)
|
||||
dc->drawText(2, 2, "<<", flags);
|
||||
else if (value == 0)
|
||||
dc->drawText(2, 2, "--", flags);
|
||||
else
|
||||
drawNumber(dc, 2, 2, lswTimerValue(cs->v2 + value), flags | PREC1);
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
else if (cstate == LS_FAMILY_COMP) {
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V1);
|
||||
new SourceChoice(logicalSwitchOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM, GET_SET_DEFAULT(cs->v1));
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V2);
|
||||
new SourceChoice(logicalSwitchOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM, GET_SET_DEFAULT(cs->v2));
|
||||
grid.nextLine();
|
||||
}
|
||||
else if (cstate == LS_FAMILY_TIMER) {
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V1);
|
||||
auto timer = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), -128, 122, GET_SET_DEFAULT(cs->v1));
|
||||
timer->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, 2, 2, lswTimerValue(value), flags | PREC1);
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V2);
|
||||
timer = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), -128, 122, GET_SET_DEFAULT(cs->v2));
|
||||
timer->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, 2, 2, lswTimerValue(value), flags | PREC1);
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
else {
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V1);
|
||||
new SourceChoice(logicalSwitchOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM, GET_DEFAULT(cs->v1),
|
||||
[=](int32_t newValue) {
|
||||
cs->v1 = newValue;
|
||||
SET_DIRTY();
|
||||
v2Edit->invalidate();
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_V2);
|
||||
int16_t v2_min = 0, v2_max = 0;
|
||||
getMixSrcRange(cs->v1, v2_min, v2_max);
|
||||
v2Edit = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), 0, MAX_LS_DELAY, GET_SET_DEFAULT(cs->v2));
|
||||
v2Edit->setDisplayHandler([=](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawSourceCustomValue(dc, 2, 2, cs->v1, (cs->v1 <= MIXSRC_LAST_CH ? calc100toRESX(value) : value), flags);
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// AND switch
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_AND_SWITCH);
|
||||
auto choice = new SwitchChoice(logicalSwitchOneWindow, grid.getFieldSlot(), -MAX_LS_ANDSW, MAX_LS_ANDSW, GET_SET_DEFAULT(cs->andsw));
|
||||
choice->setAvailableHandler(isSwitchAvailableInLogicalSwitches);
|
||||
grid.nextLine();
|
||||
|
||||
// Duration
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_DURATION);
|
||||
auto edit = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), 0, MAX_LS_DURATION, GET_SET_DEFAULT(cs->duration), PREC1);
|
||||
edit->setZeroText("---");
|
||||
grid.nextLine();
|
||||
|
||||
// Delay
|
||||
new StaticText(logicalSwitchOneWindow, grid.getLabelSlot(), STR_DELAY);
|
||||
if (cstate == LS_FAMILY_EDGE) {
|
||||
new StaticText(logicalSwitchOneWindow, grid.getFieldSlot(), STR_NA);
|
||||
}
|
||||
else {
|
||||
auto edit = new NumberEdit(logicalSwitchOneWindow, grid.getFieldSlot(), 0, MAX_LS_DELAY, GET_SET_DEFAULT(cs->delay), PREC1);
|
||||
edit->setZeroText("---");
|
||||
}
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
void buildHeader(Window * window) {
|
||||
new StaticText(window, { 70, 4, LCD_W - 100, 20 }, STR_MENULOGICALSWITCHES, MENU_TITLE_COLOR);
|
||||
headerSwitchName = new StaticText(window, { 70, 28, LCD_W - 100, 20 }, getSwitchPositionName(SWSRC_SW1+ls), MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void buildBody(Window * window) {
|
||||
LogicalSwitchData * cs = lswAddress(ls);
|
||||
|
||||
FormGridLayout grid;
|
||||
grid.spacer(10);
|
||||
|
||||
// LS Func
|
||||
new StaticText(window, grid.getLabelSlot(), STR_FUNC);
|
||||
Choice * funcChoice = new Choice(window, grid.getFieldSlot(), STR_VCSWFUNC, 0, LS_FUNC_MAX,
|
||||
GET_DEFAULT(cs->func),
|
||||
[=](int32_t newValue) {
|
||||
cs->func = newValue;
|
||||
if (lswFamily(cs->func) == LS_FAMILY_TIMER) {
|
||||
cs->v1 = cs->v2 = 0;
|
||||
}
|
||||
else if (lswFamily(cs->func) == LS_FAMILY_EDGE) {
|
||||
cs->v1 = 0; cs->v2 = -129; cs->v3 = 0;
|
||||
}
|
||||
else {
|
||||
cs->v1 = cs->v2 = 0;
|
||||
}
|
||||
SET_DIRTY();
|
||||
updateLogicalSwitchOneWindow();
|
||||
});
|
||||
funcChoice->setAvailableHandler(isLogicalSwitchFunctionAvailable);
|
||||
grid.nextLine();
|
||||
|
||||
logicalSwitchOneWindow = new Window(window, { 0, grid.getWindowHeight(), LCD_W, 0 });
|
||||
updateLogicalSwitchOneWindow();
|
||||
grid.addWindow(logicalSwitchOneWindow);
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr coord_t line1 = 2;
|
||||
static constexpr coord_t line2 = 22;
|
||||
static constexpr coord_t line3 = 42;
|
||||
static constexpr coord_t col1 = 20;
|
||||
static constexpr coord_t col2 = (LCD_W - 100) / 3 + col1;
|
||||
static constexpr coord_t col3 = ((LCD_W - 100) / 3) * 2 + col1;
|
||||
|
||||
class LogicalSwitchButton : public Button {
|
||||
public:
|
||||
LogicalSwitchButton(Window * parent, const rect_t & rect, int lsIndex, std::function<uint8_t(void)> onPress):
|
||||
Button(parent, rect, onPress),
|
||||
lsIndex(lsIndex),
|
||||
active(isActive())
|
||||
{
|
||||
LogicalSwitchData * ls = lswAddress(lsIndex);
|
||||
if (ls->andsw != SWSRC_NONE || ls->duration != 0 || ls->delay != 0)
|
||||
setHeight(getHeight() + 20);
|
||||
if (lswFamily(ls->func) == LS_FAMILY_EDGE)
|
||||
setHeight(getHeight() + 20);
|
||||
}
|
||||
|
||||
bool isActive()
|
||||
{
|
||||
return getSwitch(SWSRC_FIRST_LOGICAL_SWITCH + lsIndex);
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
if (active != isActive()) {
|
||||
invalidate();
|
||||
active = !active;
|
||||
}
|
||||
|
||||
Button::checkEvents();
|
||||
}
|
||||
|
||||
virtual void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
LogicalSwitchData * ls = lswAddress(lsIndex);
|
||||
uint8_t lsFamily = lswFamily(ls->func);
|
||||
|
||||
if (active)
|
||||
dc->drawSolidFilledRect(2, 2, rect.w-4, rect.h-4, WARNING_COLOR);
|
||||
|
||||
// The bounding rect
|
||||
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
|
||||
|
||||
// CSW func
|
||||
lcdDrawTextAtIndex(col1, line1, STR_VCSWFUNC, ls->func);
|
||||
|
||||
// CSW params
|
||||
if (lsFamily == LS_FAMILY_BOOL || lsFamily == LS_FAMILY_STICKY) {
|
||||
drawSwitch(dc, col2, line1, ls->v1);
|
||||
drawSwitch(dc, col3, line1, ls->v2);
|
||||
}
|
||||
else if (lsFamily == LS_FAMILY_EDGE) {
|
||||
drawSwitch(dc, col1, line2, ls->v1);
|
||||
putsEdgeDelayParam(col2, line2, ls);
|
||||
}
|
||||
else if (lsFamily == LS_FAMILY_COMP) {
|
||||
drawSource(dc, col2, line1, ls->v1, 0);
|
||||
drawSource(dc, col3, line1, ls->v2, 0);
|
||||
}
|
||||
else if (lsFamily == LS_FAMILY_TIMER) {
|
||||
lcdDrawNumber(col2, line1, lswTimerValue(ls->v1), LEFT|PREC1);
|
||||
lcdDrawNumber(col3, line1, lswTimerValue(ls->v2), LEFT|PREC1);
|
||||
}
|
||||
else {
|
||||
drawSource(dc, col2, line1, ls->v1, 0);
|
||||
drawSourceCustomValue(dc, col3, line1, ls->v1, (ls->v1 <= MIXSRC_LAST_CH ? calc100toRESX(ls->v2) : ls->v2), 0);
|
||||
}
|
||||
|
||||
// AND switch
|
||||
drawSwitch(dc, col1, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->andsw, 0);
|
||||
|
||||
// CSW duration
|
||||
if (ls->duration > 0) {
|
||||
drawNumber(dc, col2, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->duration, PREC1 | LEFT);
|
||||
}
|
||||
|
||||
// CSW delay
|
||||
if (lsFamily != LS_FAMILY_EDGE && ls->delay > 0) {
|
||||
drawNumber(dc, col3, (lsFamily == LS_FAMILY_EDGE) ? line3 : line2, ls->delay, PREC1 | LEFT);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t lsIndex;
|
||||
bool active;
|
||||
};
|
||||
|
||||
ModelLogicalSwitchesPage::ModelLogicalSwitchesPage():
|
||||
PageTab(STR_MENULOGICALSWITCHES, ICON_MODEL_LOGICAL_SWITCHES)
|
||||
{
|
||||
}
|
||||
|
||||
void ModelLogicalSwitchesPage::rebuild(FormWindow * window, int8_t focusIndex)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window, focusIndex);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
void ModelLogicalSwitchesPage::editLogicalSwitch(FormWindow * window, uint8_t lsIndex)
|
||||
{
|
||||
Window * lsWindow = new LogicalSwitchEditWindow(lsIndex);
|
||||
lsWindow->setCloseHandler([=]() {
|
||||
rebuild(window, lsIndex);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelLogicalSwitchesPage::build(FormWindow * window, int8_t focusIndex)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(66);
|
||||
|
||||
for (uint8_t i=0; i<MAX_LOGICAL_SWITCHES; i++) {
|
||||
LogicalSwitchData * ls = lswAddress(i);
|
||||
if (ls->func == LS_FUNC_NONE) {
|
||||
auto label = new TextButton(window, grid.getLabelSlot(), getSwitchPositionName(SWSRC_SW1+i));
|
||||
grid.spacer(label->height() + 5);
|
||||
}
|
||||
else {
|
||||
new StaticText(window, grid.getLabelSlot(), getSwitchPositionName(SWSRC_SW1 + i), BUTTON_BACKGROUND | CENTERED);
|
||||
Button * button = new LogicalSwitchButton(window, grid.getFieldSlot(), i,
|
||||
[=]() -> uint8_t {
|
||||
Menu *menu = new Menu();
|
||||
LogicalSwitchData *ls = lswAddress(i);
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
editLogicalSwitch(window, i);
|
||||
});
|
||||
if (ls->func)
|
||||
menu->addLine(STR_COPY, [=]() {
|
||||
clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH;
|
||||
clipboard.data.csw = *ls;
|
||||
});
|
||||
if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_SWITCH)
|
||||
menu->addLine(STR_PASTE, [=]() {
|
||||
*ls = clipboard.data.csw;
|
||||
storageDirty(EE_MODEL);
|
||||
rebuild(window, i);
|
||||
});
|
||||
if (ls->func || ls->v1 || ls->v2 || ls->delay || ls->duration || ls->andsw)
|
||||
menu->addLine(STR_CLEAR, [=]() {
|
||||
memset(ls, 0, sizeof(LogicalSwitchData));
|
||||
storageDirty(EE_MODEL);
|
||||
rebuild(window, i);
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
if (focusIndex == i) {
|
||||
button->setFocus();
|
||||
}
|
||||
|
||||
grid.spacer(button->height() + 5);
|
||||
}
|
||||
}
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setLastField();
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MODEL_LOGICAL_SWITCHES_H
|
||||
#define _MODEL_LOGICAL_SWITCHES_H
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelLogicalSwitchesPage: public PageTab {
|
||||
public:
|
||||
ModelLogicalSwitchesPage();
|
||||
|
||||
virtual void build(FormWindow * window) override
|
||||
{
|
||||
build(window, -1);
|
||||
}
|
||||
|
||||
protected:
|
||||
void build(FormWindow * window, int8_t focusIndex);
|
||||
void rebuild(FormWindow * window, int8_t focusIndex);
|
||||
void editLogicalSwitch(FormWindow * window, uint8_t lsIndex);
|
||||
};
|
||||
|
||||
#endif //_MODEL_LOGICAL_SWITCHES_H
|
||||
@@ -0,0 +1,530 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_mixes.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
#include "bitfield.h"
|
||||
#include "model_inputs.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
#define PASTE_BEFORE -2
|
||||
#define PASTE_AFTER -1
|
||||
|
||||
uint8_t getMixesCount()
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint8_t ch;
|
||||
|
||||
for (int i = MAX_MIXERS - 1; i >= 0; i--) {
|
||||
ch = mixAddress(i)->srcRaw;
|
||||
if (ch != 0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
bool reachMixesLimit()
|
||||
{
|
||||
if (getMixesCount() >= MAX_MIXERS) {
|
||||
POPUP_WARNING(STR_NOFREEMIXER);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
class MixEditWindow : public Page {
|
||||
public:
|
||||
MixEditWindow(int8_t channel, uint8_t mixIndex) :
|
||||
Page(ICON_MODEL_MIXER),
|
||||
channel(channel),
|
||||
mixIndex(mixIndex)
|
||||
{
|
||||
buildBody(&body);
|
||||
buildHeader(&header);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t channel;
|
||||
uint8_t mixIndex;
|
||||
Window * updateCurvesWindow = nullptr;
|
||||
Choice * curveTypeChoice = nullptr;
|
||||
|
||||
void buildHeader(Window * window)
|
||||
{
|
||||
new StaticText(window, {70, 4, 100, 20}, STR_MIXER, MENU_TITLE_COLOR);
|
||||
new StaticText(window, {70, 28, 100, 20}, getSourceString(MIXSRC_CH1 + channel), MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void updateCurves()
|
||||
{
|
||||
FormGridLayout grid;
|
||||
updateCurvesWindow->clear();
|
||||
|
||||
MixData * line = mixAddress(mixIndex);
|
||||
|
||||
new StaticText(updateCurvesWindow, grid.getLabelSlot(), STR_CURVE);
|
||||
curveTypeChoice = new Choice(updateCurvesWindow, grid.getFieldSlot(2, 0), "\004DiffExpoFuncCstm", 0, CURVE_REF_CUSTOM,
|
||||
GET_DEFAULT(line->curve.type),
|
||||
[=](int32_t newValue) {
|
||||
line->curve.type = newValue;
|
||||
line->curve.value = 0;
|
||||
SET_DIRTY();
|
||||
updateCurves();
|
||||
curveTypeChoice->setFocus();
|
||||
});
|
||||
|
||||
switch (line->curve.type) {
|
||||
case CURVE_REF_DIFF:
|
||||
case CURVE_REF_EXPO: {
|
||||
// TODO GVAR
|
||||
NumberEdit * edit = new NumberEdit(updateCurvesWindow, grid.getFieldSlot(2, 1), -100, 100,
|
||||
GET_SET_DEFAULT(line->curve.value));
|
||||
edit->setSuffix("%");
|
||||
break;
|
||||
}
|
||||
case CURVE_REF_FUNC:
|
||||
new Choice(updateCurvesWindow, grid.getFieldSlot(2, 1), STR_VCURVEFUNC, 0, CURVE_BASE - 1, GET_SET_DEFAULT(line->curve.value));
|
||||
break;
|
||||
case CURVE_REF_CUSTOM:
|
||||
//new CustomCurveChoice(updateCurvesWindow, grid.getFieldSlot(2, 1), -MAX_CURVES, MAX_CURVES, GET_SET_DEFAULT(line->curve.value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void buildBody(Window * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(8);
|
||||
|
||||
MixData * mix = mixAddress(mixIndex);
|
||||
|
||||
// Mix name
|
||||
new StaticText(window, grid.getLabelSlot(), STR_MIXNAME);
|
||||
new TextEdit(window, grid.getFieldSlot(), mix->name, sizeof(mix->name));
|
||||
grid.nextLine();
|
||||
|
||||
// Source
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SOURCE);
|
||||
new SourceChoice(window, grid.getFieldSlot(), 0, MIXSRC_LAST, GET_SET_DEFAULT(mix->srcRaw));
|
||||
grid.nextLine();
|
||||
|
||||
// Weight
|
||||
new StaticText(window, grid.getLabelSlot(), STR_WEIGHT);
|
||||
// TODO GVAR ?
|
||||
NumberEdit * edit = new NumberEdit(window, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(mix->weight));
|
||||
edit->setSuffix("%");
|
||||
grid.nextLine();
|
||||
|
||||
// Offset
|
||||
new StaticText(window, grid.getLabelSlot(), STR_OFFSET);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(), GV_RANGELARGE_OFFSET_NEG, GV_RANGELARGE_OFFSET, GET_SET_DEFAULT(mix->offset));
|
||||
edit->setSuffix("%");
|
||||
grid.nextLine();
|
||||
|
||||
// Trim
|
||||
new StaticText(window, grid.getLabelSlot(), STR_TRIM);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_INVERTED(mix->carryTrim));
|
||||
grid.nextLine();
|
||||
|
||||
// Curve
|
||||
updateCurvesWindow = new Window(window, {0, grid.getWindowHeight(), LCD_W, 0});
|
||||
updateCurves();
|
||||
grid.addWindow(updateCurvesWindow);
|
||||
|
||||
// Flight modes
|
||||
new StaticText(window, grid.getLabelSlot(), STR_FLMODE);
|
||||
for (uint8_t i = 0; i < MAX_FLIGHT_MODES; i++) {
|
||||
char fm[2] = {char('0' + i), '\0'};
|
||||
if (i > 0 && (i % 4) == 0)
|
||||
grid.nextLine();
|
||||
new TextButton(window, grid.getFieldSlot(4, i % 4), fm,
|
||||
[=]() -> uint8_t {
|
||||
BFBIT_FLIP(mix->flightModes, bfBit<uint8_t >(i));
|
||||
SET_DIRTY();
|
||||
return !(bfSingleBitGet(mix->flightModes, i));
|
||||
},
|
||||
bfSingleBitGet(mix->flightModes, i) ? 0 : BUTTON_CHECKED);
|
||||
}
|
||||
grid.nextLine();
|
||||
|
||||
// Switch
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SWITCH);
|
||||
new SwitchChoice(window, grid.getFieldSlot(), SWSRC_FIRST_IN_MIXES, SWSRC_LAST_IN_MIXES, GET_SET_DEFAULT(mix->swtch));
|
||||
grid.nextLine();
|
||||
|
||||
// Warning
|
||||
new StaticText(window, grid.getLabelSlot(), STR_MIXWARNING);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, 3, GET_SET_DEFAULT(mix->mixWarn));
|
||||
edit->setZeroText(STR_OFF);
|
||||
grid.nextLine();
|
||||
|
||||
// Multiplex
|
||||
new StaticText(window, grid.getLabelSlot(), STR_MULTPX);
|
||||
new Choice(window, grid.getFieldSlot(), STR_VMLTPX, 0, 2, GET_SET_DEFAULT(mix->mltpx));
|
||||
grid.nextLine();
|
||||
|
||||
// Delay up
|
||||
new StaticText(window, grid.getLabelSlot(), STR_DELAYUP);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
|
||||
GET_DEFAULT(mix->delayUp),
|
||||
SET_VALUE(mix->delayUp, newValue),
|
||||
PREC1);
|
||||
edit->setStep(10 / DELAY_STEP);
|
||||
edit->setSuffix("s");
|
||||
grid.nextLine();
|
||||
|
||||
// Delay down
|
||||
new StaticText(window, grid.getLabelSlot(), STR_DELAYDOWN);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
|
||||
GET_DEFAULT(mix->delayDown),
|
||||
SET_VALUE(mix->delayDown, newValue),
|
||||
PREC1);
|
||||
edit->setStep(10 / DELAY_STEP);
|
||||
edit->setSuffix("s");
|
||||
grid.nextLine();
|
||||
|
||||
// Slow up
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SLOWUP);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
|
||||
GET_DEFAULT(mix->speedUp),
|
||||
SET_VALUE(mix->speedUp, newValue),
|
||||
PREC1);
|
||||
edit->setStep(10 / DELAY_STEP);
|
||||
edit->setSuffix("s");
|
||||
grid.nextLine();
|
||||
|
||||
// Slow down
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SLOWDOWN);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), 0, DELAY_MAX,
|
||||
GET_DEFAULT(mix->speedDown),
|
||||
SET_VALUE(mix->speedDown, newValue),
|
||||
PREC1);
|
||||
edit->setStep(10 / DELAY_STEP);
|
||||
edit->setSuffix("s");
|
||||
grid.nextLine();
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
};
|
||||
|
||||
class MixLineButton : public CommonInputOrMixButton {
|
||||
public:
|
||||
MixLineButton(Window * parent, const rect_t &rect, uint8_t index) :
|
||||
CommonInputOrMixButton(parent, rect, index)
|
||||
{
|
||||
const MixData & mix = g_model.mixData[index];
|
||||
if (mix.swtch || mix.curve.value != 0 || mix.flightModes) {
|
||||
setHeight(getHeight() + 20);
|
||||
}
|
||||
}
|
||||
|
||||
bool isActive() override
|
||||
{
|
||||
return isMixActive(index);
|
||||
}
|
||||
|
||||
void paintBody(BitmapBuffer * dc) override
|
||||
{
|
||||
const MixData & line = g_model.mixData[index];
|
||||
|
||||
// first line ...
|
||||
drawValueOrGVar(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, line.weight);
|
||||
drawSource(dc, 60, FIELD_PADDING_TOP, line.srcRaw);
|
||||
|
||||
if (line.name[0]) {
|
||||
dc->drawBitmap(146, FIELD_PADDING_TOP, mixerSetupLabelBitmap);
|
||||
dc->drawSizedText(166, FIELD_PADDING_TOP, line.name, sizeof(line.name), ZCHAR);
|
||||
}
|
||||
|
||||
// second line ...
|
||||
if (line.swtch) {
|
||||
dc->drawBitmap(3, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupSwitchBitmap);
|
||||
drawSwitch(dc, 21, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, line.swtch);
|
||||
}
|
||||
|
||||
if (line.curve.value) {
|
||||
dc->drawBitmap(60, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupCurveBitmap);
|
||||
drawCurveRef(dc, 80, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, line.curve, 0);
|
||||
}
|
||||
|
||||
if (line.flightModes) {
|
||||
drawFlightModes(dc, line.flightModes);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void insertMix(uint8_t idx, uint8_t channel)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
MixData * mix = mixAddress(idx);
|
||||
memmove(mix + 1, mix, (MAX_MIXERS - (idx + 1)) * sizeof(MixData));
|
||||
memclear(mix, sizeof(MixData));
|
||||
mix->destCh = channel;
|
||||
mix->srcRaw = channel + 1;
|
||||
if (!isSourceAvailable(mix->srcRaw)) {
|
||||
mix->srcRaw = (channel > 3 ? MIXSRC_Rud - 1 + channel : MIXSRC_Rud - 1 + channelOrder(channel));
|
||||
while (!isSourceAvailable(mix->srcRaw)) {
|
||||
mix->srcRaw += 1;
|
||||
}
|
||||
}
|
||||
mix->weight = 100;
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
ModelMixesPage::ModelMixesPage() :
|
||||
PageTab(STR_MIXER, ICON_MODEL_MIXER)
|
||||
{
|
||||
}
|
||||
|
||||
void ModelMixesPage::rebuild(FormWindow * window, int8_t focusMixIndex)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window, focusMixIndex);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
void ModelMixesPage::editMix(FormWindow * window, uint8_t channel, uint8_t mixIndex)
|
||||
{
|
||||
Window * editWindow = new MixEditWindow(channel, mixIndex);
|
||||
editWindow->setCloseHandler([=]() {
|
||||
rebuild(window, mixIndex);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelMixesPage::build(FormWindow * window, int8_t focusMixIndex)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(66);
|
||||
|
||||
Window::clearFocus();
|
||||
|
||||
const BitmapBuffer * const mixerMultiplexBitmap[] = {
|
||||
mixerSetupAddBitmap,
|
||||
mixerSetupMultiBitmap,
|
||||
mixerSetupReplaceBitmap
|
||||
};
|
||||
|
||||
int mixIndex = 0;
|
||||
MixData * mix = g_model.mixData;
|
||||
for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) {
|
||||
if (mixIndex < MAX_MIXERS && mix->srcRaw > 0 && mix->destCh == ch) {
|
||||
new StaticText(window, grid.getLabelSlot(), getSourceString(MIXSRC_CH1 + ch), BUTTON_BACKGROUND | CENTERED);
|
||||
uint8_t count = 0;
|
||||
while (mixIndex < MAX_MIXERS && mix->srcRaw > 0 && mix->destCh == ch) {
|
||||
Button * button = new MixLineButton(window, grid.getFieldSlot(), mixIndex);
|
||||
if (focusMixIndex == mixIndex)
|
||||
button->setFocus();
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
button->bringToTop();
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
editMix(window, ch, mixIndex);
|
||||
});
|
||||
if (!reachMixesLimit()) {
|
||||
menu->addLine(STR_INSERT_BEFORE, [=]() {
|
||||
insertMix(mixIndex, ch);
|
||||
editMix(window, ch, mixIndex);
|
||||
});
|
||||
menu->addLine(STR_INSERT_AFTER, [=]() {
|
||||
insertMix(mixIndex + 1, ch);
|
||||
editMix(window, ch, mixIndex + 1);
|
||||
});
|
||||
menu->addLine(STR_COPY, [=]() {
|
||||
s_copyMode = COPY_MODE;
|
||||
s_copySrcIdx =mixIndex;
|
||||
});
|
||||
if (s_copyMode != 0) {
|
||||
menu->addLine(STR_PASTE_BEFORE, [=]() {
|
||||
copyMix(s_copySrcIdx, mixIndex, PASTE_BEFORE);
|
||||
if(s_copyMode == MOVE_MODE) {
|
||||
deleteMix((s_copySrcIdx > mixIndex) ? s_copySrcIdx+1 : s_copySrcIdx);
|
||||
s_copyMode = 0;
|
||||
}
|
||||
rebuild(window, mixIndex);
|
||||
});
|
||||
menu->addLine(STR_PASTE_AFTER, [=]() {
|
||||
copyMix(s_copySrcIdx, mixIndex, PASTE_AFTER);
|
||||
if(s_copyMode == MOVE_MODE) {
|
||||
deleteMix((s_copySrcIdx > mixIndex) ? s_copySrcIdx+1 : s_copySrcIdx);
|
||||
s_copyMode = 0;
|
||||
}
|
||||
rebuild(window, mixIndex+1);
|
||||
});
|
||||
}
|
||||
}
|
||||
menu->addLine(STR_MOVE, [=]() {
|
||||
s_copyMode = MOVE_MODE;
|
||||
s_copySrcIdx = mixIndex;
|
||||
});
|
||||
menu->addLine(STR_DELETE, [=]() {
|
||||
deleteMix(mixIndex);
|
||||
rebuild(window, -1);
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
|
||||
if (count++ > 0) {
|
||||
new StaticBitmap(window, {35, button->top() + (button->height() - 18) / 2, 25, 17}, mixerMultiplexBitmap[mix->mltpx]);
|
||||
}
|
||||
|
||||
grid.spacer(button->height() - 2);
|
||||
++mixIndex;
|
||||
++mix;
|
||||
}
|
||||
|
||||
grid.spacer(7);
|
||||
}
|
||||
else {
|
||||
auto button = new TextButton(window, grid.getLabelSlot(), getSourceString(MIXSRC_CH1 + ch));
|
||||
if (focusMixIndex == mixIndex)
|
||||
button->setFocus();
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
button->bringToTop();
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
insertMix(mixIndex, ch);
|
||||
editMix(window, ch, mixIndex);
|
||||
return 0;
|
||||
});
|
||||
if (!reachMixesLimit()) {
|
||||
if (s_copyMode != 0) {
|
||||
menu->addLine(STR_PASTE, [=]() {
|
||||
copyMix(s_copySrcIdx, mixIndex, ch);
|
||||
if(s_copyMode == MOVE_MODE) {
|
||||
deleteMix((s_copySrcIdx >= mixIndex) ? s_copySrcIdx+1 : s_copySrcIdx);
|
||||
s_copyMode = 0;
|
||||
}
|
||||
rebuild(window, -1);
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
// TODO STR_MOVE
|
||||
return 0;
|
||||
});
|
||||
|
||||
grid.spacer(button->height() + 5);
|
||||
}
|
||||
}
|
||||
|
||||
Window * focus = Window::getFocus();
|
||||
if (focus) {
|
||||
focus->bringToTop();
|
||||
}
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setLastField();
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
|
||||
void deleteMix(uint8_t idx)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
MixData * mix = mixAddress(idx);
|
||||
memmove(mix, mix + 1, (MAX_MIXERS - (idx + 1)) * sizeof(MixData));
|
||||
memclear(&g_model.mixData[MAX_MIXERS - 1], sizeof(MixData));
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
void insertMix(uint8_t idx)
|
||||
{
|
||||
insertMix(idx, s_currCh + 1);
|
||||
}
|
||||
|
||||
void copyMix(uint8_t source, uint8_t dest, int8_t ch)
|
||||
{
|
||||
pauseMixerCalculations();
|
||||
MixData sourceMix;
|
||||
memcpy(&sourceMix, mixAddress(source), sizeof(MixData));
|
||||
MixData * mix = mixAddress(dest);
|
||||
if(ch == PASTE_AFTER) {
|
||||
memmove(mix+2, mix+1, (MAX_MIXERS-(source+1))*sizeof(MixData));
|
||||
memcpy(mix+1, &sourceMix, sizeof(MixData));
|
||||
(mix+1)->destCh = (mix)->destCh;
|
||||
}
|
||||
else if(ch == PASTE_BEFORE) {
|
||||
memmove(mix+1, mix, (MAX_MIXERS-(source+1))*sizeof(MixData));
|
||||
memcpy(mix, &sourceMix, sizeof(MixData));
|
||||
mix->destCh = (mix+1)->destCh;
|
||||
}
|
||||
else {
|
||||
memmove(mix+1, mix, (MAX_MIXERS-(source+1))*sizeof(MixData));
|
||||
memcpy(mix, &sourceMix, sizeof(MixData));
|
||||
mix->destCh = ch;
|
||||
}
|
||||
|
||||
//memmove(mix + 1, mix, (MAX_MIXERS - (dest + 1)) * sizeof(MixData));
|
||||
resumeMixerCalculations();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
bool swapMixes(uint8_t &idx, uint8_t up)
|
||||
{
|
||||
MixData * x, * y;
|
||||
int8_t tgt_idx = (up ? idx - 1 : idx + 1);
|
||||
|
||||
x = mixAddress(idx);
|
||||
|
||||
if (tgt_idx < 0) {
|
||||
if (x->destCh == 0)
|
||||
return false;
|
||||
x->destCh--;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (tgt_idx == MAX_MIXERS) {
|
||||
if (x->destCh == MAX_OUTPUT_CHANNELS - 1)
|
||||
return false;
|
||||
x->destCh++;
|
||||
return true;
|
||||
}
|
||||
|
||||
y = mixAddress(tgt_idx);
|
||||
uint8_t destCh = x->destCh;
|
||||
if (!y->srcRaw || destCh != y->destCh) {
|
||||
if (up) {
|
||||
if (destCh > 0) x->destCh--;
|
||||
else return false;
|
||||
}
|
||||
else {
|
||||
if (destCh < MAX_OUTPUT_CHANNELS - 1) x->destCh++;
|
||||
else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
pauseMixerCalculations();
|
||||
memswap(x, y, sizeof(MixData));
|
||||
resumeMixerCalculations();
|
||||
|
||||
idx = tgt_idx;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MODEL_MIXES_H_
|
||||
#define _MODEL_MIXES_H_
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelMixesPage: public PageTab {
|
||||
public:
|
||||
ModelMixesPage();
|
||||
|
||||
void build(FormWindow * window) override
|
||||
{
|
||||
build(window, 0);
|
||||
}
|
||||
|
||||
protected:
|
||||
void build(FormWindow * window, int8_t focusMixIndex);
|
||||
void rebuild(FormWindow * window, int8_t focusMixIndex);
|
||||
void editMix(FormWindow * window, uint8_t channel, uint8_t mixIndex);
|
||||
uint8_t s_copySrcIdx;
|
||||
};
|
||||
|
||||
#endif // _MODEL_MIXES_H_
|
||||
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_outputs.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
class OutputEditWindow : public Page {
|
||||
public:
|
||||
OutputEditWindow(uint8_t channel) :
|
||||
Page(ICON_MODEL_OUTPUTS),
|
||||
channel(channel)
|
||||
{
|
||||
buildBody(&body);
|
||||
buildHeader(&header);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t channel;
|
||||
|
||||
void buildHeader(Window * window)
|
||||
{
|
||||
new StaticText(window, {70, 4, 100, 20}, STR_MENULIMITS, MENU_TITLE_COLOR);
|
||||
new StaticText(window, {70, 28, 100, 20}, getSourceString(MIXSRC_CH1 + channel), MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void buildBody(Window * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(8);
|
||||
|
||||
int limit = (g_model.extendedLimits ? LIMIT_EXT_MAX : 1000);
|
||||
|
||||
LimitData * output = limitAddress(channel);
|
||||
|
||||
// Name
|
||||
new StaticText(window, grid.getLabelSlot(), STR_NAME);
|
||||
new TextEdit(window, grid.getFieldSlot(), output->name, sizeof(output->name));
|
||||
grid.nextLine();
|
||||
|
||||
// Offset
|
||||
new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_SUBTRIM);
|
||||
new NumberEdit(window, grid.getFieldSlot(), -1000, +1000, GET_SET_DEFAULT(output->offset), PREC1);
|
||||
grid.nextLine();
|
||||
|
||||
// Min
|
||||
new StaticText(window, grid.getLabelSlot(), TR_MIN);
|
||||
new NumberEdit(window, grid.getFieldSlot(), -limit, 0,
|
||||
GET_VALUE(output->min - 1000),
|
||||
SET_VALUE(output->min, newValue + 1000),
|
||||
PREC1);
|
||||
grid.nextLine();
|
||||
|
||||
// Max
|
||||
new StaticText(window, grid.getLabelSlot(), TR_MAX);
|
||||
new NumberEdit(window, grid.getFieldSlot(), 0, +limit,
|
||||
GET_VALUE(output->max + 1000),
|
||||
SET_VALUE(output->max, newValue - 1000),
|
||||
PREC1);
|
||||
grid.nextLine();
|
||||
|
||||
// Direction
|
||||
new StaticText(window, grid.getLabelSlot(), "Inverted"); // TODO translation
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(output->revert));
|
||||
grid.nextLine();
|
||||
|
||||
// Curve
|
||||
new StaticText(window, grid.getLabelSlot(), TR_CURVE);
|
||||
auto edit = new NumberEdit(window, grid.getFieldSlot(), -MAX_CURVES, +MAX_CURVES, GET_SET_DEFAULT(output->curve));
|
||||
edit->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
dc->drawText(2, 2, getCurveString(value));
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// PPM center
|
||||
new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_PPMCENTER);
|
||||
new NumberEdit(window, grid.getFieldSlot(), PPM_CENTER - PPM_CENTER_MAX, PPM_CENTER + PPM_CENTER_MAX,
|
||||
GET_VALUE(output->ppmCenter + PPM_CENTER),
|
||||
SET_VALUE(output->ppmCenter, newValue - PPM_CENTER));
|
||||
grid.nextLine();
|
||||
|
||||
// PPM center
|
||||
new StaticText(window, grid.getLabelSlot(), TR_LIMITS_HEADERS_SUBTRIMMODE);
|
||||
new Choice(window, grid.getFieldSlot(), "\001\306=", 0, 1, GET_SET_DEFAULT(output->symetrical));
|
||||
grid.nextLine();
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
};
|
||||
|
||||
class OutputLineButton : public Button {
|
||||
public:
|
||||
OutputLineButton(Window * parent, const rect_t &rect, LimitData * output) :
|
||||
Button(parent, rect),
|
||||
output(output)
|
||||
{
|
||||
if (output->revert || output->curve || output->name[0]) {
|
||||
setHeight(getHeight() + PAGE_LINE_HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
// first line
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, output->min - 1000, PREC1);
|
||||
drawNumber(dc, 68, FIELD_PADDING_TOP, output->max + 1000, PREC1);
|
||||
drawNumber(dc, 132, FIELD_PADDING_TOP, output->offset, PREC1);
|
||||
drawNumber(dc, 226, FIELD_PADDING_TOP, PPM_CENTER + output->ppmCenter, RIGHT);
|
||||
dc->drawText(228, FIELD_PADDING_TOP - 3, output->symetrical ? "=" : "\306");
|
||||
|
||||
// second line
|
||||
if (output->revert) {
|
||||
drawTextAtIndex(dc, 4, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, STR_MMMINV, output->revert);
|
||||
}
|
||||
if (output->curve) {
|
||||
dc->drawBitmap(68, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupCurveBitmap);
|
||||
dc->drawText(88, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, getCurveString(output->curve));
|
||||
}
|
||||
if (output->name[0]) {
|
||||
dc->drawBitmap(146, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, mixerSetupLabelBitmap);
|
||||
dc->drawSizedText(166, PAGE_LINE_HEIGHT + FIELD_PADDING_TOP, output->name, sizeof(output->name), ZCHAR);
|
||||
}
|
||||
|
||||
// bounding rect
|
||||
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
|
||||
}
|
||||
|
||||
protected:
|
||||
LimitData * output;
|
||||
};
|
||||
|
||||
ModelOutputsPage::ModelOutputsPage() :
|
||||
PageTab(STR_MENULIMITS, ICON_MODEL_OUTPUTS)
|
||||
{
|
||||
}
|
||||
|
||||
void ModelOutputsPage::rebuild(FormWindow * window, int8_t focusChannel)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window, focusChannel);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
void ModelOutputsPage::build(FormWindow * window, int8_t focusChannel)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(66);
|
||||
|
||||
for (uint8_t ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++) {
|
||||
LimitData * output = limitAddress(ch);
|
||||
|
||||
// Channel label
|
||||
new StaticText(window, grid.getLabelSlot(), getSourceString(MIXSRC_CH1 + ch), BUTTON_BACKGROUND | CENTERED);
|
||||
|
||||
// Channel settings
|
||||
Button * button = new OutputLineButton(window, grid.getFieldSlot(), output);
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
editOutput(window, ch);
|
||||
});
|
||||
menu->addLine(STR_RESET, [=]() {
|
||||
output->min = 0;
|
||||
output->max = 0;
|
||||
output->offset = 0;
|
||||
output->ppmCenter = 0;
|
||||
output->revert = false;
|
||||
output->curve = 0;
|
||||
output->symetrical = 0;
|
||||
storageDirty(EE_MODEL);
|
||||
rebuild(window, ch);
|
||||
});
|
||||
menu->addLine(STR_COPY_STICKS_TO_OFS, [=]() {
|
||||
copySticksToOffset(ch);
|
||||
storageDirty(EE_MODEL);
|
||||
button->invalidate();
|
||||
});
|
||||
menu->addLine(STR_COPY_TRIMS_TO_OFS, [=]() {
|
||||
copyTrimsToOffset(ch);
|
||||
storageDirty(EE_MODEL);
|
||||
button->invalidate();
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
|
||||
if (focusChannel == ch) {
|
||||
button->setFocus();
|
||||
}
|
||||
|
||||
grid.spacer(button->height() + 5);
|
||||
}
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setLastField();
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
|
||||
void ModelOutputsPage::editOutput(FormWindow * window, uint8_t channel)
|
||||
{
|
||||
Window * editWindow = new OutputEditWindow(channel);
|
||||
editWindow->setCloseHandler([=]() {
|
||||
rebuild(window, channel);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MODEL_OUTPUTS_H_
|
||||
#define _MODEL_OUTPUTS_H_
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelOutputsPage: public PageTab {
|
||||
public:
|
||||
ModelOutputsPage();
|
||||
|
||||
virtual void build(FormWindow * window) override
|
||||
{
|
||||
build(window, -1);
|
||||
}
|
||||
|
||||
protected:
|
||||
void build(FormWindow * window, int8_t focusChannel);
|
||||
void rebuild(FormWindow * window, int8_t focusChannel);
|
||||
void editOutput(FormWindow * window, uint8_t channel);
|
||||
};
|
||||
|
||||
#endif // _MODEL_OUTPUTS_H_
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
#include "opentx.h"
|
||||
#include "storage/modelslist.h"
|
||||
#include "modelslist.h"
|
||||
|
||||
#define CATEGORIES_WIDTH 120
|
||||
#define MODELS_LEFT 123
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class FailSafeMenu: public TabsGroup {
|
||||
public:
|
||||
FailSafeMenu(uint8_t moduleIndex);
|
||||
};
|
||||
|
||||
class TextButton;
|
||||
class ModuleWindow;
|
||||
|
||||
class ModelSetupPage: public PageTab {
|
||||
public:
|
||||
ModelSetupPage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
};
|
||||
@@ -0,0 +1,542 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "model_telemetry.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
static constexpr coord_t SENSOR_COL1 = 30;
|
||||
static constexpr coord_t SENSOR_COL2 = SENSOR_COL1 + 70;
|
||||
static constexpr coord_t SENSOR_COL3 = LCD_W - 50;
|
||||
|
||||
class SensorSourceChoice : public SourceChoice {
|
||||
public:
|
||||
SensorSourceChoice(Window * window, const rect_t &rect, uint8_t * source, IsValueAvailable isValueAvailable) :
|
||||
SourceChoice(window, rect, MIXSRC_NONE, MIXSRC_LAST_TELEM,
|
||||
GET_DEFAULT(*source ? MIXSRC_FIRST_TELEM + 3 * (*source - 1) : MIXSRC_NONE),
|
||||
[=](uint8_t newValue) {
|
||||
*source = newValue == MIXSRC_NONE ? 0 : (newValue - MIXSRC_FIRST_TELEM) / 3 + 1;
|
||||
})
|
||||
{
|
||||
setAvailableHandler([=](int16_t value) {
|
||||
if (value == MIXSRC_NONE)
|
||||
return true;
|
||||
if (value < MIXSRC_FIRST_TELEM)
|
||||
return false;
|
||||
auto qr = div(value - MIXSRC_FIRST_TELEM, 3);
|
||||
return qr.rem == 0 && isValueAvailable(qr.quot + 1);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
class SensorButton : public Button {
|
||||
public:
|
||||
SensorButton(Window * parent, const rect_t &rect, uint8_t index) :
|
||||
Button(parent, rect),
|
||||
index(index)
|
||||
{
|
||||
}
|
||||
|
||||
static constexpr coord_t line1 = 1;
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
TelemetryItem &telemetryItem = telemetryItems[index];
|
||||
if (telemetryItem.isFresh()) {
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
TelemetryItem &telemetryItem = telemetryItems[index];
|
||||
|
||||
if (telemetryItem.isFresh()) {
|
||||
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, WARNING_COLOR);
|
||||
}
|
||||
|
||||
drawNumber(dc, 2, 1, index + 1, LEFT, 0, NULL, ":");
|
||||
|
||||
lcdDrawSizedText(SENSOR_COL1, line1, g_model.telemetrySensors[index].label, TELEM_LABEL_LEN, ZCHAR);
|
||||
|
||||
if (telemetryItem.isAvailable()) {
|
||||
LcdFlags color = telemetryItem.isOld() ? ALARM_COLOR : TEXT_COLOR;
|
||||
drawSensorCustomValue(dc, SENSOR_COL2, line1, index, getValue(MIXSRC_FIRST_TELEM + 3 * index), LEFT | color);
|
||||
}
|
||||
else {
|
||||
dc->drawText(SENSOR_COL2, line1, "---", CURVE_COLOR);
|
||||
}
|
||||
|
||||
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) {
|
||||
drawNumber(dc, SENSOR_COL3, line1, sensor->instance, LEFT);
|
||||
}
|
||||
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t index;
|
||||
};
|
||||
|
||||
class SensorEditWindow : public Page {
|
||||
public:
|
||||
SensorEditWindow(uint8_t index) :
|
||||
Page(ICON_MODEL_TELEMETRY),
|
||||
index(index)
|
||||
{
|
||||
buildBody(&body);
|
||||
buildHeader(&header);
|
||||
}
|
||||
|
||||
~SensorEditWindow()
|
||||
{
|
||||
body.deleteChildren();
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t index;
|
||||
Window * sensorOneWindow = nullptr;
|
||||
|
||||
void buildHeader(Window * window)
|
||||
{
|
||||
new StaticText(window, {70, 4, 200, 20}, STR_SENSOR + std::to_string(index + 1), MENU_TITLE_COLOR);
|
||||
// dynamic display of sensor value ?
|
||||
//new StaticText(window, {70, 28, 100, 20}, "SF" + std::to_string(index), MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void updateSensorOneWindow()
|
||||
{
|
||||
// Sensor variable part
|
||||
FormGridLayout grid;
|
||||
sensorOneWindow->clear();
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[index];
|
||||
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
// Formula
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_FORMULA);
|
||||
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VFORMULAS, 0, TELEM_FORMULA_LAST, GET_DEFAULT(sensor->formula),
|
||||
[=](uint8_t newValue) {
|
||||
sensor->formula = newValue;
|
||||
sensor->param = 0;
|
||||
if (sensor->formula == TELEM_FORMULA_CELL) {
|
||||
sensor->unit = UNIT_VOLTS;
|
||||
sensor->prec = 2;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
||||
sensor->unit = UNIT_DIST;
|
||||
sensor->prec = 0;
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
|
||||
sensor->unit = UNIT_MAH;
|
||||
sensor->prec = 0;
|
||||
}
|
||||
SET_DIRTY();
|
||||
telemetryItems[index].clear();
|
||||
updateSensorOneWindow();
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
else {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_ID);
|
||||
auto hex = new NumberEdit(sensorOneWindow, grid.getFieldSlot(2, 0), 0, 0xffff, GET_SET_DEFAULT(sensor->id));
|
||||
hex->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawHexNumber(dc, 2, 2, value, 0);
|
||||
});
|
||||
new NumberEdit(sensorOneWindow, grid.getFieldSlot(2, 1), 0, 0xff, GET_SET_DEFAULT(sensor->instance));
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Unit
|
||||
if ((sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_DIST)) || sensor->isConfigurable()) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_UNIT);
|
||||
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VTELEMUNIT, 0, UNIT_MAX, GET_DEFAULT(sensor->unit),
|
||||
[=](uint8_t newValue) {
|
||||
sensor->unit = newValue;
|
||||
if (sensor->unit == UNIT_FAHRENHEIT) {
|
||||
sensor->prec = 0;
|
||||
}
|
||||
SET_DIRTY();
|
||||
telemetryItems[index].clear();
|
||||
updateSensorOneWindow();
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Precision
|
||||
if (sensor->isPrecConfigurable() && sensor->unit != UNIT_FAHRENHEIT) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_PRECISION);
|
||||
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VPREC, 0, 2, GET_DEFAULT(sensor->prec),
|
||||
[=](uint8_t newValue) {
|
||||
sensor->prec = newValue;
|
||||
SET_DIRTY();
|
||||
telemetryItems[index].clear();
|
||||
updateSensorOneWindow();
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Params
|
||||
if (sensor->unit < UNIT_FIRST_VIRTUAL) {
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
if (sensor->formula == TELEM_FORMULA_CELL) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_CELLSENSOR);
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->cell.source, isCellsSensor);
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_GPSSENSOR);
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->dist.gps, isGPSSensor);
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_CONSUMPTION) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_CURRENTSENSOR);
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable);
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_TOTALIZE) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE);
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->consumption.source, isSensorAvailable);
|
||||
}
|
||||
else {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(1));
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[0], isSensorAvailable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (sensor->unit == UNIT_RPMS) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_BLADES);
|
||||
new NumberEdit(sensorOneWindow, grid.getFieldSlot(), 1, 30000, GET_SET_DEFAULT(sensor->custom.ratio));
|
||||
}
|
||||
else {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_RATIO);
|
||||
auto edit = new NumberEdit(sensorOneWindow, grid.getFieldSlot(), 0, 30000, GET_SET_DEFAULT(sensor->custom.ratio));
|
||||
edit->setZeroText("-");
|
||||
}
|
||||
}
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
if (!(sensor->unit == UNIT_GPS || sensor->unit == UNIT_DATETIME || sensor->unit == UNIT_CELLS ||
|
||||
(sensor->type == TELEM_TYPE_CALCULATED && (sensor->formula == TELEM_FORMULA_CONSUMPTION || sensor->formula == TELEM_FORMULA_TOTALIZE)))) {
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
if (sensor->formula == TELEM_FORMULA_CELL) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_CELLINDEX);
|
||||
new Choice(sensorOneWindow, grid.getFieldSlot(), STR_VCELLINDEX, 0, 8, GET_SET_DEFAULT(sensor->cell.index));
|
||||
}
|
||||
else if (sensor->formula == TELEM_FORMULA_DIST) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_ALTSENSOR);
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), &sensor->dist.alt, isAltSensor);
|
||||
}
|
||||
else {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(2));
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[1], isSensorAvailable);
|
||||
}
|
||||
}
|
||||
else if (sensor->unit == UNIT_RPMS) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_MULTIPLIER);
|
||||
new NumberEdit(sensorOneWindow, grid.getFieldSlot(), 1, 30000, GET_SET_DEFAULT(sensor->custom.offset));
|
||||
}
|
||||
else {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_OFFSET);
|
||||
new NumberEdit(sensorOneWindow, grid.getFieldSlot(), -30000, 30000, GET_SET_DEFAULT(sensor->custom.offset),
|
||||
(sensor->prec > 0) ? (sensor->prec == 2 ? PREC2 : PREC1) : 0);
|
||||
}
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
if ((sensor->type == TELEM_TYPE_CALCULATED && sensor->formula < TELEM_FORMULA_MULTIPLY)) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(3));
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[2], isSensorAvailable);
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_SOURCE + std::to_string(4));
|
||||
new SensorSourceChoice(sensorOneWindow, grid.getFieldSlot(), (uint8_t *) &sensor->calc.sources[3], isSensorAvailable);
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Auto Offset
|
||||
if (sensor->unit != UNIT_RPMS && sensor->isConfigurable()) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_AUTOOFFSET);
|
||||
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->autoOffset));
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
if (sensor->isConfigurable()) {
|
||||
// Only positive
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_ONLYPOSITIVE);
|
||||
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->onlyPositive));
|
||||
grid.nextLine();
|
||||
|
||||
// Filter
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_FILTER);
|
||||
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(sensor->filter));
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_PERSISTENT);
|
||||
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_DEFAULT(sensor->persistent), [=](int32_t newValue) {
|
||||
sensor->persistent = newValue;
|
||||
if (!sensor->persistent)
|
||||
sensor->persistentValue = 0;
|
||||
SET_DIRTY();
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
new StaticText(sensorOneWindow, grid.getLabelSlot(), STR_LOGS);
|
||||
new CheckBox(sensorOneWindow, grid.getFieldSlot(), GET_DEFAULT(sensor->logs), [=](int32_t newValue) {
|
||||
sensor->logs = newValue;
|
||||
logsClose();
|
||||
SET_DIRTY();
|
||||
});
|
||||
|
||||
coord_t delta = sensorOneWindow->adjustHeight();
|
||||
Window * parent = sensorOneWindow->getParent();
|
||||
parent->moveWindowsTop(sensorOneWindow->top(), delta);
|
||||
}
|
||||
|
||||
void buildBody(Window * window)
|
||||
{
|
||||
// Sensor one
|
||||
FormGridLayout grid;
|
||||
grid.spacer(8);
|
||||
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[index];
|
||||
|
||||
// Name
|
||||
new StaticText(window, grid.getLabelSlot(), STR_NAME);
|
||||
new TextEdit(window, grid.getFieldSlot(), sensor->label, TELEM_LABEL_LEN);
|
||||
grid.nextLine();
|
||||
|
||||
// Type
|
||||
new StaticText(window, grid.getLabelSlot(), STR_TYPE);
|
||||
new Choice(window, grid.getFieldSlot(), STR_VSENSORTYPES, 0, 1, GET_DEFAULT(sensor->type),
|
||||
[=](uint8_t newValue) {
|
||||
sensor->type = newValue;
|
||||
sensor->instance = 0;
|
||||
if (sensor->type == TELEM_TYPE_CALCULATED) {
|
||||
sensor->param = 0;
|
||||
sensor->filter = 0;
|
||||
sensor->autoOffset = 0;
|
||||
}
|
||||
SET_DIRTY();
|
||||
updateSensorOneWindow();
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
sensorOneWindow = new Window(window, {0, grid.getWindowHeight(), LCD_W, 0});
|
||||
updateSensorOneWindow();
|
||||
grid.addWindow(sensorOneWindow);
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
};
|
||||
|
||||
ModelTelemetryPage::ModelTelemetryPage() :
|
||||
PageTab(STR_MENUTELEMETRY, ICON_MODEL_TELEMETRY)
|
||||
{
|
||||
}
|
||||
|
||||
void ModelTelemetryPage::checkEvents()
|
||||
{
|
||||
if (lastKnownIndex != availableTelemetryIndex()) {
|
||||
lastKnownIndex = availableTelemetryIndex();
|
||||
rebuild(window);
|
||||
}
|
||||
|
||||
PageTab::checkEvents();
|
||||
}
|
||||
|
||||
void ModelTelemetryPage::rebuild(FormWindow * window, int8_t focusSensorIndex)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window, focusSensorIndex);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
|
||||
void ModelTelemetryPage::editSensor(FormWindow * window, uint8_t index)
|
||||
{
|
||||
Window * editWindow = new SensorEditWindow(index);
|
||||
editWindow->setCloseHandler([=]() {
|
||||
rebuild(window, index);
|
||||
});
|
||||
}
|
||||
|
||||
void ModelTelemetryPage::build(FormWindow * window, int8_t focusSensorIndex)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(8);
|
||||
grid.setLabelWidth(250);
|
||||
|
||||
this->window = window;
|
||||
|
||||
// RSSI
|
||||
if (g_model.moduleData[EXTERNAL_MODULE].type == MODULE_TYPE_MULTIMODULE &&
|
||||
g_model.moduleData[EXTERNAL_MODULE].getMultiProtocol(false) == MODULE_SUBTYPE_MULTI_FS_AFHDS2A)
|
||||
new Subtitle(window, grid.getLineSlot(), "RSNR");
|
||||
else
|
||||
new Subtitle(window, grid.getLineSlot(), "RSSI");
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_LOWALARM);
|
||||
auto edit = new NumberEdit(window, grid.getFieldSlot(), -30, 30, GET_SET_DEFAULT(g_model.rssiAlarms.warning));
|
||||
edit->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, g_model.rssiAlarms.getWarningRssi(), flags);
|
||||
});
|
||||
window->setFirstField(edit);
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_CRITICALALARM);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(), -30, 30, GET_SET_DEFAULT(g_model.rssiAlarms.critical));
|
||||
edit->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, 2, 2, g_model.rssiAlarms.getCriticalRssi(), flags);
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_DISABLE_ALARM);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_model.rssiAlarms.disabled));
|
||||
grid.nextLine();
|
||||
|
||||
// Sensors
|
||||
grid.setLabelWidth(140);
|
||||
new Subtitle(window, grid.getLineSlot(), STR_TELEMETRY_SENSORS);
|
||||
new StaticText(window, {SENSOR_COL2, grid.getWindowHeight() + 3, SENSOR_COL3 - SENSOR_COL2, PAGE_LINE_HEIGHT}, STR_VALUE, SMLSIZE | TEXT_DISABLE_COLOR);
|
||||
if (!g_model.ignoreSensorIds && !IS_SPEKTRUM_PROTOCOL())
|
||||
new StaticText(window, {SENSOR_COL3, grid.getWindowHeight() + 3, LCD_W - SENSOR_COL3, PAGE_LINE_HEIGHT}, STR_ID, SMLSIZE | TEXT_DISABLE_COLOR);
|
||||
grid.nextLine();
|
||||
|
||||
for (uint8_t idx = 0; idx < MAX_TELEMETRY_SENSORS; idx++) {
|
||||
if (g_model.telemetrySensors[idx].isAvailable()) {
|
||||
Button * button = new SensorButton(window, grid.getLineSlot(), idx);
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
button->bringToTop();
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
editSensor(window, idx);
|
||||
});
|
||||
menu->addLine(STR_COPY, [=]() {
|
||||
auto newIndex = availableTelemetryIndex();
|
||||
if (newIndex >= 0) {
|
||||
TelemetrySensor &sourceSensor = g_model.telemetrySensors[idx];
|
||||
TelemetrySensor &newSensor = g_model.telemetrySensors[newIndex];
|
||||
newSensor = sourceSensor;
|
||||
TelemetryItem &sourceItem = telemetryItems[idx];
|
||||
TelemetryItem &newItem = telemetryItems[newIndex];
|
||||
newItem = sourceItem;
|
||||
SET_DIRTY();
|
||||
rebuild(window, newIndex);
|
||||
}
|
||||
else {
|
||||
new FullScreenDialog(WARNING_TYPE_ALERT, "", STR_TELEMETRYFULL);
|
||||
}
|
||||
});
|
||||
menu->addLine(STR_DELETE, [=]() {
|
||||
delTelemetryIndex(idx); // calls setDirty internally
|
||||
rebuild(window);
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
if (focusSensorIndex == idx) {
|
||||
button->setFocus();
|
||||
}
|
||||
grid.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
// Autodiscover button
|
||||
auto discover = new TextButton(window, grid.getLineSlot(), STR_DISCOVER_SENSORS);
|
||||
discover->setPressHandler([=]() {
|
||||
allowNewSensors = !allowNewSensors;
|
||||
if (allowNewSensors) {
|
||||
discover->setText(STR_STOP_DISCOVER_SENSORS);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
discover->setText(STR_DISCOVER_SENSORS);
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// New sensor button
|
||||
new TextButton(window, grid.getLineSlot(), STR_TELEMETRY_NEWSENSOR,
|
||||
[=]() -> uint8_t {
|
||||
int res = availableTelemetryIndex();
|
||||
if (res >= 0)
|
||||
editSensor(window, res);
|
||||
else
|
||||
new FullScreenDialog(WARNING_TYPE_ALERT, "", STR_TELEMETRYFULL);
|
||||
return 0;
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// Delete all sensors button
|
||||
new TextButton(window, grid.getLineSlot(), STR_DELETE_ALL_SENSORS,
|
||||
[]() -> uint8_t {
|
||||
new FullScreenDialog(WARNING_TYPE_CONFIRM, STR_CONFIRMDELETE, "", [=]() {
|
||||
for (int i = 0; i < MAX_TELEMETRY_SENSORS; i++) {
|
||||
delTelemetryIndex(i);
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// Ignore instance button
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_IGNORE_INSTANCE);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_model.ignoreSensorIds));
|
||||
grid.nextLine();
|
||||
|
||||
// Vario
|
||||
grid.setLabelWidth(100);
|
||||
new Subtitle(window, grid.getLineSlot(), STR_VARIO);
|
||||
grid.nextLine();
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_SOURCE);
|
||||
auto choice = new SourceChoice(window, grid.getFieldSlot(), MIXSRC_NONE, MIXSRC_LAST_TELEM,
|
||||
GET_DEFAULT(g_model.varioData.source ? MIXSRC_FIRST_TELEM + 3 * (g_model.varioData.source - 1) : MIXSRC_NONE),
|
||||
SET_VALUE(g_model.varioData.source, newValue == MIXSRC_NONE ? 0 : (newValue - MIXSRC_FIRST_TELEM) / 3 + 1));
|
||||
choice->setAvailableHandler([=](int16_t value) {
|
||||
if (value == MIXSRC_NONE)
|
||||
return true;
|
||||
if (value < MIXSRC_FIRST_TELEM)
|
||||
return false;
|
||||
auto qr = div(value - MIXSRC_FIRST_TELEM, 3);
|
||||
return qr.rem == 0 && isSensorAvailable(qr.quot + 1);
|
||||
});
|
||||
grid.nextLine();
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_RANGE);
|
||||
new NumberEdit(window, grid.getFieldSlot(2, 0), -7, 7, GET_SET_WITH_OFFSET(g_model.varioData.min, -10));
|
||||
new NumberEdit(window, grid.getFieldSlot(2, 1), -7, 7, GET_SET_WITH_OFFSET(g_model.varioData.max, 10));
|
||||
grid.nextLine();
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_CENTER);
|
||||
new NumberEdit(window, grid.getFieldSlot(3, 0), -7, 7, GET_SET_WITH_OFFSET(g_model.varioData.min, -5), PREC1);
|
||||
new NumberEdit(window, grid.getFieldSlot(3, 1), -7, 7, GET_SET_WITH_OFFSET(g_model.varioData.max, 5), PREC1);
|
||||
new Choice(window, grid.getFieldSlot(3, 2), STR_VVARIOCENTER, 0, 1, GET_SET_DEFAULT(g_model.varioData.centerSilent));
|
||||
grid.nextLine();
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MODEL_TELEMETRY_H
|
||||
#define _MODEL_TELEMETRY_H
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class ModelTelemetryPage: public PageTab {
|
||||
public:
|
||||
ModelTelemetryPage();
|
||||
|
||||
virtual void build(FormWindow * window) override
|
||||
{
|
||||
build(window, -1);
|
||||
}
|
||||
|
||||
void checkEvents() override;
|
||||
|
||||
protected:
|
||||
FormWindow * window = nullptr;
|
||||
void editSensor(FormWindow * window, uint8_t index);
|
||||
int lastKnownIndex = 0;
|
||||
void build(FormWindow * window, int8_t focusSensorIndex=-1);
|
||||
void rebuild(FormWindow * window, int8_t focusSensorIndex=-1);
|
||||
};
|
||||
|
||||
#endif //_MODEL_TELEMETRY_H
|
||||
@@ -0,0 +1,572 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "modelslist.h"
|
||||
using std::list;
|
||||
|
||||
ModelsList modelslist;
|
||||
|
||||
ModelCell::ModelCell(const char * name)
|
||||
: buffer(NULL), valid_rfData(false)
|
||||
{
|
||||
strncpy(modelFilename, name, sizeof(modelFilename));
|
||||
memset(modelName, 0, sizeof(modelName));
|
||||
}
|
||||
|
||||
ModelCell::~ModelCell()
|
||||
{
|
||||
resetBuffer();
|
||||
}
|
||||
|
||||
void ModelCell::setModelName(char* name)
|
||||
{
|
||||
zchar2str(modelName, name, LEN_MODEL_NAME);
|
||||
if (modelName[0] == 0) {
|
||||
char * tmp;
|
||||
strncpy(modelName, modelFilename, LEN_MODEL_NAME);
|
||||
tmp = (char *) memchr(modelName, '.', LEN_MODEL_NAME);
|
||||
if (tmp != NULL)
|
||||
*tmp = 0;
|
||||
}
|
||||
|
||||
resetBuffer();
|
||||
}
|
||||
|
||||
void ModelCell::setModelId(uint8_t moduleIdx, uint8_t id)
|
||||
{
|
||||
modelId[moduleIdx] = id;
|
||||
}
|
||||
|
||||
void ModelCell::resetBuffer()
|
||||
{
|
||||
if (buffer) {
|
||||
delete buffer;
|
||||
buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const BitmapBuffer * ModelCell::getBuffer()
|
||||
{
|
||||
if (!buffer) {
|
||||
loadBitmap();
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void ModelCell::loadBitmap()
|
||||
{
|
||||
uint8_t version;
|
||||
|
||||
PACK(struct {
|
||||
ModelHeader header;
|
||||
TimerData timers[MAX_TIMERS];
|
||||
}) partialmodel;
|
||||
const char * error = NULL;
|
||||
|
||||
if (strncmp(modelFilename, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME) == 0) {
|
||||
memcpy(&partialmodel.header, &g_model.header, sizeof(partialmodel));
|
||||
}
|
||||
else {
|
||||
error = readModel(modelFilename, (uint8_t *)&partialmodel.header, sizeof(partialmodel), &version);
|
||||
// LEN_BITMAP_NAME has now 4 bytes more
|
||||
if (version <= 218) {
|
||||
memmove(partialmodel.timers, &(partialmodel.header.bitmap[10]), sizeof(TimerData)*MAX_TIMERS);
|
||||
memclear(&(partialmodel.header.bitmap[10]), 4);
|
||||
}
|
||||
}
|
||||
|
||||
if ((modelName[0] == 0) && ! error)
|
||||
setModelName(partialmodel.header.name); // resets buffer!!!
|
||||
|
||||
buffer = new BitmapBuffer(BMP_RGB565, MODELCELL_WIDTH, MODELCELL_HEIGHT);
|
||||
if (buffer == NULL) {
|
||||
return;
|
||||
}
|
||||
buffer->clear(TEXT_BGCOLOR);
|
||||
|
||||
if (error) {
|
||||
buffer->drawText(5, 2, "(Invalid Model)", TEXT_COLOR);
|
||||
buffer->drawBitmapPattern(5, 23, LBM_LIBRARY_SLOT, TEXT_COLOR);
|
||||
}
|
||||
else {
|
||||
char timer[LEN_TIMER_STRING];
|
||||
buffer->drawSizedText(5, 2, modelName, LEN_MODEL_NAME, SMLSIZE|TEXT_COLOR);
|
||||
getTimerString(timer, 0);
|
||||
for (uint8_t i = 0; i < MAX_TIMERS; i++) {
|
||||
if (partialmodel.timers[i].mode > 0 && partialmodel.timers[i].persistent) {
|
||||
getTimerString(timer, partialmodel.timers[i].value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
buffer->drawText(101, 40, timer, TEXT_COLOR);
|
||||
for (int i=0; i<4; i++) {
|
||||
buffer->drawBitmapPattern(104+i*11, 25, LBM_SCORE0, TITLE_BGCOLOR);
|
||||
}
|
||||
GET_FILENAME(filename, BITMAPS_PATH, partialmodel.header.bitmap, "");
|
||||
const BitmapBuffer * bitmap = BitmapBuffer::load(filename);
|
||||
if (bitmap) {
|
||||
buffer->drawScaledBitmap(bitmap, 5, 24, 56, 32);
|
||||
delete bitmap;
|
||||
}
|
||||
else {
|
||||
buffer->drawBitmapPattern(5, 23, LBM_LIBRARY_SLOT, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
buffer->drawSolidHorizontalLine(5, 19, 143, LINE_COLOR);
|
||||
}
|
||||
|
||||
void ModelCell::save(FIL* file)
|
||||
{
|
||||
f_puts(modelFilename, file);
|
||||
f_putc('\n', file);
|
||||
}
|
||||
|
||||
void ModelCell::setRfData(ModelData* model)
|
||||
{
|
||||
for (uint8_t i = 0; i < NUM_MODULES; i++) {
|
||||
modelId[i] = model->header.modelId[i];
|
||||
setRfModuleData(i, &(model->moduleData[i]));
|
||||
TRACE("<%s/%i> : %X,%X,%X",
|
||||
strlen(modelName) ? modelName : modelFilename,
|
||||
i, moduleData[i].type, moduleData[i].rfProtocol, modelId[i]);
|
||||
}
|
||||
valid_rfData = true;
|
||||
}
|
||||
|
||||
void ModelCell::setRfModuleData(uint8_t moduleIdx, ModuleData* modData)
|
||||
{
|
||||
moduleData[moduleIdx].type = modData->type;
|
||||
if (modData->type != MODULE_TYPE_MULTIMODULE) {
|
||||
moduleData[moduleIdx].rfProtocol = (uint8_t)modData->rfProtocol;
|
||||
}
|
||||
else {
|
||||
// do we care here about MM_RF_CUSTOM_SELECTED? probably not...
|
||||
moduleData[moduleIdx].rfProtocol = modData->getMultiProtocol(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool ModelCell::fetchRfData()
|
||||
{
|
||||
//TODO: use g_model in case fetching data for current model
|
||||
//
|
||||
char buf[256];
|
||||
getModelPath(buf, modelFilename);
|
||||
|
||||
FIL file;
|
||||
uint16_t size;
|
||||
uint8_t version;
|
||||
|
||||
const char * err = openFile(buf, &file, &size, &version);
|
||||
if (err || version != EEPROM_VER) return false;
|
||||
|
||||
FSIZE_t start_offset = f_tell(&file);
|
||||
|
||||
UINT read;
|
||||
if ((f_read(&file, buf, LEN_MODEL_NAME, &read) != FR_OK) || (read != LEN_MODEL_NAME))
|
||||
goto error;
|
||||
|
||||
setModelName(buf);
|
||||
|
||||
// 1. fetch modelId: NUM_MODULES @ offsetof(ModelHeader, modelId)
|
||||
// if (f_lseek(&file, start_offset + offsetof(ModelHeader, modelId)) != FR_OK)
|
||||
// goto error;
|
||||
if ((f_read(&file, modelId, NUM_MODULES, &read) != FR_OK) || (read != NUM_MODULES))
|
||||
goto error;
|
||||
|
||||
// 2. fetch ModuleData: sizeof(ModuleData)*NUM_MODULES @ offsetof(ModelData, moduleData)
|
||||
if (f_lseek(&file, start_offset + offsetof(ModelData, moduleData)) != FR_OK)
|
||||
goto error;
|
||||
|
||||
for(uint8_t i=0; i<NUM_MODULES; i++) {
|
||||
ModuleData modData;
|
||||
if ((f_read(&file, &modData, NUM_MODULES, &read) != FR_OK) || (read != NUM_MODULES))
|
||||
goto error;
|
||||
|
||||
setRfModuleData(i, &modData);
|
||||
}
|
||||
|
||||
valid_rfData = true;
|
||||
f_close(&file);
|
||||
return true;
|
||||
|
||||
error:
|
||||
f_close(&file);
|
||||
return false;
|
||||
}
|
||||
|
||||
ModelsCategory::ModelsCategory(const char * name)
|
||||
{
|
||||
strncpy(this->name, name, sizeof(this->name));
|
||||
}
|
||||
|
||||
ModelsCategory::~ModelsCategory()
|
||||
{
|
||||
for (list<ModelCell *>::iterator it = begin(); it != end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ModelCell * ModelsCategory::addModel(const char * name)
|
||||
{
|
||||
ModelCell * result = new ModelCell(name);
|
||||
push_back(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ModelsCategory::removeModel(ModelCell * model)
|
||||
{
|
||||
delete model;
|
||||
remove(model);
|
||||
}
|
||||
|
||||
void ModelsCategory::moveModel(ModelCell * model, int8_t step)
|
||||
{
|
||||
ModelsCategory::iterator current = begin();
|
||||
for (; current != end(); current++) {
|
||||
if (*current == model) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ModelsCategory::iterator new_position = current;
|
||||
if (step > 0) {
|
||||
while (step >= 0 && new_position != end()) {
|
||||
new_position++;
|
||||
step--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
while (step < 0 && new_position != begin()) {
|
||||
new_position--;
|
||||
step++;
|
||||
}
|
||||
}
|
||||
|
||||
insert(new_position, 1, *current);
|
||||
erase(current);
|
||||
}
|
||||
|
||||
void ModelsCategory::save(FIL * file)
|
||||
{
|
||||
f_puts("[", file);
|
||||
f_puts(name, file);
|
||||
f_puts("]", file);
|
||||
f_putc('\n', file);
|
||||
for (list<ModelCell *>::iterator it = begin(); it != end(); ++it) {
|
||||
(*it)->save(file);
|
||||
}
|
||||
}
|
||||
|
||||
ModelsList::ModelsList()
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
ModelsList::~ModelsList()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void ModelsList::init()
|
||||
{
|
||||
loaded = false;
|
||||
currentCategory = NULL;
|
||||
currentModel = NULL;
|
||||
modelsCount = 0;
|
||||
}
|
||||
|
||||
void ModelsList::clear()
|
||||
{
|
||||
for (list<ModelsCategory *>::iterator it = categories.begin(); it != categories.end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
categories.clear();
|
||||
init();
|
||||
}
|
||||
|
||||
bool ModelsList::load()
|
||||
{
|
||||
char line[LEN_MODELS_IDX_LINE+1];
|
||||
ModelsCategory * category = NULL;
|
||||
|
||||
if (loaded)
|
||||
return true;
|
||||
|
||||
FRESULT result = f_open(&file, RADIO_MODELSLIST_PATH, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result == FR_OK) {
|
||||
while (readNextLine(line, LEN_MODELS_IDX_LINE)) {
|
||||
int len = strlen(line); // TODO could be returned by readNextLine
|
||||
if (len > 2 && line[0] == '[' && line[len-1] == ']') {
|
||||
line[len-1] = '\0';
|
||||
category = new ModelsCategory(&line[1]);
|
||||
categories.push_back(category);
|
||||
}
|
||||
else if (len > 0) {
|
||||
|
||||
//char* rf_data_str = cutModelFilename(line);
|
||||
ModelCell * model = new ModelCell(line);
|
||||
if (!category) {
|
||||
category = new ModelsCategory("Models");
|
||||
categories.push_back(category);
|
||||
}
|
||||
category->push_back(model);
|
||||
if (!strncmp(line, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME)) {
|
||||
currentCategory = category;
|
||||
currentModel = model;
|
||||
}
|
||||
//parseModulesData(model, rf_data_str);
|
||||
//TRACE("model=<%s>, valid_rfData=<%i>",model->modelFilename,model->valid_rfData);
|
||||
model->fetchRfData();
|
||||
modelsCount += 1;
|
||||
}
|
||||
}
|
||||
f_close(&file);
|
||||
|
||||
if (!getCurrentModel()) {
|
||||
TRACE("currentModel is NULL");
|
||||
}
|
||||
}
|
||||
|
||||
if (categories.size() == 0) {
|
||||
category = new ModelsCategory("Models");
|
||||
categories.push_back(category);
|
||||
}
|
||||
|
||||
loaded = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ModelsList::save()
|
||||
{
|
||||
FRESULT result = f_open(&file, RADIO_MODELSLIST_PATH, FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (result != FR_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (list<ModelsCategory *>::iterator it = categories.begin(); it != categories.end(); ++it) {
|
||||
(*it)->save(&file);
|
||||
}
|
||||
|
||||
f_close(&file);
|
||||
}
|
||||
|
||||
void ModelsList::setCurrentCategorie(ModelsCategory* cat)
|
||||
{
|
||||
currentCategory = cat;
|
||||
}
|
||||
|
||||
void ModelsList::setCurrentModel(ModelCell* cell)
|
||||
{
|
||||
currentModel = cell;
|
||||
if (!currentModel->valid_rfData)
|
||||
currentModel->fetchRfData();
|
||||
}
|
||||
|
||||
bool ModelsList::readNextLine(char * line, int maxlen)
|
||||
{
|
||||
if (f_gets(line, maxlen, &file) != NULL) {
|
||||
int curlen = strlen(line) - 1;
|
||||
if (line[curlen] == '\n') { // remove unwanted chars if file was edited using windows
|
||||
if (line[curlen - 1] == '\r') {
|
||||
line[curlen - 1] = 0;
|
||||
}
|
||||
else {
|
||||
line[curlen] = 0;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ModelsCategory * ModelsList::createCategory()
|
||||
{
|
||||
ModelsCategory * result = new ModelsCategory("Category");
|
||||
categories.push_back(result);
|
||||
save();
|
||||
return result;
|
||||
}
|
||||
|
||||
ModelCell * ModelsList::addModel(ModelsCategory * category, const char * name)
|
||||
{
|
||||
ModelCell * result = category->addModel(name);
|
||||
modelsCount++;
|
||||
save();
|
||||
return result;
|
||||
}
|
||||
|
||||
void ModelsList::removeCategory(ModelsCategory * category)
|
||||
{
|
||||
modelsCount -= category->size();
|
||||
delete category;
|
||||
categories.remove(category);
|
||||
}
|
||||
|
||||
void ModelsList::removeModel(ModelsCategory * category, ModelCell * model)
|
||||
{
|
||||
category->removeModel(model);
|
||||
modelsCount--;
|
||||
save();
|
||||
}
|
||||
|
||||
void ModelsList::moveModel(ModelsCategory * category, ModelCell * model, int8_t step)
|
||||
{
|
||||
category->moveModel(model, step);
|
||||
save();
|
||||
}
|
||||
|
||||
void ModelsList::moveModel(ModelCell * model, ModelsCategory * previous_category, ModelsCategory * new_category)
|
||||
{
|
||||
previous_category->remove(model);
|
||||
new_category->push_back(model);
|
||||
save();
|
||||
}
|
||||
|
||||
bool ModelsList::isModelIdUnique(uint8_t moduleIdx, char* warn_buf, size_t warn_buf_len)
|
||||
{
|
||||
ModelCell* mod_cell = modelslist.getCurrentModel();
|
||||
if (!mod_cell || !mod_cell->valid_rfData) {
|
||||
// in doubt, pretend it's unique
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t modelId = mod_cell->modelId[moduleIdx];
|
||||
uint8_t type = mod_cell->moduleData[moduleIdx].type;
|
||||
uint8_t rfProtocol = mod_cell->moduleData[moduleIdx].rfProtocol;
|
||||
|
||||
uint8_t additionalOnes = 0;
|
||||
char* curr = warn_buf;
|
||||
curr[0] = 0;
|
||||
|
||||
bool hit_found = false;
|
||||
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
|
||||
std::list<ModelsCategory*>::const_iterator cat_it = cats.begin();
|
||||
for (;cat_it != cats.end(); cat_it++) {
|
||||
for (ModelsCategory::const_iterator it = (*cat_it)->begin(); it != (*cat_it)->end(); it++) {
|
||||
if (mod_cell == *it)
|
||||
continue;
|
||||
|
||||
if (!(*it)->valid_rfData)
|
||||
continue;
|
||||
|
||||
if ((type != MODULE_TYPE_NONE) &&
|
||||
(type == (*it)->moduleData[moduleIdx].type) &&
|
||||
(rfProtocol == (*it)->moduleData[moduleIdx].rfProtocol) &&
|
||||
(modelId == (*it)->modelId[moduleIdx])) {
|
||||
|
||||
// Hit found!
|
||||
hit_found = true;
|
||||
|
||||
const char* modelName = (*it)->modelName;
|
||||
const char* modelFilename = (*it)->modelFilename;
|
||||
|
||||
// you cannot rely exactly on WARNING_LINE_LEN so using WARNING_LINE_LEN-2 (-2 for the ",")
|
||||
if ((warn_buf_len - 2 - (curr - warn_buf)) > LEN_MODEL_NAME) {
|
||||
if (warn_buf[0] != 0)
|
||||
curr = strAppend(curr, ", ");
|
||||
if (modelName[0] == 0) {
|
||||
size_t len = min<size_t>(strlen(modelFilename),LEN_MODEL_NAME);
|
||||
curr = strAppendFilename(curr, modelFilename, len);
|
||||
}
|
||||
else
|
||||
curr = strAppend(curr, modelName, LEN_MODEL_NAME);
|
||||
}
|
||||
else {
|
||||
additionalOnes++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (additionalOnes && (warn_buf_len - (curr - warn_buf) >= 7)) {
|
||||
curr = strAppend(curr, " (+");
|
||||
curr = strAppendUnsigned(curr, additionalOnes);
|
||||
curr = strAppend(curr, ")");
|
||||
}
|
||||
|
||||
return !hit_found;
|
||||
}
|
||||
|
||||
uint8_t ModelsList::findNextUnusedModelId(uint8_t moduleIdx)
|
||||
{
|
||||
ModelCell* mod_cell = modelslist.getCurrentModel();
|
||||
if (!mod_cell || !mod_cell->valid_rfData) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t type = mod_cell->moduleData[moduleIdx].type;
|
||||
uint8_t rfProtocol = mod_cell->moduleData[moduleIdx].rfProtocol;
|
||||
|
||||
// assume 63 is the highest Model ID
|
||||
// and use 64 bits
|
||||
uint8_t usedModelIds[8];
|
||||
memset(usedModelIds, 0, sizeof(usedModelIds));
|
||||
|
||||
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
|
||||
std::list<ModelsCategory*>::const_iterator cat_it = cats.begin();
|
||||
for (;cat_it != cats.end(); cat_it++) {
|
||||
for (ModelsCategory::const_iterator it = (*cat_it)->begin(); it != (*cat_it)->end(); it++) {
|
||||
if (mod_cell == *it)
|
||||
continue;
|
||||
|
||||
if (!(*it)->valid_rfData)
|
||||
continue;
|
||||
|
||||
// match module type and RF protocol
|
||||
if ((type != MODULE_TYPE_NONE) &&
|
||||
(type == (*it)->moduleData[moduleIdx].type) &&
|
||||
(rfProtocol == (*it)->moduleData[moduleIdx].rfProtocol)) {
|
||||
|
||||
uint8_t id = (*it)->modelId[moduleIdx];
|
||||
|
||||
uint8_t mask = 1;
|
||||
for (uint8_t i = 1; i < (id & 7); i++)
|
||||
mask <<= 1;
|
||||
|
||||
usedModelIds[id >> 3] |= mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t new_id = 1;
|
||||
uint8_t tst_mask = 1;
|
||||
for (;new_id < getMaxRxNum(moduleIdx); new_id++) {
|
||||
if (!(usedModelIds[new_id >> 3] & tst_mask)) {
|
||||
// found free ID
|
||||
return new_id;
|
||||
}
|
||||
if ((tst_mask <<= 1) == 0)
|
||||
tst_mask = 1;
|
||||
}
|
||||
|
||||
// failed finding something...
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ModelsList::onNewModelCreated(ModelCell* cell, ModelData* model)
|
||||
{
|
||||
cell->setModelName(model->header.name);
|
||||
cell->setRfData(model);
|
||||
|
||||
uint8_t new_id = findNextUnusedModelId(INTERNAL_MODULE);
|
||||
model->header.modelId[INTERNAL_MODULE] = new_id;
|
||||
cell->setModelId(INTERNAL_MODULE, new_id);
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _MODELSLIST_H_
|
||||
#define _MODELSLIST_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <list>
|
||||
#include "sdcard.h"
|
||||
|
||||
#define MODELCELL_WIDTH 172
|
||||
#define MODELCELL_HEIGHT 59
|
||||
|
||||
// modelXXXXXXX.bin F,FF F,3F,FF\r\n
|
||||
#define LEN_MODELS_IDX_LINE (LEN_MODEL_FILENAME + sizeof(" F,FF F,3F,FF\r\n")-1)
|
||||
|
||||
struct SimpleModuleData
|
||||
{
|
||||
uint8_t type;
|
||||
uint8_t rfProtocol;
|
||||
};
|
||||
|
||||
class ModelCell
|
||||
{
|
||||
public:
|
||||
char modelFilename[LEN_MODEL_FILENAME+1];
|
||||
char modelName[LEN_MODEL_NAME+1];
|
||||
BitmapBuffer * buffer;
|
||||
|
||||
bool valid_rfData;
|
||||
uint8_t modelId[NUM_MODULES];
|
||||
SimpleModuleData moduleData[NUM_MODULES];
|
||||
|
||||
ModelCell(const char * name);
|
||||
~ModelCell();
|
||||
|
||||
void save(FIL* file);
|
||||
|
||||
void setModelName(char* name);
|
||||
void setRfData(ModelData* model);
|
||||
|
||||
void setModelId(uint8_t moduleIdx, uint8_t id);
|
||||
void setRfModuleData(uint8_t moduleIdx, ModuleData* modData);
|
||||
|
||||
bool fetchRfData();
|
||||
void loadBitmap();
|
||||
const BitmapBuffer * getBuffer();
|
||||
void resetBuffer();
|
||||
};
|
||||
|
||||
class ModelsCategory: public std::list<ModelCell *>
|
||||
{
|
||||
public:
|
||||
char name[LEN_MODEL_FILENAME+1];
|
||||
|
||||
ModelsCategory(const char * name);
|
||||
~ModelsCategory();
|
||||
|
||||
ModelCell * addModel(const char * name);
|
||||
void removeModel(ModelCell * model);
|
||||
void moveModel(ModelCell * model, int8_t step);
|
||||
void save(FIL * file);
|
||||
};
|
||||
|
||||
class ModelsList
|
||||
{
|
||||
bool loaded;
|
||||
std::list<ModelsCategory *> categories;
|
||||
ModelsCategory * currentCategory;
|
||||
ModelCell * currentModel;
|
||||
unsigned int modelsCount;
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
|
||||
ModelsList();
|
||||
~ModelsList();
|
||||
|
||||
bool load();
|
||||
void save();
|
||||
void clear();
|
||||
|
||||
const std::list<ModelsCategory *>& getCategories() const {
|
||||
return categories;
|
||||
}
|
||||
|
||||
void setCurrentCategorie(ModelsCategory* cat);
|
||||
ModelsCategory* getCurrentCategory() const {
|
||||
return currentCategory;
|
||||
}
|
||||
|
||||
void setCurrentModel(ModelCell* cell);
|
||||
ModelCell* getCurrentModel() const {
|
||||
return currentModel;
|
||||
}
|
||||
|
||||
unsigned int getModelsCount() const {
|
||||
return modelsCount;
|
||||
}
|
||||
|
||||
bool readNextLine(char * line, int maxlen);
|
||||
|
||||
ModelsCategory * createCategory();
|
||||
void removeCategory(ModelsCategory * category);
|
||||
|
||||
ModelCell * addModel(ModelsCategory * category, const char * name);
|
||||
void removeModel(ModelsCategory * category, ModelCell * model);
|
||||
void moveModel(ModelsCategory * category, ModelCell * model, int8_t step);
|
||||
void moveModel(ModelCell * model, ModelsCategory * previous_category, ModelsCategory * new_category);
|
||||
|
||||
bool isModelIdUnique(uint8_t moduleIdx, char* warn_buf, size_t warn_buf_len);
|
||||
uint8_t findNextUnusedModelId(uint8_t moduleIdx);
|
||||
|
||||
void onNewModelCreated(ModelCell* cell, ModelData* model);
|
||||
|
||||
protected:
|
||||
FIL file;
|
||||
|
||||
};
|
||||
|
||||
extern ModelsList modelslist;
|
||||
|
||||
#endif // _MODELSLIST_H_
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _POPUPS_H_
|
||||
#define _POPUPS_H_
|
||||
|
||||
#include <functional>
|
||||
|
||||
typedef std::function<void(const char *, const char *, int, int)> ProgressHandler;
|
||||
|
||||
#endif // _POPUPS_H_
|
||||
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "radio_calibration.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define XPOT_DELTA 10
|
||||
#define XPOT_DELAY 5 /* cycles */
|
||||
|
||||
uint8_t menuCalibrationState;
|
||||
|
||||
class StickCalibrationWindow: public Window {
|
||||
public:
|
||||
StickCalibrationWindow(Window * parent, const rect_t & rect, uint8_t stickX, uint8_t stickY):
|
||||
Window(parent, rect, REFRESH_ALWAYS),
|
||||
stickX(stickX),
|
||||
stickY(stickY)
|
||||
{
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
dc->drawBitmap(0, 0, calibStickBackground);
|
||||
int16_t x = calibratedAnalogs[CONVERT_MODE(stickX)];
|
||||
int16_t y = calibratedAnalogs[CONVERT_MODE(stickY)];
|
||||
dc->drawBitmap(width() / 2 - 9 + (bitmapSize / 2 * x) / RESX, height() / 2 - 9 - (bitmapSize / 2 * y) / RESX, calibStick);
|
||||
}
|
||||
|
||||
protected:
|
||||
static constexpr coord_t bitmapSize = 68;
|
||||
uint8_t stickX, stickY;
|
||||
};
|
||||
|
||||
class MultiPosCalibrationWindow: public Window {
|
||||
public:
|
||||
MultiPosCalibrationWindow(Window * parent, const rect_t & rect, uint8_t potIndex):
|
||||
Window(parent, rect),
|
||||
potIndex(potIndex)
|
||||
{
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
// will always force a full monitor window refresh
|
||||
invalidate();
|
||||
}
|
||||
|
||||
virtual void paint(BitmapBuffer * dc)
|
||||
{
|
||||
drawHorizontalSlider(5, 8, rect.w - 18, 1 + (potsPos[potIndex] & 0x0f), 1, XPOTS_MULTIPOS_COUNT+1, XPOTS_MULTIPOS_COUNT, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_NUMBER_BUTTON);
|
||||
}
|
||||
|
||||
protected:
|
||||
static constexpr coord_t bitmapSize = 68;
|
||||
uint8_t potIndex;
|
||||
};
|
||||
|
||||
class PotCalibrationWindow: public Window {
|
||||
public:
|
||||
PotCalibrationWindow(Window * parent, const rect_t & rect, uint8_t potIndex):
|
||||
Window(parent, rect),
|
||||
potIndex(potIndex)
|
||||
{
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
// will always force a full monitor window refresh
|
||||
invalidate();
|
||||
}
|
||||
|
||||
virtual void paint(BitmapBuffer * dc)
|
||||
{
|
||||
if(rect.h > rect.w)
|
||||
drawVerticalSlider(5, 8, rect.h - 18, calibratedAnalogs[potIndex], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
else
|
||||
drawHorizontalSlider(5, 8, rect.w - 18, calibratedAnalogs[potIndex], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
}
|
||||
|
||||
protected:
|
||||
static constexpr coord_t bitmapSize = 68;
|
||||
uint8_t potIndex;
|
||||
};
|
||||
|
||||
RadioCalibrationPage::RadioCalibrationPage(bool initial):
|
||||
Page(ICON_RADIO_CALIBRATION),
|
||||
initial(initial)
|
||||
{
|
||||
buildHeader(&header);
|
||||
buildBody(&body);
|
||||
}
|
||||
|
||||
void RadioCalibrationPage::buildHeader(Window * window)
|
||||
{
|
||||
new StaticText(window, { 55, 0, 300, 20 }, STR_MENUCALIBRATION, MENU_TITLE_COLOR);
|
||||
text = new StaticText(window, { 55, FH+2, LCD_W-55, 20 }, STR_MENUTOSTART, MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void RadioCalibrationPage::buildBody(FormWindow * window)
|
||||
{
|
||||
menuCalibrationState = CALIB_START;
|
||||
|
||||
// Background radio image
|
||||
#if LCD_W > LCD_H
|
||||
new StaticBitmap(window, {LCD_W/2 -calibRadioPict->getWidth()/2, 5, calibRadioPict->getHeight(), calibRadioPict->getWidth()}, calibRadioPict);
|
||||
#else
|
||||
new StaticBitmap(window, {LCD_W/2 -calibRadioPict->getWidth()/2, LCD_H/2 -calibRadioPict->getHeight()/2, calibRadioPict->getHeight(), calibRadioPict->getWidth()}, calibRadioPict);
|
||||
#endif
|
||||
// The two sticks
|
||||
new StickCalibrationWindow(window, {40, 20, 90, 90}, STICK1, STICK2);
|
||||
new StickCalibrationWindow(window, {LCD_W-130, 20, 90, 90}, STICK4, STICK3);
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
// The 2 main sliders
|
||||
new PotCalibrationWindow(window, {0, 2, 20, 150}, SLIDER1);
|
||||
new PotCalibrationWindow(window, {LCD_W-20, 2, 20, 150}, SLIDER2);
|
||||
|
||||
// The 3 pots
|
||||
new PotCalibrationWindow(window, {0, window->height()-25, 150, 20}, POT1);
|
||||
new MultiPosCalibrationWindow(window, {LCD_W/2-25,window->height()-25, 50, 20}, POT2);
|
||||
new PotCalibrationWindow(window, {LCD_W-150, window->height()-25, 150, 20}, POT3);
|
||||
#elif defined(PCBNV14)
|
||||
new PotCalibrationWindow(window, {0, window->height()-25, 150, 20}, POT1);
|
||||
new PotCalibrationWindow(window, {LCD_W-150, window->height()-25, 150, 20}, POT2);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RadioCalibrationPage::checkEvents()
|
||||
{
|
||||
Page::checkEvents();
|
||||
|
||||
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_MOUSE_ANALOGS; i++) { // get low and high vals for sticks and trims
|
||||
int16_t vt = i<TX_VOLTAGE ? anaIn(i) : anaIn(i+1);
|
||||
reusableBuffer.calib.loVals[i] = min(vt, reusableBuffer.calib.loVals[i]);
|
||||
reusableBuffer.calib.hiVals[i] = max(vt, reusableBuffer.calib.hiVals[i]);
|
||||
if (i >= POT1 && i <= POT_LAST) {
|
||||
if (IS_POT_WITHOUT_DETENT(i)) {
|
||||
reusableBuffer.calib.midVals[i] = (reusableBuffer.calib.hiVals[i] + reusableBuffer.calib.loVals[i]) / 2;
|
||||
}
|
||||
#if NUM_XPOTS > 0
|
||||
uint8_t idx = i - POT1;
|
||||
int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount;
|
||||
if (IS_POT_MULTIPOS(i) && count <= XPOTS_MULTIPOS_COUNT) {
|
||||
// use raw analog value for multipos calibraton, anaIn() already has multipos decoded value
|
||||
vt = getAnalogValue(i) >> 1;
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].lastCount == 0 || vt < reusableBuffer.calib.xpotsCalib[idx].lastPosition - XPOT_DELTA || vt > reusableBuffer.calib.xpotsCalib[idx].lastPosition + XPOT_DELTA) {
|
||||
reusableBuffer.calib.xpotsCalib[idx].lastPosition = vt;
|
||||
reusableBuffer.calib.xpotsCalib[idx].lastCount = 1;
|
||||
}
|
||||
else {
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].lastCount < 255) {
|
||||
reusableBuffer.calib.xpotsCalib[idx].lastCount++;
|
||||
}
|
||||
}
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].lastCount == XPOT_DELAY) {
|
||||
int16_t position = reusableBuffer.calib.xpotsCalib[idx].lastPosition;
|
||||
bool found = false;
|
||||
for (int j=0; j<count; j++) {
|
||||
int16_t step = reusableBuffer.calib.xpotsCalib[idx].steps[j];
|
||||
if (position >= step-XPOT_DELTA && position <= step+XPOT_DELTA) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
if (count < XPOTS_MULTIPOS_COUNT) {
|
||||
reusableBuffer.calib.xpotsCalib[idx].steps[count] = position;
|
||||
}
|
||||
reusableBuffer.calib.xpotsCalib[idx].stepsCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (menuCalibrationState == CALIB_SET_MIDPOINT) {
|
||||
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS + NUM_MOUSE_ANALOGS; i++) {
|
||||
reusableBuffer.calib.loVals[i] = 15000;
|
||||
reusableBuffer.calib.hiVals[i] = -15000;
|
||||
reusableBuffer.calib.midVals[i] = i < TX_VOLTAGE ? anaIn(i) : anaIn(i + 1);
|
||||
#if NUM_XPOTS > 0
|
||||
if (i < NUM_XPOTS) {
|
||||
reusableBuffer.calib.xpotsCalib[i].stepsCount = 0;
|
||||
reusableBuffer.calib.xpotsCalib[i].lastCount = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (menuCalibrationState == CALIB_MOVE_STICKS) {
|
||||
for (uint8_t i = 0; i < NUM_STICKS + NUM_POTS + NUM_SLIDERS + NUM_MOUSE_ANALOGS; i++) {
|
||||
if (abs(reusableBuffer.calib.loVals[i] - reusableBuffer.calib.hiVals[i]) > 50) {
|
||||
g_eeGeneral.calib[i].mid = reusableBuffer.calib.midVals[i];
|
||||
int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i];
|
||||
g_eeGeneral.calib[i].spanNeg = v - v / STICK_TOLERANCE;
|
||||
v = reusableBuffer.calib.hiVals[i] - reusableBuffer.calib.midVals[i];
|
||||
g_eeGeneral.calib[i].spanPos = v - v / STICK_TOLERANCE;
|
||||
}
|
||||
}
|
||||
#if NUM_XPOTS > 0
|
||||
for (int i=POT1; i<=POT_LAST; i++) {
|
||||
int idx = i - POT1;
|
||||
int count = reusableBuffer.calib.xpotsCalib[idx].stepsCount;
|
||||
if (IS_POT_MULTIPOS(i)) {
|
||||
if (count > 1 && count <= XPOTS_MULTIPOS_COUNT) {
|
||||
for (int j=0; j<count; j++) {
|
||||
for (int k=j+1; k<count; k++) {
|
||||
if (reusableBuffer.calib.xpotsCalib[idx].steps[k] < reusableBuffer.calib.xpotsCalib[idx].steps[j]) {
|
||||
SWAP(reusableBuffer.calib.xpotsCalib[idx].steps[j], reusableBuffer.calib.xpotsCalib[idx].steps[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i];
|
||||
calib->count = count - 1;
|
||||
for (int j=0; j<calib->count; j++) {
|
||||
calib->steps[j] = (reusableBuffer.calib.xpotsCalib[idx].steps[j+1] + reusableBuffer.calib.xpotsCalib[idx].steps[j]) >> 5;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// g_eeGeneral.potsConfig &= ~(0x03<<(2*idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void RadioCalibrationPage::onKeyEvent(event_t event)
|
||||
{
|
||||
TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event);
|
||||
|
||||
if (event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
nextStep();
|
||||
}
|
||||
else if (event == EVT_KEY_BREAK(KEY_EXIT) && menuCalibrationState != CALIB_START)
|
||||
{
|
||||
menuCalibrationState = CALIB_START;
|
||||
text->setText(STR_MENUTOSTART);
|
||||
|
||||
}
|
||||
else {
|
||||
Page::onKeyEvent(event);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void RadioCalibrationPage::nextStep()
|
||||
{
|
||||
menuCalibrationState++;
|
||||
|
||||
switch (menuCalibrationState) {
|
||||
case CALIB_SET_MIDPOINT:
|
||||
text->setText(STR_SETMIDPOINT);
|
||||
break;
|
||||
|
||||
case CALIB_MOVE_STICKS:
|
||||
text->setText(STR_MOVESTICKSPOTS);
|
||||
break;
|
||||
|
||||
case CALIB_STORE:
|
||||
text->setText(STR_CALIB_DONE);
|
||||
g_eeGeneral.chkSum = evalChkSum();
|
||||
storageDirty(EE_GENERAL);
|
||||
menuCalibrationState = CALIB_FINISHED;
|
||||
if (initial)
|
||||
text->getParent()->getParent()->deleteLater();
|
||||
break;
|
||||
|
||||
default:
|
||||
text->setText(STR_MENUTOSTART);
|
||||
menuCalibrationState = CALIB_START;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void startCalibration()
|
||||
{
|
||||
new RadioCalibrationPage();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class StaticText;
|
||||
|
||||
class RadioCalibrationPage: public Page {
|
||||
public:
|
||||
RadioCalibrationPage(bool initial=false);
|
||||
|
||||
void checkEvents() override;
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onKeyEvent(event_t event) override;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
StaticText * text = nullptr;
|
||||
TextButton * button = nullptr;
|
||||
bool initial;
|
||||
void nextStep();
|
||||
void buildHeader(Window * window);
|
||||
void buildBody(FormWindow * window);
|
||||
};
|
||||
|
||||
void startCalibration();
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "radio_hardware.h"
|
||||
#include "radio_calibration.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_GENERAL)
|
||||
|
||||
#if defined(PCBHORUS)
|
||||
#define SWITCH_TYPE_MAX(sw) ((MIXSRC_SF-MIXSRC_FIRST_SWITCH == sw || MIXSRC_SH-MIXSRC_FIRST_SWITCH == sw) ? SWITCH_2POS : SWITCH_3POS)
|
||||
#else
|
||||
#define SWITCH_TYPE_MAX(sw) (SWITCH_3POS)
|
||||
#endif
|
||||
|
||||
class SwitchDynamicLabel : public StaticText {
|
||||
public:
|
||||
SwitchDynamicLabel(Window * parent, const rect_t & rect, uint8_t index):
|
||||
StaticText(parent, rect),
|
||||
index(index)
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
std::string label()
|
||||
{
|
||||
return TEXT_AT_INDEX(STR_VSRCRAW, (index + MIXSRC_FIRST_SWITCH - MIXSRC_Rud + 1)) + std::string(&"\300-\301"[lastpos], 1);
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
uint8_t newpos = position();
|
||||
if (newpos != lastpos) {
|
||||
lastpos = newpos;
|
||||
setText(label());
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t position()
|
||||
{
|
||||
auto value = getValue(MIXSRC_FIRST_SWITCH + index);
|
||||
if (value > 0)
|
||||
return 2;
|
||||
else if (value < 0)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
update();
|
||||
}
|
||||
|
||||
protected:
|
||||
uint8_t index;
|
||||
uint8_t lastpos = 0xff;
|
||||
};
|
||||
|
||||
RadioHardwarePage::RadioHardwarePage():
|
||||
PageTab(STR_HARDWARE, ICON_RADIO_HARDWARE)
|
||||
{
|
||||
}
|
||||
|
||||
void RadioHardwarePage::build(FormWindow * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
#if LCD_W > LCD_H
|
||||
grid.setLabelWidth(130);
|
||||
#else
|
||||
grid.setLabelWidth(100);
|
||||
#endif
|
||||
grid.spacer(6);
|
||||
|
||||
// Calibration
|
||||
new StaticText(window, grid.getLabelSlot(), STR_INPUTS, BOLD);
|
||||
auto calib = new TextButton(window, grid.getFieldSlot(), STR_CALIBRATION);
|
||||
calib->setPressHandler([=]() -> uint8_t {
|
||||
auto calibrationPage = new RadioCalibrationPage();
|
||||
calibrationPage->setCloseHandler([=]() {
|
||||
calib->setFocus();
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// Sticks
|
||||
new Subtitle(window, grid.getLineSlot(), STR_STICKS);
|
||||
grid.nextLine();
|
||||
for(int i=0; i < NUM_STICKS; i++){
|
||||
new StaticText(window, grid.getLabelSlot(true), TEXT_AT_INDEX(STR_VSRCRAW, (i + 1)));
|
||||
new TextEdit(window, grid.getFieldSlot(2,0), g_eeGeneral.anaNames[i], LEN_ANA_NAME);
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Pots
|
||||
new Subtitle(window, grid.getLineSlot(), STR_POTS);
|
||||
grid.nextLine();
|
||||
for(int i=0; i < NUM_POTS; i++){
|
||||
new StaticText(window, grid.getLabelSlot(true), TEXT_AT_INDEX(STR_VSRCRAW, (i + NUM_STICKS + 1)));
|
||||
new TextEdit(window, grid.getFieldSlot(2,0), g_eeGeneral.anaNames[i + NUM_STICKS], LEN_ANA_NAME);
|
||||
new Choice(window, grid.getFieldSlot(2,1), STR_POTTYPES, POT_NONE, POT_WITHOUT_DETENT, GET_SET_BF(g_eeGeneral.potsConfig, 2 * i, 2));
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Switches
|
||||
new Subtitle(window, grid.getLineSlot(), STR_SWITCHES);
|
||||
grid.nextLine();
|
||||
for(int i=0; i < NUM_SWITCHES; i++) {
|
||||
new SwitchDynamicLabel(window, grid.getLabelSlot(true), i);
|
||||
new TextEdit(window, grid.getFieldSlot(2, 0), g_eeGeneral.switchNames[i], LEN_SWITCH_NAME);
|
||||
new Choice(window, grid.getFieldSlot(2, 1), STR_SWTYPES, SWITCH_NONE, SWITCH_TYPE_MAX(i),
|
||||
[=]() -> int {
|
||||
return SWITCH_CONFIG(i);
|
||||
},
|
||||
[=](int newValue) {
|
||||
swconfig_t mask = (swconfig_t)0x03 << (2*i);
|
||||
g_eeGeneral.switchConfig = (g_eeGeneral.switchConfig & ~mask) | ((swconfig_t(newValue) & 0x03) << (2*i));
|
||||
SET_DIRTY();
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
#if LCD_W > LCD_H
|
||||
grid.setLabelWidth(180);
|
||||
#else
|
||||
grid.setLabelWidth(130);
|
||||
#endif
|
||||
|
||||
// ADC filter
|
||||
new StaticText(window, grid.getLabelSlot(), STR_JITTER_FILTER);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_INVERTED(g_eeGeneral.jitterFilter));
|
||||
grid.nextLine();
|
||||
|
||||
// Bat calibration
|
||||
new StaticText(window, grid.getLabelSlot(), STR_BATT_CALIB);
|
||||
auto batCal = new NumberEdit(window, grid.getFieldSlot(), -127, 127, GET_SET_DEFAULT(g_eeGeneral.txVoltageCalibration));
|
||||
batCal->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, 2, 0, getBatteryVoltage(), flags | PREC2, 0, nullptr, "V");
|
||||
});
|
||||
batCal->setWindowFlags(REFRESH_ALWAYS);
|
||||
grid.nextLine();
|
||||
|
||||
// Factory reset
|
||||
new TextButton(window, grid.getFieldSlot(), STR_FACTORYRESET,
|
||||
[=]() -> int8_t {
|
||||
new FullScreenDialog(WARNING_TYPE_CONFIRM, STR_CONFIRMRESET, STR_POPUPS_ENTER_EXIT, [=]() {
|
||||
storageEraseAll(false);
|
||||
NVIC_SystemReset();
|
||||
return 0;
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
window->setLastField();
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef _RADIO_HARDWARE_H_
|
||||
#define _RADIO_HARDWARE_H_
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class RadioHardwarePage: public PageTab {
|
||||
public:
|
||||
RadioHardwarePage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
#endif //_RADIO_HARDWARE_H_
|
||||
@@ -0,0 +1,321 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "radio_sdmanager.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
#include "io/frsky_firmware_update.h"
|
||||
|
||||
RadioSdManagerPage::RadioSdManagerPage() :
|
||||
PageTab(SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD, ICON_RADIO_SD_MANAGER)
|
||||
{
|
||||
}
|
||||
|
||||
void RadioSdManagerPage::rebuild(FormWindow *window)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
// TODO elsewhere
|
||||
extern bool compare_nocase(const std::string &first, const std::string &second);
|
||||
|
||||
|
||||
char *getFullPath(const std::string &filename)
|
||||
{
|
||||
static char full_path[_MAX_LFN + 1]; // TODO optimize that!
|
||||
f_getcwd(full_path, _MAX_LFN);
|
||||
strcat(full_path, "/");
|
||||
strcat(full_path, filename.c_str());
|
||||
return full_path;
|
||||
}
|
||||
|
||||
class FilePreview : public Window
|
||||
{
|
||||
public:
|
||||
FilePreview(Window *parent, const rect_t &rect) :
|
||||
Window(parent, rect, NO_SCROLLBAR)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
virtual std::string getName()
|
||||
{
|
||||
return "FilePreview";
|
||||
}
|
||||
#endif
|
||||
|
||||
void setFile(const char *filename)
|
||||
{
|
||||
delete bitmap;
|
||||
const char *ext = getFileExtension(filename);
|
||||
if (ext && isExtensionMatching(ext, BITMAPS_EXT)) {
|
||||
bitmap = BitmapBuffer::load(filename);
|
||||
} else {
|
||||
bitmap = nullptr;
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer *dc) override
|
||||
{
|
||||
coord_t y = parent->getScrollPositionY() + 2;
|
||||
coord_t h = MENU_BODY_HEIGHT - 4;
|
||||
lcd->drawSolidFilledRect(0, y, width(), h, CURVE_AXIS_COLOR);
|
||||
if (bitmap) {
|
||||
coord_t bitmapHeight = min<coord_t>(h, bitmap->getHeight());
|
||||
coord_t bitmapWidth = min<coord_t>(width(), bitmap->getWidth());
|
||||
dc->drawScaledBitmap(bitmap, (width() - bitmapWidth) / 2, y + (h - bitmapHeight) / 2, bitmapWidth,
|
||||
bitmapHeight);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
BitmapBuffer *bitmap = nullptr;
|
||||
};
|
||||
|
||||
class FlashModuleDialog: public FullScreenDialog
|
||||
{
|
||||
public:
|
||||
FlashModuleDialog(ModuleIndex module):
|
||||
FullScreenDialog(WARNING_TYPE_INFO, "Flash device"),
|
||||
device(module),
|
||||
progress(this, {100, 100, 100, 15})
|
||||
{
|
||||
}
|
||||
|
||||
void flash(const char * filename)
|
||||
{
|
||||
device.flashFirmware(filename, [=](const char * title, const char * message, int count, int total) -> void {
|
||||
setMessage(message);
|
||||
progress.setValue(total > 0 ? count * 100 / total : 0);
|
||||
mainWindow.run(false);
|
||||
});
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
protected:
|
||||
FrskyDeviceFirmwareUpdate device;
|
||||
Progress progress;
|
||||
};
|
||||
|
||||
void RadioSdManagerPage::build(FormWindow *window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
|
||||
FILINFO fno;
|
||||
DIR dir;
|
||||
std::list<std::string> files;
|
||||
std::list<std::string> directories;
|
||||
|
||||
auto preview = new FilePreview(window, {LCD_W / 2 + 6, 0, LCD_W / 2 - 16, window->height()});
|
||||
|
||||
FRESULT res = f_opendir(&dir, "."); // Open the directory
|
||||
if (res == FR_OK) {
|
||||
// read all entries
|
||||
bool firstTime = true;
|
||||
for (;;) {
|
||||
res = sdReadDir(&dir, &fno, firstTime);
|
||||
|
||||
if (res != FR_OK || fno.fname[0] == 0)
|
||||
break; // Break on error or end of dir
|
||||
if (strlen(fno.fname) > SD_SCREEN_FILE_LENGTH)
|
||||
continue;
|
||||
if (fno.fname[0] == '.' && fno.fname[1] != '.')
|
||||
continue; // Ignore hidden files under UNIX, but not ..
|
||||
|
||||
if (fno.fattrib & AM_DIR) {
|
||||
directories.push_back(fno.fname);
|
||||
} else {
|
||||
files.push_back(fno.fname);
|
||||
}
|
||||
}
|
||||
|
||||
// sort directories and files
|
||||
directories.sort(compare_nocase);
|
||||
files.sort(compare_nocase);
|
||||
|
||||
for (auto name: directories) {
|
||||
auto button = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t {
|
||||
f_chdir(name.data());
|
||||
window->clear();
|
||||
build(window);
|
||||
return 0;
|
||||
}, 0);
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
for (auto name: files) {
|
||||
auto button = new TextButton(window, grid.getLabelSlot(), name, [=]() -> uint8_t {
|
||||
auto menu = new Menu();
|
||||
const char *ext = getFileExtension(name.data());
|
||||
if (ext) {
|
||||
if (!strcasecmp(ext, SOUNDS_EXT)) {
|
||||
menu->addLine(STR_PLAY_FILE, [=]() {
|
||||
audioQueue.stopAll();
|
||||
audioQueue.playFile(getFullPath(name), 0, ID_PLAY_FROM_SD_MANAGER);
|
||||
});
|
||||
}
|
||||
else if (isExtensionMatching(ext, BITMAPS_EXT)) {
|
||||
// TODO
|
||||
}
|
||||
else if (!strcasecmp(ext, TEXT_EXT)) {
|
||||
menu->addLine(STR_VIEW_TEXT, [=]() {
|
||||
// TODO
|
||||
});
|
||||
}
|
||||
else if (!READ_ONLY() && !strcasecmp(ext, SPORT_FIRMWARE_EXT)) {
|
||||
if (HAS_SPORT_UPDATE_CONNECTOR()) {
|
||||
menu->addLine(STR_FLASH_EXTERNAL_DEVICE, [=]() {
|
||||
auto dialog = new FlashModuleDialog(SPORT_MODULE);
|
||||
dialog->flash(getFullPath(name));
|
||||
});
|
||||
}
|
||||
menu->addLine(STR_FLASH_INTERNAL_MODULE, [=]() {
|
||||
auto dialog = new FlashModuleDialog(INTERNAL_MODULE);
|
||||
dialog->flash(getFullPath(name));
|
||||
});
|
||||
menu->addLine(STR_FLASH_EXTERNAL_MODULE, [=]() {
|
||||
auto dialog = new FlashModuleDialog(EXTERNAL_MODULE);
|
||||
dialog->flash(getFullPath(name));
|
||||
});
|
||||
}
|
||||
#if defined(LUA)
|
||||
else if (isExtensionMatching(ext, SCRIPTS_EXT)) {
|
||||
menu->addLine(STR_EXECUTE_FILE, [=]() {
|
||||
luaExec(getFullPath(name));
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (!READ_ONLY()) {
|
||||
menu->addLine(STR_COPY_FILE, [=]() {
|
||||
clipboard.type = CLIPBOARD_TYPE_SD_FILE;
|
||||
f_getcwd(clipboard.data.sd.directory, CLIPBOARD_PATH_LEN);
|
||||
strncpy(clipboard.data.sd.filename, name.c_str(), CLIPBOARD_PATH_LEN - 1);
|
||||
});
|
||||
if (clipboard.type == CLIPBOARD_TYPE_SD_FILE) {
|
||||
menu->addLine(STR_PASTE, [=]() {
|
||||
// TODO
|
||||
});
|
||||
}
|
||||
menu->addLine(STR_RENAME_FILE, [=]() {
|
||||
// TODO
|
||||
});
|
||||
menu->addLine(STR_DELETE_FILE, [=]() {
|
||||
f_unlink(getFullPath(name));
|
||||
rebuild(window);
|
||||
});
|
||||
}
|
||||
return 0;
|
||||
}, 0);
|
||||
button->setFocusHandler([=]() {
|
||||
preview->setFile(getFullPath(name));
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
}
|
||||
|
||||
window->setLastField();
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
preview->setHeight(max(window->height(), grid.getWindowHeight()));
|
||||
}
|
||||
|
||||
#if 0
|
||||
bool menuRadioSdManagerInfo(event_t event)
|
||||
{
|
||||
SIMPLE_SUBMENU(STR_SD_INFO_TITLE, ICON_RADIO_SD_MANAGER, 1);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 2*FH, STR_SD_TYPE);
|
||||
lcdDrawText(100, 2*FH, SD_IS_HC() ? STR_SDHC_CARD : STR_SD_CARD);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 3*FH, STR_SD_SIZE);
|
||||
lcdDrawNumber(100, 3*FH, sdGetSize(), LEFT, 0, NULL, "M");
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 4*FH, STR_SD_SECTORS);
|
||||
#if defined(SD_GET_FREE_BLOCKNR)
|
||||
lcdDrawNumber(100, 4*FH, SD_GET_FREE_BLOCKNR()/1000, LEFT, 0, NULL, "/");
|
||||
lcdDrawNumber(150, 4*FH, sdGetNoSectors()/1000, LEFT);
|
||||
#else
|
||||
lcdDrawNumber(100, 4*FH, sdGetNoSectors()/1000, LEFT, 0, NULL, "k");
|
||||
#endif
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, 5*FH, STR_SD_SPEED);
|
||||
lcdDrawNumber(100, 5*FH, SD_GET_SPEED()/1000, LEFT, 0, NULL, "kb/s");
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void onSdManagerMenu(const char * result)
|
||||
{
|
||||
TCHAR lfn[_MAX_LFN+1];
|
||||
|
||||
// TODO possible buffer overflows here!
|
||||
|
||||
uint8_t index = menuVerticalPosition-menuVerticalOffset;
|
||||
char *line = reusableBuffer.sdmanager.lines[index];
|
||||
|
||||
if (result == STR_SD_INFO) {
|
||||
pushMenu(menuRadioSdManagerInfo);
|
||||
}
|
||||
else if (result == STR_SD_FORMAT) {
|
||||
POPUP_CONFIRMATION(STR_CONFIRM_FORMAT);
|
||||
}
|
||||
else if (result == STR_PASTE) {
|
||||
f_getcwd(lfn, _MAX_LFN);
|
||||
// if destination is dir, copy into that dir
|
||||
if (IS_DIRECTORY(line)) {
|
||||
strcat(lfn, PSTR("/"));
|
||||
strcat(lfn, line);
|
||||
}
|
||||
if (strcmp(clipboard.data.sd.directory, lfn)) { // prevent copying to the same directory
|
||||
POPUP_WARNING(sdCopyFile(clipboard.data.sd.filename, clipboard.data.sd.directory, clipboard.data.sd.filename, lfn));
|
||||
REFRESH_FILES();
|
||||
}
|
||||
}
|
||||
else if (result == STR_RENAME_FILE) {
|
||||
memcpy(reusableBuffer.sdmanager.originalName, line, sizeof(reusableBuffer.sdmanager.originalName));
|
||||
uint8_t fnlen = 0, extlen = 0;
|
||||
getFileExtension(line, 0, LEN_FILE_EXTENSION_MAX, &fnlen, &extlen);
|
||||
// write spaces to allow extending the length of a filename
|
||||
memset(line + fnlen - extlen, ' ', SD_SCREEN_FILE_LENGTH - fnlen + extlen);
|
||||
line[SD_SCREEN_FILE_LENGTH-extlen] = '\0';
|
||||
s_editMode = EDIT_MODIFY_STRING;
|
||||
editNameCursorPos = 0;
|
||||
}
|
||||
else if (result == STR_ASSIGN_BITMAP) {
|
||||
memcpy(g_model.header.bitmap, line, sizeof(g_model.header.bitmap));
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (result == STR_ASSIGN_SPLASH) {
|
||||
f_getcwd(lfn, _MAX_LFN);
|
||||
sdCopyFile(line, lfn, SPLASH_FILE, BITMAPS_PATH);
|
||||
}
|
||||
else if (result == STR_VIEW_TEXT) {
|
||||
getSelectionFullPath(lfn);
|
||||
pushMenuTextView(lfn);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class RadioSdManagerPage: public PageTab {
|
||||
public:
|
||||
RadioSdManagerPage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
|
||||
protected:
|
||||
void rebuild(FormWindow * window);
|
||||
};
|
||||
@@ -0,0 +1,470 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#define LANGUAGE_PACKS_DEFINITION
|
||||
|
||||
#include "radio_setup.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_GENERAL)
|
||||
|
||||
class DateTimeWindow : public Window {
|
||||
public:
|
||||
DateTimeWindow(Window * parent, const rect_t &rect) :
|
||||
Window(parent, rect, FORWARD_SCROLL)
|
||||
{
|
||||
build();
|
||||
}
|
||||
|
||||
~DateTimeWindow()
|
||||
{
|
||||
deleteChildren();
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
Window::checkEvents();
|
||||
|
||||
if (get_tmr10ms() - lastRefresh > 100) {
|
||||
invalidate();
|
||||
lastRefresh = get_tmr10ms();
|
||||
}
|
||||
}
|
||||
|
||||
FormField * getFirstField()
|
||||
{
|
||||
return firstField;
|
||||
}
|
||||
|
||||
protected:
|
||||
tmr10ms_t lastRefresh = 0;
|
||||
FormField * firstField = nullptr;
|
||||
|
||||
void build()
|
||||
{
|
||||
FormGridLayout grid;
|
||||
|
||||
// Date
|
||||
new StaticText(this, grid.getLabelSlot(), STR_DATE);
|
||||
firstField = new NumberEdit(this, grid.getFieldSlot(3, 0), 2018, 2100,
|
||||
[=]() -> int32_t {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
return TM_YEAR_BASE + t.tm_year;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
t.tm_year = newValue - TM_YEAR_BASE;
|
||||
SET_LOAD_DATETIME(&t);
|
||||
});
|
||||
auto month = new NumberEdit(this, grid.getFieldSlot(3, 1), 1, 12,
|
||||
[=]() -> int32_t {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
return 1 + t.tm_mon;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
t.tm_mon = newValue - 1;
|
||||
SET_LOAD_DATETIME(&t);
|
||||
});
|
||||
month->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
|
||||
});
|
||||
|
||||
/* TODO dynamic max instead of 31 ...
|
||||
int16_t year = TM_YEAR_BASE + t.tm_year;
|
||||
int8_t dlim = (((((year%4==0) && (year%100!=0)) || (year%400==0)) && (t.tm_mon==1)) ? 1 : 0);
|
||||
static const pm_uint8_t dmon[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
dlim += *(&dmon[t.tm_mon]);*/
|
||||
int8_t dlim = 31;
|
||||
auto day = new NumberEdit(this, grid.getFieldSlot(3, 2), 1, dlim,
|
||||
[=]() -> int32_t {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
return t.tm_mday;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
t.tm_mday = newValue;
|
||||
SET_LOAD_DATETIME(&t);
|
||||
});
|
||||
day->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
|
||||
//Time
|
||||
new StaticText(this, grid.getLabelSlot(), STR_TIME);
|
||||
auto hour = new NumberEdit(this, grid.getFieldSlot(3, 0), 0, 24,
|
||||
[=]() -> int32_t {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
return t.tm_hour;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
t.tm_hour = newValue;
|
||||
SET_LOAD_DATETIME(&t);
|
||||
});
|
||||
hour->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
|
||||
});
|
||||
|
||||
auto minutes = new NumberEdit(this, grid.getFieldSlot(3, 1), 0, 59,
|
||||
[=]() -> int32_t {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
return t.tm_min;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
t.tm_min = newValue;
|
||||
SET_LOAD_DATETIME(&t);
|
||||
});
|
||||
minutes->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
|
||||
});
|
||||
|
||||
auto seconds = new NumberEdit(this, grid.getFieldSlot(3, 2), 0, 59,
|
||||
[=]() -> int32_t {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
return t.tm_sec;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
t.tm_sec = newValue;
|
||||
SET_LOAD_DATETIME(&t);
|
||||
});
|
||||
seconds->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value, flags | LEADING0, 2);
|
||||
});
|
||||
grid.nextLine();
|
||||
getParent()->moveWindowsTop(top(), adjustHeight());
|
||||
}
|
||||
};
|
||||
|
||||
RadioSetupPage::RadioSetupPage():
|
||||
PageTab(STR_MENURADIOSETUP, ICON_RADIO_SETUP)
|
||||
{
|
||||
}
|
||||
|
||||
void RadioSetupPage::build(FormWindow * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
|
||||
// Date and Time
|
||||
auto timeWindow = new DateTimeWindow(window, {0, grid.getWindowHeight(), LCD_W, 0});
|
||||
grid.addWindow(timeWindow);
|
||||
window->setFirstField(timeWindow->getFirstField());
|
||||
|
||||
// Batt meter range - Range 3.0v to 16v
|
||||
new StaticText(window, grid.getLabelSlot(), STR_BATTERY_RANGE);
|
||||
auto batMinEdit = new NumberEdit(window, grid.getFieldSlot(2, 0), -60 + 90, g_eeGeneral.vBatMax + 29 + 90, GET_SET_WITH_OFFSET(g_eeGeneral.vBatMin, 90), PREC1);
|
||||
batMinEdit->setSuffix("V");
|
||||
auto batMaxEdit = new NumberEdit(window, grid.getFieldSlot(2, 1), g_eeGeneral.vBatMin - 29 + 120, 40 + 120, GET_SET_WITH_OFFSET(g_eeGeneral.vBatMax, 120), PREC1);
|
||||
batMaxEdit->setSuffix("V");
|
||||
batMinEdit->setSetValueHandler([=](int32_t newValue) {
|
||||
g_eeGeneral.vBatMin= newValue - 90;
|
||||
SET_DIRTY();
|
||||
batMaxEdit->setMin(g_eeGeneral.vBatMin - 29 + 120);
|
||||
batMaxEdit->invalidate();
|
||||
});
|
||||
batMaxEdit->setSetValueHandler([=](int32_t newValue) {
|
||||
g_eeGeneral.vBatMax= newValue - 120;
|
||||
SET_DIRTY();
|
||||
batMinEdit->setMax(g_eeGeneral.vBatMax + 29 + 90);
|
||||
batMinEdit->invalidate();
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
new Subtitle(window, grid.getLabelSlot(), STR_SOUND_LABEL);
|
||||
grid.nextLine();
|
||||
|
||||
// Beeps mode
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_SPEAKER);
|
||||
new Choice(window, grid.getFieldSlot(), STR_VBEEPMODE, -2, 1, GET_SET_DEFAULT(g_eeGeneral.beepMode));
|
||||
grid.nextLine();
|
||||
|
||||
// Main volume
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_SPEAKER_VOLUME);
|
||||
new Slider(window, grid.getFieldSlot(), -VOLUME_LEVEL_DEF, VOLUME_LEVEL_MAX-VOLUME_LEVEL_DEF, GET_SET_DEFAULT(g_eeGeneral.speakerVolume));
|
||||
grid.nextLine();
|
||||
|
||||
// Beeps volume
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_BEEP_VOLUME);
|
||||
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.beepVolume));
|
||||
grid.nextLine();
|
||||
|
||||
// Wav volume
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_WAV_VOLUME);
|
||||
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.wavVolume));
|
||||
grid.nextLine();
|
||||
|
||||
// Background volume
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_BG_VOLUME);
|
||||
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.backgroundVolume));
|
||||
grid.nextLine();
|
||||
|
||||
// Beeps length
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_BEEP_LENGTH);
|
||||
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.beepLength));
|
||||
grid.nextLine();
|
||||
|
||||
// Beeps pitch
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_SPKRPITCH);
|
||||
auto edit = new NumberEdit(window, grid.getFieldSlot(), 0, 300,
|
||||
GET_DEFAULT(15 * g_eeGeneral.speakerPitch),
|
||||
[=](int32_t newValue) {
|
||||
g_eeGeneral.speakerPitch = newValue / 15;
|
||||
SET_DIRTY();
|
||||
});
|
||||
edit->setStep(15);
|
||||
edit->setPrefix("+");
|
||||
edit->setSuffix("Hz");
|
||||
grid.nextLine();
|
||||
|
||||
#if defined(VARIO)
|
||||
new Subtitle(window, grid.getLabelSlot(), STR_VARIO);
|
||||
grid.nextLine();
|
||||
|
||||
// Vario volume
|
||||
new StaticText(window, grid.getLabelSlot(true), TR_SPEAKER_VOLUME);
|
||||
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.varioVolume));
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_PITCH_AT_ZERO);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(), VARIO_FREQUENCY_ZERO-400, VARIO_FREQUENCY_ZERO+400,
|
||||
GET_DEFAULT(VARIO_FREQUENCY_ZERO+(g_eeGeneral.varioPitch*10)),
|
||||
SET_VALUE(g_eeGeneral.varioPitch, (newValue - VARIO_FREQUENCY_ZERO) / 10));
|
||||
edit->setStep(10);
|
||||
edit->setSuffix("Hz");
|
||||
grid.nextLine();
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(HAPTIC)
|
||||
{
|
||||
new Subtitle(window, grid.getLabelSlot(), STR_HAPTIC_LABEL);
|
||||
grid.nextLine();
|
||||
|
||||
// Haptic mode
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_MODE);
|
||||
new Choice(window, grid.getFieldSlot(), STR_VBEEPMODE, -2, 1, GET_SET_DEFAULT(g_eeGeneral.hapticMode));
|
||||
grid.nextLine();
|
||||
|
||||
// Haptic duration
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_LENGTH);
|
||||
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.hapticLength));
|
||||
grid.nextLine();
|
||||
|
||||
// Haptic strength
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_HAPTICSTRENGTH);
|
||||
new Slider(window, grid.getFieldSlot(), -2, +2, GET_SET_DEFAULT(g_eeGeneral.hapticStrength));
|
||||
grid.nextLine();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Alarms
|
||||
{
|
||||
new Subtitle(window, grid.getLabelSlot(), STR_ALARMS_LABEL);
|
||||
grid.nextLine();
|
||||
|
||||
// Battery warning
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_BATTERYWARNING);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(), 30, 120, GET_SET_DEFAULT(g_eeGeneral.vBatWarn), PREC1);
|
||||
edit->setSuffix("v");
|
||||
grid.nextLine();
|
||||
|
||||
// Alarms warning
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_ALARMWARNING);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_INVERTED(g_eeGeneral.disableAlarmWarning));
|
||||
grid.nextLine();
|
||||
|
||||
// RSSI shutdown alarm
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_RSSISHUTDOWNALARM);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_INVERTED(g_eeGeneral.disableRssiPoweroffAlarm));
|
||||
grid.nextLine();
|
||||
|
||||
// Inactivity alarm
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_INACTIVITYALARM);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(), 0, 250, GET_SET_DEFAULT(g_eeGeneral.inactivityTimer));
|
||||
edit->setSuffix("minutes");
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// Backlight
|
||||
{
|
||||
new Subtitle(window, grid.getLabelSlot(), STR_BACKLIGHT_LABEL);
|
||||
grid.nextLine();
|
||||
|
||||
// Backlight mode
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_MODE);
|
||||
new Choice(window, grid.getFieldSlot(2,0), STR_VBLMODE, e_backlight_mode_off, e_backlight_mode_on, GET_SET_DEFAULT(g_eeGeneral.backlightMode));
|
||||
//grid.nextLine();
|
||||
|
||||
// Delay
|
||||
auto edit = new NumberEdit(window, grid.getFieldSlot(2, 1), 0, 600,
|
||||
GET_DEFAULT(g_eeGeneral.lightAutoOff * 5),
|
||||
SET_VALUE(g_eeGeneral.lightAutoOff, newValue / 5));
|
||||
edit->setStep(5);
|
||||
edit->setSuffix("s");
|
||||
grid.nextLine();
|
||||
|
||||
// Backlight ON bright
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_BLONBRIGHTNESS);
|
||||
new Slider(window, grid.getFieldSlot(), BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX,
|
||||
[=]() -> int32_t {
|
||||
return BACKLIGHT_LEVEL_MAX - g_eeGeneral.backlightBright;
|
||||
},
|
||||
[=](int32_t newValue) {
|
||||
g_eeGeneral.backlightBright = BACKLIGHT_LEVEL_MAX - newValue;
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// Backlight OFF bright
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_BLOFFBRIGHTNESS);
|
||||
new Slider(window, grid.getFieldSlot(), BACKLIGHT_LEVEL_MIN, BACKLIGHT_LEVEL_MAX, GET_SET_DEFAULT(g_eeGeneral.blOffBright));
|
||||
grid.nextLine();
|
||||
|
||||
// Flash beep
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_ALARM);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_eeGeneral.alarmsFlash));
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
// GPS
|
||||
{
|
||||
new Subtitle(window, grid.getLabelSlot(), STR_GPS);
|
||||
grid.nextLine();
|
||||
|
||||
// Timezone
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_TIMEZONE);
|
||||
new NumberEdit(window, grid.getFieldSlot(2, 0), -12, 12, GET_SET_DEFAULT(g_eeGeneral.timezone));
|
||||
grid.nextLine();
|
||||
|
||||
// Adjust RTC (from telemetry)
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_ADJUST_RTC);
|
||||
new CheckBox(window, grid.getFieldSlot(), GET_SET_DEFAULT(g_eeGeneral.adjustRTC));
|
||||
grid.nextLine();
|
||||
|
||||
// GPS format
|
||||
new StaticText(window, grid.getLabelSlot(true), STR_GPSCOORD);
|
||||
new Choice(window, grid.getFieldSlot(), STR_GPSFORMAT, 0, 1, GET_SET_DEFAULT(g_eeGeneral.gpsFormat));
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
#if defined(PXX2)
|
||||
// Owner ID
|
||||
new StaticText(window, grid.getLabelSlot(), STR_OWNER_ID);
|
||||
new TextEdit(window, grid.getFieldSlot(), g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID);
|
||||
grid.nextLine();
|
||||
#endif
|
||||
|
||||
// Country code
|
||||
new StaticText(window, grid.getLabelSlot(), STR_COUNTRYCODE);
|
||||
new Choice(window, grid.getFieldSlot(), STR_COUNTRYCODES, 0, 2, GET_SET_DEFAULT(g_eeGeneral.countryCode));
|
||||
grid.nextLine();
|
||||
|
||||
// Audio language
|
||||
new StaticText(window, grid.getLabelSlot(), STR_VOICELANG);
|
||||
auto choice = new Choice(window, grid.getFieldSlot(), nullptr, 0, DIM(languagePacks) - 2, GET_VALUE(currentLanguagePackIdx),
|
||||
[](uint8_t newValue) {
|
||||
currentLanguagePackIdx = newValue;
|
||||
currentLanguagePack = languagePacks[currentLanguagePackIdx];
|
||||
strncpy(g_eeGeneral.ttsLanguage, currentLanguagePack->id, 2);
|
||||
});
|
||||
choice->setTextHandler([](uint8_t value) {
|
||||
return languagePacks[value]->name;
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// Imperial units
|
||||
new StaticText(window, grid.getLabelSlot(), STR_UNITSSYSTEM);
|
||||
new Choice(window, grid.getFieldSlot(), STR_VUNITSSYSTEM, 0, 1, GET_SET_DEFAULT(g_eeGeneral.imperial));
|
||||
grid.nextLine();
|
||||
|
||||
#if defined(FAI_CHOICE)
|
||||
/* case ITEM_SETUP_FAI:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "FAI Mode");
|
||||
if (g_eeGeneral.fai) {
|
||||
lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, "Locked in FAI Mode");
|
||||
}
|
||||
else {
|
||||
g_eeGeneral.fai = editCheckBox(g_eeGeneral.fai, RADIO_SETUP_2ND_COLUMN, y, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
g_eeGeneral.fai = false;
|
||||
POPUP_CONFIRMATION("FAI mode?");
|
||||
}
|
||||
}
|
||||
break;*/
|
||||
#endif
|
||||
|
||||
// Switches delay
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SWITCHES_DELAY);
|
||||
edit = new NumberEdit(window, grid.getFieldSlot(2, 0), -15, 100 - 15, GET_SET_VALUE_WITH_OFFSET(g_eeGeneral.switchesDelay, 15));
|
||||
edit->setSuffix(std::string("0") + STR_MS);
|
||||
grid.nextLine();
|
||||
|
||||
// USB mode
|
||||
new StaticText(window, grid.getLabelSlot(), STR_USBMODE);
|
||||
new Choice(window, grid.getFieldSlot(), STR_USBMODES, USB_UNSELECTED_MODE, USB_MAX_MODE, GET_SET_DEFAULT(g_eeGeneral.USBMode));
|
||||
grid.nextLine();
|
||||
|
||||
// RX channel order
|
||||
new StaticText(window, grid.getLabelSlot(), STR_RXCHANNELORD); // RAET->AETR
|
||||
choice = new Choice(window, grid.getFieldSlot(), nullptr, 0, 4*3*2 - 1, GET_SET_DEFAULT(g_eeGeneral.templateSetup));
|
||||
choice->setTextHandler([](uint8_t value) {
|
||||
char s[5];
|
||||
for (uint8_t i=0; i<4; i++) {
|
||||
s[i] = STR_RETA123[channelOrder(value, i + 1)];
|
||||
}
|
||||
s[4] = '\0';
|
||||
return std::string(s);
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
// Stick mode
|
||||
new StaticText(window, grid.getLabelSlot(), STR_MODE);
|
||||
choice = new Choice(window, grid.getFieldSlot(), nullptr, 0, 3, GET_DEFAULT(g_eeGeneral.stickMode),
|
||||
[=](uint8_t newValue) {
|
||||
pausePulses();
|
||||
g_eeGeneral.stickMode = newValue;
|
||||
SET_DIRTY();
|
||||
checkThrottleStick();
|
||||
resumePulses();
|
||||
});
|
||||
choice->setTextHandler([](uint8_t value) {
|
||||
return std::to_string(1 + value) + ": left=" + std::string(&getSourceString(MIXSRC_Rud + modn12x3[4 * value])[1]) + "+" + std::string(&getSourceString(MIXSRC_Rud + modn12x3[4 * value + 1])[1]);
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
FormField::link(FormField::getCurrentField(), timeWindow->getFirstField());
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
class RadioSetupPage: public PageTab {
|
||||
public:
|
||||
RadioSetupPage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
};
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "radio_spectrum_analyser.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define SPECTRUM_HEIGHT 200
|
||||
|
||||
class SpectrumWindow : public Window
|
||||
{
|
||||
public:
|
||||
SpectrumWindow(Window *parent, const rect_t &rect) :
|
||||
Window(parent, rect, REFRESH_ALWAYS)
|
||||
{
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
if (TELEMETRY_STREAMING()) {
|
||||
dc->drawText(width() / 2, height() / 2, STR_TURN_OFF_RECEIVER, CENTERED);
|
||||
return;
|
||||
}
|
||||
|
||||
coord_t peak_y = 1;
|
||||
coord_t peak_x = 0;
|
||||
for (coord_t i = 0; i < LCD_W; i++) {
|
||||
coord_t h = min<coord_t >(reusableBuffer.spectrumAnalyser.bars[i], SPECTRUM_HEIGHT);
|
||||
if (h > peak_y) {
|
||||
peak_x = i;
|
||||
peak_y = h;
|
||||
}
|
||||
dc->drawVerticalLine(i, SPECTRUM_HEIGHT - h, h, SOLID, 0);
|
||||
}
|
||||
|
||||
coord_t y = max<coord_t>(FH, SPECTRUM_HEIGHT - peak_y - FH);
|
||||
drawNumber(dc, min<coord_t>(100, peak_x), y, ((reusableBuffer.spectrumAnalyser.freq - reusableBuffer.spectrumAnalyser.span / 2) + peak_x * (reusableBuffer.spectrumAnalyser.span / 128)) / 1000000, TINSIZE);
|
||||
dc->drawText(lcdNextPos, y, "M", TINSIZE);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
RadioSpectrumAnalyser::RadioSpectrumAnalyser(uint8_t moduleIdx) :
|
||||
Page(ICON_RADIO_TOOLS),
|
||||
moduleIdx(moduleIdx)
|
||||
{
|
||||
buildBody(&body);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
void RadioSpectrumAnalyser::buildBody(FormWindow * window)
|
||||
{
|
||||
new SpectrumWindow(window, {0, 0, LCD_W, SPECTRUM_HEIGHT});
|
||||
}
|
||||
|
||||
void RadioSpectrumAnalyser::start()
|
||||
{
|
||||
if (isModuleR9MAccess(moduleIdx)) {
|
||||
reusableBuffer.spectrumAnalyser.spanDefault = 20;
|
||||
reusableBuffer.spectrumAnalyser.spanMax = 40;
|
||||
reusableBuffer.spectrumAnalyser.freqDefault = 890;
|
||||
reusableBuffer.spectrumAnalyser.freqMin = 850;
|
||||
reusableBuffer.spectrumAnalyser.freqMax = 930;
|
||||
}
|
||||
else {
|
||||
reusableBuffer.spectrumAnalyser.spanDefault = 40; // 40MHz
|
||||
reusableBuffer.spectrumAnalyser.spanMax = 80;
|
||||
reusableBuffer.spectrumAnalyser.freqDefault = 2440; // 2440MHz
|
||||
reusableBuffer.spectrumAnalyser.freqMin = 2400;
|
||||
reusableBuffer.spectrumAnalyser.freqMax = 2485;
|
||||
}
|
||||
|
||||
if (moduleState[moduleIdx].mode != MODULE_MODE_SPECTRUM_ANALYSER) {
|
||||
memclear(reusableBuffer.spectrumAnalyser.bars, sizeof(reusableBuffer.spectrumAnalyser.bars));
|
||||
reusableBuffer.spectrumAnalyser.span = reusableBuffer.spectrumAnalyser.spanDefault * 1000000;
|
||||
reusableBuffer.spectrumAnalyser.freq = reusableBuffer.spectrumAnalyser.freqDefault * 1000000;
|
||||
reusableBuffer.spectrumAnalyser.step = reusableBuffer.spectrumAnalyser.span / LCD_W;
|
||||
reusableBuffer.spectrumAnalyser.dirty = true;
|
||||
moduleState[moduleIdx].mode = MODULE_MODE_SPECTRUM_ANALYSER;
|
||||
}
|
||||
}
|
||||
|
||||
void RadioSpectrumAnalyser::stop()
|
||||
{
|
||||
new MessageDialog(STR_MODULE, STR_STOPPING);
|
||||
moduleState[moduleIdx].readModuleInformation(&reusableBuffer.moduleSetup.pxx2.moduleInformation, PXX2_HW_INFO_TX_ID, PXX2_HW_INFO_TX_ID);
|
||||
/* wait 1s to resume normal operation before leaving */
|
||||
// watchdogSuspend(1000);
|
||||
// RTOS_WAIT_MS(1000);
|
||||
}
|
||||