New UI merged
This commit is contained in:
@@ -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()
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
/*
|
||||
* Header bitmaps
|
||||
*/
|
||||
|
||||
const uint8_t LBM_DOT[] = {
|
||||
#include "mask_dot.lbm"
|
||||
};
|
||||
|
||||
/*
|
||||
* Main view bitmaps
|
||||
*/
|
||||
|
||||
const uint8_t LBM_TOPMENU_USB[] = {
|
||||
#include "mask_topmenu_usb.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TOPMENU_VOLUME_0[] = {
|
||||
#include "mask_volume_0.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TOPMENU_VOLUME_1[] = {
|
||||
#include "mask_volume_1.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TOPMENU_VOLUME_2[] = {
|
||||
#include "mask_volume_2.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TOPMENU_VOLUME_3[] = {
|
||||
#include "mask_volume_3.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TOPMENU_VOLUME_4[] = {
|
||||
#include "mask_volume_4.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TOPMENU_VOLUME_SCALE[] = {
|
||||
#include "mask_volume_scale.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TOPMENU_TXBATT[] = {
|
||||
#include "mask_txbat.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_HTRIM_FRAME[] = {
|
||||
#include "mask_htrim_frame.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_VTRIM_FRAME[] = {
|
||||
#include "mask_vtrim_frame.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TRIM_SHADOW[] = {
|
||||
#include "mask_trim_shadow.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TIMER_BACKGROUND[] = {
|
||||
#include "mask_timer_bg.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_TIMER[] = {
|
||||
#include "mask_timer.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_RSCALE[] = {
|
||||
#include "mask_rscale.lbm"
|
||||
};
|
||||
|
||||
/*
|
||||
* Model selection screen bitmaps
|
||||
*/
|
||||
|
||||
const uint8_t LBM_LIBRARY_SLOT[] = {
|
||||
#include "mask_library_slot.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_ACTIVE_MODEL[] = {
|
||||
#include "mask_library_active_model.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SCORE0[] = {
|
||||
#include "mask_library_score_0.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SCORE1[] = {
|
||||
#include "mask_library_score_1.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_STAR0[] = {
|
||||
#include "mask_library_star_0.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_STAR1[] = {
|
||||
#include "mask_library_star_1.lbm"
|
||||
};
|
||||
|
||||
/*
|
||||
* Other
|
||||
*/
|
||||
|
||||
const uint8_t LBM_POINT[] = {
|
||||
#include "mask_point.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_CURVE_POINT[] = {
|
||||
#include "mask_cvpoint.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_CURVE_POINT_CENTER[] = {
|
||||
#include "mask_cvpoint_center.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_CURVE_COORD_SHADOW[] = {
|
||||
#include "mask_coord_shadow.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SHUTDOWN_CIRCLE[] = {
|
||||
#include "mask_shutdown_circle.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SLIDER_BAR_LEFT[] __ALIGNED(4) = {
|
||||
#include "bar_left.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SLIDER_BAR_RIGHT[] __ALIGNED(4) = {
|
||||
#include "bar_right.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SLIDER_POINT_OUT[] __ALIGNED(4) = {
|
||||
#include "point_out.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SLIDER_POINT_MID[] __ALIGNED(4) = {
|
||||
#include "point_mid.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SLIDER_POINT_IN[] __ALIGNED(4) = {
|
||||
#include "point_in.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_CARROUSSEL_LEFT[] = {
|
||||
#include "mask_carroussel_left.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_CARROUSSEL_RIGHT[] = {
|
||||
#include "mask_carroussel_right.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SWIPE_CIRCLE[] = {
|
||||
#include "mask_swipe_circle.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SWIPE_LEFT[] = {
|
||||
#include "mask_swipe_left.lbm"
|
||||
};
|
||||
|
||||
const uint8_t LBM_SWIPE_RIGHT[] = {
|
||||
#include "mask_swipe_right.lbm"
|
||||
};
|
||||
|
||||
BitmapBuffer * calibStick = NULL;
|
||||
BitmapBuffer * calibStickBackground = NULL;
|
||||
BitmapBuffer * calibTrackpBackground = NULL;
|
||||
BitmapBuffer * calibRadioPict = NULL;
|
||||
BitmapBuffer * modelselIconBitmap = NULL;
|
||||
BitmapBuffer * modelselSdFreeBitmap = NULL;
|
||||
BitmapBuffer * modelselModelQtyBitmap = NULL;
|
||||
BitmapBuffer * modelselModelNameBitmap = NULL;
|
||||
BitmapBuffer * modelselModelMoveBackground = NULL;
|
||||
BitmapBuffer * modelselModelMoveIcon = NULL;
|
||||
BitmapBuffer * modelselWizardBackground = NULL;
|
||||
BitmapBuffer * chanMonLockedBitmap = NULL;
|
||||
BitmapBuffer * chanMonInvertedBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupMixerBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupToBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupOutputBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupAddBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupMultiBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupReplaceBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupLabelBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupCurveBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupSwitchIcon = NULL;
|
||||
BitmapBuffer * mixerSetupDelayBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupSlowBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupDelaySlowBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupFlightmodeIcon = NULL;
|
||||
BitmapBuffer * mixerSetupFlightmodeBitmap = NULL;
|
||||
BitmapBuffer * mixerSetupSwitchBitmap = NULL;
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef _BITMAPS_H_
|
||||
#define _BITMAPS_H_
|
||||
|
||||
// Header bitmaps
|
||||
extern const uint8_t LBM_DOT[];
|
||||
|
||||
// Main view icons
|
||||
extern const uint8_t LBM_TOPMENU_USB[];
|
||||
extern const uint8_t LBM_TOPMENU_VOLUME_0[];
|
||||
extern const uint8_t LBM_TOPMENU_VOLUME_1[];
|
||||
extern const uint8_t LBM_TOPMENU_VOLUME_2[];
|
||||
extern const uint8_t LBM_TOPMENU_VOLUME_3[];
|
||||
extern const uint8_t LBM_TOPMENU_VOLUME_4[];
|
||||
extern const uint8_t LBM_TOPMENU_VOLUME_SCALE[];
|
||||
extern const uint8_t LBM_TOPMENU_TXBATT[];
|
||||
extern const uint8_t LBM_HTRIM_FRAME[];
|
||||
extern const uint8_t LBM_VTRIM_FRAME[];
|
||||
extern const uint8_t LBM_TRIM_SHADOW[];
|
||||
extern const uint8_t LBM_TIMER_BACKGROUND[];
|
||||
extern const uint8_t LBM_TIMER[];
|
||||
extern const uint8_t LBM_RSCALE[];
|
||||
|
||||
// Model selection icons
|
||||
extern const uint8_t LBM_LIBRARY_SLOT[];
|
||||
extern const uint8_t LBM_ACTIVE_MODEL[];
|
||||
extern const uint8_t LBM_SCORE0[];
|
||||
extern const uint8_t LBM_SCORE1[];
|
||||
extern const uint8_t LBM_STAR0[];
|
||||
extern const uint8_t LBM_STAR1[];
|
||||
|
||||
// Other icons
|
||||
extern const uint8_t LBM_SPLASH[];
|
||||
extern const uint8_t LBM_POINT[];
|
||||
extern const uint8_t LBM_CURVE_POINT[];
|
||||
extern const uint8_t LBM_CURVE_POINT_CENTER[];
|
||||
extern const uint8_t LBM_CURVE_COORD_SHADOW[];
|
||||
extern const uint8_t LBM_SHUTDOWN_CIRCLE[];
|
||||
|
||||
// Slider bitmaps
|
||||
extern const uint8_t LBM_SLIDER_BAR_LEFT[];
|
||||
extern const uint8_t LBM_SLIDER_BAR_RIGHT[];
|
||||
extern const uint8_t LBM_SLIDER_POINT_OUT[];
|
||||
extern const uint8_t LBM_SLIDER_POINT_MID[];
|
||||
extern const uint8_t LBM_SLIDER_POINT_IN[];
|
||||
|
||||
// Carroussel bitmaps
|
||||
extern const uint8_t LBM_CARROUSSEL_LEFT[];
|
||||
extern const uint8_t LBM_CARROUSSEL_RIGHT[];
|
||||
|
||||
extern const uint8_t LBM_SWIPE_CIRCLE[];
|
||||
extern const uint8_t LBM_SWIPE_LEFT[];
|
||||
extern const uint8_t LBM_SWIPE_RIGHT[];
|
||||
|
||||
extern BitmapBuffer * modelselIconBitmap;
|
||||
extern BitmapBuffer * modelselSdFreeBitmap;
|
||||
extern BitmapBuffer * modelselModelQtyBitmap;
|
||||
extern BitmapBuffer * modelselModelNameBitmap;
|
||||
extern BitmapBuffer * modelselModelMoveBackground;
|
||||
extern BitmapBuffer * modelselModelMoveIcon;
|
||||
extern BitmapBuffer * modelselWizardBackground;
|
||||
|
||||
// calibration bitmaps
|
||||
extern BitmapBuffer * calibStick;
|
||||
extern BitmapBuffer * calibStickBackground;
|
||||
extern BitmapBuffer * calibTrackpBackground;
|
||||
extern BitmapBuffer * calibRadioPict;
|
||||
|
||||
// Channels monitor bitmaps
|
||||
extern BitmapBuffer * chanMonLockedBitmap;
|
||||
extern BitmapBuffer * chanMonInvertedBitmap;
|
||||
|
||||
// Mixer setup bitmaps
|
||||
extern BitmapBuffer * mixerSetupMixerBitmap;
|
||||
extern BitmapBuffer * mixerSetupToBitmap;
|
||||
extern BitmapBuffer * mixerSetupOutputBitmap;
|
||||
extern BitmapBuffer * mixerSetupAddBitmap;
|
||||
extern BitmapBuffer * mixerSetupMultiBitmap;
|
||||
extern BitmapBuffer * mixerSetupReplaceBitmap;
|
||||
extern BitmapBuffer * mixerSetupLabelBitmap;
|
||||
extern BitmapBuffer * mixerSetupFlightmodeIcon;
|
||||
extern BitmapBuffer * mixerSetupCurveBitmap;
|
||||
extern BitmapBuffer * mixerSetupSwitchIcon;
|
||||
extern BitmapBuffer * mixerSetupDelayBitmap;
|
||||
extern BitmapBuffer * mixerSetupSlowBitmap;
|
||||
extern BitmapBuffer * mixerSetupDelaySlowBitmap;
|
||||
extern BitmapBuffer * mixerSetupFlightmodeBitmap;
|
||||
extern BitmapBuffer * mixerSetupSwitchBitmap;
|
||||
|
||||
#endif // _BITMAPS_H_
|
||||
@@ -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 _COLORS_H_
|
||||
#define _COLORS_H_
|
||||
|
||||
// remove windows default definitions
|
||||
#undef OPAQUE
|
||||
#undef RGB
|
||||
|
||||
#define RGB(r, g, b) (uint16_t)((((r) & 0xF8) << 8) + (((g) & 0xFC) << 3) + (((b) & 0xF8) >> 3))
|
||||
#define ARGB(a, r, g, b) (uint16_t)((((a) & 0xF0) << 8) + (((r) & 0xF0) << 4) + (((g) & 0xF0) << 0) + (((b) & 0xF0) >> 4))
|
||||
|
||||
#define WHITE RGB(0xFF, 0xFF, 0xFF)
|
||||
#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)
|
||||
#define RED RGB(229, 32, 30)
|
||||
#define DARKRED RGB(160, 0, 6)
|
||||
#define GREEN RGB(25, 150, 50)
|
||||
|
||||
#define OPACITY_MAX 0x0F
|
||||
#define OPACITY(x) ((x)<<24)
|
||||
|
||||
enum LcdColorIndex
|
||||
{
|
||||
TEXT_COLOR_INDEX,
|
||||
TEXT_BGCOLOR_INDEX,
|
||||
TEXT_INVERTED_COLOR_INDEX,
|
||||
TEXT_INVERTED_BGCOLOR_INDEX,
|
||||
TEXT_STATUSBAR_COLOR_INDEX,
|
||||
LINE_COLOR_INDEX,
|
||||
SCROLLBOX_COLOR_INDEX,
|
||||
MENU_TITLE_BGCOLOR_INDEX,
|
||||
MENU_TITLE_COLOR_INDEX,
|
||||
MENU_TITLE_DISABLE_COLOR_INDEX,
|
||||
HEADER_COLOR_INDEX,
|
||||
ALARM_COLOR_INDEX,
|
||||
WARNING_COLOR_INDEX,
|
||||
TEXT_DISABLE_COLOR_INDEX,
|
||||
CURVE_AXIS_COLOR_INDEX,
|
||||
CURVE_COLOR_INDEX,
|
||||
CURVE_CURSOR_COLOR_INDEX,
|
||||
HEADER_BGCOLOR_INDEX,
|
||||
HEADER_ICON_BGCOLOR_INDEX,
|
||||
HEADER_CURRENT_BGCOLOR_INDEX,
|
||||
TITLE_BGCOLOR_INDEX,
|
||||
TRIM_BGCOLOR_INDEX,
|
||||
TRIM_SHADOW_COLOR_INDEX,
|
||||
MAINVIEW_PANES_COLOR_INDEX,
|
||||
MAINVIEW_GRAPHICS_COLOR_INDEX,
|
||||
OVERLAY_COLOR_INDEX,
|
||||
CUSTOM_COLOR_INDEX,
|
||||
BARGRAPH1_COLOR_INDEX,
|
||||
BARGRAPH2_COLOR_INDEX,
|
||||
BARGRAPH_BGCOLOR_INDEX,
|
||||
LCD_COLOR_COUNT
|
||||
};
|
||||
|
||||
extern uint16_t lcdColorTable[LCD_COLOR_COUNT];
|
||||
|
||||
#define COLOR(index) LcdFlags((index) << 16)
|
||||
#define COLOR_IDX(att) uint8_t((att) >> 16)
|
||||
|
||||
#define TEXT_COLOR COLOR(TEXT_COLOR_INDEX)
|
||||
#define TEXT_BGCOLOR COLOR(TEXT_BGCOLOR_INDEX)
|
||||
#define TEXT_INVERTED_COLOR COLOR(TEXT_INVERTED_COLOR_INDEX)
|
||||
#define TEXT_INVERTED_BGCOLOR COLOR(TEXT_INVERTED_BGCOLOR_INDEX)
|
||||
#define TEXT_STATUSBAR_COLOR COLOR(TEXT_STATUSBAR_COLOR_INDEX)
|
||||
#define LINE_COLOR COLOR(LINE_COLOR_INDEX)
|
||||
#define SCROLLBOX_COLOR COLOR(SCROLLBOX_COLOR_INDEX)
|
||||
#define HEADER_SEPARATOR_COLOR COLOR(HEADER_SEPARATOR_COLOR_INDEX)
|
||||
#define MENU_TITLE_BGCOLOR COLOR(MENU_TITLE_BGCOLOR_INDEX)
|
||||
#define MENU_TITLE_COLOR COLOR(MENU_TITLE_COLOR_INDEX)
|
||||
#define MENU_TITLE_DISABLE_COLOR COLOR(MENU_TITLE_DISABLE_COLOR_INDEX)
|
||||
#define HEADER_COLOR COLOR(HEADER_COLOR_INDEX)
|
||||
#define ALARM_COLOR COLOR(ALARM_COLOR_INDEX)
|
||||
#define WARNING_COLOR COLOR(WARNING_COLOR_INDEX)
|
||||
#define TEXT_DISABLE_COLOR COLOR(TEXT_DISABLE_COLOR_INDEX)
|
||||
#define CURVE_AXIS_COLOR COLOR(CURVE_AXIS_COLOR_INDEX)
|
||||
#define CURVE_COLOR COLOR(CURVE_COLOR_INDEX)
|
||||
#define CURVE_CURSOR_COLOR COLOR(CURVE_CURSOR_COLOR_INDEX)
|
||||
#define TITLE_BGCOLOR COLOR(TITLE_BGCOLOR_INDEX)
|
||||
#define TRIM_BGCOLOR COLOR(TRIM_BGCOLOR_INDEX)
|
||||
#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)
|
||||
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)
|
||||
#define BARGRAPH1_COLOR COLOR(BARGRAPH1_COLOR_INDEX)
|
||||
#define BARGRAPH2_COLOR COLOR(BARGRAPH2_COLOR_INDEX)
|
||||
#define BARGRAPH_BGCOLOR COLOR(BARGRAPH_BGCOLOR_INDEX)
|
||||
#define CUSTOM_COLOR COLOR(CUSTOM_COLOR_INDEX)
|
||||
|
||||
#define ARGB_SPLIT(color, a, r, g, b) \
|
||||
uint16_t a = ((color) & 0xF000) >> 12; \
|
||||
uint16_t r = ((color) & 0x0F00) >> 8; \
|
||||
uint16_t g = ((color) & 0x00F0) >> 4; \
|
||||
uint16_t b = ((color) & 0x000F)
|
||||
|
||||
#define RGB_SPLIT(color, r, g, b) \
|
||||
uint16_t r = ((color) & 0xF800) >> 11; \
|
||||
uint16_t g = ((color) & 0x07E0) >> 5; \
|
||||
uint16_t b = ((color) & 0x001F)
|
||||
|
||||
#define RGB_JOIN(r, g, b) \
|
||||
(((r) << 11) + ((g) << 5) + (b))
|
||||
|
||||
#define GET_RED(color) \
|
||||
(((color) & 0xF800) >> 8)
|
||||
|
||||
#define GET_GREEN(color) \
|
||||
(((color) & 0x07E0) >> 3)
|
||||
|
||||
#define GET_BLUE(color) \
|
||||
(((color) & 0x001F) << 3)
|
||||
|
||||
#endif // _COLORS_H_
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
coord_t getCurveYCoord(FnFuncP fn, int x, int width)
|
||||
{
|
||||
return limit(-width, -divRoundClosest(fn(divRoundClosest(x * RESX, width)) * width, RESX), +width);
|
||||
}
|
||||
|
||||
void drawFunction(FnFuncP fn, int x, int y, int width)
|
||||
{
|
||||
int left = x - width;
|
||||
int right = x + width;
|
||||
|
||||
// Axis
|
||||
lcdDrawSolidHorizontalLine(left, y, width*2+1, CURVE_AXIS_COLOR);
|
||||
lcdDrawSolidVerticalLine(x, y-width, width*2, CURVE_AXIS_COLOR);
|
||||
|
||||
// Extra lines
|
||||
lcdDrawVerticalLine(left+width/2, y-width, width*2, STASHED, CURVE_AXIS_COLOR);
|
||||
lcdDrawVerticalLine(right-width/2, y-width, width*2, STASHED, CURVE_AXIS_COLOR);
|
||||
lcdDrawHorizontalLine(left, y-width/2, width*2+1, STASHED, CURVE_AXIS_COLOR);
|
||||
lcdDrawHorizontalLine(left, y+width/2, width*2+1, STASHED, CURVE_AXIS_COLOR);
|
||||
|
||||
// Outside border
|
||||
lcdDrawSolidVerticalLine(left, y-width, width*2, TEXT_COLOR);
|
||||
lcdDrawSolidVerticalLine(right, y-width, width*2, TEXT_COLOR);
|
||||
lcdDrawSolidHorizontalLine(left, y-width, width*2+1, TEXT_COLOR);
|
||||
lcdDrawSolidHorizontalLine(left, y+width, width*2+1, TEXT_COLOR);
|
||||
|
||||
coord_t prev_yv = (coord_t)-1;
|
||||
|
||||
for (int xv=-width; xv<=width; xv+=1) {
|
||||
coord_t yv = y + getCurveYCoord(fn, xv, width);
|
||||
if (prev_yv != (coord_t)-1) {
|
||||
if (prev_yv < yv) {
|
||||
for (int y=prev_yv; y<=yv; y+=1) {
|
||||
lcdDrawBitmapPattern(x+xv-2, y-2, LBM_POINT, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int y=yv; y<=prev_yv; y+=1) {
|
||||
lcdDrawBitmapPattern(x+xv-2, y-2, LBM_POINT, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
prev_yv = yv;
|
||||
}
|
||||
}
|
||||
|
||||
void drawCurveVerticalScale(int x)
|
||||
{
|
||||
for (int i=0; i<=20; i++) {
|
||||
lcdDrawSolidHorizontalLine(x, CURVE_CENTER_Y-CURVE_SIDE_WIDTH+i*CURVE_SIDE_WIDTH/10, 10, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawCurveHorizontalScale()
|
||||
{
|
||||
for (int i=0; i<=20; i++) {
|
||||
lcdDrawSolidVerticalLine(CURVE_CENTER_X-CURVE_SIDE_WIDTH+i*CURVE_SIDE_WIDTH/10, CURVE_CENTER_Y+CURVE_SIDE_WIDTH+5, 10, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawCurveCoord(int x, int y, const char * text, bool active)
|
||||
{
|
||||
lcd->drawSolidFilledRect(x, y, CURVE_COORD_WIDTH, CURVE_COORD_HEIGHT, CURVE_CURSOR_COLOR);
|
||||
lcdDrawText(x+3+(CURVE_COORD_WIDTH-1-getTextWidth(text, SMLSIZE))/2, y+1, text, LEFT|SMLSIZE|TEXT_BGCOLOR);
|
||||
if (active) {
|
||||
lcdDrawBitmapPattern(x, y, LBM_CURVE_COORD_SHADOW, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawCurvePoint(int x, int y, LcdFlags color)
|
||||
{
|
||||
lcdDrawBitmapPattern(x, y, LBM_CURVE_POINT, color);
|
||||
lcdDrawBitmapPattern(x, y, LBM_CURVE_POINT_CENTER, TEXT_BGCOLOR);
|
||||
}
|
||||
@@ -0,0 +1,604 @@
|
||||
/*
|
||||
* 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 drawStatusText(const char * text)
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_FOOTER_TOP, text, TEXT_STATUSBAR_COLOR);
|
||||
}
|
||||
|
||||
void drawColumnHeader(const char * const * headers, const char * const * descriptions, uint8_t index)
|
||||
{
|
||||
lcdDrawText(LCD_W-MENUS_MARGIN_LEFT, MENU_TITLE_TOP + 2, headers[index], RIGHT | SMLSIZE | MENU_TITLE_COLOR);
|
||||
if (descriptions) {
|
||||
drawStatusText(descriptions[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void drawCheckBox(coord_t x, coord_t y, uint8_t value, LcdFlags attr)
|
||||
{
|
||||
if (attr) {
|
||||
lcdDrawSolidFilledRect(x-1, y+3, 14, 14, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawSolidFilledRect(x+1, y+5, 10, 10, TEXT_BGCOLOR);
|
||||
if (value) {
|
||||
lcdDrawSolidFilledRect(x+2, y+6, 8, 8, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (value) {
|
||||
lcdDrawSolidFilledRect(x+2, y+6, 8, 8, SCROLLBOX_COLOR);
|
||||
lcdDrawSolidRect(x, y+4, 12, 12, 1, LINE_COLOR);
|
||||
}
|
||||
else {
|
||||
lcdDrawSolidRect(x, y+4, 12, 12, 1, LINE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawVerticalScrollbar(coord_t x, coord_t y, coord_t h, uint16_t offset, uint16_t count, uint8_t visible)
|
||||
{
|
||||
if (visible < count) {
|
||||
lcdDrawSolidVerticalLine(x, y, h, LINE_COLOR);
|
||||
coord_t yofs = (h*offset + count/2) / count;
|
||||
coord_t yhgt = (h*visible + count/2) / count;
|
||||
if (yhgt + yofs > h)
|
||||
yhgt = h - yofs;
|
||||
lcdDrawSolidFilledRect(x-1, y + yofs, 3, yhgt, SCROLLBOX_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawTrimSquare(coord_t x, coord_t y)
|
||||
{
|
||||
lcdDrawSolidFilledRect(x-2, y, 15, 15, TRIM_BGCOLOR);
|
||||
lcdDrawBitmapPattern(x-2, y, LBM_TRIM_SHADOW, TRIM_SHADOW_COLOR);
|
||||
}
|
||||
|
||||
void drawHorizontalTrimPosition(coord_t x, coord_t y, int16_t dir)
|
||||
{
|
||||
drawTrimSquare(x, y);
|
||||
if (dir >= 0) {
|
||||
lcdDrawSolidVerticalLine(x+8, y+3, 9, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
if (dir <= 0) {
|
||||
lcdDrawSolidVerticalLine(x+2, y+3, 9, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
// if (exttrim) {
|
||||
// lcdDrawSolidVerticalLine(xm, ym, 9, TEXT_INVERTED_COLOR);
|
||||
// }
|
||||
}
|
||||
|
||||
void drawVerticalTrimPosition(coord_t x, coord_t y, int16_t dir)
|
||||
{
|
||||
drawTrimSquare(x, y);
|
||||
if (dir >= 0) {
|
||||
lcdDrawSolidHorizontalLine(x+1, y+4, 9, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
if (dir <= 0) {
|
||||
lcdDrawSolidHorizontalLine(x+1, y+10, 9, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
// if (exttrim) {
|
||||
// lcdDrawSolidHorizontalLine(xm-1, ym, 3, TEXT_INVERTED_COLOR);
|
||||
// }
|
||||
}
|
||||
|
||||
void drawVerticalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options)
|
||||
{
|
||||
val = limit(min, val, max);
|
||||
if (steps) {
|
||||
int delta = len / steps;
|
||||
for (int i = 0; i <= len; i += delta) {
|
||||
if ((options & OPTION_SLIDER_BIG_TICKS) && (i == 0 || i == len / 2 || i == len))
|
||||
lcdDrawSolidHorizontalLine(x, y + i, 13, TEXT_COLOR);
|
||||
else
|
||||
lcdDrawSolidHorizontalLine(x + 2, y + i, 9, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawBitmapPattern(x + 1, y, LBM_VTRIM_FRAME, TEXT_COLOR);
|
||||
/* if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) {
|
||||
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
|
||||
lcdDrawNumber((stickIndex==0 ? TRIM_LH_X : TRIM_RH_X)+(trim>0 ? -20 : 50), ym+1, trim, TINSIZE);
|
||||
}
|
||||
} */
|
||||
}
|
||||
y += len - divRoundClosest(len * (val - min), max - min) - 5;
|
||||
if (options & OPTION_SLIDER_TRIM_BUTTON) {
|
||||
drawVerticalTrimPosition(x, y - 2, val);
|
||||
}
|
||||
else if (options & OPTION_SLIDER_NUMBER_BUTTON) {
|
||||
drawTrimSquare(x, y - 2);
|
||||
lcdDrawChar(x + 2, y - 1, '0' + val, SMLSIZE | TEXT_INVERTED_COLOR);
|
||||
}
|
||||
else {
|
||||
drawTrimSquare(x, y - 2);
|
||||
}
|
||||
}
|
||||
|
||||
void drawHorizontalSlider(coord_t x, coord_t y, int len, int val, int min, int max, uint8_t steps, uint32_t options)
|
||||
{
|
||||
val = limit(min, val, max);
|
||||
int w = divRoundClosest(len * (val - min), max - min);
|
||||
if (options & OPTION_SLIDER_TICKS) {
|
||||
if (steps) {
|
||||
int delta = len / steps;
|
||||
for (int i = 0; i <= len; i += delta) {
|
||||
if ((options & OPTION_SLIDER_BIG_TICKS) && (i == 0 || i == len / 2 || i == len))
|
||||
lcdDrawSolidVerticalLine(x + i, y, 13, TEXT_COLOR);
|
||||
else
|
||||
lcdDrawSolidVerticalLine(x + i, y + 2, 9, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (options & OPTION_SLIDER_EMPTY_BAR) {
|
||||
lcdDrawBitmapPattern(x, y + 1, LBM_HTRIM_FRAME, TEXT_COLOR);
|
||||
}
|
||||
else if (options & OPTION_SLIDER_DBL_COLOR) {
|
||||
lcdDrawBitmapPattern(x, y + 8, LBM_SLIDER_BAR_LEFT, w <= 0 ? LINE_COLOR : TEXT_INVERTED_BGCOLOR);
|
||||
if (w > 4)
|
||||
lcdDrawSolidFilledRect(x + 4, y + 8, w - 4, 4, TEXT_INVERTED_BGCOLOR);
|
||||
if (w < len - 4)
|
||||
lcdDrawSolidFilledRect(x + w, y + 8, len - w - 4, 4, LINE_COLOR);
|
||||
lcdDrawBitmapPattern(x + len - 4, y + 8, LBM_SLIDER_BAR_RIGHT, w >= len ? TEXT_INVERTED_BGCOLOR : LINE_COLOR);
|
||||
}
|
||||
else {
|
||||
lcdDrawBitmapPattern(x, y + 8, LBM_SLIDER_BAR_LEFT, LINE_COLOR);
|
||||
lcdDrawSolidFilledRect(x + 4, y + 8, len - 8, 4, LINE_COLOR);
|
||||
lcdDrawBitmapPattern(x + len - 4, y + 8, LBM_SLIDER_BAR_RIGHT, LINE_COLOR);
|
||||
//
|
||||
/* if (g_model.displayTrims != DISPLAY_TRIMS_NEVER && trim != 0) {
|
||||
if (g_model.displayTrims == DISPLAY_TRIMS_ALWAYS || (trimsDisplayTimer > 0 && (trimsDisplayMask & (1<<i)))) {
|
||||
lcdDrawNumber((stickIndex==0 ? TRIM_LH_X : TRIM_RH_X)+(trim>0 ? -20 : 50), ym+1, trim, TINSIZE);
|
||||
}
|
||||
} */
|
||||
}
|
||||
x += w - 5;
|
||||
if (options & OPTION_SLIDER_TRIM_BUTTON) {
|
||||
drawHorizontalTrimPosition(x, y - 1, val);
|
||||
}
|
||||
else if (options & OPTION_SLIDER_NUMBER_BUTTON) {
|
||||
drawTrimSquare(x+2, y - 1);
|
||||
char text[] = { (char)('0' + val), '\0' };
|
||||
lcdDrawText(x + 7, y - 1, text, SMLSIZE | CENTERED | TEXT_INVERTED_COLOR);
|
||||
}
|
||||
else if (options & OPTION_SLIDER_SQUARE_BUTTON) {
|
||||
drawTrimSquare(x, y - 1);
|
||||
}
|
||||
else {
|
||||
lcdDrawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_OUT, TEXT_COLOR);
|
||||
lcdDrawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_MID, TEXT_BGCOLOR);
|
||||
if ((options & INVERS) && (!(options & BLINK) || !BLINK_ON_PHASE))
|
||||
lcdDrawBitmapPattern(x, y + 2, LBM_SLIDER_POINT_IN, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(GVARS)
|
||||
bool noZero(int val)
|
||||
{
|
||||
return val != 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
flags |= (prec == 1 ? PREC1 : PREC2);
|
||||
}
|
||||
drawValueWithUnit(x, y, value, g_model.gvars[gvar].unit ? UNIT_PERCENT : UNIT_RAW, flags);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
uint16_t delta = GV_GET_GV1_VALUE(max);
|
||||
bool invers = (attr & INVERS);
|
||||
|
||||
// TRACE("editGVarFieldValue(val=%d min=%d max=%d)", value, min, max);
|
||||
|
||||
if (invers && event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
s_editMode = !s_editMode;
|
||||
if (attr & PREC1)
|
||||
value = (GV_IS_GV_VALUE(value, min, max) ? GET_GVAR(value, min, max, mixerCurrentFlightMode)*10 : delta);
|
||||
else
|
||||
value = (GV_IS_GV_VALUE(value, min, max) ? GET_GVAR(value, min, max, mixerCurrentFlightMode) : delta);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
|
||||
if (GV_IS_GV_VALUE(value, min, max)) {
|
||||
attr &= ~PREC1;
|
||||
|
||||
int8_t idx = (int16_t) GV_INDEX_CALC_DELTA(value, delta);
|
||||
if (idx >= 0) ++idx; // transform form idx=0=GV1 to idx=1=GV1 in order to handle double keys invert
|
||||
if (invers) {
|
||||
CHECK_INCDEC_MODELVAR_CHECK(event, idx, -MAX_GVARS, MAX_GVARS, noZero);
|
||||
if (idx == 0) idx = 1; // handle reset to zero, map to GV1
|
||||
}
|
||||
if (idx < 0) {
|
||||
value = (int16_t) GV_CALC_VALUE_IDX_NEG(idx, delta);
|
||||
idx = -idx;
|
||||
drawStringWithIndex(x, y, STR_GV, idx, attr, "-");
|
||||
}
|
||||
else {
|
||||
drawStringWithIndex(x, y, STR_GV, idx, attr);
|
||||
value = (int16_t) GV_CALC_VALUE_IDX_POS(idx-1, delta);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(x, y, value, attr, 0, NULL, "%");
|
||||
if (invers) value = checkIncDec(event, value, min, max, EE_MODEL | editflags);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
#else
|
||||
void drawValueOrGVar(BitmapBuffer * dc, coord_t x, coord_t y, gvar_t value, LcdFlags flags)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
#define SHUTDOWN_CIRCLE_DIAMETER 150
|
||||
void drawShutdownAnimation(uint32_t duration, uint32_t totalDuration, const char * message)
|
||||
{
|
||||
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(lcd);
|
||||
lcd->drawBitmap((LCD_W-shutdown->getWidth())/2, (LCD_H-shutdown->getHeight())/2, shutdown);
|
||||
lcdStoreBackupBuffer();
|
||||
}
|
||||
else {
|
||||
lcdRestoreBackupBuffer();
|
||||
int quarter = duration / (totalDuration / 5);
|
||||
if (quarter >= 1) lcdDrawBitmapPattern(LCD_W/2, (LCD_H-SHUTDOWN_CIRCLE_DIAMETER)/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, 0, SHUTDOWN_CIRCLE_DIAMETER/2);
|
||||
if (quarter >= 2) lcdDrawBitmapPattern(LCD_W/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER/2, SHUTDOWN_CIRCLE_DIAMETER/2);
|
||||
if (quarter >= 3) lcdDrawBitmapPattern((LCD_W-SHUTDOWN_CIRCLE_DIAMETER)/2, LCD_H/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER, SHUTDOWN_CIRCLE_DIAMETER/2);
|
||||
if (quarter >= 4) lcdDrawBitmapPattern((LCD_W-SHUTDOWN_CIRCLE_DIAMETER)/2, (LCD_H-SHUTDOWN_CIRCLE_DIAMETER)/2, LBM_SHUTDOWN_CIRCLE, TEXT_COLOR, SHUTDOWN_CIRCLE_DIAMETER*3/2, SHUTDOWN_CIRCLE_DIAMETER/2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcd->clear();
|
||||
int quarter = duration / (totalDuration / 5);
|
||||
for (int i=1; i<=4; i++) {
|
||||
if (quarter >= i) {
|
||||
lcd->drawSolidFilledRect(LCD_W / 2 - 70 + 24 * i, LCD_H / 2 - 10, 20, 20, TEXT_BGCOLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lcdRefresh();
|
||||
lastDuration = duration;
|
||||
}
|
||||
|
||||
void drawCurveRef(BitmapBuffer * dc, coord_t x, coord_t y, const CurveRef & curve, LcdFlags 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 _DRAW_FUNCTIONS_H_
|
||||
#define _DRAW_FUNCTIONS_H_
|
||||
|
||||
#include "opentx.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
|
||||
#define OPTION_SLIDER_TICKS 0x20
|
||||
#define OPTION_SLIDER_BIG_TICKS 0x40
|
||||
#define OPTION_SLIDER_TRIM_BUTTON 0x80
|
||||
#define OPTION_SLIDER_NUMBER_BUTTON 0x100
|
||||
#define OPTION_SLIDER_SQUARE_BUTTON 0x200
|
||||
|
||||
void drawStatusText(const char * text);
|
||||
void drawColumnHeader(const char * const * headers, const char * const * descriptions, uint8_t index);
|
||||
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 drawProgressScreen(const char * title, const char * message, int num, int den);
|
||||
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);
|
||||
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 drawSplash();
|
||||
void drawSleepBitmap();
|
||||
void drawShutdownAnimation(uint32_t index, const char * message);
|
||||
|
||||
// Main view standard widgets
|
||||
void drawMainPots();
|
||||
void drawTrims(uint8_t flightMode);
|
||||
|
||||
#endif // _DRAW_FUNCTIONS_H_
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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 "rle.h"
|
||||
|
||||
const uint16_t font_tinsize_specs[] = {
|
||||
#include "font_9.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_tinsize[] = {
|
||||
#include "font_9.lbm"
|
||||
};
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
const uint16_t font_smlsize_specs[] = {
|
||||
#include "font_15.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_smlsize[] = {
|
||||
#include "font_15.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_stdsize_specs[] = {
|
||||
#include "font_17.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_stdsize[] = {
|
||||
#include "font_17.lbm"
|
||||
};
|
||||
|
||||
const uint16_t font_stdsizebold_specs[] = {
|
||||
#include "font_bold17.specs"
|
||||
};
|
||||
|
||||
const unsigned char font_stdsizebold[] = {
|
||||
#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,
|
||||
font_stdsizebold_specs, font_tinsize_specs, font_smlsize_specs, font_midsize_specs, font_dblsize_specs, font_xxlsize_specs, font_stdsize_specs, font_stdsize_specs
|
||||
};
|
||||
|
||||
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
|
||||
|
||||
uint8_t * decompressFont(const uint8_t * font)
|
||||
{
|
||||
uint16_t width = *((uint16_t *)font);
|
||||
uint16_t height = *(((uint16_t *)font)+1);
|
||||
|
||||
size_t font_size = width * height;
|
||||
uint8_t* dec_buf = (uint8_t*)malloc(font_size + 4);
|
||||
|
||||
// copy width / height
|
||||
memcpy(dec_buf,font,4);
|
||||
|
||||
rle_decode_8bit(dec_buf+4, font_size, font+4);
|
||||
return dec_buf;
|
||||
}
|
||||
|
||||
void loadFonts()
|
||||
{
|
||||
static bool fonts_loaded = false;
|
||||
if (fonts_loaded) return;
|
||||
|
||||
#if !defined(BOOT)
|
||||
int i=0;
|
||||
for (; i<9; i++)
|
||||
fontsTable[i] = decompressFont(fontsTable[i]);
|
||||
|
||||
for (; i<16; i++)
|
||||
fontsTable[i] = fontsTable[i-9];
|
||||
#else
|
||||
fontsTable[0] = decompressFont(fontsTable[0]);
|
||||
#endif
|
||||
|
||||
fonts_loaded = true;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 _GUI_H_
|
||||
#define _GUI_H_
|
||||
|
||||
#include "gui_common.h"
|
||||
#include "lcd.h"
|
||||
#include "menus.h"
|
||||
#include "popups.h"
|
||||
#include "draw_functions.h"
|
||||
#include "bitmaps.h"
|
||||
#include "theme.h"
|
||||
#include "libopenui_config.h"
|
||||
|
||||
#define LOAD_MODEL_BITMAP()
|
||||
|
||||
#if defined(FLIGHT_MODES)
|
||||
void displayFlightModes(coord_t x, coord_t y, FlightModesType value, uint8_t attr);
|
||||
FlightModesType editFlightModes(coord_t x, coord_t y, event_t event, FlightModesType value, uint8_t attr);
|
||||
#else
|
||||
#define displayFlightModes(...)
|
||||
#endif
|
||||
|
||||
// Curve functions
|
||||
coord_t getCurveYCoord(FnFuncP fn, int x, int width);
|
||||
void drawFunction(FnFuncP fn, int offset);
|
||||
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);
|
||||
|
||||
extern Layout * customScreens[MAX_CUSTOM_SCREENS];
|
||||
extern Topbar * topbar;
|
||||
|
||||
void drawAlertBox(const char * title, const char * text, const char * action);
|
||||
void showAlertBox(const char * title, const char * text, const char * action, uint8_t sound);
|
||||
|
||||
#define IS_MAIN_VIEW_DISPLAYED() menuHandlers[0] == menuMainView
|
||||
#define IS_TELEMETRY_VIEW_DISPLAYED() false
|
||||
#define IS_OTHER_VIEW_DISPLAYED() false
|
||||
|
||||
#endif // _GUI_H_
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
std::list<const LayoutFactory *> & getRegisteredLayouts()
|
||||
{
|
||||
static std::list<const LayoutFactory *> layouts;
|
||||
return layouts;
|
||||
}
|
||||
|
||||
void registerLayout(const LayoutFactory * factory)
|
||||
{
|
||||
TRACE("register layout %s", factory->getName());
|
||||
getRegisteredLayouts().push_back(factory);
|
||||
}
|
||||
|
||||
const LayoutFactory * getLayoutFactory(const char * name)
|
||||
{
|
||||
std::list<const LayoutFactory *>::const_iterator it = getRegisteredLayouts().cbegin();
|
||||
for (; it != getRegisteredLayouts().cend(); ++it) {
|
||||
if (!strcmp(name, (*it)->getName())) {
|
||||
return (*it);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Layout * loadLayout(const char * name, Layout::PersistentData * persistentData)
|
||||
{
|
||||
const LayoutFactory * factory = getLayoutFactory(name);
|
||||
if (factory) {
|
||||
return factory->load(persistentData);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void loadCustomScreens()
|
||||
{
|
||||
for (unsigned int i=0; i<MAX_CUSTOM_SCREENS; i++) {
|
||||
delete customScreens[i];
|
||||
char name[LAYOUT_NAME_LEN + 1];
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, g_model.screenData[i].layoutName, LAYOUT_NAME_LEN);
|
||||
customScreens[i] = loadLayout(name, &g_model.screenData[i].layoutData);
|
||||
}
|
||||
|
||||
if (customScreens[0] == nullptr && getRegisteredLayouts().size()) {
|
||||
customScreens[0] = getRegisteredLayouts().front()->create(&g_model.screenData[0].layoutData);
|
||||
}
|
||||
|
||||
if (topbar) {
|
||||
topbar->load();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 _LAYOUT_H_
|
||||
#define _LAYOUT_H_
|
||||
|
||||
#include <list>
|
||||
#include "widgets_container.h"
|
||||
#include "lcd.h"
|
||||
|
||||
#define MAX_LAYOUT_ZONES 10
|
||||
#define MAX_LAYOUT_OPTIONS 10
|
||||
|
||||
class LayoutFactory;
|
||||
|
||||
class Layout: public WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>
|
||||
{
|
||||
friend class LayoutFactory;
|
||||
|
||||
public:
|
||||
Layout(const LayoutFactory * factory, PersistentData * persistentData):
|
||||
WidgetsContainer<MAX_LAYOUT_ZONES, MAX_LAYOUT_OPTIONS>(persistentData),
|
||||
factory(factory)
|
||||
{
|
||||
}
|
||||
|
||||
inline const LayoutFactory * getFactory() const
|
||||
{
|
||||
return factory;
|
||||
}
|
||||
|
||||
virtual void update()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
const LayoutFactory * factory;
|
||||
};
|
||||
|
||||
void registerLayout(const LayoutFactory * factory);
|
||||
|
||||
class LayoutFactory
|
||||
{
|
||||
public:
|
||||
LayoutFactory(const char * name):
|
||||
name(name)
|
||||
{
|
||||
registerLayout(this);
|
||||
}
|
||||
const char * getName() const { return name; }
|
||||
virtual void drawThumb(uint16_t x, uint16_t y, uint32_t flags) const = 0;
|
||||
virtual const ZoneOption * getOptions() const = 0;
|
||||
virtual Layout * create(Layout::PersistentData * persistentData) const = 0;
|
||||
virtual Layout * load(Layout::PersistentData * persistentData) const = 0;
|
||||
|
||||
protected:
|
||||
const char * name;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class BaseLayoutFactory: public LayoutFactory
|
||||
{
|
||||
public:
|
||||
BaseLayoutFactory(const char * name, const uint8_t * bitmap, const ZoneOption * options):
|
||||
LayoutFactory(name),
|
||||
bitmap(bitmap),
|
||||
options(options)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void drawThumb(uint16_t x, uint16_t y, uint32_t flags) const
|
||||
{
|
||||
lcdDrawBitmapPattern(x, y, bitmap, flags);
|
||||
}
|
||||
|
||||
virtual const ZoneOption * getOptions() const
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
virtual Layout * create(Layout::PersistentData * persistentData) const
|
||||
{
|
||||
Layout * layout = new T(this, persistentData);
|
||||
if (layout) {
|
||||
layout->create();
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
virtual Layout * load(Layout::PersistentData * persistentData) const
|
||||
{
|
||||
Layout * layout = new T(this, persistentData);
|
||||
if (layout) {
|
||||
layout->load();
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
protected:
|
||||
const uint8_t * bitmap;
|
||||
const ZoneOption * options;
|
||||
};
|
||||
|
||||
Layout * loadLayout(const char * name, Layout::PersistentData * persistentData);
|
||||
void loadCustomScreens();
|
||||
|
||||
std::list<const LayoutFactory *> & getRegisteredLayouts();
|
||||
|
||||
#endif // _LAYOUT_H_
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 uint8_t LBM_LAYOUT_1x1[] = {
|
||||
#include "mask_layout1x1.lbm"
|
||||
};
|
||||
|
||||
const ZoneOption OPTIONS_LAYOUT_1x1[] = {
|
||||
{ "Top bar", ZoneOption::Bool },
|
||||
{ "Sliders+Trims", ZoneOption::Bool },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
class Layout1x1: public Layout
|
||||
{
|
||||
public:
|
||||
Layout1x1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
|
||||
Layout(factory, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void create()
|
||||
{
|
||||
Layout::create();
|
||||
persistentData->options[0].boolValue = true;
|
||||
persistentData->options[1].boolValue = true;
|
||||
}
|
||||
|
||||
virtual unsigned int getZonesCount() const
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
virtual Zone getZone(unsigned int index) const
|
||||
{
|
||||
Zone zone = { 10, 10, LCD_W - 2*10, LCD_H - 2*10 };
|
||||
if (persistentData->options[0].boolValue) {
|
||||
zone.y += MENU_HEADER_HEIGHT;
|
||||
zone.h -= MENU_HEADER_HEIGHT;
|
||||
}
|
||||
if (persistentData->options[1].boolValue) {
|
||||
zone.x += 35;
|
||||
zone.w -= 2*35;
|
||||
zone.h -= 35;
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
};
|
||||
|
||||
void Layout1x1::refresh()
|
||||
{
|
||||
theme->drawBackground();
|
||||
|
||||
if (persistentData->options[0].boolValue) {
|
||||
drawTopBar();
|
||||
}
|
||||
|
||||
if (persistentData->options[1].boolValue) {
|
||||
// Sliders + Trims + Flight mode
|
||||
lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name, sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE) / 2,
|
||||
232,
|
||||
g_model.flightModeData[mixerCurrentFlightMode].name,
|
||||
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
|
||||
drawMainPots();
|
||||
drawTrims(mixerCurrentFlightMode);
|
||||
}
|
||||
|
||||
Layout::refresh();
|
||||
}
|
||||
|
||||
BaseLayoutFactory<Layout1x1> layout1x1("Layout1x1", LBM_LAYOUT_1x1, OPTIONS_LAYOUT_1x1);
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* 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 uint8_t LBM_LAYOUT_2P1[] = {
|
||||
#include "mask_layout2+1.lbm"
|
||||
};
|
||||
|
||||
const ZoneOption OPTIONS_LAYOUT_2P1[] = {
|
||||
{ "Top bar", ZoneOption::Bool },
|
||||
{ "Flight mode", ZoneOption::Bool },
|
||||
{ "Sliders", ZoneOption::Bool },
|
||||
{ "Trims", ZoneOption::Bool },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
const Zone ZONES_LAYOUT_2P1[3] = {
|
||||
{ 240, 60, 192, 152 },
|
||||
{ 48, 60, 180, 70 },
|
||||
{ 48, 142, 180, 70 }
|
||||
};
|
||||
|
||||
class Layout2P1: public Layout
|
||||
{
|
||||
public:
|
||||
Layout2P1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
|
||||
Layout(factory, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void create()
|
||||
{
|
||||
Layout::create();
|
||||
persistentData->options[0].boolValue = true;
|
||||
persistentData->options[1].boolValue = true;
|
||||
persistentData->options[2].boolValue = true;
|
||||
persistentData->options[3].boolValue = true;
|
||||
}
|
||||
|
||||
virtual unsigned int getZonesCount() const
|
||||
{
|
||||
return DIM(ZONES_LAYOUT_2P1);
|
||||
}
|
||||
|
||||
virtual Zone getZone(unsigned int index) const
|
||||
{
|
||||
return ZONES_LAYOUT_2P1[index];
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
};
|
||||
|
||||
void Layout2P1::refresh()
|
||||
{
|
||||
theme->drawBackground();
|
||||
|
||||
if (persistentData->options[0].boolValue) {
|
||||
drawTopBar();
|
||||
}
|
||||
|
||||
if (persistentData->options[1].boolValue) {
|
||||
// Flight mode
|
||||
lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
|
||||
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
|
||||
ZCHAR | SMLSIZE) / 2,
|
||||
232,
|
||||
g_model.flightModeData[mixerCurrentFlightMode].name,
|
||||
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
|
||||
}
|
||||
|
||||
if (persistentData->options[2].boolValue) {
|
||||
// Pots and rear sliders positions
|
||||
drawMainPots();
|
||||
}
|
||||
|
||||
if (persistentData->options[3].boolValue) {
|
||||
// Trims
|
||||
drawTrims(mixerCurrentFlightMode);
|
||||
}
|
||||
|
||||
Layout::refresh();
|
||||
}
|
||||
|
||||
BaseLayoutFactory<Layout2P1> layout2P1("Layout2P1", LBM_LAYOUT_2P1, OPTIONS_LAYOUT_2P1);
|
||||
const LayoutFactory * defaultLayout = &layout2P1;
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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 uint8_t LBM_LAYOUT_2x1[] = {
|
||||
#include "mask_layout2x1.lbm"
|
||||
};
|
||||
|
||||
const ZoneOption OPTIONS_LAYOUT_2x1[] = {
|
||||
{ "Top bar", ZoneOption::Bool },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
class Layout2x1: public Layout
|
||||
{
|
||||
public:
|
||||
Layout2x1(const LayoutFactory * factory, Layout::PersistentData * persistentData):
|
||||
Layout(factory, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void create()
|
||||
{
|
||||
Layout::create();
|
||||
persistentData->options[0].boolValue = true;
|
||||
}
|
||||
|
||||
virtual unsigned int getZonesCount() const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
virtual Zone getZone(unsigned int index) const
|
||||
{
|
||||
Zone zone;
|
||||
zone.w = (LCD_W-3*10) / 2;
|
||||
zone.x = (index & 1) ? 20 + zone.w : 10;
|
||||
if (persistentData->options[0].boolValue) {
|
||||
zone.h = (LCD_H-MENU_HEADER_HEIGHT-2*10);
|
||||
zone.y = MENU_HEADER_HEIGHT + 10;
|
||||
}
|
||||
else {
|
||||
zone.h = (LCD_H-2*10);
|
||||
zone.y = 10;
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
};
|
||||
|
||||
void Layout2x1::refresh()
|
||||
{
|
||||
theme->drawBackground();
|
||||
|
||||
if (persistentData->options[0].boolValue) {
|
||||
drawTopBar();
|
||||
}
|
||||
|
||||
Layout::refresh();
|
||||
}
|
||||
|
||||
BaseLayoutFactory<Layout2x1> Layout2x1("Layout2x1", LBM_LAYOUT_2x1, OPTIONS_LAYOUT_2x1);
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 uint8_t LBM_LAYOUT_2x2[] = {
|
||||
#include "mask_layout2x2.lbm"
|
||||
};
|
||||
|
||||
const ZoneOption OPTIONS_LAYOUT_2x2[] = {
|
||||
{ "Top bar", ZoneOption::Bool },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
class Layout2x2: public Layout
|
||||
{
|
||||
public:
|
||||
Layout2x2(const LayoutFactory * factory, Layout::PersistentData * persistentData):
|
||||
Layout(factory, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void create()
|
||||
{
|
||||
Layout::create();
|
||||
persistentData->options[0].boolValue = true;
|
||||
}
|
||||
|
||||
virtual unsigned int getZonesCount() const
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
virtual Zone getZone(unsigned int index) const
|
||||
{
|
||||
Zone zone;
|
||||
zone.w = (LCD_W-3*10) / 2;
|
||||
zone.x = (index & 1) ? 20 + zone.w : 10;
|
||||
if (persistentData->options[0].boolValue) {
|
||||
zone.h = (LCD_H-MENU_HEADER_HEIGHT-3*10) / 2;
|
||||
zone.y = MENU_HEADER_HEIGHT + 10;
|
||||
}
|
||||
else {
|
||||
zone.h = (LCD_H-3*10) / 2;
|
||||
zone.y = 10;
|
||||
}
|
||||
if (index >= 2) {
|
||||
zone.y += 10 + zone.h;
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
};
|
||||
|
||||
void Layout2x2::refresh()
|
||||
{
|
||||
theme->drawBackground();
|
||||
|
||||
if (persistentData->options[0].boolValue) {
|
||||
drawTopBar();
|
||||
}
|
||||
|
||||
Layout::refresh();
|
||||
}
|
||||
|
||||
BaseLayoutFactory<Layout2x2> layout2x2("Layout2x2", LBM_LAYOUT_2x2, OPTIONS_LAYOUT_2x2);
|
||||
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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 uint8_t LBM_LAYOUT_2x4[] = {
|
||||
#include "mask_layout2x4.lbm"
|
||||
};
|
||||
|
||||
const ZoneOption OPTIONS_LAYOUT_2x4[] = {
|
||||
{ "Top bar", ZoneOption::Bool },
|
||||
{ "Flight mode", ZoneOption::Bool },
|
||||
{ "Sliders", ZoneOption::Bool },
|
||||
{ "Trims", ZoneOption::Bool },
|
||||
{ "Panel1 background", ZoneOption::Bool },
|
||||
{ " Color", ZoneOption::Color },
|
||||
{ "Panel2 background", ZoneOption::Bool },
|
||||
{ " Color", ZoneOption::Color },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
class Layout2x4: public Layout
|
||||
{
|
||||
public:
|
||||
Layout2x4(const LayoutFactory * factory, Layout::PersistentData * persistentData):
|
||||
Layout(factory, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void create()
|
||||
{
|
||||
Layout::create();
|
||||
persistentData->options[0].boolValue = true;
|
||||
persistentData->options[1].boolValue = true;
|
||||
persistentData->options[2].boolValue = true;
|
||||
persistentData->options[3].boolValue = true;
|
||||
persistentData->options[4].boolValue = true;
|
||||
persistentData->options[5].unsignedValue = RGB(77, 112, 203);
|
||||
persistentData->options[6].boolValue = false;
|
||||
persistentData->options[7].unsignedValue = RGB(77, 112, 203);
|
||||
}
|
||||
|
||||
virtual unsigned int getZonesCount() const
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
virtual Zone getZone(unsigned int index) const
|
||||
{
|
||||
Zone zone;
|
||||
zone.x = (index >= 4) ? 260 : 60;
|
||||
zone.y = 56 + (index % 4) * 42;
|
||||
zone.w = 160;
|
||||
zone.h = 32;
|
||||
return zone;
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
};
|
||||
|
||||
void Layout2x4::refresh()
|
||||
{
|
||||
theme->drawBackground();
|
||||
|
||||
if (persistentData->options[0].boolValue) {
|
||||
drawTopBar();
|
||||
}
|
||||
|
||||
if (persistentData->options[1].boolValue) {
|
||||
// Flight mode
|
||||
lcdDrawSizedText(LCD_W / 2 - getTextWidth(g_model.flightModeData[mixerCurrentFlightMode].name,
|
||||
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name),
|
||||
ZCHAR | SMLSIZE) / 2,
|
||||
232,
|
||||
g_model.flightModeData[mixerCurrentFlightMode].name,
|
||||
sizeof(g_model.flightModeData[mixerCurrentFlightMode].name), ZCHAR | SMLSIZE);
|
||||
}
|
||||
|
||||
if (persistentData->options[2].boolValue) {
|
||||
// Pots and rear sliders positions
|
||||
drawMainPots();
|
||||
}
|
||||
|
||||
if (persistentData->options[3].boolValue) {
|
||||
// Trims
|
||||
drawTrims(mixerCurrentFlightMode);
|
||||
}
|
||||
|
||||
if (persistentData->options[4].boolValue) {
|
||||
lcdSetColor(persistentData->options[5].unsignedValue);
|
||||
lcdDrawSolidFilledRect(50, 50, 180, 170, CUSTOM_COLOR);
|
||||
}
|
||||
|
||||
if (persistentData->options[6].boolValue) {
|
||||
lcdSetColor(persistentData->options[7].unsignedValue);
|
||||
lcdDrawSolidFilledRect(250, 50, 180, 170, CUSTOM_COLOR);
|
||||
}
|
||||
|
||||
Layout::refresh();
|
||||
}
|
||||
|
||||
BaseLayoutFactory<Layout2x4> layout2x4("Layout2x4", LBM_LAYOUT_2x4, OPTIONS_LAYOUT_2x4);
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 169 B |
Binary file not shown.
|
After Width: | Height: | Size: 233 B |
Binary file not shown.
|
After Width: | Height: | Size: 178 B |
Binary file not shown.
|
After Width: | Height: | Size: 208 B |
Binary file not shown.
|
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
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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 _LCD_H_
|
||||
#define _LCD_H_
|
||||
|
||||
#include "bitmapbuffer.h"
|
||||
#include "opentx_types.h"
|
||||
|
||||
#if LCD_W >= 480
|
||||
#define LCD_COLS 40
|
||||
#else
|
||||
#define LCD_COLS 30
|
||||
#endif
|
||||
|
||||
#define CENTER
|
||||
|
||||
/* lcd common flags */
|
||||
#define BLINK 0x01
|
||||
|
||||
/* drawText flags */
|
||||
#define INVERS 0x02
|
||||
#define LEFT 0x00 /* align left */
|
||||
#define CENTERED 0x04 /* align center */
|
||||
#define RIGHT 0x08 /* align right */
|
||||
#define SHADOWED 0x80 /* black copy at +1 +1 */
|
||||
|
||||
/* drawNumber flags */
|
||||
#define LEADING0 0x10
|
||||
#define PREC1 0x20
|
||||
#define PREC2 0x30
|
||||
#define MODE(flags) ((((int8_t)(flags) & 0x30) - 0x10) >> 4)
|
||||
|
||||
#define ZCHAR 0x10
|
||||
|
||||
/* rect, square flags */
|
||||
#define ROUND 0x04
|
||||
|
||||
/* telemetry flags */
|
||||
#define NO_UNIT 0x40
|
||||
|
||||
#define TIMEBLINK 0x1000
|
||||
#define TIMEHOUR 0x2000
|
||||
#define EXPANDED 0x2000
|
||||
#define VERTICAL 0x4000
|
||||
|
||||
#include "colors.h"
|
||||
|
||||
#define DISPLAY_PIXELS_COUNT (LCD_W*LCD_H)
|
||||
#define DISPLAY_BUFFER_SIZE (DISPLAY_PIXELS_COUNT)
|
||||
|
||||
#if defined(SIMU)
|
||||
extern display_t displayBuf[DISPLAY_BUFFER_SIZE];
|
||||
#else
|
||||
#define displayBuf lcd->getData()
|
||||
#endif
|
||||
|
||||
#define DISPLAY_END (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);
|
||||
|
||||
void lcdDrawTextAtIndex(coord_t x, coord_t y, const char * s, uint8_t idx, LcdFlags flags=0);
|
||||
|
||||
inline void lcdClear()
|
||||
{
|
||||
lcd->clear();
|
||||
}
|
||||
|
||||
inline void lcdDrawText(coord_t x, coord_t y, const char * s, LcdFlags attr=0)
|
||||
{
|
||||
lcd->drawText(x, y, s, attr);
|
||||
}
|
||||
|
||||
inline void lcdDrawCenteredText(coord_t y, const char * s, LcdFlags attr=0)
|
||||
{
|
||||
lcd->drawText(LCD_W/2, y, s, attr | CENTERED);
|
||||
}
|
||||
|
||||
inline void lcdDrawSizedText(coord_t x, coord_t y, const char * s, uint8_t len, LcdFlags attr=0)
|
||||
{
|
||||
lcd->drawSizedText(x, y, s, len, attr);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
#define SOLID 0xff
|
||||
#define DOTTED 0x55
|
||||
#define STASHED 0x33
|
||||
|
||||
#if defined(PCBX10) && !defined(SIMU)
|
||||
#define PIXEL_PTR(x, y) &displayBuf[(LCD_H*LCD_W-1) - (y)*LCD_W - (x)]
|
||||
#else
|
||||
#define PIXEL_PTR(x, y) &displayBuf[(y)*LCD_W + (x)]
|
||||
#endif
|
||||
|
||||
void lcdDrawAlphaPixel(display_t * p, uint8_t opacity, uint16_t color);
|
||||
void lcdDrawPoint(coord_t x, coord_t y, LcdFlags att=0);
|
||||
|
||||
inline void lcdDrawSolidHorizontalLine(coord_t x, coord_t y, coord_t w, LcdFlags att)
|
||||
{
|
||||
lcd->drawSolidHorizontalLine(x, y, w, att);
|
||||
}
|
||||
|
||||
inline void lcdDrawSolidVerticalLine(coord_t x, coord_t y, coord_t h, LcdFlags att)
|
||||
{
|
||||
lcd->drawSolidVerticalLine(x, y, h, att);
|
||||
}
|
||||
|
||||
inline void lcdDrawSolidFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, LcdFlags flags)
|
||||
{
|
||||
lcd->drawSolidFilledRect(x, y, w, h, flags);
|
||||
}
|
||||
|
||||
inline void lcdDrawHorizontalLine(coord_t x, coord_t y, coord_t w, uint8_t pat, LcdFlags att=0)
|
||||
{
|
||||
lcd->drawHorizontalLine(x, y, w, pat, att);
|
||||
}
|
||||
|
||||
inline void lcdDrawVerticalLine(coord_t x, coord_t y, coord_t h, uint8_t pat, LcdFlags att=0)
|
||||
{
|
||||
lcd->drawVerticalLine(x, y, h, pat, att);
|
||||
}
|
||||
|
||||
void lcdDrawLine(coord_t x1, coord_t y1, coord_t x2, coord_t y2, uint8_t pat=SOLID, LcdFlags att=0);
|
||||
|
||||
inline void lcdDrawAlphaPixel(coord_t x, coord_t y, uint8_t opacity, uint16_t color)
|
||||
{
|
||||
display_t * p = PIXEL_PTR(x, y);
|
||||
lcdDrawAlphaPixel(p, opacity, color);
|
||||
}
|
||||
|
||||
inline void lcdSetColor(uint16_t color)
|
||||
{
|
||||
lcdColorTable[CUSTOM_COLOR_INDEX] = color;
|
||||
}
|
||||
|
||||
inline void lcdDrawSolidRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness=1, LcdFlags att=0)
|
||||
{
|
||||
lcd->drawSolidFilledRect(x, y, thickness, h, att);
|
||||
lcd->drawSolidFilledRect(x+w-thickness, y, thickness, h, att);
|
||||
lcd->drawSolidFilledRect(x, y, w, thickness, att);
|
||||
lcd->drawSolidFilledRect(x, y+h-thickness, w, thickness, att);
|
||||
}
|
||||
|
||||
inline void lcdDrawFilledRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t pat, LcdFlags att=0)
|
||||
{
|
||||
lcd->drawFilledRect(x, y, w, h, pat, att);
|
||||
}
|
||||
|
||||
void lcdDrawBlackOverlay();
|
||||
inline void lcdDrawRect(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t thickness=1, uint8_t pat=SOLID, LcdFlags att=0)
|
||||
{
|
||||
lcd->drawRect(x, y, w, h, thickness, pat, att);
|
||||
}
|
||||
|
||||
void lcdDrawCircle(int x0, int y0, int radius);
|
||||
void lcdDrawPie(int x0, int y0, int radius, int angle1=0, int angle2=360);
|
||||
void lcdDrawBitmapPie(int x0, int y0, const uint16_t * img, int startAngle, int endAngle);
|
||||
|
||||
inline void lcdDrawBitmapPatternPie(coord_t x0, coord_t y0, const uint8_t * bmp, LcdFlags flags=0, int startAngle=0, int endAngle=360)
|
||||
{
|
||||
lcd->drawBitmapPatternPie(x0, y0, bmp, flags, startAngle, endAngle);
|
||||
}
|
||||
|
||||
inline void lcdDrawSquare(coord_t x, coord_t y, coord_t w, LcdFlags att=0)
|
||||
{
|
||||
lcdDrawSolidRect(x, y, w, w, att);
|
||||
}
|
||||
|
||||
inline int getBitmapWidth(const uint8_t * bmp)
|
||||
{
|
||||
return *((const uint16_t *)bmp);
|
||||
}
|
||||
|
||||
inline int getBitmapHeight(const uint8_t * bmp)
|
||||
{
|
||||
return *(((const uint16_t *)bmp)+1);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
inline void lcdDrawBitmapPattern(coord_t x, coord_t y, const uint8_t * img, LcdFlags flags=0, coord_t offset=0, coord_t width=0)
|
||||
{
|
||||
lcd->drawBitmapPattern(x, y, img, flags, offset, width);
|
||||
}
|
||||
|
||||
#if defined(BOOT)
|
||||
#define BLINK_ON_PHASE (0)
|
||||
#else
|
||||
#define BLINK_ON_PHASE (g_blinkTmr10ms & (1<<6))
|
||||
#define SLOW_BLINK_ON_PHASE (g_blinkTmr10ms & (1<<7))
|
||||
#endif
|
||||
|
||||
#endif // _LCD_H_
|
||||
@@ -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_
|
||||
@@ -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 "opentx.h"
|
||||
|
||||
void onModelCustomScriptMenu(const char *result)
|
||||
{
|
||||
ScriptData &sd = g_model.scriptsData[s_currIdx];
|
||||
|
||||
if (result == STR_UPDATE_LIST) {
|
||||
if (!sdListFiles(SCRIPTS_MIXES_PATH, SCRIPTS_EXT, sizeof(sd.file), NULL)) {
|
||||
POPUP_WARNING(STR_NO_SCRIPTS_ON_SD);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// The user choosed a lua file in the list
|
||||
copySelection(sd.file, result, sizeof(sd.file));
|
||||
memset(sd.inputs, 0, sizeof(sd.inputs));
|
||||
storageDirty(EE_MODEL);
|
||||
LUA_LOAD_MODEL_SCRIPT(s_currIdx);
|
||||
}
|
||||
}
|
||||
|
||||
enum menuModelCustomScriptItems {
|
||||
ITEM_MODEL_CUSTOMSCRIPT_FILE,
|
||||
ITEM_MODEL_CUSTOMSCRIPT_NAME,
|
||||
ITEM_MODEL_CUSTOMSCRIPT_PARAMS_LABEL,
|
||||
};
|
||||
|
||||
#define SCRIPT_ONE_2ND_COLUMN_POS (120)
|
||||
#define SCRIPT_ONE_3RD_COLUMN_POS (240)
|
||||
|
||||
bool menuModelCustomScriptOne(event_t event)
|
||||
{
|
||||
ScriptData &sd = g_model.scriptsData[s_currIdx];
|
||||
|
||||
// drawStringWithIndex(lcdLastRightPos+FW, 0, "LUA", s_currIdx+1, 0);
|
||||
|
||||
SUBMENU(STR_MENUCUSTOMSCRIPTS, ICON_MODEL_LUA_SCRIPTS, 3+scriptInputsOutputs[s_currIdx].inputsCount, { 0, 0, LABEL(inputs), 0/*repeated*/ });
|
||||
|
||||
int8_t sub = menuVerticalPosition;
|
||||
|
||||
for (int k=0; k<NUM_BODY_LINES; k++) {
|
||||
coord_t y = MENU_CONTENT_TOP + k*FH;
|
||||
int i = k + menuVerticalOffset;
|
||||
LcdFlags attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
|
||||
|
||||
if (i == ITEM_MODEL_CUSTOMSCRIPT_FILE) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_SCRIPT);
|
||||
if (ZEXIST(sd.file))
|
||||
lcdDrawSizedText(SCRIPT_ONE_2ND_COLUMN_POS, y, sd.file, sizeof(sd.file), attr);
|
||||
else
|
||||
lcdDrawTextAtIndex(SCRIPT_ONE_2ND_COLUMN_POS, y, STR_VCSWFUNC, 0, attr);
|
||||
if (attr) s_editMode = 0;
|
||||
if (attr && event==EVT_KEY_FIRST(KEY_ENTER) && !READ_ONLY()) {
|
||||
killEvents(KEY_ENTER);
|
||||
if (sdListFiles(SCRIPTS_MIXES_PATH, SCRIPTS_EXT, sizeof(sd.file), sd.file, LIST_NONE_SD_FILE)) {
|
||||
POPUP_MENU_START(onModelCustomScriptMenu);
|
||||
}
|
||||
else {
|
||||
POPUP_WARNING(STR_NO_SCRIPTS_ON_SD);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (i == ITEM_MODEL_CUSTOMSCRIPT_NAME) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, TR_NAME);
|
||||
editName(SCRIPT_ONE_2ND_COLUMN_POS, y, sd.name, sizeof(sd.name), event, attr);
|
||||
}
|
||||
else if (i == ITEM_MODEL_CUSTOMSCRIPT_PARAMS_LABEL) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_INPUTS);
|
||||
}
|
||||
else if (i <= ITEM_MODEL_CUSTOMSCRIPT_PARAMS_LABEL+scriptInputsOutputs[s_currIdx].inputsCount) {
|
||||
int inputIdx = i-ITEM_MODEL_CUSTOMSCRIPT_PARAMS_LABEL-1;
|
||||
lcdDrawSizedText(INDENT_WIDTH, y, scriptInputsOutputs[s_currIdx].inputs[inputIdx].name, 10, 0);
|
||||
if (scriptInputsOutputs[s_currIdx].inputs[inputIdx].type == INPUT_TYPE_VALUE) {
|
||||
lcdDrawNumber(SCRIPT_ONE_2ND_COLUMN_POS, y, g_model.scriptsData[s_currIdx].inputs[inputIdx].value+ \
|
||||
scriptInputsOutputs[s_currIdx].inputs[inputIdx].def, attr|LEFT);
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELVAR(event, g_model.scriptsData[s_currIdx].inputs[inputIdx].value, \
|
||||
scriptInputsOutputs[s_currIdx].inputs[inputIdx].min-scriptInputsOutputs[s_currIdx].inputs[inputIdx].def, \
|
||||
scriptInputsOutputs[s_currIdx].inputs[inputIdx].max-scriptInputsOutputs[s_currIdx].inputs[inputIdx].def);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawSource(SCRIPT_ONE_2ND_COLUMN_POS, y, g_model.scriptsData[s_currIdx].inputs[inputIdx].source, attr);
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELSOURCE(event, g_model.scriptsData[s_currIdx].inputs[inputIdx].source, 0, MIXSRC_LAST_TELEM);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scriptInputsOutputs[s_currIdx].outputsCount > 0) {
|
||||
lcdDrawSolidVerticalLine(SCRIPT_ONE_3RD_COLUMN_POS-4, DEFAULT_SCROLLBAR_Y, DEFAULT_SCROLLBAR_H+5, TEXT_COLOR);
|
||||
// lcdDrawText(SCRIPT_ONE_3RD_COLUMN_POS, FH+1, STR_OUTPUTS);
|
||||
|
||||
for (int i=0; i<scriptInputsOutputs[s_currIdx].outputsCount; i++) {
|
||||
drawSource(SCRIPT_ONE_3RD_COLUMN_POS+INDENT_WIDTH, MENU_CONTENT_TOP+i*FH, MIXSRC_FIRST_LUA+(s_currIdx*MAX_SCRIPT_OUTPUTS)+i, 0);
|
||||
lcdDrawNumber(SCRIPT_ONE_3RD_COLUMN_POS+130, MENU_CONTENT_TOP+i*FH, calcRESXto1000(scriptInputsOutputs[s_currIdx].outputs[i].value), PREC1);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define SCRIPTS_COLUMN_FILE 70
|
||||
#define SCRIPTS_COLUMN_NAME 160
|
||||
#define SCRIPTS_COLUMN_STATE 300
|
||||
|
||||
bool menuModelCustomScripts(event_t event)
|
||||
{
|
||||
// lcdDrawNumber(19*FW, 0, luaGetMemUsed(lsScripts), 0);
|
||||
// lcdDrawText(19*FW+1, 0, STR_BYTES);
|
||||
|
||||
MENU(STR_MENUCUSTOMSCRIPTS, MODEL_ICONS, menuTabModel, MENU_MODEL_CUSTOM_SCRIPTS, MAX_SCRIPTS, { NAVIGATION_LINE_BY_LINE|3/*repeated*/ });
|
||||
|
||||
int8_t sub = menuVerticalPosition;
|
||||
|
||||
if (event == EVT_KEY_FIRST(KEY_ENTER) && sub >= 0) {
|
||||
s_currIdx = sub;
|
||||
pushMenu(menuModelCustomScriptOne);
|
||||
}
|
||||
|
||||
for (int i=0, scriptIndex=0; i<MAX_SCRIPTS; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i*FH;
|
||||
|
||||
ScriptData &sd = g_model.scriptsData[i];
|
||||
|
||||
// LUAx header
|
||||
drawStringWithIndex(MENUS_MARGIN_LEFT, y, "LUA", i+1, sub==i ? INVERS : 0);
|
||||
|
||||
// LUA script
|
||||
if (ZEXIST(sd.file)) {
|
||||
lcdDrawSizedText(SCRIPTS_COLUMN_FILE, y, sd.file, sizeof(sd.file), 0);
|
||||
switch (scriptInternalData[scriptIndex].state) {
|
||||
case SCRIPT_SYNTAX_ERROR:
|
||||
lcdDrawText(SCRIPTS_COLUMN_STATE, y, "(error)");
|
||||
break;
|
||||
case SCRIPT_KILLED:
|
||||
lcdDrawText(SCRIPTS_COLUMN_STATE, y, "(killed)");
|
||||
break;
|
||||
default:
|
||||
lcdDrawNumber(SCRIPTS_COLUMN_STATE, y, luaGetCpuUsed(scriptIndex), LEFT|TEXT_COLOR, 0, NULL, "%");
|
||||
break;
|
||||
}
|
||||
scriptIndex++;
|
||||
}
|
||||
else {
|
||||
lcdDrawTextAtIndex(SCRIPTS_COLUMN_FILE, y, STR_VCSWFUNC, 0, 0);
|
||||
}
|
||||
|
||||
// Script name
|
||||
lcdDrawSizedText(SCRIPTS_COLUMN_NAME, y, sd.name, sizeof(sd.name), ZCHAR);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#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];
|
||||
int16_t vmin, vmax;
|
||||
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);
|
||||
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);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
else if (s_editMode > 0) {
|
||||
v = checkIncDec(event, v, vmin, vmax, EE_MODEL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum GVarFields {
|
||||
GVAR_FIELD_NAME,
|
||||
GVAR_FIELD_UNIT,
|
||||
GVAR_FIELD_PREC,
|
||||
GVAR_FIELD_MIN,
|
||||
GVAR_FIELD_MAX,
|
||||
GVAR_FIELD_FM0,
|
||||
GVAR_FIELD_LAST = GVAR_FIELD_FM0 + MAX_FLIGHT_MODES
|
||||
};
|
||||
|
||||
bool menuModelGVarOne(event_t event)
|
||||
{
|
||||
SIMPLE_SUBMENU(STR_GVARS, ICON_MODEL_GVARS, GVAR_FIELD_LAST);
|
||||
|
||||
GVarData * gvar = &g_model.gvars[s_currIdx];
|
||||
drawStringWithIndex(50, 3+FH, STR_GV, s_currIdx+1, MENU_TITLE_COLOR, NULL, "=");
|
||||
drawGVarValue(lcdNextPos + 2, 3+FH, s_currIdx, getGVarValue(s_currIdx, getFlightMode()), LEFT | MENU_TITLE_COLOR);
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES+1; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP - FH - 2 + i*FH;
|
||||
int k = i + menuVerticalOffset;
|
||||
LcdFlags attr = (menuVerticalPosition == k ? (s_editMode > 0 ? BLINK | INVERS : INVERS) : 0);
|
||||
|
||||
switch (k) {
|
||||
case GVAR_FIELD_NAME:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_NAME);
|
||||
editName(MIXES_2ND_COLUMN, y, gvar->name, LEN_GVAR_NAME, event, attr);
|
||||
break;
|
||||
|
||||
case GVAR_FIELD_UNIT:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_UNIT);
|
||||
gvar->unit = editChoice(MIXES_2ND_COLUMN, y, "\001-%", gvar->unit, 0, 1, attr, event);
|
||||
break;
|
||||
|
||||
case GVAR_FIELD_PREC:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_PRECISION);
|
||||
gvar->prec = editChoice(MIXES_2ND_COLUMN, y, STR_VPREC, gvar->prec, 0, 1, attr, event);
|
||||
break;
|
||||
|
||||
case GVAR_FIELD_MIN:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MIN);
|
||||
drawGVarValue(MIXES_2ND_COLUMN, y, s_currIdx, GVAR_MIN+gvar->min, LEFT|attr);
|
||||
if (attr) gvar->min = checkIncDec(event, GVAR_MIN+gvar->min, GVAR_MIN, GVAR_MAX-gvar->max, EE_MODEL) - GVAR_MIN;
|
||||
break;
|
||||
|
||||
case GVAR_FIELD_MAX:
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_MAX);
|
||||
drawGVarValue(MIXES_2ND_COLUMN, y, s_currIdx, GVAR_MAX-gvar->max, LEFT|attr);
|
||||
if (attr) gvar->max = GVAR_MAX - checkIncDec(event, GVAR_MAX-gvar->max, GVAR_MIN+gvar->min, GVAR_MAX, EE_MODEL);
|
||||
break;
|
||||
|
||||
default:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onGVARSMenu(const char * result)
|
||||
{
|
||||
int sub = menuVerticalPosition;
|
||||
|
||||
if (result == STR_EDIT) {
|
||||
s_currIdx = sub;
|
||||
pushMenu(menuModelGVarOne);
|
||||
}
|
||||
else if (result == STR_CLEAR) {
|
||||
for (int i=0; i<MAX_FLIGHT_MODES; i++) {
|
||||
g_model.flightModeData[i].gvars[sub] = 0;
|
||||
}
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
}
|
||||
|
||||
#define GVARS_FM_COLUMN(p) (127 + (p)*44)
|
||||
#define GVAR_MAX_COLUMNS (NAVIGATION_LINE_BY_LINE|(MAX_FLIGHT_MODES-1))
|
||||
|
||||
bool menuModelGVars(event_t event)
|
||||
{
|
||||
MENU(STR_MENUGLOBALVARS, MODEL_ICONS, menuTabModel, MENU_MODEL_GVARS/* TODO, first2seconds ? CHECK_FLAG_NO_SCREEN_INDEX : 0*/, MAX_GVARS, { GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS, GVAR_MAX_COLUMNS});
|
||||
|
||||
int sub = menuVerticalPosition;
|
||||
int curfm = getFlightMode();
|
||||
|
||||
#if defined(MENU_TOOLTIPS)
|
||||
if (menuVerticalPosition>= 0 && menuHorizontalPosition>=0) {
|
||||
drawColumnHeader(STR_GVAR_HEADERS, NULL, menuHorizontalPosition);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (uint8_t l=0; l<NUM_BODY_LINES; l++) {
|
||||
int i = l + menuVerticalOffset;
|
||||
coord_t y = MENU_CONTENT_TOP + l*FH;
|
||||
if (g_model.gvars[i].popup) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT+25, y, "!");
|
||||
}
|
||||
|
||||
drawStringWithIndex(MENUS_MARGIN_LEFT-3, y, STR_GV, i+1, ((sub==i && menuHorizontalPosition<0) ? INVERS : 0));
|
||||
lcdDrawSizedText(MENUS_MARGIN_LEFT+35, y, g_model.gvars[i].name, LEN_GVAR_NAME, ZCHAR);
|
||||
|
||||
for (int j=0; j<MAX_FLIGHT_MODES; j++) {
|
||||
FlightModeData * fm = &g_model.flightModeData[j];
|
||||
gvar_t v = fm->gvars[i];
|
||||
|
||||
LcdFlags attr = RIGHT | ((sub == i && menuHorizontalPosition == j) ? (s_editMode > 0 ? BLINK | INVERS : INVERS) : 0);
|
||||
if (j == curfm)
|
||||
attr |= BOLD;
|
||||
coord_t x = GVARS_FM_COLUMN(j);
|
||||
coord_t yval = y;
|
||||
if (v <= GVAR_MAX && (g_model.gvars[i].prec > 0 || abs(v) >= 1000 || ( abs(v) >= 100 && g_model.gvars[i].unit > 0))) {
|
||||
attr |= SMLSIZE;
|
||||
yval += 3;
|
||||
}
|
||||
if (v <= GVAR_MAX && g_model.gvars[i].unit > 0) {
|
||||
x -= 9;
|
||||
lcdDrawText(GVARS_FM_COLUMN(j) - 9, y+5, "%", TINSIZE);
|
||||
}
|
||||
editGVarValue(x, yval, event, i, j, attr | NO_UNIT);
|
||||
}
|
||||
}
|
||||
|
||||
if (menuHorizontalPosition < 0 && event==EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
POPUP_MENU_ADD_ITEM(STR_EDIT);
|
||||
POPUP_MENU_ADD_ITEM(STR_CLEAR);
|
||||
POPUP_MENU_START(onGVARSMenu);
|
||||
}
|
||||
|
||||
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_
|
||||
@@ -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 "opentx.h"
|
||||
#include "modelslist.h"
|
||||
|
||||
#define CATEGORIES_WIDTH 120
|
||||
#define MODELS_LEFT 123
|
||||
#define MODELS_COLUMN_WIDTH 174
|
||||
|
||||
enum ModelSelectMode {
|
||||
MODE_SELECT_MODEL,
|
||||
MODE_RENAME_CATEGORY,
|
||||
MODE_MOVE_MODEL,
|
||||
};
|
||||
|
||||
enum ModelDeleteMode {
|
||||
MODE_DELETE_MODEL,
|
||||
MODE_DELETE_CATEGORY,
|
||||
};
|
||||
|
||||
uint8_t selectMode, deleteMode;
|
||||
|
||||
ModelsCategory * currentCategory;
|
||||
int currentCategoryIndex;
|
||||
ModelCell * currentModel;
|
||||
|
||||
void drawCategory(coord_t y, const char * name, bool selected)
|
||||
{
|
||||
if (selected) {
|
||||
lcdDrawSolidFilledRect(1, y-INVERT_VERT_MARGIN, CATEGORIES_WIDTH-10, INVERT_LINE_HEIGHT+2, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawText(6, y, name, TEXT_COLOR | INVERS);
|
||||
}
|
||||
else {
|
||||
lcdDrawText(6, y, name, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawModel(coord_t x, coord_t y, ModelCell * model, bool current, bool selected)
|
||||
{
|
||||
lcd->drawBitmap(x+1, y+1, model->getBuffer());
|
||||
if (current) {
|
||||
lcd->drawBitmapPattern(x+66, y+43, LBM_ACTIVE_MODEL, TITLE_BGCOLOR);
|
||||
}
|
||||
if (selected) {
|
||||
lcdDrawSolidRect(x, y, MODELCELL_WIDTH+2, MODELCELL_HEIGHT+2, 1, TITLE_BGCOLOR);
|
||||
drawShadow(x, y, MODELCELL_WIDTH+2, MODELCELL_HEIGHT+2);
|
||||
if (selectMode == MODE_MOVE_MODEL) {
|
||||
lcd->drawMask(x+MODELCELL_WIDTH+2-modelselModelMoveBackground->getWidth(), y, modelselModelMoveBackground, TITLE_BGCOLOR);
|
||||
lcd->drawMask(x+MODELCELL_WIDTH+2-modelselModelMoveBackground->getWidth()+12, y+5, modelselModelMoveIcon, TEXT_BGCOLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t categoriesVerticalOffset = 0;
|
||||
uint16_t categoriesVerticalPosition = 0;
|
||||
#define MODEL_INDEX() (menuVerticalPosition*2+menuHorizontalPosition)
|
||||
|
||||
void setCurrentModel(unsigned int index)
|
||||
{
|
||||
std::list<ModelCell *>::iterator it = currentCategory->begin();
|
||||
std::advance(it, index);
|
||||
currentModel = *it;
|
||||
menuVerticalPosition = index / 2;
|
||||
menuHorizontalPosition = index & 1;
|
||||
menuVerticalOffset = limit<int>(menuVerticalPosition-2, menuVerticalOffset, min<int>(menuVerticalPosition, max<int>(0, (currentCategory->size()-7)/2)));
|
||||
}
|
||||
|
||||
void setCurrentCategory(unsigned int index)
|
||||
{
|
||||
currentCategoryIndex = index;
|
||||
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
|
||||
std::list<ModelsCategory *>::const_iterator it = cats.begin();
|
||||
std::advance(it, index);
|
||||
currentCategory = *it;
|
||||
categoriesVerticalPosition = index;
|
||||
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-4, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, cats.size()-5)));
|
||||
if (currentCategory->size() > 0)
|
||||
setCurrentModel(0);
|
||||
else
|
||||
currentModel = NULL;
|
||||
}
|
||||
|
||||
#if defined(LUA)
|
||||
|
||||
#define MAX_WIZARD_NAME_LEN (sizeof(WIZARD_PATH)+20)
|
||||
#define WIZARD_SPACING 40
|
||||
#define WIZARD_LEFT_SPACING 30
|
||||
#define WIZARD_ICON_X 80
|
||||
#define WIZARD_ICON_Y 110
|
||||
#define WIZARD_TEXT_Y 195
|
||||
|
||||
uint8_t getWizardCount()
|
||||
{
|
||||
uint8_t wizCnt=0;
|
||||
DIR dir;
|
||||
static FILINFO fno;
|
||||
|
||||
FRESULT res = f_opendir(&dir, WIZARD_PATH);
|
||||
if (res == FR_OK) {
|
||||
for (;;) {
|
||||
res = f_readdir(&dir, &fno);
|
||||
if (res != FR_OK || fno.fname[0] == 0) {
|
||||
break;
|
||||
}
|
||||
if (fno.fattrib & AM_DIR) {
|
||||
wizCnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
f_closedir(&dir);
|
||||
return wizCnt;
|
||||
}
|
||||
|
||||
bool menuModelWizard(event_t event)
|
||||
{
|
||||
static uint8_t wizardSelected = 0;
|
||||
static uint8_t wizardCnt = getWizardCount();
|
||||
bool executeMe = false;
|
||||
uint8_t first = 0;
|
||||
DIR dir;
|
||||
static FILINFO fno;
|
||||
char wizpath[MAX_WIZARD_NAME_LEN];
|
||||
|
||||
if (wizardCnt == 0) {
|
||||
chainMenu(menuModelSelect);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(event) {
|
||||
case 0:
|
||||
// no need to refresh the screen
|
||||
return false;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
chainMenu(menuModelSelect);
|
||||
return false;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
executeMe = true;
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
if (wizardSelected < wizardCnt-1) {
|
||||
wizardSelected++;
|
||||
}
|
||||
if (wizardSelected > 3) {
|
||||
first = wizardSelected - 3;
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_LEFT:
|
||||
if (wizardSelected != 0) {
|
||||
wizardSelected--;
|
||||
}
|
||||
if(wizardSelected < first)
|
||||
{
|
||||
first = wizardSelected;
|
||||
}
|
||||
break;
|
||||
}
|
||||
strcpy(wizpath, WIZARD_PATH);
|
||||
strcpy(&wizpath[sizeof(WIZARD_PATH)-1], "/");
|
||||
lcdDrawSolidFilledRect(0, 0, LCD_W, LCD_H, TEXT_BGCOLOR);
|
||||
lcd->drawBitmap(0, 0, modelselWizardBackground);
|
||||
FRESULT res = f_opendir(&dir, WIZARD_PATH);
|
||||
if (res == FR_OK) {
|
||||
for (uint8_t wizidx=0;;wizidx++) {
|
||||
res = f_readdir(&dir, &fno);
|
||||
if (res != FR_OK || fno.fname[0] == 0) {
|
||||
break;
|
||||
}
|
||||
if (fno.fattrib & AM_DIR) {
|
||||
if((wizidx >= first) && (wizidx < (first+4))) {
|
||||
uint16_t x = WIZARD_LEFT_SPACING + (wizidx - first) * (WIZARD_SPACING + WIZARD_ICON_X);
|
||||
strcpy(&wizpath[sizeof(WIZARD_PATH)], fno.fname);
|
||||
strcpy(&wizpath[sizeof(WIZARD_PATH) + strlen(fno.fname)], "/icon.png");
|
||||
lcdDrawText(x + 10, WIZARD_TEXT_Y, fno.fname);
|
||||
BitmapBuffer * background = BitmapBuffer::load(wizpath);
|
||||
lcd->drawBitmap(x, WIZARD_ICON_Y, background);
|
||||
if(wizidx == wizardSelected ) {
|
||||
if (wizardSelected < 5) {
|
||||
lcdDrawRect(x, WIZARD_ICON_Y, 85, 130, 2, SOLID, MAINVIEW_GRAPHICS_COLOR_INDEX);
|
||||
lcdDrawRect(x+5, WIZARD_TEXT_Y, 75, 4, 2, SOLID, MAINVIEW_GRAPHICS_COLOR_INDEX);
|
||||
}
|
||||
if (executeMe) {
|
||||
strcpy(&wizpath[sizeof(WIZARD_PATH)+strlen(fno.fname)], "/wizard.lua");
|
||||
if (isFileAvailable(wizpath)) {
|
||||
wizpath[sizeof(WIZARD_PATH) + strlen(fno.fname)] = 0;
|
||||
f_chdir(wizpath);
|
||||
luaExec(WIZARD_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
delete background;
|
||||
}
|
||||
}
|
||||
}
|
||||
f_closedir(&dir);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void onModelSelectMenu(const char * result)
|
||||
{
|
||||
if (result == STR_SELECT_MODEL) {
|
||||
// we store the latest changes if any
|
||||
storageFlushCurrentModel();
|
||||
storageCheck(true);
|
||||
memcpy(g_eeGeneral.currModelFilename, currentModel->modelFilename, LEN_MODEL_FILENAME);
|
||||
modelslist.setCurrentModel(currentModel);
|
||||
loadModel(g_eeGeneral.currModelFilename, true);
|
||||
storageDirty(EE_GENERAL);
|
||||
storageCheck(true);
|
||||
chainMenu(menuMainView);
|
||||
}
|
||||
else if (result == STR_DELETE_MODEL) {
|
||||
POPUP_CONFIRMATION(STR_DELETEMODEL);
|
||||
SET_WARNING_INFO(currentModel->modelName, LEN_MODEL_NAME, 0);
|
||||
deleteMode = MODE_DELETE_MODEL;
|
||||
}
|
||||
else if (result == STR_CREATE_MODEL) {
|
||||
storageCheck(true);
|
||||
modelslist.addModel(currentCategory, createModel());
|
||||
selectMode = MODE_SELECT_MODEL;
|
||||
setCurrentModel(currentCategory->size() - 1);
|
||||
modelslist.setCurrentModel(currentModel);
|
||||
modelslist.onNewModelCreated(currentModel, &g_model);
|
||||
#if defined(LUA)
|
||||
chainMenu(menuModelWizard);
|
||||
#endif
|
||||
}
|
||||
else if (result == STR_DUPLICATE_MODEL) {
|
||||
char duplicatedFilename[LEN_MODEL_FILENAME+1];
|
||||
memcpy(duplicatedFilename, currentModel->modelFilename, sizeof(duplicatedFilename));
|
||||
if (findNextFileIndex(duplicatedFilename, LEN_MODEL_FILENAME, MODELS_PATH)) {
|
||||
sdCopyFile(currentModel->modelFilename, MODELS_PATH, duplicatedFilename, MODELS_PATH);
|
||||
ModelCell* dup_model = modelslist.addModel(currentCategory, duplicatedFilename);
|
||||
dup_model->fetchRfData();
|
||||
setCurrentModel(currentCategory->size() - 1);
|
||||
}
|
||||
else {
|
||||
POPUP_WARNING("Invalid File");
|
||||
}
|
||||
}
|
||||
else if (result == STR_MOVE_MODEL) {
|
||||
selectMode = MODE_MOVE_MODEL;
|
||||
}
|
||||
else if (result == STR_CREATE_CATEGORY) {
|
||||
currentCategory = modelslist.createCategory();
|
||||
setCurrentCategory(modelslist.getCategories().size() - 1);
|
||||
}
|
||||
else if (result == STR_RENAME_CATEGORY) {
|
||||
selectMode = MODE_RENAME_CATEGORY;
|
||||
s_editMode = EDIT_MODIFY_STRING;
|
||||
editNameCursorPos = 0;
|
||||
}
|
||||
else if (result == STR_DELETE_CATEGORY) {
|
||||
if (currentCategory->size() > 0){
|
||||
POPUP_WARNING(STR_DELETE_ERROR);
|
||||
SET_WARNING_INFO(STR_CAT_NOT_EMPTY, sizeof(TR_CAT_NOT_EMPTY), 0);
|
||||
}
|
||||
else {
|
||||
POPUP_CONFIRMATION(STR_DELETEMODEL);
|
||||
SET_WARNING_INFO(currentCategory->name, LEN_MODEL_FILENAME, 0);
|
||||
deleteMode = MODE_DELETE_CATEGORY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void initModelsList()
|
||||
{
|
||||
modelslist.load();
|
||||
|
||||
categoriesVerticalOffset = 0;
|
||||
bool found = false;
|
||||
int index = 0;
|
||||
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
|
||||
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
|
||||
if (*it == modelslist.getCurrentCategory()) {
|
||||
setCurrentCategory(index);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
setCurrentCategory(0);
|
||||
}
|
||||
|
||||
menuVerticalOffset = 0;
|
||||
found = false;
|
||||
index = 0;
|
||||
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
|
||||
if (*it == modelslist.getCurrentModel()) {
|
||||
setCurrentModel(index);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
setCurrentModel(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool menuModelSelect(event_t event)
|
||||
{
|
||||
if (warningResult) {
|
||||
warningResult = 0;
|
||||
if (deleteMode == MODE_DELETE_CATEGORY) {
|
||||
TRACE("DELETE CATEGORY");
|
||||
modelslist.removeCategory(currentCategory);
|
||||
modelslist.save();
|
||||
setCurrentCategory(currentCategoryIndex > 0 ? currentCategoryIndex-1 : currentCategoryIndex);
|
||||
}
|
||||
else if (deleteMode == MODE_DELETE_MODEL){
|
||||
int modelIndex = MODEL_INDEX();
|
||||
modelslist.removeModel(currentCategory, currentModel);
|
||||
s_copyMode = 0;
|
||||
event = EVT_REFRESH;
|
||||
if (modelIndex > 0) {
|
||||
modelIndex--;
|
||||
}
|
||||
setCurrentModel(modelIndex);
|
||||
}
|
||||
}
|
||||
|
||||
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
|
||||
switch(event) {
|
||||
case 0:
|
||||
// no need to refresh the screen
|
||||
return false;
|
||||
|
||||
case EVT_ENTRY:
|
||||
selectMode = MODE_SELECT_MODEL;
|
||||
initModelsList();
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_ENTER):
|
||||
if (selectMode == MODE_MOVE_MODEL)
|
||||
selectMode = MODE_SELECT_MODEL;
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
switch (selectMode) {
|
||||
case MODE_MOVE_MODEL:
|
||||
selectMode = MODE_SELECT_MODEL;
|
||||
break;
|
||||
case MODE_SELECT_MODEL:
|
||||
chainMenu(menuMainView);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_PGUP):
|
||||
#if defined(PCBX10)
|
||||
case EVT_KEY_LONG(KEY_PGDN):
|
||||
#endif
|
||||
if (selectMode == MODE_SELECT_MODEL) {
|
||||
if (categoriesVerticalPosition == 0)
|
||||
categoriesVerticalPosition = cats.size() - 1;
|
||||
else
|
||||
categoriesVerticalPosition -= 1;
|
||||
setCurrentCategory(categoriesVerticalPosition);
|
||||
}
|
||||
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition > 0) {
|
||||
ModelsCategory * previous_category = currentCategory;
|
||||
ModelCell * model = currentModel;
|
||||
categoriesVerticalPosition -= 1;
|
||||
setCurrentCategory(categoriesVerticalPosition);
|
||||
modelslist.moveModel(model, previous_category, currentCategory);
|
||||
setCurrentModel(currentCategory->size()-1);
|
||||
}
|
||||
killEvents(event);
|
||||
break;
|
||||
|
||||
#if defined(PCBX12S)
|
||||
case EVT_KEY_FIRST(KEY_PGDN):
|
||||
#elif defined(PCBX10)
|
||||
case EVT_KEY_BREAK(KEY_PGDN):
|
||||
#endif
|
||||
if (selectMode == MODE_SELECT_MODEL) {
|
||||
categoriesVerticalPosition += 1;
|
||||
if (categoriesVerticalPosition >= cats.size())
|
||||
categoriesVerticalPosition = 0;
|
||||
setCurrentCategory(categoriesVerticalPosition);
|
||||
}
|
||||
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition < cats.size()-1) {
|
||||
ModelsCategory * previous_category = currentCategory;
|
||||
ModelCell * model = currentModel;
|
||||
categoriesVerticalPosition += 1;
|
||||
setCurrentCategory(categoriesVerticalPosition);
|
||||
modelslist.moveModel(model, previous_category, currentCategory);
|
||||
setCurrentModel(currentCategory->size()-1);
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
if (selectMode == MODE_SELECT_MODEL) {
|
||||
killEvents(event);
|
||||
if (currentModel && currentModel != modelslist.getCurrentModel()) {
|
||||
POPUP_MENU_ADD_ITEM(STR_SELECT_MODEL);
|
||||
}
|
||||
POPUP_MENU_ADD_ITEM(STR_CREATE_MODEL);
|
||||
if (currentModel) {
|
||||
POPUP_MENU_ADD_ITEM(STR_DUPLICATE_MODEL);
|
||||
POPUP_MENU_ADD_ITEM(STR_MOVE_MODEL);
|
||||
}
|
||||
// POPUP_MENU_ADD_SD_ITEM(STR_BACKUP_MODEL);
|
||||
if (currentModel && currentModel != modelslist.getCurrentModel()) {
|
||||
POPUP_MENU_ADD_ITEM(STR_DELETE_MODEL);
|
||||
}
|
||||
// POPUP_MENU_ADD_ITEM(STR_RESTORE_MODEL);
|
||||
POPUP_MENU_ADD_ITEM(STR_CREATE_CATEGORY);
|
||||
POPUP_MENU_ADD_ITEM(STR_RENAME_CATEGORY);
|
||||
if (cats.size() > 1) {
|
||||
POPUP_MENU_ADD_ITEM(STR_DELETE_CATEGORY);
|
||||
}
|
||||
POPUP_MENU_START(onModelSelectMenu);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
lcdDrawSolidFilledRect(0, 0, LCD_W, LCD_H, TEXT_BGCOLOR);
|
||||
lcd->drawBitmap(0, 0, modelselIconBitmap);
|
||||
|
||||
// Categories
|
||||
int index = 0;
|
||||
coord_t y = 97;
|
||||
drawVerticalScrollbar(CATEGORIES_WIDTH-1, y-1, 5*(FH+7)-5, categoriesVerticalOffset, cats.size(), 5);
|
||||
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
|
||||
if (index >= categoriesVerticalOffset && index < categoriesVerticalOffset+5) {
|
||||
if (index != categoriesVerticalOffset) {
|
||||
lcdDrawSolidHorizontalLine(1, y-4, CATEGORIES_WIDTH-10, LINE_COLOR);
|
||||
}
|
||||
if (selectMode == MODE_RENAME_CATEGORY && currentCategory == *it) {
|
||||
lcdDrawSolidFilledRect(0, y-INVERT_VERT_MARGIN+1, CATEGORIES_WIDTH-2, INVERT_LINE_HEIGHT, TEXT_BGCOLOR);
|
||||
editName(MENUS_MARGIN_LEFT, y, currentCategory->name, LEN_MODEL_FILENAME, event, 1, 0);
|
||||
if (s_editMode == 0 || event == EVT_KEY_BREAK(KEY_EXIT)) {
|
||||
modelslist.save();
|
||||
selectMode = MODE_SELECT_MODEL;
|
||||
putEvent(EVT_REFRESH);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drawCategory(y, (*it)->name, currentCategory==*it);
|
||||
}
|
||||
y += FH+7;
|
||||
}
|
||||
}
|
||||
|
||||
// Models
|
||||
index = 0;
|
||||
y = 5;
|
||||
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
|
||||
if (index >= menuVerticalOffset*2 && index < (menuVerticalOffset+4)*2) {
|
||||
bool selected = ((selectMode==MODE_SELECT_MODEL || selectMode==MODE_MOVE_MODEL) && index==menuVerticalPosition*2+menuHorizontalPosition);
|
||||
bool current = !strncmp((*it)->modelFilename, g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
|
||||
if (index & 1) {
|
||||
drawModel(MODELS_LEFT + MODELS_COLUMN_WIDTH, y, *it, current, selected);
|
||||
y += 66;
|
||||
}
|
||||
else {
|
||||
drawModel(MODELS_LEFT, y, *it, current, selected);
|
||||
}
|
||||
if (selected) {
|
||||
lcd->drawBitmap(5, LCD_H-FH, modelselModelNameBitmap);
|
||||
lcdDrawText(22, LCD_H-FH-1, (*it)->modelFilename, SMLSIZE|TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Navigation
|
||||
if (currentModel) {
|
||||
if (selectMode == MODE_SELECT_MODEL) {
|
||||
if (navigate(event, index, 4, 2) != 0) {
|
||||
setCurrentModel(MODEL_INDEX());
|
||||
putEvent(EVT_REFRESH);
|
||||
}
|
||||
}
|
||||
else if (selectMode == MODE_MOVE_MODEL) {
|
||||
int8_t direction = navigate(event, index, 4, 2, false);
|
||||
if (direction) {
|
||||
modelslist.moveModel(currentCategory, currentModel, direction);
|
||||
setCurrentModel(MODEL_INDEX());
|
||||
putEvent(EVT_REFRESH);
|
||||
}
|
||||
}
|
||||
}
|
||||
drawVerticalScrollbar(DEFAULT_SCROLLBAR_X + 4, 7, LCD_H - 15, menuVerticalOffset, (index + 1) / 2, 4);
|
||||
|
||||
// Footer
|
||||
lcd->drawBitmap(5, LCD_H-FH-20, modelselSdFreeBitmap);
|
||||
uint32_t size = sdGetSize() / 100;
|
||||
lcdDrawNumber(22, LCD_H-FH-21, size, PREC1|SMLSIZE, 0, NULL, "GB");
|
||||
lcd->drawBitmap(70, LCD_H-FH-20, modelselModelQtyBitmap);
|
||||
lcdDrawNumber(92, LCD_H-FH-21, modelslist.getModelsCount(),SMLSIZE);
|
||||
|
||||
return true;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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_SPECTRUM_ANALYSER_H
|
||||
#define _RADIO_SPECTRUM_ANALYSER_H
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class RadioSpectrumAnalyser: public Page
|
||||
{
|
||||
public:
|
||||
RadioSpectrumAnalyser(uint8_t moduleIdx);
|
||||
|
||||
protected:
|
||||
void buildBody(FormWindow * window);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
uint8_t moduleIdx;
|
||||
};
|
||||
|
||||
#endif // _RADIO_SPECTRUM_ANALYSER_H
|
||||
@@ -0,0 +1,211 @@
|
||||
/*
|
||||
* 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 "radio_tools.h"
|
||||
#include "radio_spectrum_analyser.h"
|
||||
#include "opentx.h"
|
||||
#include "libopenui.h"
|
||||
|
||||
extern uint8_t g_moduleIdx;
|
||||
|
||||
#define TOOL_NAME_MAXLEN 16
|
||||
|
||||
#if defined(LUA) || defined(DEBUG)
|
||||
bool readToolName(const char * filename, char * name)
|
||||
{
|
||||
FIL file;
|
||||
char buffer[1024];
|
||||
UINT count;
|
||||
|
||||
if (f_open(&file, filename, FA_READ) != FR_OK) {
|
||||
return "Error opening file";
|
||||
}
|
||||
|
||||
if (f_read(&file, &buffer, sizeof(buffer), &count) != FR_OK) {
|
||||
f_close(&file);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char * tns = "TNS|";
|
||||
auto * start = std::search(buffer, buffer + sizeof(buffer), tns, tns + 4);
|
||||
if (start >= buffer + sizeof(buffer))
|
||||
return false;
|
||||
|
||||
start += 4;
|
||||
|
||||
const char * tne = "|TNE";
|
||||
auto * end = std::search(buffer, buffer + sizeof(buffer), tne, tne + 4);
|
||||
if (end >= buffer + sizeof(buffer) || end <= start)
|
||||
return false;
|
||||
|
||||
uint8_t len = end - start;
|
||||
if (len > TOOL_NAME_MAXLEN)
|
||||
return false;
|
||||
|
||||
strncpy(name, start, len);
|
||||
memclear(name + len, TOOL_NAME_MAXLEN + 1 - len);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isRadioScriptTool(const char * filename)
|
||||
{
|
||||
const char * ext = getFileExtension(filename);
|
||||
return ext && !strcasecmp(ext, SCRIPT_EXT);
|
||||
}
|
||||
#endif
|
||||
|
||||
RadioToolsPage::RadioToolsPage() :
|
||||
PageTab(STR_MENUTOOLS, ICON_RADIO_TOOLS)
|
||||
{
|
||||
}
|
||||
|
||||
void RadioToolsPage::build(FormWindow * window)
|
||||
{
|
||||
this->window = window;
|
||||
|
||||
memclear(&reusableBuffer.radioTools, sizeof(reusableBuffer.radioTools));
|
||||
waiting = 0;
|
||||
|
||||
#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())) {
|
||||
waiting |= (1 << module);
|
||||
moduleState[module].readModuleInformation(&reusableBuffer.radioTools.modules[module], PXX2_HW_INFO_TX_ID, PXX2_HW_INFO_TX_ID);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
rebuild(window);
|
||||
}
|
||||
|
||||
void RadioToolsPage::checkEvents()
|
||||
{
|
||||
bool refresh = false;
|
||||
|
||||
for (uint8_t module = 0; module < NUM_MODULES; module++) {
|
||||
if ((waiting & (1 << module)) && reusableBuffer.radioTools.modules[module].information.modelID) {
|
||||
waiting &= ~(1 << module);
|
||||
refresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (refresh) {
|
||||
rebuild(window);
|
||||
}
|
||||
|
||||
PageTab::checkEvents();
|
||||
}
|
||||
|
||||
void RadioToolsPage::rebuild(FormWindow * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(8);
|
||||
grid.setLabelWidth(100);
|
||||
|
||||
window->clear();
|
||||
|
||||
// LUA scripts in TOOLS
|
||||
#if defined(LUA) || defined(DEBUG)
|
||||
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)) {
|
||||
char toolName[TOOL_NAME_MAXLEN + 1];
|
||||
const char * label;
|
||||
char * ext = (char *)getFileExtension(path);
|
||||
if (readToolName(path, toolName)) {
|
||||
label = toolName;
|
||||
}
|
||||
else {
|
||||
*ext = '\0';
|
||||
label = getBasename(path);
|
||||
}
|
||||
new StaticText(window, grid.getLabelSlot(), "lua", BUTTON_BACKGROUND | CENTERED);
|
||||
new TextButton(window, grid.getFieldSlot(1), label, [=]() -> uint8_t {
|
||||
f_chdir("/SCRIPTS/TOOLS/");
|
||||
//luaExec(path);
|
||||
return 0;
|
||||
}, 0);
|
||||
grid.nextLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PXX2)
|
||||
// PXX2 modules tools
|
||||
if (isModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER)) {
|
||||
new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND | CENTERED);
|
||||
new TextButton(window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_INT, [=]() -> uint8_t {
|
||||
new RadioSpectrumAnalyser(INTERNAL_MODULE);
|
||||
return 0;
|
||||
}, 0);
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
if (isModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[INTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER)) {
|
||||
new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND | CENTERED);
|
||||
new TextButton(window, grid.getFieldSlot(1), STR_POWER_METER_INT, [=]() -> uint8_t {
|
||||
// new RadioPowerMeter(INTERNAL_MODULE);
|
||||
return 0;
|
||||
}, 0);
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
if (isModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_SPECTRUM_ANALYSER)) {
|
||||
new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND | CENTERED);
|
||||
new TextButton(window, grid.getFieldSlot(1), STR_SPECTRUM_ANALYSER_EXT, [=]() -> uint8_t {
|
||||
new RadioSpectrumAnalyser(EXTERNAL_MODULE);
|
||||
return 0;
|
||||
}, 0);
|
||||
grid.nextLine();
|
||||
}
|
||||
|
||||
if (isModuleOptionAvailable(reusableBuffer.hardwareAndSettings.modules[EXTERNAL_MODULE].information.modelID, MODULE_OPTION_POWER_METER)) {
|
||||
new StaticText(window, grid.getLabelSlot(), "access", BUTTON_BACKGROUND | CENTERED);
|
||||
new TextButton(window, grid.getFieldSlot(1), STR_POWER_METER_EXT, [=]() -> uint8_t {
|
||||
// new RadioPowerMeter(EXTERNAL_MODULE);
|
||||
return 0;
|
||||
}, 0);
|
||||
|
||||
grid.nextLine();
|
||||
}
|
||||
#endif
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 RadioToolsPage: public PageTab {
|
||||
public:
|
||||
RadioToolsPage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
|
||||
void checkEvents() override;
|
||||
|
||||
protected:
|
||||
void rebuild(FormWindow * window);
|
||||
FormWindow * window = nullptr;
|
||||
uint8_t waiting = 0;
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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_trainer.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_GENERAL)
|
||||
|
||||
RadioTrainerPage::RadioTrainerPage():
|
||||
PageTab(STR_MENUTRAINER, ICON_RADIO_TRAINER)
|
||||
{
|
||||
}
|
||||
|
||||
void RadioTrainerPage::build(FormWindow * window)
|
||||
{
|
||||
#if LCD_W > LCD_H
|
||||
#define TRAINER_LABEL_WIDTH 180
|
||||
#else
|
||||
#define TRAINER_LABEL_WIDTH 100
|
||||
#endif
|
||||
FormGridLayout grid;
|
||||
grid.setLabelWidth(TRAINER_LABEL_WIDTH);
|
||||
grid.nextLine();
|
||||
|
||||
for (uint8_t i=0; i<NUM_STICKS; i++) {
|
||||
uint8_t chan = channelOrder(i+1);
|
||||
TrainerMix * td = &g_eeGeneral.trainer.mix[chan-1];
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(), TEXT_AT_INDEX(STR_VSRCRAW, (i + 1)));
|
||||
auto mode = new Choice(window, grid.getFieldSlot(3,0), STR_TRNMODE, 0, 2, GET_SET_DEFAULT(td->mode));
|
||||
if(i == 0) {
|
||||
window->setFirstField(mode);
|
||||
}
|
||||
auto perc = new NumberEdit(window, grid.getFieldSlot(3, 1), -125, 125, GET_SET_DEFAULT(td->studWeight));
|
||||
perc->setSuffix("%");
|
||||
new Choice(window, grid.getFieldSlot(3,2), STR_TRNCHN, 0, 3, GET_SET_DEFAULT(td->srcChn));
|
||||
grid.nextLine();
|
||||
}
|
||||
grid.nextLine();
|
||||
|
||||
// Trainer multiplier
|
||||
new StaticText(window, grid.getLabelSlot(), STR_MULTIPLIER);
|
||||
auto multiplier = new NumberEdit(window, grid.getFieldSlot(3, 0), -10, 40, GET_SET_DEFAULT(g_eeGeneral.PPM_Multiplier));
|
||||
multiplier->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
drawNumber(dc, FIELD_PADDING_LEFT, FIELD_PADDING_TOP, value+10, flags | PREC1, 0);
|
||||
});
|
||||
grid.nextLine();
|
||||
grid.nextLine();
|
||||
|
||||
// Trainer calibration
|
||||
new StaticText(window, grid.getLabelSlot(), STR_CAL);
|
||||
for (int i=0; i<4; i++) {
|
||||
#if defined (PPM_UNIT_PERCENT_PREC1)
|
||||
auto calib = new NumberEdit(window, grid.getFieldSlot(4,i), 0 , 0, [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i])*2; }, nullptr, LEFT|PREC1);
|
||||
#else
|
||||
auto calib = new NumberEdit(window, grid.getFieldSlot(4,i), 0 , 0, [=]() { return (ppmInput[i]-g_eeGeneral.trainer.calib[i])/5; }, nullptr, LEFT);
|
||||
#endif
|
||||
calib->setWindowFlags(REFRESH_ALWAYS);
|
||||
|
||||
FormField::link(multiplier, window->getFirstField());
|
||||
}
|
||||
}
|
||||
@@ -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 RadioTrainerPage: public PageTab {
|
||||
public:
|
||||
RadioTrainerPage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
|
||||
protected:
|
||||
|
||||
};
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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_version.h"
|
||||
#include "opentx.h"
|
||||
#include "options.h"
|
||||
#include "libopenui.h"
|
||||
|
||||
class OptionsText : public StaticText {
|
||||
public:
|
||||
OptionsText(Window * parent, const rect_t &rect) :
|
||||
StaticText(parent, rect)
|
||||
{
|
||||
coord_t optionWidth = 0;
|
||||
for (uint8_t i=0; options[i]; i++) {
|
||||
const char * option = options[i];
|
||||
optionWidth+= getTextWidth(option);
|
||||
if(optionWidth + 5 > width()) {
|
||||
setHeight(getHeight() + 20);
|
||||
optionWidth = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
virtual void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
coord_t y = 0;
|
||||
lcdNextPos = 0;
|
||||
for (uint8_t i=0; options[i]; i++) {
|
||||
const char * option = options[i];
|
||||
coord_t optionWidth = getTextWidth(option);
|
||||
|
||||
if((lcdNextPos + 5 + optionWidth) > width()) {
|
||||
dc->drawText(lcdNextPos, y, ",");
|
||||
lcdNextPos = 0;
|
||||
y += FH;
|
||||
}
|
||||
if (i > 0 && lcdNextPos != 0)
|
||||
dc->drawText(lcdNextPos, y, ", ");
|
||||
dc->drawText(lcdNextPos, y, option);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
RadioVersionPage::RadioVersionPage():
|
||||
PageTab(STR_MENUVERSION, ICON_RADIO_VERSION)
|
||||
{
|
||||
}
|
||||
|
||||
void RadioVersionPage::build(FormWindow * window)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.setLabelWidth(120);
|
||||
grid.spacer(PAGE_PADDING);
|
||||
|
||||
getCPUUniqueID(reusableBuffer.version.id);
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(), "FW Version");
|
||||
new StaticText(window, grid.getFieldSlot(), vers_stamp);
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(), "FW Options");
|
||||
auto firmwareOptions = new OptionsText(window, grid.getFieldSlot());
|
||||
grid.spacer(firmwareOptions->height() + PAGE_LINE_SPACING);
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(), "FW Date");
|
||||
new StaticText(window, grid.getFieldSlot(), date_stamp);
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(), "FW Time");
|
||||
new StaticText(window, grid.getFieldSlot(), time_stamp);
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(), "Data version");
|
||||
new StaticText(window, grid.getFieldSlot(), eeprom_stamp);
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(window, grid.getLabelSlot(), "CPU UID");
|
||||
new StaticText(window, grid.getFieldSlot(), reusableBuffer.version.id);
|
||||
grid.nextLine();
|
||||
}
|
||||
@@ -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 RadioVersionPage: public PageTab {
|
||||
public:
|
||||
RadioVersionPage();
|
||||
|
||||
void build(FormWindow * window) override;
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "rle.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int rle_decode_8bit(unsigned char* dest, unsigned int dest_size, const unsigned char* src)
|
||||
{
|
||||
//unsigned char count = 0;
|
||||
unsigned char prev_byte = 0;
|
||||
bool prev_byte_valid = false;
|
||||
|
||||
const unsigned char* dest_end = dest + dest_size;
|
||||
unsigned char* d = dest;
|
||||
|
||||
while(d < dest_end) {
|
||||
|
||||
*d++ = *src;
|
||||
if (prev_byte_valid && (*src == prev_byte)) {
|
||||
|
||||
src++;
|
||||
|
||||
if (d + *src > dest + dest_size) {
|
||||
TRACE("rle_decode_8bit: destination overflow!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(d, prev_byte, *src);
|
||||
d += *src++;
|
||||
prev_byte_valid = false;
|
||||
}
|
||||
else {
|
||||
prev_byte = *src++;
|
||||
prev_byte_valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
return d - dest;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef _rle_h_
|
||||
#define _rle_h_
|
||||
|
||||
int rle_decode_8bit(unsigned char* dest, unsigned int dest_size, const unsigned char* src);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,689 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
uint8_t THEME_ICONS[] = {
|
||||
ICON_THEME,
|
||||
ICON_THEME_SETUP,
|
||||
ICON_THEME_VIEW1,
|
||||
ICON_THEME_VIEW2,
|
||||
ICON_THEME_VIEW3,
|
||||
ICON_THEME_VIEW4,
|
||||
ICON_THEME_VIEW5,
|
||||
ICON_THEME_ADD_VIEW,
|
||||
};
|
||||
|
||||
Layout * currentScreen;
|
||||
WidgetsContainerInterface * currentContainer;
|
||||
Widget * currentWidget;
|
||||
uint8_t currentZone;
|
||||
bool widgetNeedsSettings;
|
||||
|
||||
#define SCREENS_SETUP_2ND_COLUMN 200
|
||||
|
||||
char fileSelection[LEN_ZONE_OPTION_STRING];
|
||||
uint8_t fileSelectionDone;
|
||||
|
||||
int updateMainviewsMenu();
|
||||
bool menuScreenAdd(event_t event);
|
||||
void onScreenSetupMenu(const char * result);
|
||||
|
||||
void onZoneOptionFileSelectionMenu(const char * result)
|
||||
{
|
||||
if (result == STR_UPDATE_LIST) {
|
||||
if (!sdListFiles(BITMAPS_PATH, BITMAPS_EXT, LEN_ZONE_OPTION_STRING, NULL)) {
|
||||
POPUP_WARNING(STR_NO_BITMAPS_ON_SD);
|
||||
}
|
||||
}
|
||||
else if (result != STR_EXIT) {
|
||||
fileSelectionDone = true;
|
||||
memcpy(fileSelection, result, sizeof(fileSelection));
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getZoneOptionColumns(const ZoneOption * option)
|
||||
{
|
||||
if (option->type == ZoneOption::Color) {
|
||||
return uint8_t(2 | NAVIGATION_LINE_BY_LINE);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t editColorPart(coord_t x, coord_t y, event_t event, uint8_t part, uint8_t value, LcdFlags attr, uint32_t i_flags)
|
||||
{
|
||||
const char * STR_COLOR_PARTS = "\002" "R:" "G:" "B:";
|
||||
uint8_t PART_BITS[] = { 5, 6, 5 };
|
||||
lcdDrawTextAtIndex(x, y, STR_COLOR_PARTS, part, (attr && menuHorizontalPosition < 0) ? TEXT_INVERTED_COLOR : TEXT_COLOR);
|
||||
lcdDrawNumber(x + 20, y, value << (8-PART_BITS[part]), LEFT|TEXT_COLOR|((attr && (menuHorizontalPosition < 0 || menuHorizontalPosition == part)) ? attr : TEXT_COLOR));
|
||||
if (attr && menuHorizontalPosition == part) {
|
||||
value = checkIncDec(event, value, 0, (1 << PART_BITS[part])-1, i_flags);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
bool editZoneOption(coord_t y, const ZoneOption * option, ZoneOptionValue * value, LcdFlags attr, uint32_t i_flags, event_t event)
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, option->name);
|
||||
|
||||
if (option->type == ZoneOption::Bool) {
|
||||
value->boolValue = editCheckBox(value->boolValue, SCREENS_SETUP_2ND_COLUMN, y, attr, event); // TODO always does storageDirty(EE_MODEL)
|
||||
}
|
||||
else if (option->type == ZoneOption::Integer) {
|
||||
lcdDrawNumber(SCREENS_SETUP_2ND_COLUMN, y, value->signedValue, attr | LEFT);
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELVAR(event, value->signedValue, option->min.signedValue, option->max.signedValue); // TODO i_flags
|
||||
}
|
||||
}
|
||||
else if (option->type == ZoneOption::String) {
|
||||
editName(SCREENS_SETUP_2ND_COLUMN, y, value->stringValue, sizeof(value->stringValue), event, attr); // TODO i_flags?
|
||||
}
|
||||
else if (option->type == ZoneOption::File) {
|
||||
if (ZEXIST(value->stringValue))
|
||||
lcdDrawSizedText(SCREENS_SETUP_2ND_COLUMN, y, value->stringValue, sizeof(value->stringValue), attr);
|
||||
else
|
||||
lcdDrawTextAtIndex(SCREENS_SETUP_2ND_COLUMN, y, STR_VCSWFUNC, 0, attr); // TODO define
|
||||
if (attr) {
|
||||
if (event==EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
if (sdListFiles(BITMAPS_PATH, BITMAPS_EXT, sizeof(value->stringValue), value->stringValue, LIST_NONE_SD_FILE)) {
|
||||
fileSelectionDone = false;
|
||||
POPUP_MENU_START(onZoneOptionFileSelectionMenu);
|
||||
}
|
||||
else {
|
||||
POPUP_WARNING(STR_NO_BITMAPS_ON_SD);
|
||||
}
|
||||
}
|
||||
else if (fileSelectionDone) {
|
||||
memcpy(value->stringValue, fileSelection, sizeof(fileSelection));
|
||||
fileSelectionDone = false;
|
||||
storageDirty(i_flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (option->type == ZoneOption::TextSize) {
|
||||
lcdDrawTextAtIndex(SCREENS_SETUP_2ND_COLUMN, y, "\010StandardTiny\0 Small\0 Mid\0 Double", value->unsignedValue, attr);
|
||||
if (attr) {
|
||||
value->unsignedValue = checkIncDec(event, value->unsignedValue, 0, 4, i_flags);
|
||||
}
|
||||
}
|
||||
else if (option->type == ZoneOption::Timer) {
|
||||
drawStringWithIndex(SCREENS_SETUP_2ND_COLUMN, y, STR_TIMER, value->unsignedValue + 1, attr);
|
||||
if (attr) {
|
||||
value->unsignedValue = checkIncDec(event, value->unsignedValue, 0, MAX_TIMERS - 1, i_flags);
|
||||
}
|
||||
}
|
||||
else if (option->type == ZoneOption::Source) {
|
||||
drawSource(SCREENS_SETUP_2ND_COLUMN, y, value->unsignedValue, attr);
|
||||
if (attr) {
|
||||
CHECK_INCDEC_MODELSOURCE(event, value->unsignedValue, 1, MIXSRC_LAST_TELEM);
|
||||
}
|
||||
}
|
||||
else if (option->type == ZoneOption::Color) {
|
||||
RGB_SPLIT(value->unsignedValue, r, g, b);
|
||||
|
||||
if (attr && menuHorizontalPosition < 0) {
|
||||
lcdDrawSolidFilledRect(SCREENS_SETUP_2ND_COLUMN-3, y-1, 230, FH+1, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
|
||||
lcdSetColor(value->unsignedValue);
|
||||
lcdDrawSolidFilledRect(SCREENS_SETUP_2ND_COLUMN-1, y+1, 42, 17, TEXT_COLOR);
|
||||
lcdDrawSolidFilledRect(SCREENS_SETUP_2ND_COLUMN, y+2, 40, 15, CUSTOM_COLOR);
|
||||
|
||||
r = editColorPart(SCREENS_SETUP_2ND_COLUMN + 50, y, event, 0, r, attr, i_flags);
|
||||
g = editColorPart(SCREENS_SETUP_2ND_COLUMN + 110, y, event, 1, g, attr, i_flags);
|
||||
b = editColorPart(SCREENS_SETUP_2ND_COLUMN + 170, y, event, 2, b, attr, i_flags);
|
||||
|
||||
if (attr && checkIncDec_Ret) {
|
||||
value->unsignedValue = RGB_JOIN(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
return (attr && checkIncDec_Ret);
|
||||
}
|
||||
|
||||
int getOptionsCount(const ZoneOption * options)
|
||||
{
|
||||
if (options == NULL) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
int count = 0;
|
||||
for (const ZoneOption * option = options; option->name; option++) {
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool menuSettings(const char * title, T * object, uint32_t i_flags, event_t event)
|
||||
{
|
||||
|
||||
if (object->getErrorMessage()) {
|
||||
// display error instead of widget settings
|
||||
// TODO nicer display (proper word-wrap)
|
||||
SIMPLE_SUBMENU("Widget Error", ICON_MODEL_LUA_SCRIPTS, 1);
|
||||
int len = strlen(object->getErrorMessage());
|
||||
int y = 3*FH;
|
||||
const char * p = object->getErrorMessage();
|
||||
while (len > 0) {
|
||||
lcdDrawSizedText(MENUS_MARGIN_LEFT, y, p, 30);
|
||||
p += 30;
|
||||
y += FH;
|
||||
len -= 30;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const ZoneOption * options = object->getOptions();
|
||||
linesCount = getOptionsCount(options);
|
||||
uint8_t mstate_tab[MAX_WIDGET_OPTIONS];
|
||||
for (int i=0; i<linesCount; i++) {
|
||||
mstate_tab[i] = getZoneOptionColumns(&options[i]);
|
||||
}
|
||||
|
||||
CUSTOM_SUBMENU_WITH_OPTIONS(title, ICON_THEME, linesCount, OPTION_MENU_TITLE_BAR);
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES+1; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i * FH;
|
||||
int k = i + menuVerticalOffset;
|
||||
LcdFlags blink = ((s_editMode>0) ? BLINK|INVERS : INVERS);
|
||||
LcdFlags attr = (menuVerticalPosition == k ? blink : 0);
|
||||
if (k < linesCount) {
|
||||
const ZoneOption * option = &options[k];
|
||||
ZoneOptionValue * value = object->getOptionValue(k);
|
||||
if (editZoneOption(y, option, value, attr, i_flags, event)) {
|
||||
object->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool menuWidgetSettings(event_t event)
|
||||
{
|
||||
return menuSettings<Widget>(STR_WIDGET_SETTINGS, currentWidget, EE_MODEL, event);
|
||||
}
|
||||
|
||||
bool menuWidgetChoice(event_t event)
|
||||
{
|
||||
static Widget * previousWidget = NULL;
|
||||
static Widget * currentWidget = NULL;
|
||||
static std::list<const WidgetFactory *>::const_iterator iterator;
|
||||
static Widget::PersistentData tempData;
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
{
|
||||
previousWidget = currentContainer->getWidget(currentZone);
|
||||
currentContainer->setWidget(currentZone, NULL);
|
||||
iterator = getRegisteredWidgets().cbegin();
|
||||
if (previousWidget) {
|
||||
const WidgetFactory * factory = previousWidget->getFactory();
|
||||
std::list<const WidgetFactory *>::const_iterator it = getRegisteredWidgets().cbegin();
|
||||
for (; it != getRegisteredWidgets().cend(); ++it) {
|
||||
if (factory->getName() == (*it)->getName()) {
|
||||
iterator = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (iterator != getRegisteredWidgets().cend())
|
||||
currentWidget = (*iterator)->create(currentContainer->getZone(currentZone), &tempData);
|
||||
break;
|
||||
}
|
||||
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
if (previousWidget) {
|
||||
if (currentWidget)
|
||||
delete currentWidget;
|
||||
currentContainer->setWidget(currentZone, previousWidget);
|
||||
}
|
||||
popMenu();
|
||||
return false;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_ENTER):
|
||||
if (iterator != getRegisteredWidgets().cend()) {
|
||||
if (previousWidget)
|
||||
delete previousWidget;
|
||||
currentContainer->createWidget(currentZone, *iterator);
|
||||
widgetNeedsSettings = currentContainer->getWidget(currentZone)->getFactory()->getOptions();
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
popMenu();
|
||||
return false;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
if (iterator != getRegisteredWidgets().cend() && iterator != --getRegisteredWidgets().cend()) {
|
||||
++iterator;
|
||||
if (currentWidget)
|
||||
delete currentWidget;
|
||||
currentWidget = (*iterator)->create(currentContainer->getZone(currentZone), &tempData);
|
||||
}
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_LEFT:
|
||||
if (iterator != getRegisteredWidgets().cbegin()) {
|
||||
--iterator;
|
||||
if (currentWidget)
|
||||
delete currentWidget;
|
||||
currentWidget = (*iterator)->create(currentContainer->getZone(currentZone), &tempData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
currentScreen->refresh();
|
||||
|
||||
Zone zone = currentContainer->getZone(currentZone);
|
||||
lcdDrawFilledRect(0, 0, zone.x-2, LCD_H, SOLID, OVERLAY_COLOR | (8<<24));
|
||||
lcdDrawFilledRect(zone.x+zone.w+2, 0, LCD_W-zone.x-zone.w-2, LCD_H, SOLID, OVERLAY_COLOR | (8<<24));
|
||||
lcdDrawFilledRect(zone.x-2, 0, zone.w+4, zone.y-2, SOLID, OVERLAY_COLOR | (8<<24));
|
||||
lcdDrawFilledRect(zone.x-2, zone.y+zone.h+2, zone.w+4, LCD_H-zone.y-zone.h-2, SOLID, OVERLAY_COLOR | (8<<24));
|
||||
|
||||
if (currentWidget)
|
||||
currentWidget->refresh();
|
||||
|
||||
if (iterator != getRegisteredWidgets().cbegin()) {
|
||||
lcdDrawBitmapPattern(zone.x-10, zone.y+zone.h/2-10, LBM_SWIPE_CIRCLE, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawBitmapPattern(zone.x-10, zone.y+zone.h/2-10, LBM_SWIPE_LEFT, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
if (iterator != --getRegisteredWidgets().cend()) {
|
||||
lcdDrawBitmapPattern(zone.x+zone.w-9, zone.y+zone.h/2-10, LBM_SWIPE_CIRCLE, TEXT_INVERTED_BGCOLOR);
|
||||
lcdDrawBitmapPattern(zone.x+zone.w-9, zone.y+zone.h/2-10, LBM_SWIPE_RIGHT, TEXT_INVERTED_COLOR);
|
||||
}
|
||||
if (currentWidget)
|
||||
lcdDrawText(zone.x + zone.w, zone.y-1, currentWidget->getFactory()->getName(), RIGHT | TEXT_COLOR | SMLSIZE | INVERS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void onZoneMenu(const char * result)
|
||||
{
|
||||
if (result == STR_SELECT_WIDGET) {
|
||||
pushMenu(menuWidgetChoice);
|
||||
}
|
||||
else if (result == STR_WIDGET_SETTINGS) {
|
||||
pushMenu(menuWidgetSettings);
|
||||
}
|
||||
else if (result == STR_REMOVE_WIDGET) {
|
||||
currentContainer->createWidget(currentZone, NULL);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
}
|
||||
|
||||
bool menuWidgetsSetup(event_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
menuVerticalPosition = 0;
|
||||
break;
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
killEvents(KEY_EXIT);
|
||||
popMenu();
|
||||
return false;
|
||||
}
|
||||
|
||||
currentScreen->refresh();
|
||||
|
||||
for (int i=currentContainer->getZonesCount()-1; i>=0; i--) {
|
||||
Zone zone = currentContainer->getZone(i);
|
||||
LcdFlags color;
|
||||
int padding, thickness;
|
||||
if (currentContainer == topbar) {
|
||||
color = MENU_TITLE_COLOR;
|
||||
padding = 2;
|
||||
thickness = 1;
|
||||
}
|
||||
else {
|
||||
color = TEXT_INVERTED_BGCOLOR;
|
||||
padding = 4;
|
||||
thickness = 2;
|
||||
}
|
||||
if (menuVerticalPosition == i) {
|
||||
lcdDrawSolidRect(zone.x-padding, zone.y-padding, zone.w+2*padding, zone.h+2*padding, thickness, color);
|
||||
if (event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
killEvents(KEY_ENTER);
|
||||
currentZone = menuVerticalPosition;
|
||||
currentWidget = currentContainer->getWidget(menuVerticalPosition);
|
||||
if (currentWidget) {
|
||||
POPUP_MENU_ADD_ITEM(STR_SELECT_WIDGET);
|
||||
if (currentWidget->getFactory()->getOptions())
|
||||
POPUP_MENU_ADD_ITEM(STR_WIDGET_SETTINGS);
|
||||
POPUP_MENU_ADD_ITEM(STR_REMOVE_WIDGET);
|
||||
POPUP_MENU_START(onZoneMenu);
|
||||
}
|
||||
else {
|
||||
onZoneMenu(STR_SELECT_WIDGET);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (widgetNeedsSettings) {
|
||||
currentWidget = currentContainer->getWidget(menuVerticalPosition);
|
||||
if (currentWidget) {
|
||||
widgetNeedsSettings = false;
|
||||
onZoneMenu(STR_WIDGET_SETTINGS);
|
||||
}
|
||||
}
|
||||
lcdDrawRect(zone.x-padding, zone.y-padding, zone.w+2*padding, zone.h+2*padding, thickness, 0x3F, color);
|
||||
}
|
||||
}
|
||||
navigate(event, currentContainer->getZonesCount(), currentContainer->getZonesCount(), 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T * editThemeChoice(coord_t x, coord_t y, std::list<T *> & elList, T * current, bool needsOffsetCheck, LcdFlags attr, event_t event)
|
||||
{
|
||||
static uint8_t menuHorizontalOffset = 0;
|
||||
uint8_t elCount = elList.size(), last, idx;
|
||||
coord_t pos;
|
||||
int currentIndex = 0;
|
||||
typename std::list<T *>::const_iterator elItr = elList.cbegin();
|
||||
|
||||
if (!elCount)
|
||||
return NULL;
|
||||
|
||||
for (; elItr != elList.cend(); ++elItr, ++currentIndex) {
|
||||
if ((*elItr) == current)
|
||||
break;
|
||||
}
|
||||
|
||||
if (event == EVT_ENTRY) {
|
||||
menuHorizontalOffset = 0;
|
||||
needsOffsetCheck = true;
|
||||
}
|
||||
|
||||
if (needsOffsetCheck) {
|
||||
if (currentIndex < menuHorizontalOffset) {
|
||||
menuHorizontalOffset = currentIndex;
|
||||
}
|
||||
else if (currentIndex > menuHorizontalOffset + 3) {
|
||||
menuHorizontalOffset = currentIndex - 3;
|
||||
}
|
||||
}
|
||||
if (attr) {
|
||||
if (menuHorizontalPosition < 0) {
|
||||
lcdDrawSolidFilledRect(x-3, y-1, min<uint8_t>(4, elCount)*56+1, 2*FH-5, TEXT_INVERTED_BGCOLOR);
|
||||
}
|
||||
else {
|
||||
if (needsOffsetCheck) {
|
||||
menuHorizontalPosition = currentIndex;
|
||||
}
|
||||
else if (menuHorizontalPosition < menuHorizontalOffset) {
|
||||
menuHorizontalOffset = menuHorizontalPosition;
|
||||
}
|
||||
else if (menuHorizontalPosition > menuHorizontalOffset + 3) {
|
||||
menuHorizontalOffset = menuHorizontalPosition - 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
last = min<uint8_t>(menuHorizontalOffset + 4, elCount);
|
||||
idx = menuHorizontalOffset;
|
||||
pos = x;
|
||||
elItr = elList.cbegin();
|
||||
std::advance(elItr, min<uint8_t>(menuHorizontalOffset, elCount - 1));
|
||||
for (; idx < last && elItr != elList.cend(); ++idx, ++elItr, pos += 56) {
|
||||
(*elItr)->drawThumb(pos, y+1, current == (*elItr) ? ((attr && menuHorizontalPosition < 0) ? TEXT_INVERTED_COLOR : TEXT_INVERTED_BGCOLOR) : LINE_COLOR);
|
||||
}
|
||||
if (elCount > 4) {
|
||||
lcdDrawBitmapPattern(x - 12, y+1, LBM_CARROUSSEL_LEFT, menuHorizontalOffset > 0 ? LINE_COLOR : CURVE_AXIS_COLOR);
|
||||
lcdDrawBitmapPattern(x + 4 * 56, y+1, LBM_CARROUSSEL_RIGHT, last < getRegisteredLayouts().size() ? LINE_COLOR : CURVE_AXIS_COLOR);
|
||||
}
|
||||
if (attr && menuHorizontalPosition >= 0) {
|
||||
lcdDrawSolidRect(x + (menuHorizontalPosition - menuHorizontalOffset) * 56 - 3, y - 1, 57, 35, 1, TEXT_INVERTED_BGCOLOR);
|
||||
if (event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
s_editMode = 0;
|
||||
elItr = elList.cbegin();
|
||||
if (menuHorizontalPosition < (int)elList.size())
|
||||
std::advance(elItr, menuHorizontalPosition);
|
||||
if (elItr != elList.cend())
|
||||
return (*elItr);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
enum menuScreensThemeItems {
|
||||
ITEM_SCREEN_SETUP_THEME,
|
||||
ITEM_SCREEN_SETUP_THEME_OPTION1 = ITEM_SCREEN_SETUP_THEME+2
|
||||
};
|
||||
|
||||
bool menuScreensTheme(event_t event)
|
||||
{
|
||||
bool needsOffsetCheck = (menuVerticalPosition != 0 || menuHorizontalPosition < 0);
|
||||
const ZoneOption * options = theme->getOptions();
|
||||
int optionsCount = getOptionsCount(options);
|
||||
linesCount = ITEM_SCREEN_SETUP_THEME_OPTION1 + optionsCount + 1;
|
||||
|
||||
menuPageCount = updateMainviewsMenu();
|
||||
uint8_t mstate_tab[2 + MAX_THEME_OPTIONS + 1] = { uint8_t(NAVIGATION_LINE_BY_LINE | uint8_t(getRegisteredThemes().size()-1)), ORPHAN_ROW };
|
||||
for (int i=0; i<optionsCount; i++) {
|
||||
mstate_tab[2+i] = getZoneOptionColumns(&options[i]);
|
||||
}
|
||||
mstate_tab[2+optionsCount] = 0; // The button for the Topbar setup
|
||||
CUSTOM_MENU_WITH_OPTIONS(STR_USER_INTERFACE, THEME_ICONS, menuTabScreensSetup, menuPageCount, 0, linesCount);
|
||||
|
||||
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 = (menuVerticalPosition == k ? blink : 0);
|
||||
switch (k) {
|
||||
case ITEM_SCREEN_SETUP_THEME: {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y + FH / 2, STR_THEME);
|
||||
Theme * new_theme = editThemeChoice<Theme>(SCREENS_SETUP_2ND_COLUMN, y, getRegisteredThemes(), theme, needsOffsetCheck, attr, event);
|
||||
if (new_theme) {
|
||||
new_theme->init();
|
||||
loadTheme(new_theme);
|
||||
strncpy(g_eeGeneral.themeName, new_theme->getName(), sizeof(g_eeGeneral.themeName));
|
||||
killEvents(KEY_ENTER);
|
||||
storageDirty(EE_GENERAL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SCREEN_SETUP_THEME+1:
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
uint8_t index = k - ITEM_SCREEN_SETUP_THEME_OPTION1;
|
||||
if (index < optionsCount) {
|
||||
const ZoneOption * option = &options[index];
|
||||
ZoneOptionValue * value = theme->getOptionValue(index);
|
||||
bool ret = editZoneOption(y, option, value, attr, EE_GENERAL, event);
|
||||
if (option->type == ZoneOption::Color) {
|
||||
if (attr && event == EVT_KEY_FIRST(KEY_EXIT)) {
|
||||
theme->update();
|
||||
}
|
||||
}
|
||||
else if (ret) {
|
||||
theme->update();
|
||||
}
|
||||
}
|
||||
else if (index == optionsCount) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TOP_BAR);
|
||||
drawButton(SCREENS_SETUP_2ND_COLUMN, y, STR_SETUP, attr);
|
||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
currentScreen = customScreens[0];
|
||||
currentContainer = topbar;
|
||||
pushMenu(menuWidgetsSetup);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
enum MenuScreenSetupItems {
|
||||
ITEM_SCREEN_SETUP_LAYOUT,
|
||||
ITEM_SCREEN_SETUP_WIDGETS_SETUP = ITEM_SCREEN_SETUP_LAYOUT+2,
|
||||
ITEM_SCREEN_SETUP_LAYOUT_OPTION1,
|
||||
};
|
||||
|
||||
bool menuScreenSetup(int index, event_t event)
|
||||
{
|
||||
if (customScreens[index] == NULL) {
|
||||
return menuScreenAdd(event);
|
||||
}
|
||||
|
||||
currentScreen = customScreens[index];
|
||||
currentContainer = currentScreen;
|
||||
bool needsOffsetCheck = (menuVerticalPosition != 0 || menuHorizontalPosition < 0);
|
||||
|
||||
char title[] = "Main view X";
|
||||
title[sizeof(title)-2] = '1' + index;
|
||||
menuPageCount = updateMainviewsMenu();
|
||||
|
||||
const ZoneOption * options = currentScreen->getFactory()->getOptions();
|
||||
int optionsCount = getOptionsCount(options);
|
||||
linesCount = ITEM_SCREEN_SETUP_LAYOUT_OPTION1 + optionsCount;
|
||||
if (menuPageCount > 3)
|
||||
++linesCount;
|
||||
|
||||
uint8_t mstate_tab[2 + MAX_LAYOUT_OPTIONS + 1] = { uint8_t(NAVIGATION_LINE_BY_LINE | uint8_t(getRegisteredLayouts().size()-1)), ORPHAN_ROW };
|
||||
for (int i=0; i<optionsCount; i++) {
|
||||
mstate_tab[3+i] = getZoneOptionColumns(&options[i]);
|
||||
}
|
||||
mstate_tab[3+optionsCount] = 0; // The remove button
|
||||
|
||||
CUSTOM_MENU_WITH_OPTIONS(title, THEME_ICONS, menuTabScreensSetup, menuPageCount, index+1, linesCount);
|
||||
|
||||
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 = (menuVerticalPosition == k ? blink : 0);
|
||||
switch(k) {
|
||||
case ITEM_SCREEN_SETUP_LAYOUT:
|
||||
{
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y + FH / 2, STR_LAYOUT);
|
||||
const LayoutFactory * factory = editThemeChoice<const LayoutFactory>(SCREENS_SETUP_2ND_COLUMN, y, getRegisteredLayouts(), currentScreen->getFactory(), needsOffsetCheck, attr, event);
|
||||
if (factory) {
|
||||
delete customScreens[index];
|
||||
currentScreen = customScreens[index] = factory->create(&g_model.screenData[index].layoutData);
|
||||
strncpy(g_model.screenData[index].layoutName, factory->getName(), sizeof(g_model.screenData[index].layoutName));
|
||||
killEvents(KEY_ENTER);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ITEM_SCREEN_SETUP_LAYOUT+1:
|
||||
break;
|
||||
|
||||
case ITEM_SCREEN_SETUP_WIDGETS_SETUP:
|
||||
drawButton(SCREENS_SETUP_2ND_COLUMN, y, STR_SETUP_WIDGETS, attr);
|
||||
if (attr && event == EVT_KEY_FIRST(KEY_ENTER)) {
|
||||
pushMenu(menuWidgetsSetup);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
uint8_t o = k - ITEM_SCREEN_SETUP_LAYOUT_OPTION1;
|
||||
if (o < optionsCount) {
|
||||
const ZoneOption * option = &options[o];
|
||||
ZoneOptionValue * value = currentScreen->getOptionValue(o);
|
||||
if (editZoneOption(y, option, value, attr, EE_MODEL, event)) {
|
||||
currentScreen->update();
|
||||
}
|
||||
}
|
||||
else if (menuPageCount > 3 && o == optionsCount) {
|
||||
drawButton(SCREENS_SETUP_2ND_COLUMN, y, STR_REMOVE_SCREEN, attr);
|
||||
if (attr && event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
delete currentScreen;
|
||||
if (index != MAX_CUSTOM_SCREENS-1) {
|
||||
memmove(&g_model.screenData[index], &g_model.screenData[index + 1], sizeof(CustomScreenData) * (MAX_CUSTOM_SCREENS - index - 1));
|
||||
memmove(&customScreens[index], &customScreens[index + 1], sizeof(Layout *) * (MAX_CUSTOM_SCREENS - index - 1));
|
||||
}
|
||||
memset(&g_model.screenData[MAX_CUSTOM_SCREENS-1], 0, sizeof(CustomScreenData));
|
||||
customScreens[MAX_CUSTOM_SCREENS-1] = NULL;
|
||||
loadCustomScreens();
|
||||
killEvents(KEY_ENTER);
|
||||
chainMenu(menuTabScreensSetup[index > 0 ? index : 1]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
bool menuCustomScreenSetup(event_t event)
|
||||
{
|
||||
return menuScreenSetup(N, event);
|
||||
}
|
||||
|
||||
const MenuHandlerFunc menuTabScreensSetup[1+MAX_CUSTOM_SCREENS] = {
|
||||
menuScreensTheme,
|
||||
menuCustomScreenSetup<0>,
|
||||
menuCustomScreenSetup<1>,
|
||||
menuCustomScreenSetup<2>,
|
||||
menuCustomScreenSetup<3>,
|
||||
menuCustomScreenSetup<4>
|
||||
};
|
||||
|
||||
int updateMainviewsMenu()
|
||||
{
|
||||
for (int index=1; index<MAX_CUSTOM_SCREENS; index++) {
|
||||
if (customScreens[index]) {
|
||||
THEME_ICONS[2+index] = ICON_THEME_VIEW1+index;
|
||||
}
|
||||
else {
|
||||
THEME_ICONS[2+index] = ICON_THEME_ADD_VIEW;
|
||||
return 2+index;
|
||||
}
|
||||
}
|
||||
return 1+MAX_CUSTOM_SCREENS;
|
||||
}
|
||||
|
||||
bool menuScreenAdd(event_t event)
|
||||
{
|
||||
menuPageCount = updateMainviewsMenu();
|
||||
|
||||
if (event == EVT_KEY_FIRST(KEY_ENTER) && getRegisteredLayouts().size()) {
|
||||
const LayoutFactory * lf = getRegisteredLayouts().front();
|
||||
customScreens[menuPageCount-2] = lf->create(&g_model.screenData[menuPageCount-2].layoutData);
|
||||
strncpy(g_model.screenData[menuPageCount-2].layoutName, lf->getName(), sizeof(g_model.screenData[menuPageCount-2].layoutName));
|
||||
s_editMode = 0;
|
||||
menuHorizontalPosition = -1;
|
||||
killEvents(KEY_ENTER);
|
||||
storageDirty(EE_MODEL);
|
||||
return false;
|
||||
}
|
||||
|
||||
SIMPLE_MENU_WITH_OPTIONS(STR_ADDMAINVIEW, THEME_ICONS, menuTabScreensSetup, menuPageCount, menuPageCount-1, 0);
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,498 @@
|
||||
/*
|
||||
* 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 "special_functions.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(functions == g_model.customFn ? EE_MODEL : EE_GENERAL)
|
||||
|
||||
class SpecialFunctionEditPage : public Page {
|
||||
public:
|
||||
SpecialFunctionEditPage(CustomFunctionData * functions, uint8_t index) :
|
||||
Page(functions == g_model.customFn ? ICON_MODEL_SPECIAL_FUNCTIONS : ICON_RADIO_GLOBAL_FUNCTIONS),
|
||||
functions(functions),
|
||||
index(index)
|
||||
{
|
||||
buildHeader(&header);
|
||||
buildBody(&body);
|
||||
}
|
||||
|
||||
protected:
|
||||
CustomFunctionData * functions;
|
||||
uint8_t index;
|
||||
Window * specialFunctionOneWindow = nullptr;
|
||||
StaticText * headerSF = nullptr;
|
||||
bool active = false;
|
||||
|
||||
bool isActive()
|
||||
{
|
||||
return ((functions == g_model.customFn ? modelFunctionsContext.activeSwitches : globalFunctionsContext.activeSwitches) & ((MASK_CFN_TYPE)1 << index) ? 1 : 0);
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
Page::checkEvents();
|
||||
if (active != isActive()) {
|
||||
invalidate();
|
||||
headerSF->setFlags(isActive() ? BOLD|WARNING_COLOR : MENU_TITLE_COLOR);
|
||||
active = !active;
|
||||
}
|
||||
}
|
||||
|
||||
void buildHeader(Window * window)
|
||||
{
|
||||
new StaticText(window, { 60, 2, 200, 20 }, functions == g_model.customFn ? STR_MENUCUSTOMFUNC : STR_MENUSPECIALFUNCS, MENU_TITLE_COLOR);
|
||||
headerSF = new StaticText(window, { 60, 22, 100, 20 }, (functions == g_model.customFn ? "SF" : "GF" ) + std::to_string(index), MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
void updateSpecialFunctionOneWindow(FormField * previousField, FormField * nextField)
|
||||
{
|
||||
// SF.one variable part
|
||||
FormGridLayout grid;
|
||||
specialFunctionOneWindow->clear();
|
||||
|
||||
CustomFunctionData * cfn = &functions[index];
|
||||
uint8_t func = CFN_FUNC(cfn);
|
||||
|
||||
FormField::setCurrentField(previousField);
|
||||
|
||||
// Func param
|
||||
switch (func) {
|
||||
case FUNC_OVERRIDE_CHANNEL:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_CH);
|
||||
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 1, MAX_OUTPUT_CHANNELS, GET_SET_VALUE_WITH_OFFSET(CFN_CH_INDEX(cfn), 1));
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
|
||||
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), -100, 100, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_TRAINER:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_TIMER);
|
||||
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0, 4, GET_SET_DEFAULT(CFN_TIMER_INDEX(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_RESET:
|
||||
if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) {
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_RESET);
|
||||
auto choice = new Choice(specialFunctionOneWindow, grid.getFieldSlot(), nullptr, 0,
|
||||
FUNC_RESET_PARAM_FIRST_TELEM + lastUsedTelemetryIndex(),
|
||||
GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
choice->setAvailableHandler(isSourceAvailableInResetSpecialFunction);
|
||||
choice->setTextHandler([=](int32_t value) {
|
||||
if (value < FUNC_RESET_PARAM_FIRST_TELEM)
|
||||
return TEXT_AT_INDEX(STR_VFSWRESET, value);
|
||||
else
|
||||
return std::string(g_model.telemetrySensors[value - FUNC_RESET_PARAM_FIRST_TELEM].label, TELEM_LABEL_LEN);
|
||||
});
|
||||
grid.nextLine();
|
||||
}
|
||||
break;
|
||||
|
||||
case FUNC_VOLUME:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_SPEAKER_VOLUME);
|
||||
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_CH, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_PLAY_SOUND:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
|
||||
new Choice(specialFunctionOneWindow, grid.getFieldSlot(), STR_FUNCSOUNDS, 0,
|
||||
AU_SPECIAL_SOUND_LAST - AU_SPECIAL_SOUND_FIRST - 1, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_PLAY_TRACK:
|
||||
case FUNC_BACKGND_MUSIC:
|
||||
case FUNC_PLAY_SCRIPT:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
|
||||
new FileChoice(specialFunctionOneWindow, grid.getFieldSlot(),
|
||||
func == FUNC_PLAY_SCRIPT ? SCRIPTS_FUNCS_PATH : std::string(SOUNDS_PATH, SOUNDS_PATH_LNG_OFS) +
|
||||
std::string(currentLanguagePack->id, 2),
|
||||
func == FUNC_PLAY_SCRIPT ? SCRIPTS_EXT : SOUNDS_EXT,
|
||||
sizeof(cfn->play.name),
|
||||
[=]() {
|
||||
return std::string(cfn->play.name, ZLEN(cfn->play.name));
|
||||
},
|
||||
[=](std::string newValue) {
|
||||
strncpy(cfn->play.name, newValue.c_str(), sizeof(cfn->play.name));
|
||||
SET_DIRTY();
|
||||
});
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_SET_TIMER: {
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_TIMER);
|
||||
auto timerchoice = new Choice(specialFunctionOneWindow, grid.getFieldSlot(), nullptr, 0, TIMERS - 1, GET_SET_DEFAULT(CFN_TIMER_INDEX(cfn)));
|
||||
timerchoice->setTextHandler([](int32_t value) {
|
||||
return std::string(STR_TIMER) + std::to_string(value + 1);
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
|
||||
new TimeEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 9 * 60 * 60 - 1, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
}
|
||||
|
||||
case FUNC_SET_FAILSAFE:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_MODULE);
|
||||
new Choice(specialFunctionOneWindow, grid.getFieldSlot(), "\004Int.Ext.", 0, NUM_MODULES - 1, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_PLAY_VALUE:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
|
||||
new SourceChoice(specialFunctionOneWindow, grid.getFieldSlot(), 0, MIXSRC_LAST_TELEM, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_HAPTIC:
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
|
||||
new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 3, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
grid.nextLine();
|
||||
break;
|
||||
|
||||
case FUNC_LOGS: {
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_VALUE);
|
||||
auto edit = new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(), 0, 255, GET_SET_DEFAULT(CFN_PARAM(cfn)));
|
||||
edit->setDisplayHandler([=](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
lcdDrawNumber(2, 2, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s");
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (HAS_ENABLE_PARAM(func)) {
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_ENABLE);
|
||||
new CheckBox(specialFunctionOneWindow, grid.getFieldSlot(), GET_SET_DEFAULT(CFN_ACTIVE(cfn)));
|
||||
grid.nextLine();
|
||||
}
|
||||
else if (HAS_REPEAT_PARAM(func)) { // !1x 1x 1s 2s 3s ...
|
||||
new StaticText(specialFunctionOneWindow, grid.getLabelSlot(), STR_REPEAT);
|
||||
auto repeat = new NumberEdit(specialFunctionOneWindow, grid.getFieldSlot(2, 1), -1, 60/CFN_PLAY_REPEAT_MUL, GET_SET_DEFAULT(CFN_PLAY_REPEAT(cfn)));
|
||||
repeat->setDisplayHandler([](BitmapBuffer * dc, LcdFlags flags, int32_t value) {
|
||||
if (value == 0)
|
||||
lcdDrawText(3, 0, "1x", flags);
|
||||
else if (value == CFN_PLAY_REPEAT_NOSTART)
|
||||
lcdDrawText(3, 0, "!1x", flags);
|
||||
else
|
||||
drawNumber(dc, 3, 0, value * CFN_PLAY_REPEAT_MUL, flags, 0, nullptr, "s");
|
||||
});
|
||||
}
|
||||
|
||||
FormField::link(FormField::getCurrentField(), nextField);
|
||||
}
|
||||
|
||||
void buildBody(FormWindow * window)
|
||||
{
|
||||
// SF.one
|
||||
FormGridLayout grid;
|
||||
grid.spacer(8);
|
||||
|
||||
CustomFunctionData * cfn = &functions[index];
|
||||
|
||||
// Switch
|
||||
new StaticText(window, grid.getLabelSlot(), STR_SWITCH);
|
||||
auto switchChoice = new SwitchChoice(window, grid.getFieldSlot(), SWSRC_FIRST, SWSRC_LAST, GET_SET_DEFAULT(CFN_SWITCH(cfn)));
|
||||
switchChoice->setAvailableHandler([=](int value) {
|
||||
return (functions == g_model.customFn ? isSwitchAvailable(value, ModelCustomFunctionsContext)
|
||||
: isSwitchAvailable(value,
|
||||
GeneralCustomFunctionsContext));
|
||||
});
|
||||
window->setFirstField(switchChoice);
|
||||
grid.nextLine();
|
||||
|
||||
// Function
|
||||
new StaticText(window, grid.getLabelSlot(), STR_FUNC);
|
||||
auto functionChoice = new Choice(window, grid.getFieldSlot(), STR_VFSWFUNC, 0, FUNC_MAX - 1, GET_DEFAULT(CFN_FUNC(cfn)));
|
||||
functionChoice->setSetValueHandler([=](int32_t newValue) {
|
||||
CFN_FUNC(cfn) = newValue;
|
||||
CFN_RESET(cfn);
|
||||
SET_DIRTY();
|
||||
updateSpecialFunctionOneWindow(functionChoice, switchChoice);
|
||||
});
|
||||
functionChoice->setAvailableHandler([=](int value) {
|
||||
return isAssignableFunctionAvailable(value, functions);
|
||||
});
|
||||
grid.nextLine();
|
||||
|
||||
specialFunctionOneWindow = new Window(window, {0, grid.getWindowHeight(), LCD_W, 0});
|
||||
updateSpecialFunctionOneWindow(functionChoice, switchChoice);
|
||||
grid.addWindow(specialFunctionOneWindow);
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr coord_t line1 = 0;
|
||||
static constexpr coord_t line2 = 20;
|
||||
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 + 20;
|
||||
|
||||
class SpecialFunctionButton : public Button {
|
||||
public:
|
||||
SpecialFunctionButton(FormWindow * parent, const rect_t &rect, CustomFunctionData * functions, uint8_t index) :
|
||||
Button(parent, rect),
|
||||
functions(functions),
|
||||
index(index)
|
||||
{
|
||||
const CustomFunctionData * cfn = &functions[index];
|
||||
uint8_t func = CFN_FUNC(cfn);
|
||||
if (!CFN_EMPTY(cfn) &&
|
||||
(HAS_ENABLE_PARAM(func) || HAS_REPEAT_PARAM(func) || (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC || func == FUNC_PLAY_SCRIPT))) {
|
||||
setHeight(getHeight() + 20);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "SpecialFunctionButton";
|
||||
}
|
||||
#endif
|
||||
|
||||
bool isActive()
|
||||
{
|
||||
return ((functions == g_model.customFn ? modelFunctionsContext.activeSwitches : globalFunctionsContext.activeSwitches) & ((MASK_CFN_TYPE)1 << index) ? 1 : 0);
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
Button::checkEvents();
|
||||
if (active != isActive()) {
|
||||
invalidate();
|
||||
active = !active;
|
||||
}
|
||||
}
|
||||
|
||||
void paintSpecialFunctionLine(BitmapBuffer * dc)
|
||||
{
|
||||
// SF.all
|
||||
const CustomFunctionData * cfn = &functions[index];
|
||||
if (functions[index].func == FUNC_OVERRIDE_CHANNEL && functions != g_model.customFn) {
|
||||
functions[index].func = FUNC_OVERRIDE_CHANNEL + 1;
|
||||
}
|
||||
uint8_t func = CFN_FUNC(cfn);
|
||||
|
||||
drawSwitch(dc, col1, line1, CFN_SWITCH(cfn), 0);
|
||||
if (CFN_EMPTY(cfn))
|
||||
return;
|
||||
|
||||
lcdDrawTextAtIndex(col2, line1, STR_VFSWFUNC, func, 0);
|
||||
int16_t val_min = 0;
|
||||
int16_t val_max = 255;
|
||||
|
||||
switch (func) {
|
||||
case FUNC_OVERRIDE_CHANNEL:
|
||||
drawChn(dc, col1, line2, CFN_CH_INDEX(cfn) + 1, 0);
|
||||
getMixSrcRange(MIXSRC_FIRST_CH, val_min, val_max);
|
||||
lcdDrawNumber(col2, line2, CFN_PARAM(cfn));
|
||||
break;
|
||||
|
||||
case FUNC_TRAINER:
|
||||
drawSource(dc, col1, line2, CFN_CH_INDEX(cfn) == 0 ? 0 : MIXSRC_Rud + CFN_CH_INDEX(cfn) - 1);
|
||||
break;
|
||||
|
||||
case FUNC_RESET:
|
||||
if (CFN_PARAM(cfn) < FUNC_RESET_PARAM_FIRST_TELEM) {
|
||||
lcdDrawTextAtIndex(col1, line2, STR_VFSWRESET, CFN_PARAM(cfn));
|
||||
}
|
||||
else {
|
||||
TelemetrySensor * sensor = &g_model.telemetrySensors[CFN_PARAM(cfn) - FUNC_RESET_PARAM_FIRST_TELEM];
|
||||
lcdDrawSizedText(col1, line2, sensor->label, TELEM_LABEL_LEN, ZCHAR);
|
||||
}
|
||||
break;
|
||||
|
||||
case FUNC_VOLUME:
|
||||
drawSource(dc, col1, line2, CFN_PARAM(cfn), 0);
|
||||
break;
|
||||
|
||||
case FUNC_PLAY_SOUND:
|
||||
lcdDrawTextAtIndex(col1, line2, STR_FUNCSOUNDS, CFN_PARAM(cfn));
|
||||
break;
|
||||
|
||||
case FUNC_PLAY_TRACK:
|
||||
case FUNC_BACKGND_MUSIC:
|
||||
case FUNC_PLAY_SCRIPT:
|
||||
if (ZEXIST(cfn->play.name))
|
||||
lcdDrawSizedText(col1, line2, cfn->play.name, sizeof(cfn->play.name), 0);
|
||||
else
|
||||
lcdDrawTextAtIndex(col1, line2, STR_VCSWFUNC, 0, 0);
|
||||
break;
|
||||
|
||||
case FUNC_SET_TIMER:
|
||||
drawStringWithIndex(col1, line2, STR_TIMER, CFN_TIMER_INDEX(cfn) + 1, 0);
|
||||
break;
|
||||
|
||||
case FUNC_SET_FAILSAFE:
|
||||
lcdDrawTextAtIndex(col1, line2, "\004Int.Ext.", CFN_PARAM(cfn), 0);
|
||||
break;
|
||||
|
||||
case FUNC_PLAY_VALUE:
|
||||
drawSource(dc, col1, line2, CFN_PARAM(cfn), 0);
|
||||
break;
|
||||
|
||||
case FUNC_HAPTIC:
|
||||
lcdDrawNumber(col1, line2, CFN_PARAM(cfn), 0);
|
||||
break;
|
||||
|
||||
case FUNC_LOGS:
|
||||
lcdDrawNumber(col3, line1, CFN_PARAM(cfn), PREC1, sizeof(CFN_PARAM(cfn)), nullptr, "s");
|
||||
break;
|
||||
}
|
||||
if (HAS_ENABLE_PARAM(func)) {
|
||||
drawCheckBox(col3, line2, CFN_ACTIVE(cfn), 0);
|
||||
}
|
||||
else if (HAS_REPEAT_PARAM(func)) {
|
||||
if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
lcdDrawText(col3, line2, "1x", 0);
|
||||
}
|
||||
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
|
||||
lcdDrawText(col3, line2, "!1x", 0);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(col3 + 12, line2, CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL, 0 | RIGHT, 0, nullptr, "s");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
if (active)
|
||||
dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, WARNING_COLOR);
|
||||
paintSpecialFunctionLine(dc);
|
||||
drawSolidRect(dc, 0, 0, rect.w, rect.h, 2, hasFocus() ? SCROLLBOX_COLOR : CURVE_AXIS_COLOR);
|
||||
}
|
||||
|
||||
protected:
|
||||
CustomFunctionData * functions;
|
||||
uint8_t index;
|
||||
bool active = false;
|
||||
};
|
||||
|
||||
SpecialFunctionsPage::SpecialFunctionsPage(CustomFunctionData * functions) :
|
||||
PageTab(functions == g_model.customFn ? STR_MENUCUSTOMFUNC : STR_MENUSPECIALFUNCS,
|
||||
functions == g_model.customFn ? ICON_MODEL_SPECIAL_FUNCTIONS : ICON_RADIO_GLOBAL_FUNCTIONS),
|
||||
functions(functions)
|
||||
{
|
||||
}
|
||||
|
||||
void SpecialFunctionsPage::rebuild(FormWindow * window, int8_t focusSpecialFunctionIndex)
|
||||
{
|
||||
coord_t scrollPosition = window->getScrollPositionY();
|
||||
window->clear();
|
||||
build(window, focusSpecialFunctionIndex);
|
||||
window->setScrollPositionY(scrollPosition);
|
||||
}
|
||||
|
||||
void SpecialFunctionsPage::editSpecialFunction(FormWindow * window, uint8_t index)
|
||||
{
|
||||
auto editPage = new SpecialFunctionEditPage(functions, index);
|
||||
editPage->setCloseHandler([=]() {
|
||||
rebuild(window, index);
|
||||
});
|
||||
}
|
||||
|
||||
void SpecialFunctionsPage::build(FormWindow * window, int8_t focusIndex)
|
||||
{
|
||||
FormGridLayout grid;
|
||||
grid.spacer(PAGE_PADDING);
|
||||
grid.setLabelWidth(66);
|
||||
|
||||
Window::clearFocus();
|
||||
|
||||
char s[5] = "SF";
|
||||
if (functions == g_eeGeneral.customFn)
|
||||
s[0] = 'G';
|
||||
|
||||
FormField * first = nullptr;
|
||||
|
||||
for (uint8_t i = 0; i < MAX_SPECIAL_FUNCTIONS; i++) {
|
||||
CustomFunctionData * cfn = &functions[i];
|
||||
|
||||
strAppendUnsigned(&s[2], i);
|
||||
new StaticText(window, grid.getLabelSlot(), s, BUTTON_BACKGROUND | CENTERED);
|
||||
|
||||
Button * button = new SpecialFunctionButton(window, grid.getFieldSlot(), functions, i);
|
||||
if (i == 0)
|
||||
first = button;
|
||||
|
||||
if (focusIndex == i)
|
||||
button->setFocus();
|
||||
|
||||
button->setPressHandler([=]() -> uint8_t {
|
||||
button->bringToTop();
|
||||
Menu * menu = new Menu();
|
||||
#warning "TODO When only EDIT available => directy open the edit window without the menu"
|
||||
menu->addLine(STR_EDIT, [=]() {
|
||||
editSpecialFunction(window, i);
|
||||
});
|
||||
if (!CFN_EMPTY(cfn)) {
|
||||
menu->addLine(STR_COPY, [=]() {
|
||||
clipboard.type = CLIPBOARD_TYPE_CUSTOM_FUNCTION;
|
||||
clipboard.data.cfn = *cfn;
|
||||
});
|
||||
}
|
||||
if (clipboard.type == CLIPBOARD_TYPE_CUSTOM_FUNCTION) {
|
||||
menu->addLine(STR_PASTE, [=]() {
|
||||
*cfn = clipboard.data.cfn;
|
||||
SET_DIRTY();
|
||||
rebuild(window, i);
|
||||
});
|
||||
}
|
||||
if (!CFN_EMPTY(cfn) && CFN_EMPTY(&functions[MAX_SPECIAL_FUNCTIONS - 1])) {
|
||||
menu->addLine(STR_INSERT, [=]() {
|
||||
memmove(cfn + 1, cfn, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData));
|
||||
memset(cfn, 0, sizeof(CustomFunctionData));
|
||||
SET_DIRTY();
|
||||
rebuild(window, i);
|
||||
});
|
||||
}
|
||||
if (!CFN_EMPTY(cfn)) {
|
||||
menu->addLine(STR_CLEAR, [=]() {
|
||||
memset(cfn, 0, sizeof(CustomFunctionData));
|
||||
SET_DIRTY();
|
||||
});
|
||||
}
|
||||
for (int j = i; j < MAX_SPECIAL_FUNCTIONS; j++) {
|
||||
if (!CFN_EMPTY(&functions[j])) {
|
||||
menu->addLine(STR_DELETE, [=]() {
|
||||
memmove(cfn, cfn + 1, (MAX_SPECIAL_FUNCTIONS - i - 1) * sizeof(CustomFunctionData));
|
||||
memset(&functions[MAX_SPECIAL_FUNCTIONS - 1], 0, sizeof(CustomFunctionData));
|
||||
SET_DIRTY();
|
||||
rebuild(window, i);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
grid.spacer(button->height() + 5);
|
||||
}
|
||||
|
||||
FormField::link(FormField::getCurrentField(), first);
|
||||
|
||||
grid.nextLine();
|
||||
|
||||
window->setInnerHeight(grid.getWindowHeight());
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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 _SPECIAL_FUNCTIONS_H
|
||||
#define _SPECIAL_FUNCTIONS_H
|
||||
|
||||
#include "tabsgroup.h"
|
||||
|
||||
struct CustomFunctionData;
|
||||
|
||||
class SpecialFunctionsPage: public PageTab {
|
||||
public:
|
||||
SpecialFunctionsPage(CustomFunctionData * functions);
|
||||
|
||||
void build(FormWindow * window) override
|
||||
{
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
build(window, -1);
|
||||
#else
|
||||
build(window, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
CustomFunctionData * functions;
|
||||
void build(FormWindow * window, int8_t focusSpecialFunctionIndex);
|
||||
void rebuild(FormWindow * window, int8_t focusSpecialFunctionIndex);
|
||||
void editSpecialFunction(FormWindow * window, uint8_t index);
|
||||
};
|
||||
|
||||
#endif //_SPECIAL_FUNCTIONS_H
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
#if defined(SPLASH)
|
||||
|
||||
const uint8_t __bmp_splash[] __ALIGNED(4) {
|
||||
#include "bmp_splash.lbm"
|
||||
};
|
||||
Bitmap BMP_SPLASH(BMP_RGB565, (const uint16_t *)__bmp_splash);
|
||||
|
||||
void drawSplash()
|
||||
{
|
||||
static bool loadImgFromSD = true;
|
||||
static BitmapBuffer * splashImg = nullptr;
|
||||
|
||||
if (loadImgFromSD && splashImg == nullptr) {
|
||||
bool sd_mounted = sdMounted();
|
||||
if (!sd_mounted)
|
||||
sdInit();
|
||||
splashImg = BitmapBuffer::load(BITMAPS_PATH "/" SPLASH_FILE);
|
||||
loadImgFromSD = false;
|
||||
if (!sd_mounted)
|
||||
sdDone();
|
||||
}
|
||||
|
||||
lcd->clear();
|
||||
|
||||
if (splashImg) {
|
||||
lcd->drawBitmap((LCD_W - splashImg->getWidth())/2,
|
||||
(LCD_H - splashImg->getHeight())/2,
|
||||
splashImg);
|
||||
}
|
||||
else {
|
||||
lcd->drawBitmap((LCD_W - BMP_SPLASH.getWidth())/2,
|
||||
(LCD_H - BMP_SPLASH.getHeight())/2,
|
||||
&BMP_SPLASH);
|
||||
}
|
||||
|
||||
lcdRefresh();
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* 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 BitmapBuffer * Theme::asterisk = NULL;
|
||||
const BitmapBuffer * Theme::question = NULL;
|
||||
const BitmapBuffer * Theme::busy = NULL;
|
||||
|
||||
std::list<Theme *> & getRegisteredThemes()
|
||||
{
|
||||
static std::list<Theme *> themes;
|
||||
return themes;
|
||||
}
|
||||
|
||||
void registerTheme(Theme * theme)
|
||||
{
|
||||
TRACE("register theme %s", theme->getName());
|
||||
getRegisteredThemes().push_back(theme);
|
||||
}
|
||||
|
||||
void Theme::init() const
|
||||
{
|
||||
memset(&g_eeGeneral.themeData, 0, sizeof(Theme::PersistentData));
|
||||
if (options) {
|
||||
int i = 0;
|
||||
for (const ZoneOption * option = options; option->name; option++, i++) {
|
||||
// TODO compiler bug? The CPU freezes ... g_eeGeneral.themeData.options[i] = &option->deflt;
|
||||
memcpy(&g_eeGeneral.themeData.options[i], &option->deflt, sizeof(ZoneOptionValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Theme::load() const
|
||||
{
|
||||
if (!asterisk) asterisk = BitmapBuffer::load(getThemePath("asterisk.bmp"));
|
||||
if (!question) question = BitmapBuffer::load(getThemePath("question.bmp"));
|
||||
if (!busy) busy = BitmapBuffer::load(getThemePath("busy.bmp"));
|
||||
}
|
||||
|
||||
ZoneOptionValue * Theme::getOptionValue(unsigned int index) const
|
||||
{
|
||||
return &g_eeGeneral.themeData.options[index];
|
||||
}
|
||||
|
||||
const char * Theme::getFilePath(const char * filename) const
|
||||
{
|
||||
static char path[_MAX_LFN+1] = THEMES_PATH "/";
|
||||
strcpy(path + sizeof(THEMES_PATH), getName());
|
||||
int len = sizeof(THEMES_PATH) + strlen(path + sizeof(THEMES_PATH));
|
||||
path[len] = '/';
|
||||
strcpy(path+len+1, filename);
|
||||
return path;
|
||||
}
|
||||
|
||||
void Theme::drawThumb(coord_t x, coord_t y, uint32_t flags)
|
||||
{
|
||||
#define THUMB_WIDTH 51
|
||||
#define THUMB_HEIGHT 31
|
||||
if (!thumb) {
|
||||
thumb = BitmapBuffer::load(getFilePath("thumb.bmp"));
|
||||
}
|
||||
lcd->drawBitmap(x, y, thumb);
|
||||
if (flags == LINE_COLOR) {
|
||||
lcdDrawFilledRect(x, y, THUMB_WIDTH, THUMB_HEIGHT, SOLID, OVERLAY_COLOR | OPACITY(10));
|
||||
}
|
||||
}
|
||||
|
||||
void Theme::drawBackground(BitmapBuffer * dc) const
|
||||
{
|
||||
dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, TEXT_BGCOLOR);
|
||||
}
|
||||
|
||||
void Theme::drawMessageBox(const char * title, const char * text, const char * action, uint32_t type) const
|
||||
{
|
||||
|
||||
}
|
||||
//{
|
||||
// //if (flags & MESSAGEBOX_TYPE_ALERT) {
|
||||
// drawBackground();
|
||||
// lcdDrawFilledRect(0, POPUP_Y, LCD_W, POPUP_H, SOLID, TEXT_INVERTED_COLOR | OPACITY(8));
|
||||
// //}
|
||||
//
|
||||
// if (type == WARNING_TYPE_ALERT || type == WARNING_TYPE_ASTERISK)
|
||||
// lcd->drawBitmap(POPUP_X-80, POPUP_Y+12, asterisk);
|
||||
// else if (type == WARNING_TYPE_INFO)
|
||||
// lcd->drawBitmap(POPUP_X-80, POPUP_Y+12, busy);
|
||||
// else
|
||||
// lcd->drawBitmap(POPUP_X-80, POPUP_Y+12, question);
|
||||
//
|
||||
// if (type == WARNING_TYPE_ALERT) {
|
||||
//#if defined(TRANSLATIONS_FR) || defined(TRANSLATIONS_IT) || defined(TRANSLATIONS_CZ)
|
||||
// lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y, STR_WARNING, ALARM_COLOR|DBLSIZE);
|
||||
// lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+28, title, ALARM_COLOR|DBLSIZE);
|
||||
//#else
|
||||
// lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y, title, ALARM_COLOR|DBLSIZE);
|
||||
// lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+28, STR_WARNING, ALARM_COLOR|DBLSIZE);
|
||||
//#endif
|
||||
// }
|
||||
// else if (title) {
|
||||
// lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y, title, ALARM_COLOR|DBLSIZE);
|
||||
// }
|
||||
//
|
||||
// if (text) {
|
||||
// lcdDrawText(WARNING_LINE_X, WARNING_INFOLINE_Y, text);
|
||||
// }
|
||||
//
|
||||
// if (action) {
|
||||
// lcdDrawText(WARNING_LINE_X, WARNING_INFOLINE_Y+24, action);
|
||||
// }
|
||||
//}
|
||||
|
||||
Theme * getTheme(const char * name)
|
||||
{
|
||||
std::list<Theme *>::const_iterator it = getRegisteredThemes().cbegin();
|
||||
for (; it != getRegisteredThemes().cend(); ++it) {
|
||||
if (!strcmp(name, (*it)->getName())) {
|
||||
return (*it);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void loadTheme(Theme * newTheme)
|
||||
{
|
||||
TRACE("load theme %s", newTheme->getName());
|
||||
theme = newTheme;
|
||||
theme->load();
|
||||
}
|
||||
|
||||
void loadTheme()
|
||||
{
|
||||
char name[THEME_NAME_LEN + 1];
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, g_eeGeneral.themeName, THEME_NAME_LEN);
|
||||
Theme * newTheme = getTheme(name);
|
||||
if (newTheme) {
|
||||
loadTheme(newTheme);
|
||||
}
|
||||
else {
|
||||
theme->load();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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 _THEME_H_
|
||||
#define _THEME_H_
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include "zone.h"
|
||||
|
||||
class BitmapBuffer;
|
||||
class PageTab;
|
||||
|
||||
#define MAX_THEME_OPTIONS 5
|
||||
|
||||
class Theme;
|
||||
void registerTheme(Theme * theme);
|
||||
|
||||
class Theme
|
||||
{
|
||||
public:
|
||||
struct PersistentData {
|
||||
ZoneOptionValue options[MAX_THEME_OPTIONS];
|
||||
};
|
||||
|
||||
Theme(const char * name, const ZoneOption * options = nullptr):
|
||||
name(name),
|
||||
options(options),
|
||||
thumb(nullptr)
|
||||
{
|
||||
registerTheme(this);
|
||||
}
|
||||
|
||||
inline const char * getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
const char * getFilePath(const char * filename) const;
|
||||
|
||||
void drawThumb(coord_t x, coord_t y, uint32_t flags);
|
||||
|
||||
inline const ZoneOption * getOptions() const
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
void init() const;
|
||||
|
||||
virtual void update() const
|
||||
{
|
||||
}
|
||||
|
||||
ZoneOptionValue * getOptionValue(unsigned int index) const;
|
||||
|
||||
virtual void load() const;
|
||||
|
||||
virtual void drawBackground(BitmapBuffer * dc) const;
|
||||
|
||||
virtual const BitmapBuffer * getIconButtonBitmap(uint8_t index, bool selected) const
|
||||
{
|
||||
TRACE("No bitmap for icon %d in this theme", index);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual const BitmapBuffer * getIconMask(uint8_t index) const
|
||||
{
|
||||
TRACE("No mask for icon %d in this theme", index);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
virtual void drawMenuBackground(BitmapBuffer * dc, uint8_t icon, const char *title) const = 0;
|
||||
|
||||
virtual void drawMenuHeader(BitmapBuffer * dc, std::vector<PageTab *> & tabs, uint8_t currentIndex) const = 0;
|
||||
|
||||
virtual void drawMessageBox(const char * title, const char * text, const char * action, uint32_t flags) const;
|
||||
|
||||
virtual void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const = 0;
|
||||
|
||||
protected:
|
||||
const char * name;
|
||||
const ZoneOption * options;
|
||||
BitmapBuffer * thumb;
|
||||
|
||||
public:
|
||||
static const BitmapBuffer * asterisk;
|
||||
static const BitmapBuffer * question;
|
||||
static const BitmapBuffer * busy;
|
||||
};
|
||||
|
||||
extern Theme * theme;
|
||||
|
||||
inline const char * getThemePath(const char * filename)
|
||||
{
|
||||
return theme->getFilePath(filename);
|
||||
}
|
||||
|
||||
Theme * getTheme(const char * name);
|
||||
void loadTheme(Theme * theme);
|
||||
void loadTheme();
|
||||
|
||||
std::list<Theme *> & getRegisteredThemes();
|
||||
|
||||
#endif // _THEME_H_
|
||||
@@ -0,0 +1,436 @@
|
||||
/*
|
||||
* 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 "tabsgroup.h"
|
||||
|
||||
const ZoneOption OPTIONS_THEME_DEFAULT[] = {
|
||||
{ STR_BACKGROUND_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(WHITE) },
|
||||
{ STR_MAIN_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ nullptr, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
class FlyskyTheme: public Theme
|
||||
{
|
||||
public:
|
||||
FlyskyTheme():
|
||||
Theme("FlySky", OPTIONS_THEME_DEFAULT)
|
||||
{
|
||||
loadColors();
|
||||
}
|
||||
|
||||
void loadColors() const
|
||||
{
|
||||
TRACE("Load FlySky theme colors");
|
||||
|
||||
lcdColorTable[TEXT_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[TEXT_BGCOLOR_INDEX] = WHITE;
|
||||
lcdColorTable[TEXT_INVERTED_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = RED;
|
||||
lcdColorTable[TEXT_STATUSBAR_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[LINE_COLOR_INDEX] = GREY;
|
||||
lcdColorTable[SCROLLBOX_COLOR_INDEX] = RED;
|
||||
lcdColorTable[MENU_TITLE_BGCOLOR_INDEX] = DARKGREY;
|
||||
lcdColorTable[MENU_TITLE_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[MENU_TITLE_DISABLE_COLOR_INDEX] = RGB(GET_RED(RED)>>1, GET_GREEN(RED)>>1, GET_BLUE(RED)>>1);
|
||||
lcdColorTable[HEADER_COLOR_INDEX] = DARKGREY;
|
||||
lcdColorTable[ALARM_COLOR_INDEX] = RED;
|
||||
lcdColorTable[WARNING_COLOR_INDEX] = YELLOW;
|
||||
lcdColorTable[TEXT_DISABLE_COLOR_INDEX] = GREY;
|
||||
lcdColorTable[CURVE_AXIS_COLOR_INDEX] = LIGHTGREY;
|
||||
lcdColorTable[CURVE_COLOR_INDEX] = RED;
|
||||
lcdColorTable[CURVE_CURSOR_COLOR_INDEX] = RED;
|
||||
lcdColorTable[TRIM_BGCOLOR_INDEX] = RED;
|
||||
lcdColorTable[TRIM_SHADOW_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[MAINVIEW_PANES_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[MAINVIEW_GRAPHICS_COLOR_INDEX] = RED;
|
||||
|
||||
// The menu header (top bar)
|
||||
lcdColorTable[HEADER_BGCOLOR_INDEX] = DARKBLUE;
|
||||
lcdColorTable[HEADER_ICON_BGCOLOR_INDEX] = RGB(0, 71, 157);
|
||||
lcdColorTable[HEADER_CURRENT_BGCOLOR_INDEX] = RGB(2, 114, 250);
|
||||
|
||||
// The menu title
|
||||
lcdColorTable[TITLE_BGCOLOR_INDEX] = RGB(0, 71, 157);
|
||||
|
||||
lcdColorTable[OVERLAY_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[BARGRAPH1_COLOR_INDEX] = RED;
|
||||
lcdColorTable[BARGRAPH2_COLOR_INDEX] = RGB(167, 167, 167);
|
||||
lcdColorTable[BARGRAPH_BGCOLOR_INDEX] = RGB(222, 222, 222);
|
||||
}
|
||||
|
||||
void loadMenuIcon(uint8_t index, const char * filename, uint32_t color=MENU_TITLE_COLOR) const
|
||||
{
|
||||
TRACE("loadMenuIcon %s", getThemePath(filename));
|
||||
|
||||
BitmapBuffer * mask = BitmapBuffer::loadMask(getThemePath(filename));
|
||||
if (mask) {
|
||||
delete iconMask[index];
|
||||
iconMask[index] = mask;
|
||||
|
||||
uint8_t width = mask->getWidth();
|
||||
uint8_t height = mask->getHeight();
|
||||
|
||||
if (0) {
|
||||
delete menuIconNormal[index];
|
||||
menuIconNormal[index] = new BitmapBuffer(BMP_RGB565, width, height);
|
||||
if (menuIconNormal[index]) {
|
||||
menuIconNormal[index]->clear(HEADER_BGCOLOR);
|
||||
menuIconNormal[index]->drawMask(0, 0, mask, color);
|
||||
}
|
||||
|
||||
delete menuIconSelected[index];
|
||||
menuIconSelected[index] = new BitmapBuffer(BMP_RGB565, width, height);
|
||||
if (menuIconSelected[index]) {
|
||||
menuIconSelected[index]->clear(HEADER_CURRENT_BGCOLOR);
|
||||
menuIconSelected[index]->drawMask(0, 0, mask, color);
|
||||
}
|
||||
}
|
||||
else {
|
||||
delete menuIconNormal[index];
|
||||
menuIconNormal[index] = new BitmapBuffer(BMP_RGB565, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH);
|
||||
if (menuIconNormal[index]) {
|
||||
menuIconNormal[index]->clear(HEADER_BGCOLOR);
|
||||
menuIconNormal[index]->drawMask((MENU_HEADER_BUTTON_WIDTH-width)/2, (MENU_HEADER_BUTTON_WIDTH-width)/2, mask, color);
|
||||
}
|
||||
|
||||
delete menuIconSelected[index];
|
||||
menuIconSelected[index] = new BitmapBuffer(BMP_RGB565, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH);
|
||||
if (menuIconSelected[index]) {
|
||||
if (index < ICON_RADIO)
|
||||
menuIconSelected[index]->clear(HEADER_CURRENT_BGCOLOR /*HEADER_LOGO_BGCOLOR*/);
|
||||
else
|
||||
menuIconSelected[index]->clear(HEADER_CURRENT_BGCOLOR);
|
||||
menuIconSelected[index]->drawMask((MENU_HEADER_BUTTON_WIDTH-width)/2, (MENU_HEADER_BUTTON_WIDTH-height)/2, mask, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadIcons() const
|
||||
{
|
||||
#if defined(LOG_TELEMETRY) || defined(WATCHDOG_DISABLED)
|
||||
loadMenuIcon(ICON_OPENTX, "mask_opentx_testmode.png", TEXT_COLOR);
|
||||
#else
|
||||
loadMenuIcon(ICON_OPENTX, "mask_opentx.png");
|
||||
#endif
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
loadMenuIcon(ICON_NEXT, "mask_next.png");
|
||||
loadMenuIcon(ICON_BACK, "mask_back.png");
|
||||
#endif
|
||||
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_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_CALIBRATION, "mask_radio_calibration.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");
|
||||
|
||||
BitmapBuffer * background = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_bg.png"));
|
||||
BitmapBuffer * shadow = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_shadow.png"));
|
||||
BitmapBuffer * dot = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_dot.png"));
|
||||
|
||||
if (!currentMenuBackground) {
|
||||
currentMenuBackground = new BitmapBuffer(BMP_RGB565, 36, 53);
|
||||
}
|
||||
if (currentMenuBackground) {
|
||||
currentMenuBackground->drawSolidFilledRect(0, 0, currentMenuBackground->getWidth(), MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
currentMenuBackground->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, currentMenuBackground->getWidth(), MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR);
|
||||
currentMenuBackground->drawSolidFilledRect(0, MENU_TITLE_TOP, currentMenuBackground->getWidth(), currentMenuBackground->getHeight() - MENU_TITLE_TOP, TITLE_BGCOLOR);
|
||||
currentMenuBackground->drawMask(0, 0, background, HEADER_CURRENT_BGCOLOR);
|
||||
currentMenuBackground->drawMask(0, 0, shadow, TRIM_SHADOW_COLOR);
|
||||
currentMenuBackground->drawMask(10, 39, dot, MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
delete topleftBitmap;
|
||||
topleftBitmap = BitmapBuffer::loadMaskOnBackground("topleft.png", TITLE_BGCOLOR, HEADER_BGCOLOR);
|
||||
|
||||
delete background;
|
||||
delete shadow;
|
||||
delete dot;
|
||||
}
|
||||
|
||||
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 calibRadioPict;
|
||||
calibRadioPict = BitmapBuffer::load(getThemePath("NV14.bmp"));
|
||||
|
||||
// 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"));
|
||||
|
||||
// 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);
|
||||
|
||||
// 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", MENU_TITLE_COLOR, 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 mixerSetupSwitchIcon;
|
||||
mixerSetupSwitchIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_switch.png"));
|
||||
|
||||
delete mixerSetupFlightmodeIcon;
|
||||
mixerSetupFlightmodeIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_fm.png"));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
virtual void load() const override
|
||||
{
|
||||
loadColors();
|
||||
Theme::load();
|
||||
if (!backgroundBitmap) {
|
||||
backgroundBitmap = BitmapBuffer::load(getThemePath("background.png"));
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
virtual void update() const override
|
||||
{
|
||||
TRACE("TODO THEME::UPDATE()");
|
||||
|
||||
#if 0
|
||||
uint32_t color = g_eeGeneral.themeData.options[1].unsignedValue;
|
||||
uint32_t bg_color = UNEXPECTED_SHUTDOWN() ? WHITE : g_eeGeneral.themeData.options[0].unsignedValue;
|
||||
|
||||
lcdColorTable[TEXT_BGCOLOR_INDEX] = bg_color;
|
||||
lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[SCROLLBOX_COLOR_INDEX] = color;
|
||||
lcdColorTable[CURVE_COLOR_INDEX] = color;
|
||||
lcdColorTable[CURVE_CURSOR_COLOR_INDEX] = color;
|
||||
lcdColorTable[TITLE_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[MENU_TITLE_DISABLE_COLOR_INDEX] =
|
||||
RGB(GET_RED(color)>>1, GET_GREEN(color)>>1, GET_BLUE(color)>>1);
|
||||
lcdColorTable[TRIM_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[MAINVIEW_GRAPHICS_COLOR_INDEX] = color;
|
||||
#define DARKER(x) ((x * 70) / 100)
|
||||
lcdColorTable[HEADER_BGCOLOR_INDEX] = RGB(DARKER(GET_RED(color)), DARKER(GET_GREEN(color)), DARKER(GET_BLUE(color)));
|
||||
lcdColorTable[HEADER_ICON_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[HEADER_CURRENT_BGCOLOR_INDEX] = color;
|
||||
#endif
|
||||
loadIcons();
|
||||
loadThemeBitmaps();
|
||||
}
|
||||
|
||||
void drawBackground(BitmapBuffer * dc) const override
|
||||
{
|
||||
if (backgroundBitmap) {
|
||||
dc->drawBitmap(0, 0, backgroundBitmap);
|
||||
}
|
||||
else {
|
||||
lcdSetColor(g_eeGeneral.themeData.options[0].unsignedValue);
|
||||
dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, CUSTOM_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawMenuBackground(BitmapBuffer * dc, uint8_t icon, const char * title) const override
|
||||
{
|
||||
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
|
||||
if (topleftBitmap) {
|
||||
dc->drawBitmap(0, 0, topleftBitmap);
|
||||
uint16_t width = topleftBitmap->getWidth();
|
||||
dc->drawSolidFilledRect(width, 0, LCD_W-width, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
}
|
||||
else {
|
||||
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
}
|
||||
|
||||
if (icon == ICON_OPENTX)
|
||||
dc->drawBitmap(4, 10, menuIconSelected[ICON_OPENTX]);
|
||||
else
|
||||
dc->drawBitmap(5, 7, menuIconSelected[icon]);
|
||||
|
||||
dc->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR); // the white separation line
|
||||
dc->drawSolidFilledRect(0, MENU_TITLE_TOP, LCD_W, MENU_TITLE_HEIGHT, TITLE_BGCOLOR); // the title line background
|
||||
if (title) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP, title, MENU_TITLE_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
const BitmapBuffer * getIconMask(uint8_t index) const override
|
||||
{
|
||||
return iconMask[index];
|
||||
}
|
||||
|
||||
const BitmapBuffer * getIconButtonBitmap(uint8_t index, bool selected) const override
|
||||
{
|
||||
return selected ? menuIconSelected[index] : menuIconNormal[index];
|
||||
}
|
||||
|
||||
void drawMenuHeader(BitmapBuffer * dc, std::vector<PageTab *> & tabs, uint8_t currentIndex) const override
|
||||
{
|
||||
uint8_t padding_left = 0;
|
||||
|
||||
dc->drawSolidFilledRect(0, 0, padding_left, MENU_HEADER_BUTTON_WIDTH, HEADER_BGCOLOR);
|
||||
for (unsigned i=0; i<tabs.size(); i++) {
|
||||
dc->drawBitmap(padding_left + i*MENU_HEADER_BUTTON_WIDTH, 0, theme->getIconButtonBitmap(tabs[i]->getIcon(), currentIndex == i));
|
||||
}
|
||||
coord_t x = padding_left + MENU_HEADER_BUTTON_WIDTH * tabs.size();
|
||||
// coord_t w = width() - x;
|
||||
// if (w > 0) {
|
||||
// dc->drawSolidFilledRect(x, 0, w, MENU_HEADER_BUTTON_WIDTH, HEADER_BGCOLOR);
|
||||
// }
|
||||
}
|
||||
|
||||
void drawMenuDatetime(BitmapBuffer * dc) const
|
||||
{
|
||||
dc->drawSolidVerticalLine(DATETIME_SEPARATOR_X, 7, 31, TEXT_INVERTED_COLOR);
|
||||
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
char str[10];
|
||||
const char * const STR_MONTHS[] = TR_MONTHS;
|
||||
sprintf(str, "%d %s", t.tm_mday, STR_MONTHS[t.tm_mon]);
|
||||
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE1, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
|
||||
|
||||
getTimerString(str, getValue(MIXSRC_TX_TIME));
|
||||
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE2, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
|
||||
}
|
||||
|
||||
void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const override
|
||||
{
|
||||
drawSolidRect(dc, x, y, w, h, 1, TEXT_COLOR);
|
||||
if (value > 0) {
|
||||
int width = (w * value) / 100;
|
||||
dc->drawSolidFilledRect(x + 2, y + 2, width - 4, h - 4, SCROLLBOX_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
static const BitmapBuffer * backgroundBitmap;
|
||||
static BitmapBuffer * topleftBitmap;
|
||||
static BitmapBuffer * menuIconNormal[MENUS_ICONS_COUNT];
|
||||
static BitmapBuffer * menuIconSelected[MENUS_ICONS_COUNT];
|
||||
static BitmapBuffer * iconMask[MENUS_ICONS_COUNT];
|
||||
static BitmapBuffer * currentMenuBackground;
|
||||
};
|
||||
|
||||
const BitmapBuffer * FlyskyTheme::backgroundBitmap = nullptr;
|
||||
BitmapBuffer * FlyskyTheme::topleftBitmap = nullptr;
|
||||
BitmapBuffer * FlyskyTheme::iconMask[MENUS_ICONS_COUNT] = { nullptr };
|
||||
BitmapBuffer * FlyskyTheme::menuIconNormal[MENUS_ICONS_COUNT] = { nullptr };
|
||||
BitmapBuffer * FlyskyTheme::menuIconSelected[MENUS_ICONS_COUNT] = { nullptr };
|
||||
BitmapBuffer * FlyskyTheme::currentMenuBackground = nullptr;
|
||||
|
||||
FlyskyTheme flyskyTheme;
|
||||
|
||||
#if defined(PCBFLYSKY)
|
||||
Theme * theme = &flyskyTheme;
|
||||
#endif
|
||||
@@ -0,0 +1,413 @@
|
||||
/*
|
||||
* 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 "tabsgroup.h"
|
||||
|
||||
const ZoneOption OPTIONS_THEME_DEFAULT[] = {
|
||||
{ STR_BACKGROUND_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(WHITE) },
|
||||
{ STR_MAIN_COLOR, ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ nullptr, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
class FrskyTheme: public Theme
|
||||
{
|
||||
public:
|
||||
FrskyTheme():
|
||||
Theme("FrSky", OPTIONS_THEME_DEFAULT)
|
||||
{
|
||||
loadColors();
|
||||
}
|
||||
|
||||
void loadColors() const
|
||||
{
|
||||
TRACE("Load FrSky theme colors");
|
||||
lcdColorTable[TEXT_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[TEXT_BGCOLOR_INDEX] = WHITE;
|
||||
lcdColorTable[TEXT_INVERTED_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = RED;
|
||||
lcdColorTable[TEXT_STATUSBAR_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[LINE_COLOR_INDEX] = GREY;
|
||||
lcdColorTable[SCROLLBOX_COLOR_INDEX] = RED;
|
||||
lcdColorTable[MENU_TITLE_BGCOLOR_INDEX] = DARKGREY;
|
||||
lcdColorTable[MENU_TITLE_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[MENU_TITLE_DISABLE_COLOR_INDEX] = RGB(GET_RED(RED)>>1, GET_GREEN(RED)>>1, GET_BLUE(RED)>>1);
|
||||
lcdColorTable[HEADER_COLOR_INDEX] = DARKGREY;
|
||||
lcdColorTable[ALARM_COLOR_INDEX] = RED;
|
||||
lcdColorTable[WARNING_COLOR_INDEX] = YELLOW;
|
||||
lcdColorTable[TEXT_DISABLE_COLOR_INDEX] = GREY;
|
||||
lcdColorTable[CURVE_AXIS_COLOR_INDEX] = LIGHTGREY;
|
||||
lcdColorTable[CURVE_COLOR_INDEX] = RED;
|
||||
lcdColorTable[CURVE_CURSOR_COLOR_INDEX] = RED;
|
||||
lcdColorTable[TITLE_BGCOLOR_INDEX] = RED;
|
||||
lcdColorTable[TRIM_BGCOLOR_INDEX] = RED;
|
||||
lcdColorTable[TRIM_SHADOW_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[MAINVIEW_PANES_COLOR_INDEX] = WHITE;
|
||||
lcdColorTable[MAINVIEW_GRAPHICS_COLOR_INDEX] = RED;
|
||||
lcdColorTable[HEADER_BGCOLOR_INDEX] = DARKRED;
|
||||
lcdColorTable[HEADER_ICON_BGCOLOR_INDEX] = RED;
|
||||
lcdColorTable[HEADER_CURRENT_BGCOLOR_INDEX] = RED;
|
||||
lcdColorTable[OVERLAY_COLOR_INDEX] = BLACK;
|
||||
lcdColorTable[BARGRAPH1_COLOR_INDEX] = RED;
|
||||
lcdColorTable[BARGRAPH2_COLOR_INDEX] = RGB(167, 167, 167);
|
||||
lcdColorTable[BARGRAPH_BGCOLOR_INDEX] = RGB(222, 222, 222);
|
||||
}
|
||||
|
||||
void loadMenuIcon(uint8_t index, const char * filename, uint32_t color=MENU_TITLE_COLOR) const
|
||||
{
|
||||
TRACE("loadMenuIcon %s", getThemePath(filename));
|
||||
BitmapBuffer * mask = BitmapBuffer::loadMask(getThemePath(filename));
|
||||
if (mask) {
|
||||
delete iconMask[index];
|
||||
iconMask[index] = mask;
|
||||
|
||||
delete menuIconNormal[index];
|
||||
menuIconNormal[index] = new BitmapBuffer(BMP_RGB565, mask->getWidth(), mask->getHeight());
|
||||
if (menuIconNormal[index]) {
|
||||
menuIconNormal[index]->clear(HEADER_BGCOLOR);
|
||||
menuIconNormal[index]->drawMask(0, 0, mask, color);
|
||||
}
|
||||
|
||||
delete menuIconSelected[index];
|
||||
menuIconSelected[index] = new BitmapBuffer(BMP_RGB565, mask->getWidth(), mask->getHeight());
|
||||
if (menuIconSelected[index]) {
|
||||
menuIconSelected[index]->clear(HEADER_CURRENT_BGCOLOR);
|
||||
menuIconSelected[index]->drawMask(0, 0, mask, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadIcons() const
|
||||
{
|
||||
#if defined(LOG_TELEMETRY) || defined(WATCHDOG_DISABLED)
|
||||
loadMenuIcon(ICON_OPENTX, "mask_opentx_testmode.png", TEXT_COLOR);
|
||||
#else
|
||||
loadMenuIcon(ICON_OPENTX, "mask_opentx.png");
|
||||
#endif
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
loadMenuIcon(ICON_NEXT, "mask_next.png");
|
||||
loadMenuIcon(ICON_BACK, "mask_back.png");
|
||||
#endif
|
||||
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_CALIBRATION, "mask_radio_calibration.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");
|
||||
|
||||
BitmapBuffer * background = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_bg.png"));
|
||||
BitmapBuffer * shadow = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_shadow.png"));
|
||||
BitmapBuffer * dot = BitmapBuffer::loadMask(getThemePath("mask_currentmenu_dot.png"));
|
||||
|
||||
if (!currentMenuBackground) {
|
||||
currentMenuBackground = new BitmapBuffer(BMP_RGB565, 36, 53);
|
||||
}
|
||||
if (currentMenuBackground) {
|
||||
currentMenuBackground->drawSolidFilledRect(0, 0, currentMenuBackground->getWidth(), MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
currentMenuBackground->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, currentMenuBackground->getWidth(), MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR);
|
||||
currentMenuBackground->drawSolidFilledRect(0, MENU_TITLE_TOP, currentMenuBackground->getWidth(), currentMenuBackground->getHeight() - MENU_TITLE_TOP, TITLE_BGCOLOR);
|
||||
currentMenuBackground->drawMask(0, 0, background, HEADER_CURRENT_BGCOLOR);
|
||||
currentMenuBackground->drawMask(0, 0, shadow, TRIM_SHADOW_COLOR);
|
||||
currentMenuBackground->drawMask(10, 39, dot, MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
delete topleftBitmap;
|
||||
topleftBitmap = BitmapBuffer::loadMaskOnBackground("topleft.png", TITLE_BGCOLOR, HEADER_BGCOLOR);
|
||||
|
||||
delete background;
|
||||
delete shadow;
|
||||
delete dot;
|
||||
}
|
||||
|
||||
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 calibRadioPict;
|
||||
#if defined(PCBX10)
|
||||
if(STICKS_PWM_ENABLED()) {
|
||||
calibRadioPict = BitmapBuffer::load(getThemePath("X10S.bmp"));
|
||||
}
|
||||
else {
|
||||
calibRadioPict = BitmapBuffer::load(getThemePath("X10.bmp"));
|
||||
}
|
||||
#else
|
||||
calibRadioPict = BitmapBuffer::load(getThemePath("horus.bmp"));
|
||||
#endif
|
||||
|
||||
// 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"));
|
||||
|
||||
// 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);
|
||||
|
||||
// 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", MENU_TITLE_COLOR, 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 mixerSetupSwitchIcon;
|
||||
mixerSetupSwitchIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_switch.png"));
|
||||
|
||||
delete mixerSetupFlightmodeIcon;
|
||||
mixerSetupFlightmodeIcon = BitmapBuffer::loadMask(getThemePath("mask_textline_fm.png"));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
virtual void load() const override
|
||||
{
|
||||
loadColors();
|
||||
Theme::load();
|
||||
if (!backgroundBitmap) {
|
||||
backgroundBitmap = BitmapBuffer::load(getThemePath("background.png"));
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
virtual void update() const override
|
||||
{
|
||||
TRACE("TODO THEME::UPDATE()");
|
||||
#if 0
|
||||
uint32_t color = g_eeGeneral.themeData.options[1].unsignedValue;
|
||||
uint32_t bg_color = UNEXPECTED_SHUTDOWN() ? WHITE : g_eeGeneral.themeData.options[0].unsignedValue;
|
||||
|
||||
lcdColorTable[TEXT_BGCOLOR_INDEX] = bg_color;
|
||||
lcdColorTable[TEXT_INVERTED_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[SCROLLBOX_COLOR_INDEX] = color;
|
||||
lcdColorTable[CURVE_COLOR_INDEX] = color;
|
||||
lcdColorTable[CURVE_CURSOR_COLOR_INDEX] = color;
|
||||
lcdColorTable[TITLE_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[MENU_TITLE_DISABLE_COLOR_INDEX] =
|
||||
RGB(GET_RED(color)>>1, GET_GREEN(color)>>1, GET_BLUE(color)>>1);
|
||||
lcdColorTable[TRIM_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[MAINVIEW_GRAPHICS_COLOR_INDEX] = color;
|
||||
#define DARKER(x) ((x * 70) / 100)
|
||||
lcdColorTable[HEADER_BGCOLOR_INDEX] = RGB(DARKER(GET_RED(color)), DARKER(GET_GREEN(color)), DARKER(GET_BLUE(color)));
|
||||
lcdColorTable[HEADER_ICON_BGCOLOR_INDEX] = color;
|
||||
lcdColorTable[HEADER_CURRENT_BGCOLOR_INDEX] = color;
|
||||
#endif
|
||||
loadIcons();
|
||||
loadThemeBitmaps();
|
||||
}
|
||||
|
||||
void drawBackground(BitmapBuffer * dc) const override
|
||||
{
|
||||
if (backgroundBitmap) {
|
||||
dc->drawBitmap(0, 0, backgroundBitmap);
|
||||
}
|
||||
else {
|
||||
lcdSetColor(g_eeGeneral.themeData.options[0].unsignedValue);
|
||||
dc->drawSolidFilledRect(0, 0, LCD_W, LCD_H, CUSTOM_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
void drawMenuBackground(BitmapBuffer * dc, uint8_t icon, const char * title) const override
|
||||
{
|
||||
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
|
||||
if (topleftBitmap) {
|
||||
dc->drawBitmap(0, 0, topleftBitmap);
|
||||
uint16_t width = topleftBitmap->getWidth();
|
||||
dc->drawSolidFilledRect(width, 0, LCD_W-width, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
}
|
||||
else {
|
||||
dc->drawSolidFilledRect(0, 0, LCD_W, MENU_HEADER_HEIGHT, HEADER_BGCOLOR);
|
||||
}
|
||||
|
||||
if (icon == ICON_OPENTX)
|
||||
dc->drawBitmap(4, 10, menuIconSelected[ICON_OPENTX]);
|
||||
else
|
||||
dc->drawBitmap(5, 7, menuIconSelected[icon]);
|
||||
|
||||
dc->drawSolidFilledRect(0, MENU_HEADER_HEIGHT, LCD_W, MENU_TITLE_TOP - MENU_HEADER_HEIGHT, TEXT_BGCOLOR); // the white separation line
|
||||
dc->drawSolidFilledRect(0, MENU_TITLE_TOP, LCD_W, MENU_TITLE_HEIGHT, TITLE_BGCOLOR); // the title line background
|
||||
if (title) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_TITLE_TOP + 1, title, MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
drawMenuDatetime(dc);
|
||||
}
|
||||
|
||||
const BitmapBuffer * getIconMask(uint8_t index) const override
|
||||
{
|
||||
return iconMask[index];
|
||||
}
|
||||
|
||||
const BitmapBuffer * getIconButtonBitmap(uint8_t index, bool selected) const override
|
||||
{
|
||||
return selected ? menuIconSelected[index] : menuIconNormal[index];
|
||||
}
|
||||
|
||||
void drawMenuHeader(BitmapBuffer * dc, std::vector<PageTab *> & tabs, uint8_t currentIndex) const override
|
||||
{
|
||||
for (unsigned index = 0; index < tabs.size(); index++) {
|
||||
if (index != currentIndex) {
|
||||
dc->drawBitmap(index*MENU_HEADER_BUTTON_WIDTH + 2, 7, menuIconNormal[tabs[index]->getIcon()]);
|
||||
}
|
||||
}
|
||||
dc->drawBitmap(currentIndex*MENU_HEADER_BUTTON_WIDTH, 0, currentMenuBackground);
|
||||
dc->drawBitmap(currentIndex*MENU_HEADER_BUTTON_WIDTH + 2, 7, menuIconSelected[tabs[currentIndex]->getIcon()]);
|
||||
}
|
||||
|
||||
void drawMenuDatetime(BitmapBuffer * dc) const
|
||||
{
|
||||
dc->drawSolidVerticalLine(DATETIME_SEPARATOR_X, 7, 31, TEXT_INVERTED_COLOR);
|
||||
|
||||
struct gtm t;
|
||||
gettime(&t);
|
||||
char str[10];
|
||||
const char * const STR_MONTHS[] = TR_MONTHS;
|
||||
sprintf(str, "%d %s", t.tm_mday, STR_MONTHS[t.tm_mon]);
|
||||
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE1, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
|
||||
|
||||
getTimerString(str, getValue(MIXSRC_TX_TIME));
|
||||
lcdDrawText(DATETIME_MIDDLE, DATETIME_LINE2, str, SMLSIZE|TEXT_INVERTED_COLOR|CENTERED);
|
||||
}
|
||||
|
||||
void drawProgressBar(BitmapBuffer * dc, coord_t x, coord_t y, coord_t w, coord_t h, int value) const override
|
||||
{
|
||||
drawSolidRect(dc, x, y, w, h, 1, TEXT_COLOR);
|
||||
if (value > 0) {
|
||||
int width = (w * value) / 100;
|
||||
dc->drawSolidFilledRect(x + 2, y + 2, width - 4, h - 4, SCROLLBOX_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
static const BitmapBuffer * backgroundBitmap;
|
||||
static BitmapBuffer * topleftBitmap;
|
||||
static BitmapBuffer * menuIconNormal[MENUS_ICONS_COUNT];
|
||||
static BitmapBuffer * menuIconSelected[MENUS_ICONS_COUNT];
|
||||
static BitmapBuffer * iconMask[MENUS_ICONS_COUNT];
|
||||
static BitmapBuffer * currentMenuBackground;
|
||||
};
|
||||
|
||||
const BitmapBuffer * FrskyTheme::backgroundBitmap = nullptr;
|
||||
BitmapBuffer * FrskyTheme::topleftBitmap = nullptr;
|
||||
BitmapBuffer * FrskyTheme::iconMask[MENUS_ICONS_COUNT] = { nullptr };
|
||||
BitmapBuffer * FrskyTheme::menuIconNormal[MENUS_ICONS_COUNT] = { nullptr };
|
||||
BitmapBuffer * FrskyTheme::menuIconSelected[MENUS_ICONS_COUNT] = { nullptr };
|
||||
BitmapBuffer * FrskyTheme::currentMenuBackground = nullptr;
|
||||
|
||||
FrskyTheme frskyTheme;
|
||||
|
||||
#if defined(PCBFRSKY)
|
||||
Theme * theme = &frskyTheme;
|
||||
#endif
|
||||
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
unsigned int Topbar::getZonesCount() const
|
||||
{
|
||||
return MAX_TOPBAR_ZONES;
|
||||
}
|
||||
|
||||
Zone Topbar::getZone(unsigned int index) const
|
||||
{
|
||||
Zone zone;
|
||||
zone.x = 49 + (TOPBAR_ZONE_WIDTH + 2*TOPBAR_ZONE_MARGIN) * index;
|
||||
zone.y = TOPBAR_ZONE_MARGIN;
|
||||
zone.w = TOPBAR_ZONE_WIDTH;
|
||||
zone.h = MENU_HEADER_HEIGHT - 2*TOPBAR_ZONE_MARGIN;
|
||||
return zone;
|
||||
}
|
||||
|
||||
const char * const STR_MONTHS[] = TR_MONTHS;
|
||||
|
||||
void drawTopBar()
|
||||
{
|
||||
theme->drawTopbarBackground(0);
|
||||
|
||||
// USB icon
|
||||
if (usbPlugged()) {
|
||||
lcdDrawBitmapPattern(LCD_W-98, 8, LBM_TOPMENU_USB, MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
// RSSI
|
||||
const uint8_t rssiBarsValue[] = {30, 40, 50, 60, 80};
|
||||
const uint8_t rssiBarsHeight[] = {5, 10, 15, 21, 31};
|
||||
for (unsigned int i = 0; i < DIM(rssiBarsHeight); i++) {
|
||||
uint8_t height = rssiBarsHeight[i];
|
||||
lcdDrawSolidFilledRect(LCD_W-90 + i * 6, 38 - height, 4, height, TELEMETRY_RSSI() >= rssiBarsValue[i] ? MENU_TITLE_COLOR : MENU_TITLE_DISABLE_COLOR);
|
||||
}
|
||||
|
||||
/* Audio volume */
|
||||
lcdDrawBitmapPattern(LCD_W-130, 4, LBM_TOPMENU_VOLUME_SCALE, MENU_TITLE_DISABLE_COLOR);
|
||||
if (requiredSpeakerVolume == 0 || g_eeGeneral.beepMode == e_mode_quiet)
|
||||
lcdDrawBitmapPattern(LCD_W-130, 4, LBM_TOPMENU_VOLUME_0, MENU_TITLE_COLOR);
|
||||
else if (requiredSpeakerVolume < 7)
|
||||
lcdDrawBitmapPattern(LCD_W-130, 4, LBM_TOPMENU_VOLUME_1, MENU_TITLE_COLOR);
|
||||
else if (requiredSpeakerVolume < 13)
|
||||
lcdDrawBitmapPattern(LCD_W-130, 4, LBM_TOPMENU_VOLUME_2, MENU_TITLE_COLOR);
|
||||
else if (requiredSpeakerVolume < 19)
|
||||
lcdDrawBitmapPattern(LCD_W-130, 4, LBM_TOPMENU_VOLUME_3, MENU_TITLE_COLOR);
|
||||
else
|
||||
lcdDrawBitmapPattern(LCD_W-130, 4, LBM_TOPMENU_VOLUME_4, MENU_TITLE_COLOR);
|
||||
|
||||
/* Tx battery */
|
||||
uint8_t bars = GET_TXBATT_BARS(5);
|
||||
lcdDrawBitmapPattern(LCD_W-130, 24, LBM_TOPMENU_TXBATT, MENU_TITLE_COLOR);
|
||||
for (unsigned int i = 0; i < 5; i++) {
|
||||
lcdDrawSolidFilledRect(LCD_W-122+4*i, 30, 2, 8, i >= bars ? MENU_TITLE_DISABLE_COLOR : MENU_TITLE_COLOR);
|
||||
}
|
||||
|
||||
topbar->refresh();
|
||||
|
||||
#if 0
|
||||
// Radio battery - TODO
|
||||
// drawValueWithUnit(370, 8, g_vbat100mV, UNIT_VOLTS, PREC1|SMLSIZE|MENU_TITLE_COLOR);
|
||||
// lcdDrawSolidRect(300, 3, 20, 50, MENU_TITLE_COLOR);
|
||||
// lcdDrawRect(batt_icon_x+FW, BAR_Y+1, 13, 7);
|
||||
// lcdDrawSolidVerticalLine(batt_icon_x+FW+13, BAR_Y+2, 5);
|
||||
|
||||
// Rx battery
|
||||
if (g_model.voltsSource) {
|
||||
TelemetryItem & item = telemetryItems[g_model.voltsSource-1];
|
||||
if (item.isAvailable()) {
|
||||
int32_t value = item.value;
|
||||
TelemetrySensor & sensor = g_model.telemetrySensors[g_model.frsky.altitudeSource-1];
|
||||
LcdFlags att = 0;
|
||||
if (sensor.prec == 2) {
|
||||
att |= PREC1;
|
||||
value /= 10;
|
||||
}
|
||||
else if (sensor.prec == 1) {
|
||||
att |= PREC1;
|
||||
}
|
||||
att |= (item.isOld() ? ALARM_COLOR : TEXT_COLOR);
|
||||
lcdDrawSolidFilledRect(ALTITUDE_X, VOLTS_Y, ALTITUDE_W, ALTITUDE_H, TEXT_BGCOLOR);
|
||||
lcdDrawText(ALTITUDE_X+PADDING, VOLTS_Y+2, "Voltage", att);
|
||||
drawValueWithUnit(ALTITUDE_X+PADDING, VOLTS_Y+12, value, UNIT_VOLTS, DBLSIZE|LEFT|att);
|
||||
}
|
||||
}
|
||||
|
||||
// Model altitude
|
||||
if (g_model.frsky.altitudeSource) {
|
||||
TelemetryItem & item = telemetryItems[g_model.frsky.altitudeSource-1];
|
||||
if (item.isAvailable()) {
|
||||
int32_t value = item.value;
|
||||
TelemetrySensor & sensor = g_model.telemetrySensors[g_model.frsky.altitudeSource-1];
|
||||
if (sensor.prec) value /= sensor.prec == 2 ? 100 : 10;
|
||||
LcdFlags att = (item.isOld() ? ALARM_COLOR : TEXT_COLOR);
|
||||
lcdDrawSolidFilledRect(ALTITUDE_X, ALTITUDE_Y, ALTITUDE_W, ALTITUDE_H, TEXT_BGCOLOR);
|
||||
lcdDrawText(ALTITUDE_X+PADDING, ALTITUDE_Y+2, "Alt", att);
|
||||
drawValueWithUnit(ALTITUDE_X+PADDING, ALTITUDE_Y+12, value, UNIT_METERS, DBLSIZE|LEFT|att);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
#ifndef _TOPBAR_H_
|
||||
#define _TOPBAR_H_
|
||||
|
||||
#include "widgets_container.h"
|
||||
|
||||
#define MAX_TOPBAR_ZONES 4
|
||||
#define MAX_TOPBAR_OPTIONS 1 // just because of VC++ which doesn't like 0-size arrays :(
|
||||
#define TOPBAR_ZONE_WIDTH 70
|
||||
#define TOPBAR_ZONE_MARGIN 3
|
||||
|
||||
class Topbar: public WidgetsContainer<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS>
|
||||
{
|
||||
public:
|
||||
explicit Topbar(PersistentData * persistentData):
|
||||
WidgetsContainer<MAX_TOPBAR_ZONES, MAX_TOPBAR_OPTIONS>(persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual unsigned int getZonesCount() const;
|
||||
|
||||
virtual Zone getZone(unsigned int index) const;
|
||||
};
|
||||
|
||||
#endif // _TOPBAR_H_
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* 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 AboutScreens {
|
||||
ABOUT_OPENTX,
|
||||
ABOUT_HARDWARE,
|
||||
ABOUT_BERTRAND,
|
||||
ABOUT_ANDRE,
|
||||
ABOUT_MIKE,
|
||||
ABOUT_KJELL,
|
||||
ABOUT_MARTIN,
|
||||
ABOUT_ROMOLO,
|
||||
ABOUT_ROB,
|
||||
ABOUT_PARENTS,
|
||||
ABOUT_END,
|
||||
ABOUT_COUNT,
|
||||
};
|
||||
|
||||
#define ABOUT_X 62
|
||||
#define ABOUT_INDENT 16
|
||||
|
||||
bool menuAboutView(event_t event)
|
||||
{
|
||||
static uint8_t screenIndex = 0;
|
||||
static uint8_t greyIndex = 0;
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
screenIndex = 0;
|
||||
greyIndex = 0;
|
||||
break;
|
||||
#if defined(PCBX12S)
|
||||
case EVT_KEY_FIRST(KEY_PGDN):
|
||||
#elif defined(PCBX10)
|
||||
case EVT_KEY_BREAK(KEY_PGDN):
|
||||
#endif
|
||||
screenIndex < ABOUT_PARENTS ? screenIndex++ : screenIndex = ABOUT_OPENTX;
|
||||
greyIndex = 0;
|
||||
break;
|
||||
case EVT_KEY_FIRST(KEY_PGUP):
|
||||
#if defined(PCBX10)
|
||||
case EVT_KEY_LONG(KEY_PGDN):
|
||||
#endif
|
||||
screenIndex > ABOUT_OPENTX ? screenIndex-- : screenIndex = ABOUT_PARENTS;
|
||||
greyIndex = 0;
|
||||
killEvents(event);
|
||||
break;
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
chainMenu(menuMainView);
|
||||
break;
|
||||
}
|
||||
|
||||
theme->drawBackground();
|
||||
theme->drawTopbarBackground(0);
|
||||
|
||||
uint8_t screenDuration = 150;
|
||||
|
||||
switch (screenIndex) {
|
||||
case ABOUT_OPENTX:
|
||||
case ABOUT_END:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_OPENTX_1);
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP + FH, STR_ABOUT_OPENTX_2);
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_OPENTX_3);
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP + 3*FH, STR_ABOUT_OPENTX_4);
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP + 4*FH, STR_ABOUT_OPENTX_5);
|
||||
screenDuration = 255;
|
||||
break;
|
||||
|
||||
case ABOUT_BERTRAND:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_BERTRAND_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_BERTRAND_2);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_BERTRAND_3);
|
||||
break;
|
||||
|
||||
case ABOUT_ANDRE:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_ANDRE_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_ANDRE_2);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_ANDRE_3);
|
||||
break;
|
||||
|
||||
case ABOUT_MIKE:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_MIKE_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_MIKE_2);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_MIKE_3);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 3*FH, STR_ABOUT_MIKE_4);
|
||||
break;
|
||||
|
||||
case ABOUT_KJELL:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_KJELL_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_KJELL_2);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_KJELL_3);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 3*FH, STR_ABOUT_KJELL_4);
|
||||
break;
|
||||
|
||||
case ABOUT_MARTIN:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_MARTIN_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_MARTIN_2);
|
||||
break;
|
||||
|
||||
case ABOUT_ROMOLO:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_ROMOLO_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_ROMOLO_2);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_ROMOLO_3);
|
||||
break;
|
||||
|
||||
case ABOUT_ROB:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_ROB_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_ROB_2);
|
||||
break;
|
||||
|
||||
case ABOUT_HARDWARE:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, "FrSky", INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_HARDWARE_2);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_HARDWARE_3);
|
||||
break;
|
||||
|
||||
case ABOUT_PARENTS:
|
||||
lcdDrawText(ABOUT_X, MENU_CONTENT_TOP, STR_ABOUT_PARENTS_1, INVERS);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + FH, STR_ABOUT_PARENTS_2);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 2*FH, STR_ABOUT_PARENTS_3);
|
||||
lcdDrawText(ABOUT_X+ABOUT_INDENT, MENU_CONTENT_TOP + 3*FH, STR_ABOUT_PARENTS_4);
|
||||
screenDuration = 255;
|
||||
break;
|
||||
}
|
||||
|
||||
if (++greyIndex == screenDuration) {
|
||||
greyIndex = 0;
|
||||
if (++screenIndex == ABOUT_COUNT) {
|
||||
chainMenu(menuMainView);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* 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 ROW_HEIGHT 42
|
||||
#define BAR_HEIGHT 13
|
||||
#define COLUMN_SIZE 200
|
||||
#define X_OFFSET 25
|
||||
#define Y_OFFSET 75
|
||||
#define Y_OUTBAR 15
|
||||
#define Y_MIXBAR 28
|
||||
#define LEG_COLORBOX 15
|
||||
|
||||
#define VIEW_CHANNELS_LIMIT_PCT (g_model.extendedLimits ? LIMIT_EXT_PERCENT : 100)
|
||||
|
||||
bool menuChannelsMonitor(event_t event, uint8_t page);
|
||||
bool menuLogicalSwitches(event_t);
|
||||
|
||||
template<int index>
|
||||
bool menuChannelsMonitor(event_t event)
|
||||
{
|
||||
lastMonitorPage = e_MonChannelsFirst + index;
|
||||
MENU(STR_MONITOR_CHANNELS[index], MONITOR_ICONS, menuTabMonitors, lastMonitorPage, 0, { 0 });
|
||||
return menuChannelsMonitor(event, index);
|
||||
}
|
||||
|
||||
const MenuHandlerFunc menuTabMonitors[] = {
|
||||
menuChannelsMonitor<0>,
|
||||
menuChannelsMonitor<1>,
|
||||
menuChannelsMonitor<2>,
|
||||
menuChannelsMonitor<3>,
|
||||
menuLogicalSwitches
|
||||
};
|
||||
|
||||
uint8_t lastMonitorPage = 0;
|
||||
|
||||
uint16_t posOnBar(int16_t value_to100)
|
||||
{
|
||||
return divRoundClosest((value_to100 + VIEW_CHANNELS_LIMIT_PCT) * COLUMN_SIZE, VIEW_CHANNELS_LIMIT_PCT * 2);
|
||||
}
|
||||
|
||||
void drawOutputBarLimits(coord_t left, coord_t right, coord_t y)
|
||||
{
|
||||
lcd->drawSolidVerticalLine(left, y, BAR_HEIGHT, TEXT_COLOR);
|
||||
lcd->drawSolidHorizontalLine(left, y, 3, TEXT_COLOR);
|
||||
lcd->drawSolidHorizontalLine(left, y + BAR_HEIGHT - 1, 3, TEXT_COLOR);
|
||||
|
||||
lcd->drawSolidVerticalLine(--right, y, BAR_HEIGHT, TEXT_COLOR);
|
||||
lcd->drawSolidHorizontalLine(right - 3, y, 3, TEXT_COLOR);
|
||||
lcd->drawSolidHorizontalLine(right - 3, y + BAR_HEIGHT - 1, 3, TEXT_COLOR);
|
||||
}
|
||||
|
||||
void drawSingleMixerBar(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t channel)
|
||||
{
|
||||
int16_t chanVal = calcRESXto100(ex_chans[channel]);
|
||||
const int16_t displayVal = chanVal;
|
||||
|
||||
// this could be handled nicer, but slower, by checking actual range for this mixer
|
||||
chanVal = limit<int16_t>(-VIEW_CHANNELS_LIMIT_PCT, chanVal, VIEW_CHANNELS_LIMIT_PCT);
|
||||
|
||||
lcdDrawSolidFilledRect(x, y, w, h, BARGRAPH_BGCOLOR);
|
||||
if (chanVal > 0) {
|
||||
lcdDrawSolidFilledRect(x + w / 2, y, divRoundClosest(chanVal * w, VIEW_CHANNELS_LIMIT_PCT * 2), h, BARGRAPH2_COLOR);
|
||||
lcdDrawNumber(x - 10 + w / 2, y - 2, displayVal, SMLSIZE | TEXT_COLOR | RIGHT, 0, NULL, "%");
|
||||
}
|
||||
else if (chanVal < 0) {
|
||||
const uint16_t endpoint = x + w / 2;
|
||||
const uint16_t size = divRoundClosest(-chanVal * w, VIEW_CHANNELS_LIMIT_PCT * 2);
|
||||
lcdDrawSolidFilledRect(endpoint - size, y, size, h, BARGRAPH2_COLOR);
|
||||
lcdDrawNumber(x + 10 + w / 2, y - 2, displayVal, SMLSIZE | TEXT_COLOR, 0, NULL, "%");
|
||||
}
|
||||
|
||||
lcd->drawSolidVerticalLine(x + w / 2, y, h, TEXT_COLOR);
|
||||
}
|
||||
|
||||
void drawSingleOutputBar(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t channel)
|
||||
{
|
||||
int16_t chanVal = calcRESXto100(channelOutputs[channel]);
|
||||
int16_t displayVal = chanVal;
|
||||
|
||||
chanVal = limit<int16_t>(-VIEW_CHANNELS_LIMIT_PCT, chanVal, VIEW_CHANNELS_LIMIT_PCT);
|
||||
|
||||
lcdDrawSolidFilledRect(x, y, w, h, BARGRAPH_BGCOLOR);
|
||||
if (chanVal > 0) {
|
||||
lcdDrawSolidFilledRect(x + w / 2, y, divRoundClosest(chanVal * w, VIEW_CHANNELS_LIMIT_PCT * 2), h, BARGRAPH1_COLOR);
|
||||
lcdDrawNumber(x - 10 + w / 2, y - 2, displayVal, SMLSIZE | TEXT_COLOR | RIGHT, 0, NULL, "%");
|
||||
}
|
||||
else if (chanVal < 0) {
|
||||
uint16_t endpoint = x + w / 2;
|
||||
uint16_t size = divRoundClosest(-chanVal * w, VIEW_CHANNELS_LIMIT_PCT * 2);
|
||||
lcdDrawSolidFilledRect(endpoint - size, y, size, h, BARGRAPH1_COLOR);
|
||||
lcdDrawNumber(x + 10 + w / 2, y - 2, displayVal, SMLSIZE | TEXT_COLOR, 0, NULL, "%");
|
||||
}
|
||||
|
||||
lcd->drawSolidVerticalLine(x + w / 2, y, h, TEXT_COLOR);
|
||||
}
|
||||
|
||||
void drawComboOutputBar(coord_t x, coord_t y, coord_t w, coord_t h, uint8_t channel)
|
||||
{
|
||||
char chanString[] = "Ch32 ";
|
||||
int16_t chanVal = calcRESXto100(channelOutputs[channel]);
|
||||
LimitData * ld = limitAddress(channel);
|
||||
int usValue = PPM_CH_CENTER(channel) + channelOutputs[channel] / 2;
|
||||
const uint16_t limPos = ld ? posOnBar(calcRESXto100((ld && ld->revert) ? -ld->offset : ld->offset)) : 0;
|
||||
uint16_t valPos;
|
||||
|
||||
strAppendSigned(&chanString[2], channel + 1, 2);
|
||||
lcdDrawText(x, y, chanString, SMLSIZE | TEXT_COLOR | LEFT);
|
||||
|
||||
lcdDrawSizedText(x + 45, y, g_model.limitData[channel].name, sizeof(g_model.limitData[channel].name), SMLSIZE | TEXT_COLOR | LEFT | ZCHAR);
|
||||
lcdDrawNumber(x + w, y, usValue, SMLSIZE | TEXT_COLOR | RIGHT, 0, NULL, STR_US);
|
||||
|
||||
lcdDrawSolidFilledRect(x, y + Y_OUTBAR, w, h, BARGRAPH_BGCOLOR);
|
||||
lcd->drawSolidVerticalLine(x + limPos, y + Y_OUTBAR, h, MAINVIEW_GRAPHICS_COLOR);
|
||||
|
||||
chanVal = limit<int16_t>(-VIEW_CHANNELS_LIMIT_PCT, chanVal, VIEW_CHANNELS_LIMIT_PCT);
|
||||
valPos = posOnBar(chanVal);
|
||||
|
||||
if (valPos > limPos) {
|
||||
lcdDrawSolidFilledRect(x + limPos, y + Y_OUTBAR, valPos - limPos, h, BARGRAPH1_COLOR);
|
||||
}
|
||||
else if (valPos < limPos) {
|
||||
uint16_t endpoint = x + limPos;
|
||||
uint16_t size = limPos - valPos;
|
||||
lcdDrawSolidFilledRect(endpoint - size, y + Y_OUTBAR, size, h, BARGRAPH1_COLOR);
|
||||
}
|
||||
|
||||
if (ld && ld->revert) {
|
||||
drawOutputBarLimits(x + posOnBar(-100 - ld->max / 10), x + posOnBar(100 - ld->min / 10), y + Y_OUTBAR);
|
||||
lcd->drawBitmap(x - X_OFFSET + 7, y + 25, chanMonInvertedBitmap);
|
||||
}
|
||||
else if (ld) {
|
||||
drawOutputBarLimits(x + posOnBar(-100 + ld->min / 10), x + posOnBar(100 + ld->max / 10), y + Y_OUTBAR);
|
||||
}
|
||||
#if defined(OVERRIDE_CHANNEL_FUNCTION)
|
||||
if (safetyCh[channel] != OVERRIDE_CHANNEL_UNDEFINED)
|
||||
lcd->drawBitmap(x - X_OFFSET + 7, y + 7, chanMonLockedBitmap);
|
||||
#endif
|
||||
lcd->drawSolidVerticalLine(x + w / 2, y + Y_OUTBAR, h, TEXT_COLOR);
|
||||
if (chanVal > calcRESXto100((ld && ld->revert) ? -ld->offset : ld->offset))
|
||||
lcdDrawNumber(x + limPos, y + h, chanVal, SMLSIZE | TEXT_COLOR | RIGHT, 0, NULL, "%");
|
||||
else
|
||||
lcdDrawNumber(x + limPos, y + h, chanVal, SMLSIZE | TEXT_COLOR, 0, NULL, "%");
|
||||
}
|
||||
|
||||
coord_t drawChannelsMonitorLegend(coord_t x, const char * s, int color)
|
||||
{
|
||||
lcdDrawSolidFilledRect(x, MENU_FOOTER_TOP + 2, LEG_COLORBOX + 2, LEG_COLORBOX + 2, BARGRAPH_BGCOLOR);
|
||||
lcdDrawSolidFilledRect(x + 1, MENU_FOOTER_TOP + 3, LEG_COLORBOX, LEG_COLORBOX, color);
|
||||
lcdDrawText(x + 20, MENU_FOOTER_TOP, s, TEXT_STATUSBAR_COLOR);
|
||||
return x + 25 + getTextWidth(s);
|
||||
}
|
||||
|
||||
bool menuChannelsMonitor(event_t event, uint8_t page)
|
||||
{
|
||||
uint8_t channel = 8 * page;
|
||||
coord_t x, y = Y_OFFSET;
|
||||
|
||||
x = drawChannelsMonitorLegend(MENUS_MARGIN_LEFT, STR_MONITOR_OUTPUT_DESC, BARGRAPH1_COLOR);
|
||||
drawChannelsMonitorLegend(x, STR_MONITOR_MIXER_DESC, BARGRAPH2_COLOR);
|
||||
|
||||
x = X_OFFSET;
|
||||
for (uint8_t i = 0; i < 8; i++, channel++, y += ROW_HEIGHT) {
|
||||
if (i == 4) {
|
||||
x = 1 + LCD_W / 2 + X_OFFSET;
|
||||
y = Y_OFFSET;
|
||||
}
|
||||
drawComboOutputBar(x, y, COLUMN_SIZE, BAR_HEIGHT, channel);
|
||||
drawSingleMixerBar(x, y + Y_MIXBAR + 1, COLUMN_SIZE, BAR_HEIGHT, channel);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 X_OFF 45
|
||||
#define Y_OFF 70
|
||||
#define HLINE_Y_OFF 215
|
||||
#define LS_COL_WIDTH 50
|
||||
#define LS_LINE_HEIGHT 17
|
||||
#define X_FUNC 50
|
||||
#define Y_FUNC 225
|
||||
|
||||
#define CSW_1ST_COLUMN 50
|
||||
#define CSW_2ND_COLUMN 120
|
||||
#define CSW_3RD_COLUMN 200
|
||||
#define CSW_4TH_COLUMN 280
|
||||
#define CSW_5TH_COLUMN 340
|
||||
#define CSW_6TH_COLUMN 390
|
||||
#define MAX_LOGICAL_SWITCHES 64
|
||||
|
||||
extern void putsEdgeDelayParam(coord_t, coord_t, LogicalSwitchData *, uint8_t, uint8_t);
|
||||
|
||||
void displayLogicalSwitchedDetails(coord_t x, coord_t y, uint8_t idx)
|
||||
{
|
||||
LogicalSwitchData * cs = lswAddress(idx);
|
||||
lcdDrawTextAtIndex(x, y, STR_VCSWFUNC, cs->func, 0);
|
||||
// CSW params
|
||||
unsigned int cstate = lswFamily(cs->func);
|
||||
|
||||
if (cstate == LS_FAMILY_BOOL || cstate == LS_FAMILY_STICKY) {
|
||||
drawSwitch(CSW_2ND_COLUMN, y, cs->v1, 0);
|
||||
drawSwitch(CSW_3RD_COLUMN, y, cs->v2, 0);
|
||||
}
|
||||
else if (cstate == LS_FAMILY_EDGE) {
|
||||
drawSwitch(CSW_2ND_COLUMN, y, cs->v1, 0);
|
||||
putsEdgeDelayParam(CSW_3RD_COLUMN, y, cs, 0, 0);
|
||||
}
|
||||
else if (cstate == LS_FAMILY_COMP) {
|
||||
drawSource(CSW_2ND_COLUMN, y, cs->v1, 0);
|
||||
drawSource(CSW_3RD_COLUMN, y, cs->v2, 0);
|
||||
}
|
||||
else if (cstate == LS_FAMILY_TIMER) {
|
||||
lcdDrawNumber(CSW_2ND_COLUMN, y, lswTimerValue(cs->v1), LEFT | PREC1);
|
||||
lcdDrawNumber(CSW_3RD_COLUMN, y, lswTimerValue(cs->v2), LEFT | PREC1);
|
||||
}
|
||||
else {
|
||||
drawSource(CSW_2ND_COLUMN, y, cs->v1, 0);
|
||||
drawSourceCustomValue(CSW_3RD_COLUMN, y, cs->v1, cs->v1 <= MIXSRC_LAST_CH ? calc100toRESX(cs->v2) : cs->v2, LEFT);
|
||||
}
|
||||
|
||||
// CSW AND switch
|
||||
drawSwitch(CSW_4TH_COLUMN, y, cs->andsw, 0);
|
||||
|
||||
// CSW duration
|
||||
if (cs->duration > 0)
|
||||
lcdDrawNumber(CSW_5TH_COLUMN, y, cs->duration, PREC1 | LEFT);
|
||||
else
|
||||
lcdDrawMMM(CSW_5TH_COLUMN, y, 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, PREC1 | LEFT);
|
||||
}
|
||||
else {
|
||||
lcdDrawMMM(CSW_6TH_COLUMN, y, 0);
|
||||
}
|
||||
}
|
||||
|
||||
bool menuLogicalSwitchesMonitor(event_t event)
|
||||
{
|
||||
char lsString[] = "L64";
|
||||
lcdColorTable[CUSTOM_COLOR_INDEX] = RGB(160, 160, 160);
|
||||
for (uint8_t i = 0; i < MAX_LOGICAL_SWITCHES; i++) {
|
||||
LcdFlags attr = (menuHorizontalPosition == i ? INVERS : 0) | LEFT;
|
||||
LogicalSwitchData * cs = lswAddress(i);
|
||||
strAppendSigned(&lsString[1], i + 1, 2);
|
||||
if (cs->func == LS_FUNC_NONE)
|
||||
attr += CUSTOM_COLOR;
|
||||
else if (getSwitch(SWSRC_SW1 + i))
|
||||
attr += BOLD;
|
||||
lcdDrawText(X_OFF + (i & 0x07) * LS_COL_WIDTH, Y_OFF + (i >> 3) * LS_LINE_HEIGHT, lsString, attr);
|
||||
}
|
||||
lcdDrawHorizontalLine(0, HLINE_Y_OFF, LCD_W, SOLID);
|
||||
if (lswAddress(menuHorizontalPosition)->func != LS_FUNC_NONE) {
|
||||
displayLogicalSwitchedDetails(X_FUNC, Y_FUNC, menuHorizontalPosition);
|
||||
}
|
||||
s_editMode = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool menuLogicalSwitches(event_t event)
|
||||
{
|
||||
MENU(STR_MONITOR_SWITCHES, MONITOR_ICONS, menuTabMonitors, e_MonLogicalSwitches, 1, { MAX_LOGICAL_SWITCHES - 1 });
|
||||
lastMonitorPage = e_MonLogicalSwitches;
|
||||
return menuLogicalSwitchesMonitor(event);
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* 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 "view_main.h"
|
||||
#include "menu_model.h"
|
||||
#include "menu_radio.h"
|
||||
// #include "menu_screens.h"
|
||||
// #include "model_select.h"
|
||||
// #include "view_channels.h"
|
||||
// #include "view_statistics.h"
|
||||
#include "opentx.h"
|
||||
|
||||
#define TRIM_WIDTH 121
|
||||
#define TRIM_LH_X 10
|
||||
#define TRIM_LV_X 14
|
||||
#define TRIM_RV_X (LCD_W-25)
|
||||
#define TRIM_RH_X (LCD_W-TRIM_LH_X-TRIM_WIDTH)
|
||||
#define TRIM_V_Y 285
|
||||
#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;
|
||||
|
||||
#if 0
|
||||
void drawMainPots()
|
||||
{
|
||||
// The 3 pots
|
||||
#if defined(PCBHORUS)
|
||||
drawHorizontalSlider(TRIM_LH_X, POTS_LINE_Y, TRIM_WIDTH, calibratedAnalogs[CALIBRATED_POT1], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
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);
|
||||
drawHorizontalSlider(TRIM_RH_X, POTS_LINE_Y, TRIM_WIDTH, 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);
|
||||
#elif defined(PCBNV14)
|
||||
drawHorizontalSlider(TRIM_LH_X, POTS_LINE_Y, TRIM_WIDTH, calibratedAnalogs[CALIBRATED_POT1], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
drawHorizontalSlider(TRIM_LH_X, POTS_LINE_Y, TRIM_WIDTH, calibratedAnalogs[CALIBRATED_POT2], -RESX, RESX, 40, OPTION_SLIDER_TICKS | OPTION_SLIDER_BIG_TICKS | OPTION_SLIDER_SQUARE_BUTTON);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
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 (vert[i]) {
|
||||
if (g_model.extendedTrims == 1) {
|
||||
drawVerticalSlider(xm, TRIM_V_Y, 120, trim, TRIM_EXTENDED_MIN, TRIM_EXTENDED_MAX, 0, OPTION_SLIDER_EMPTY_BAR|OPTION_SLIDER_TRIM_BUTTON);
|
||||
}
|
||||
else {
|
||||
drawVerticalSlider(xm, TRIM_V_Y, 120, 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, 120, trim, TRIM_EXTENDED_MIN, TRIM_EXTENDED_MAX, 0, OPTION_SLIDER_EMPTY_BAR|OPTION_SLIDER_TRIM_BUTTON);
|
||||
}
|
||||
else {
|
||||
drawHorizontalSlider(xm, TRIM_H_Y, 120, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void onMainViewMenu(const char *result)
|
||||
{
|
||||
/*if (result == STR_VIEW_NOTES) {
|
||||
pushModelNotes();
|
||||
}
|
||||
else if (result == STR_STATISTICS) {
|
||||
pushMenu(menuTabStats[0]);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
ViewMain * ViewMain::instance = nullptr;
|
||||
|
||||
ViewMain::ViewMain(bool icons):
|
||||
Window(&mainWindow, { 0, 0, LCD_W, LCD_H })
|
||||
{
|
||||
instance = this;
|
||||
focusWindow = this;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
if (icons) {
|
||||
new FabIconButton(this, 50, 100, ICON_MODEL,
|
||||
[=]() -> uint8_t {
|
||||
new ModelMenu();
|
||||
return 0;
|
||||
});
|
||||
|
||||
new FabIconButton(this, LCD_W / 2, 100, ICON_RADIO,
|
||||
[=]() -> uint8_t {
|
||||
new RadioMenu();
|
||||
return 0;
|
||||
});
|
||||
|
||||
// new FabIconButton(this, LCD_W - 50, 100, ICON_THEME,
|
||||
// [=]() -> uint8_t {
|
||||
// new ScreensMenu();
|
||||
// return 0;
|
||||
// });
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ViewMain::~ViewMain()
|
||||
{
|
||||
deleteChildren();
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void ViewMain::onKeyEvent(event_t event)
|
||||
{
|
||||
switch (event) {
|
||||
case EVT_KEY_LONG(KEY_MODEL):
|
||||
killEvents(event);
|
||||
new ModelMenu();
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_RADIO):
|
||||
killEvents(event);
|
||||
new RadioMenu();
|
||||
break;
|
||||
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_MODEL_SELECT, [=]() {
|
||||
// new ModelselectMenu();
|
||||
});
|
||||
if (1/*modelHasNotes()*/) {
|
||||
menu->addLine(STR_VIEW_NOTES, [=]() {
|
||||
// TODO
|
||||
});
|
||||
}
|
||||
menu->addLine(STR_MONITOR_SCREENS, [=]() {
|
||||
// new ChannelsMonitorMenu();
|
||||
});
|
||||
menu->addLine(STR_RESET_SUBMENU, [=]() {
|
||||
Menu * menu = new Menu();
|
||||
menu->addLine(STR_RESET_FLIGHT, [=]() {
|
||||
flightReset();
|
||||
});
|
||||
menu->addLine(STR_RESET_TIMER1, [=]() {
|
||||
timerReset(0);
|
||||
});
|
||||
menu->addLine(STR_RESET_TIMER2, [=]() {
|
||||
timerReset(1);
|
||||
});
|
||||
menu->addLine(STR_RESET_TIMER3, [=]() {
|
||||
timerReset(2);
|
||||
});
|
||||
menu->addLine(STR_RESET_TELEMETRY, [=]() {
|
||||
telemetryReset();
|
||||
});
|
||||
});
|
||||
menu->addLine(STR_STATISTICS, [=]() {
|
||||
// new StatisticsMenu();
|
||||
});
|
||||
menu->addLine(STR_ABOUT_US, [=]() {
|
||||
// TODO
|
||||
});
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void ViewMain::checkEvents()
|
||||
{
|
||||
Window::checkEvents();
|
||||
|
||||
// TODO temporary for refreshing the trims
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void ViewMain::paint(BitmapBuffer * dc)
|
||||
{
|
||||
theme->drawBackground(dc);
|
||||
|
||||
// drawMainPots();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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 _VIEW_MAIN_H_
|
||||
#define _VIEW_MAIN_H_
|
||||
|
||||
#include "window.h"
|
||||
|
||||
class ViewMain: public Window {
|
||||
public:
|
||||
ViewMain(bool icons=true);
|
||||
|
||||
~ViewMain() override;
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
virtual std::string getName()
|
||||
{
|
||||
return "ViewMain";
|
||||
}
|
||||
#endif
|
||||
|
||||
static ViewMain * instance;
|
||||
|
||||
protected:
|
||||
#if defined(HARDWARE_KEYS)
|
||||
void onKeyEvent(event_t event) override;
|
||||
#endif
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
void checkEvents() override;
|
||||
};
|
||||
|
||||
#endif // _VIEW_MAIN_H_
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* 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 "stamp.h"
|
||||
|
||||
#define MENU_STATS_COLUMN1 (MENUS_MARGIN_LEFT + 120)
|
||||
#define MENU_STATS_COLUMN2 (LCD_W/2)
|
||||
#define MENU_STATS_COLUMN3 (LCD_W/2 + 120)
|
||||
|
||||
bool menuStatsGraph(event_t event)
|
||||
{
|
||||
switch(event) {
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
g_eeGeneral.globalTimer = 0;
|
||||
storageDirty(EE_GENERAL);
|
||||
sessionTimer = 0;
|
||||
killEvents(event);
|
||||
break;
|
||||
}
|
||||
|
||||
SIMPLE_MENU(STR_STATISTICS, STATS_ICONS, menuTabStats, e_StatsGraph, 1);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP, "Session");
|
||||
drawTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP, sessionTimer, TIMEHOUR);
|
||||
lcdDrawText(MENU_STATS_COLUMN2, MENU_CONTENT_TOP, "Battery");
|
||||
drawTimer(MENU_STATS_COLUMN3, MENU_CONTENT_TOP, g_eeGeneral.globalTimer+sessionTimer, TIMEHOUR);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+FH, "Throttle");
|
||||
drawTimer(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+FH, s_timeCumThr, TIMEHOUR);
|
||||
lcdDrawText(MENU_STATS_COLUMN2, MENU_CONTENT_TOP+FH, "Throttle %", TIMEHOUR);
|
||||
drawTimer(MENU_STATS_COLUMN3, MENU_CONTENT_TOP+FH, s_timeCum16ThrP/16, TIMEHOUR);
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+2*FH, "Timers");
|
||||
lcdDrawText(MENU_STATS_COLUMN1, MENU_CONTENT_TOP+2*FH, "[1]", HEADER_COLOR);
|
||||
drawTimer(lcdNextPos+5, MENU_CONTENT_TOP+2*FH, timersStates[0].val, TIMEHOUR);
|
||||
lcdDrawText(MENU_STATS_COLUMN2, MENU_CONTENT_TOP+2*FH, "[2]", HEADER_COLOR);
|
||||
drawTimer(lcdNextPos+5, MENU_CONTENT_TOP+2*FH, timersStates[1].val, TIMEHOUR);
|
||||
#if TIMERS > 2
|
||||
lcdDrawText(MENU_STATS_COLUMN3, MENU_CONTENT_TOP+2*FH, "[3]", HEADER_COLOR);
|
||||
drawTimer(lcdNextPos+5, MENU_CONTENT_TOP+2*FH, timersStates[2].val, TIMEHOUR);
|
||||
#endif
|
||||
|
||||
const coord_t x = 10;
|
||||
const coord_t y = 240;
|
||||
lcdDrawHorizontalLine(x-3, y, MAXTRACE+3+3, SOLID, TEXT_COLOR);
|
||||
lcdDrawVerticalLine(x, y-96, 96+3, SOLID, TEXT_COLOR);
|
||||
for (coord_t i=0; i<MAXTRACE; i+=6) {
|
||||
lcdDrawVerticalLine(x+i, y-1, 3, SOLID, TEXT_COLOR);
|
||||
}
|
||||
|
||||
uint16_t traceRd = s_traceWr > MAXTRACE ? s_traceWr - MAXTRACE : 0;
|
||||
coord_t prev_yv = (coord_t)-1;
|
||||
for (coord_t i=1; i<=MAXTRACE && traceRd<s_traceWr; i++, traceRd++) {
|
||||
uint8_t h = s_traceBuf[traceRd % MAXTRACE];
|
||||
coord_t yv = y - 2 - 3*h;
|
||||
if (prev_yv != (coord_t)-1) {
|
||||
if (prev_yv < yv) {
|
||||
for (int y=prev_yv; y<=yv; y++) {
|
||||
lcdDrawBitmapPattern(x + i - 3, y, LBM_POINT, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int y=yv; y<=prev_yv; y++) {
|
||||
lcdDrawBitmapPattern(x + i - 3, y, LBM_POINT, TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
lcdDrawBitmapPattern(x + i - 3, yv, LBM_POINT, TEXT_COLOR);
|
||||
}
|
||||
prev_yv = yv;
|
||||
}
|
||||
|
||||
lcdDrawText(LCD_W/2, MENU_FOOTER_TOP, STR_MENUTORESET, MENU_TITLE_COLOR | CENTERED);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool menuStatsDebug(event_t event)
|
||||
{
|
||||
switch(event) {
|
||||
case EVT_ENTRY:
|
||||
case EVT_ENTRY_UP:
|
||||
enableVBatBridge();
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_ENTER):
|
||||
maxMixerDuration = 0;
|
||||
#if defined(LUA)
|
||||
maxLuaInterval = 0;
|
||||
maxLuaDuration = 0;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
if (!check_simple(event, e_StatsDebug, menuTabStats, DIM(menuTabStats), 1)) {
|
||||
disableVBatBridge();
|
||||
return false;
|
||||
}
|
||||
|
||||
drawMenuTemplate("Debug", 0, STATS_ICONS, OPTION_MENU_TITLE_BAR);
|
||||
|
||||
coord_t y = MENU_CONTENT_TOP;
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "Free Mem");
|
||||
lcdDrawNumber(MENU_STATS_COLUMN1, y, availableMemory(), LEFT, 0, NULL, "b");
|
||||
y += FH;
|
||||
|
||||
#if defined(LUA)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "Lua scripts");
|
||||
lcdDrawText(MENU_STATS_COLUMN1, y+1, "[Duration]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, 10*maxLuaDuration, LEFT, 0, NULL, "ms");
|
||||
lcdDrawText(lcdNextPos+20, y+1, "[Interval]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, 10*maxLuaDuration, LEFT, 0, NULL, "ms");
|
||||
y += FH;
|
||||
|
||||
// lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+line*FH, "Lua memory");
|
||||
lcdDrawText(MENU_STATS_COLUMN1, y+1, "[S]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, luaGetMemUsed(lsScripts), LEFT);
|
||||
lcdDrawText(lcdNextPos+20, y+1, "[W]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, luaGetMemUsed(lsWidgets), LEFT);
|
||||
lcdDrawText(lcdNextPos+20, y+1, "[B]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, luaExtraMemoryUsage, LEFT);
|
||||
y += FH;
|
||||
#endif
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_TMIXMAXMS);
|
||||
lcdDrawNumber(MENU_STATS_COLUMN1, y, DURATION_MS_PREC2(maxMixerDuration), PREC2|LEFT, 0, NULL, "ms");
|
||||
y += FH;
|
||||
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, STR_FREE_STACK);
|
||||
lcdDrawText(MENU_STATS_COLUMN1, y+1, "[Menus]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, menusStack.available(), LEFT);
|
||||
lcdDrawText(lcdNextPos+20, y+1, "[Mix]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, mixerStack.available(), LEFT);
|
||||
lcdDrawText(lcdNextPos+20, y+1, "[Audio]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, audioStack.available(), LEFT);
|
||||
y += FH;
|
||||
|
||||
#if defined(DISK_CACHE) && defined(DEBUG)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "SD cache hits");
|
||||
lcdDrawNumber(MENU_STATS_COLUMN1, y, diskCache.getHitRate(), PREC1|LEFT, 0, NULL, "%");
|
||||
y += FH;
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG_LATENCY)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "Heartbeat");
|
||||
if (heartbeatCapture.valid)
|
||||
lcdDrawNumber(MENU_STATS_COLUMN1, y, heartbeatCapture.count, LEFT);
|
||||
else
|
||||
lcdDrawText(MENU_STATS_COLUMN1, y, "---");
|
||||
y += FH;
|
||||
#endif
|
||||
|
||||
#if defined(DEBUG)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "Telem RX Errs");
|
||||
lcdDrawNumber(MENU_STATS_COLUMN1, y, telemetryErrors, LEFT);
|
||||
y += FH;
|
||||
#endif
|
||||
|
||||
#if defined(INTERNAL_GPS)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, y, "Internal GPS");
|
||||
lcdDrawText(MENU_STATS_COLUMN1, y+1, "[Fix]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawText(lcdNextPos+2, y, (gpsData.fix ? "Yes" : "No"), LEFT);
|
||||
lcdDrawText(lcdNextPos+20, y+1, "[Sats]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, gpsData.numSat, LEFT);
|
||||
lcdDrawText(lcdNextPos+20, y+1, "[Hdop]", HEADER_COLOR|SMLSIZE);
|
||||
lcdDrawNumber(lcdNextPos+5, y, gpsData.hdop, PREC2|LEFT);
|
||||
#endif
|
||||
|
||||
lcdDrawText(LCD_W/2, MENU_FOOTER_TOP, STR_MENUTORESET, MENU_TITLE_COLOR | CENTERED);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool menuStatsAnalogs(event_t event)
|
||||
{
|
||||
SIMPLE_MENU("Analogs", STATS_ICONS, menuTabStats, e_StatsAnalogs, 1);
|
||||
|
||||
for (uint8_t i=0; i<NUM_ANALOGS; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + (i/2)*FH;
|
||||
coord_t x = MENUS_MARGIN_LEFT + (i & 1 ? LCD_W/2 : 0);
|
||||
lcdDrawNumber(x, y, i+1, LEADING0|LEFT, 2, NULL, ":");
|
||||
lcdDrawHexNumber(x+40, y, anaIn(i));
|
||||
#if defined(JITTER_MEASURE)
|
||||
lcdDrawNumber(x+100, y, rawJitter[i].get());
|
||||
lcdDrawNumber(x+140, y, avgJitter[i].get());
|
||||
lcdDrawNumber(x+180, y, (int16_t)calibratedAnalogs[CONVERT_MODE(i)]*250/256, PREC1);
|
||||
#else
|
||||
if (i < NUM_STICKS+NUM_POTS+NUM_SLIDERS)
|
||||
lcdDrawNumber(x+100, y, (int16_t)calibratedAnalogs[CONVERT_MODE(i)]*25/256);
|
||||
#if NUM_MOUSE_ANALOGS > 0
|
||||
else if (i >= MOUSE1)
|
||||
lcdDrawNumber(x+100, y, (int16_t)calibratedAnalogs[CALIBRATED_MOUSE1+i-MOUSE1]*25/256);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
// RAS
|
||||
if ((isModuleXJT(INTERNAL_MODULE) && IS_INTERNAL_MODULE_ON()) || (isModulePXX1(EXTERNAL_MODULE) && !IS_INTERNAL_MODULE_ON())) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+7*FH, "RAS");
|
||||
lcdDrawNumber(MENUS_MARGIN_LEFT+100, MENU_CONTENT_TOP+7*FH, telemetryData.swrInternal.value());
|
||||
lcdDrawText(MENUS_MARGIN_LEFT + LCD_W/2, MENU_CONTENT_TOP+7*FH, "XJTVER");
|
||||
lcdDrawNumber(LCD_W/2 + MENUS_MARGIN_LEFT+100, MENU_CONTENT_TOP+7*FH, telemetryData.xjtVersion);
|
||||
}
|
||||
|
||||
#if (NUM_PWMSTICKS > 0) && !defined(SIMU)
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP+8*FH, STICKS_PWM_ENABLED() ? "Sticks: PWM" : "Sticks: ANA");
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#if defined(DEBUG_TRACE_BUFFER)
|
||||
#define STATS_TRACES_INDEX_POS MENUS_MARGIN_LEFT
|
||||
#define STATS_TRACES_TIME_POS MENUS_MARGIN_LEFT + 4*10
|
||||
#define STATS_TRACES_EVENT_POS MENUS_MARGIN_LEFT + 14*10
|
||||
#define STATS_TRACES_DATA_POS MENUS_MARGIN_LEFT + 20*10
|
||||
|
||||
bool menuStatsTraces(event_t event)
|
||||
{
|
||||
switch(event)
|
||||
{
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
dumpTraceBuffer();
|
||||
killEvents(event);
|
||||
break;
|
||||
}
|
||||
|
||||
SIMPLE_MENU("", STATS_ICONS, menuTabStats, e_StatsTraces, TRACE_BUFFER_LEN);
|
||||
|
||||
uint8_t k = 0;
|
||||
int8_t sub = menuVerticalPosition;
|
||||
|
||||
lcdDrawChar(STATS_TRACES_INDEX_POS, MENU_TITLE_TOP+2, '#', MENU_TITLE_COLOR);
|
||||
lcdDrawText(STATS_TRACES_TIME_POS, MENU_TITLE_TOP+2, "Time", MENU_TITLE_COLOR);
|
||||
lcdDrawText(STATS_TRACES_EVENT_POS, MENU_TITLE_TOP+2, "Event", MENU_TITLE_COLOR);
|
||||
lcdDrawText(STATS_TRACES_DATA_POS, MENU_TITLE_TOP+2, "Data", MENU_TITLE_COLOR);
|
||||
|
||||
for (uint8_t i=0; i<NUM_BODY_LINES; i++) {
|
||||
coord_t y = MENU_CONTENT_TOP + i * FH;
|
||||
k = i+menuVerticalOffset;
|
||||
|
||||
// item
|
||||
lcdDrawNumber(STATS_TRACES_INDEX_POS, y, k, LEFT | (sub==k ? INVERS : 0));
|
||||
|
||||
const struct TraceElement * te = getTraceElement(k);
|
||||
if (te) {
|
||||
// time
|
||||
int32_t tme = te->time % SECS_PER_DAY;
|
||||
drawTimer(STATS_TRACES_TIME_POS, y, tme, TIMEHOUR|LEFT);
|
||||
// event
|
||||
lcdDrawNumber(STATS_TRACES_EVENT_POS, y, te->event, LEADING0|LEFT, 3);
|
||||
// data
|
||||
lcdDrawSizedText(STATS_TRACES_DATA_POS, y, "0x", 2);
|
||||
lcdDrawHexNumber(lcdNextPos, y, (uint16_t)(te->data >> 16));
|
||||
lcdDrawHexNumber(lcdNextPos, y, (uint16_t)(te->data & 0xFFFF));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif // defined(DEBUG_TRACE_BUFFER)
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* 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 TEXT_FILE_MAXSIZE 2048
|
||||
|
||||
char s_text_file[TEXT_FILENAME_MAXLEN];
|
||||
char s_text_screen[NUM_BODY_LINES][LCD_COLS+1];
|
||||
|
||||
void readTextFile(int & lines_count)
|
||||
{
|
||||
FIL file;
|
||||
int result;
|
||||
char c;
|
||||
unsigned int sz;
|
||||
int line_length = 0;
|
||||
int escape = 0;
|
||||
char escape_chars[2];
|
||||
int current_line = 0;
|
||||
|
||||
memset(s_text_screen, 0, sizeof(s_text_screen));
|
||||
|
||||
result = f_open(&file, s_text_file, FA_OPEN_EXISTING | FA_READ);
|
||||
if (result == FR_OK) {
|
||||
for (int i=0; i<TEXT_FILE_MAXSIZE && f_read(&file, &c, 1, &sz)==FR_OK && sz==1 && (lines_count==0 || current_line-menuVerticalOffset<NUM_BODY_LINES); i++) {
|
||||
if (c == '\n') {
|
||||
++current_line;
|
||||
line_length = 0;
|
||||
escape = 0;
|
||||
}
|
||||
else if (c!='\r' && current_line>=menuVerticalOffset && current_line-menuVerticalOffset<NUM_BODY_LINES && line_length<LCD_COLS) {
|
||||
if (c=='\\' && escape==0) {
|
||||
escape = 1;
|
||||
continue;
|
||||
}
|
||||
else if (c!='\\' && escape>0 && escape<4) {
|
||||
escape_chars[escape-1] = c;
|
||||
if (escape == 2 && !strncmp(escape_chars, "up", 2)) {
|
||||
c = '\300';
|
||||
escape = 0;
|
||||
}
|
||||
else if (escape == 2 && !strncmp(escape_chars, "dn", 2)) {
|
||||
c = '\301';
|
||||
escape = 0;
|
||||
}
|
||||
else if (escape == 3) {
|
||||
int val = atoi(escape_chars);
|
||||
if (val >= 200 && val < 225) {
|
||||
c = '\200' + val-200;
|
||||
}
|
||||
escape = 0;
|
||||
}
|
||||
else {
|
||||
escape++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (c=='~') {
|
||||
c = 'z'+1;
|
||||
}
|
||||
else if (c=='\t') {
|
||||
c = 0x1D; //tab
|
||||
}
|
||||
escape = 0;
|
||||
s_text_screen[current_line-menuVerticalOffset][line_length++] = c;
|
||||
}
|
||||
}
|
||||
if (c != '\n') {
|
||||
current_line += 1;
|
||||
}
|
||||
f_close(&file);
|
||||
}
|
||||
|
||||
if (lines_count == 0) {
|
||||
lines_count = current_line;
|
||||
}
|
||||
}
|
||||
|
||||
bool menuTextView(event_t event)
|
||||
{
|
||||
static int lines_count;
|
||||
|
||||
drawMenuTemplate(STR_TEXT_VIEWER, ICON_OPENTX);
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
menuVerticalOffset = 0;
|
||||
lines_count = 0;
|
||||
readTextFile(lines_count);
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_LEFT:
|
||||
if (menuVerticalOffset == 0)
|
||||
break;
|
||||
else
|
||||
menuVerticalOffset--;
|
||||
readTextFile(lines_count);
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
if (menuVerticalOffset+NUM_BODY_LINES >= lines_count)
|
||||
break;
|
||||
else
|
||||
++menuVerticalOffset;
|
||||
readTextFile(lines_count);
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
popMenu();
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES; i++) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + i*FH, s_text_screen[i]);
|
||||
}
|
||||
|
||||
#if 0
|
||||
char * title = s_text_file;
|
||||
#if defined(SIMU)
|
||||
if (!strncmp(title, "./", 2)) title += 2;
|
||||
#endif
|
||||
lcdDrawTextAlignedCenter(MENU_FOOTER_TOP, title, HEADER_COLOR);
|
||||
#endif
|
||||
|
||||
drawVerticalScrollbar(LCD_W-5, 50, 195, menuVerticalOffset, lines_count, NUM_BODY_LINES);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void pushMenuTextView(const char *filename)
|
||||
{
|
||||
if (strlen(filename) < TEXT_FILENAME_MAXLEN) {
|
||||
strcpy(s_text_file, filename);
|
||||
pushMenu(menuTextView);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
std::list<const WidgetFactory *> & getRegisteredWidgets()
|
||||
{
|
||||
static std::list<const WidgetFactory *> widgets;
|
||||
return widgets;
|
||||
}
|
||||
|
||||
void registerWidget(const WidgetFactory * factory)
|
||||
{
|
||||
TRACE("register widget %s", factory->getName());
|
||||
getRegisteredWidgets().push_back(factory);
|
||||
}
|
||||
|
||||
const WidgetFactory * getWidgetFactory(const char * name)
|
||||
{
|
||||
std::list<const WidgetFactory *>::const_iterator it = getRegisteredWidgets().cbegin();
|
||||
for (; it != getRegisteredWidgets().cend();++it) {
|
||||
if (!strcmp(name, (*it)->getName())) {
|
||||
return (*it);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Widget * loadWidget(const char * name, const Zone & zone, Widget::PersistentData * persistentData)
|
||||
{
|
||||
const WidgetFactory * factory = getWidgetFactory(name);
|
||||
if (factory) {
|
||||
return factory->create(zone, persistentData, false);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* 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 _WIDGET_H_
|
||||
#define _WIDGET_H_
|
||||
|
||||
#include <list>
|
||||
#include "zone.h"
|
||||
|
||||
#define MAX_WIDGET_OPTIONS 5
|
||||
|
||||
class WidgetFactory;
|
||||
class Widget
|
||||
{
|
||||
public:
|
||||
struct PersistentData {
|
||||
ZoneOptionValue options[MAX_WIDGET_OPTIONS];
|
||||
};
|
||||
|
||||
Widget(const WidgetFactory * factory, const Zone & zone, PersistentData * persistentData):
|
||||
factory(factory),
|
||||
zone(zone),
|
||||
persistentData(persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Widget()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void update()
|
||||
{
|
||||
}
|
||||
|
||||
inline const WidgetFactory * getFactory() const
|
||||
{
|
||||
return factory;
|
||||
}
|
||||
|
||||
inline const ZoneOption * getOptions() const;
|
||||
|
||||
virtual const char * getErrorMessage() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline ZoneOptionValue * getOptionValue(unsigned int index) const
|
||||
{
|
||||
return &persistentData->options[index];
|
||||
}
|
||||
|
||||
virtual void refresh() = 0;
|
||||
|
||||
virtual void background()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
const WidgetFactory * factory;
|
||||
Zone zone;
|
||||
PersistentData * persistentData;
|
||||
};
|
||||
|
||||
void registerWidget(const WidgetFactory * factory);
|
||||
|
||||
class WidgetFactory
|
||||
{
|
||||
public:
|
||||
WidgetFactory(const char * name, const ZoneOption * options=NULL):
|
||||
name(name),
|
||||
options(options)
|
||||
{
|
||||
registerWidget(this);
|
||||
}
|
||||
|
||||
inline const char * getName() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
inline const ZoneOption * getOptions() const
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
void initPersistentData(Widget::PersistentData * persistentData) const
|
||||
{
|
||||
memset(persistentData, 0, sizeof(Widget::PersistentData));
|
||||
if (options) {
|
||||
int i = 0;
|
||||
for (const ZoneOption * option = options; option->name; option++) {
|
||||
TRACE("WidgetFactory::initPersistentData() setting option '%s'", option->name);
|
||||
// TODO compiler bug? The CPU freezes ... persistentData->options[i++] = option->deflt;
|
||||
memcpy(&persistentData->options[i++], &option->deflt, sizeof(ZoneOptionValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual Widget * create(const Zone & zone, Widget::PersistentData * persistentData, bool init=true) const = 0;
|
||||
|
||||
protected:
|
||||
const char * name;
|
||||
const ZoneOption * options;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class BaseWidgetFactory: public WidgetFactory
|
||||
{
|
||||
public:
|
||||
BaseWidgetFactory(const char * name, const ZoneOption * options):
|
||||
WidgetFactory(name, options)
|
||||
{
|
||||
}
|
||||
|
||||
virtual Widget * create(const Zone & zone, Widget::PersistentData * persistentData, bool init=true) const
|
||||
{
|
||||
if (init) {
|
||||
initPersistentData(persistentData);
|
||||
}
|
||||
|
||||
return new T(this, zone, persistentData);
|
||||
}
|
||||
};
|
||||
|
||||
inline const ZoneOption * Widget::getOptions() const
|
||||
{
|
||||
return getFactory()->getOptions();
|
||||
}
|
||||
|
||||
Widget * loadWidget(const char * name, const Zone & zone, Widget::PersistentData * persistentData);
|
||||
|
||||
std::list<const WidgetFactory *> & getRegisteredWidgets();
|
||||
|
||||
#endif // _WIDGET_H_
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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 GaugeWidget: public Widget
|
||||
{
|
||||
public:
|
||||
GaugeWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption GaugeWidget::options[] = {
|
||||
{ "Source", ZoneOption::Source, OPTION_VALUE_UNSIGNED(1) },
|
||||
{ "Min", ZoneOption::Integer, OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX) },
|
||||
{ "Max", ZoneOption::Integer, OPTION_VALUE_SIGNED(RESX), OPTION_VALUE_SIGNED(-RESX), OPTION_VALUE_SIGNED(RESX) },
|
||||
{ "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
void GaugeWidget::refresh()
|
||||
{
|
||||
mixsrc_t index = persistentData->options[0].unsignedValue;
|
||||
int32_t min = persistentData->options[1].signedValue;
|
||||
int32_t max = persistentData->options[2].signedValue;
|
||||
uint16_t color = persistentData->options[3].unsignedValue;
|
||||
|
||||
int32_t value = getValue(index);
|
||||
int32_t value_in_range = value;
|
||||
if (value < min)
|
||||
value_in_range = min;
|
||||
else if (value > max)
|
||||
value_in_range = max;
|
||||
|
||||
int w = divRoundClosest(zone.w * (value_in_range - min), (max - min));
|
||||
int percent = divRoundClosest(100 * (value_in_range - min), (max - min));
|
||||
|
||||
// Gauge label
|
||||
drawSource(zone.x, zone.y, index, SMLSIZE | TEXT_INVERTED_COLOR);
|
||||
|
||||
// Gauge
|
||||
lcdSetColor(color);
|
||||
lcdDrawSolidFilledRect(zone.x, zone.y + 16, zone.w, 16, TEXT_INVERTED_COLOR);
|
||||
lcdDrawNumber(zone.x+zone.w/2, zone.y + 17, percent, SMLSIZE | CUSTOM_COLOR | CENTERED, 0, NULL, "%");
|
||||
lcd->invertRect(zone.x + w, zone.y + 16, zone.w - w, 16, CUSTOM_COLOR);
|
||||
}
|
||||
|
||||
BaseWidgetFactory<GaugeWidget> gaugeWidget("Gauge", GaugeWidget::options);
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 ModelBitmapWidget: public Widget
|
||||
{
|
||||
public:
|
||||
ModelBitmapWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData),
|
||||
buffer(NULL),
|
||||
deps_hash(0)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~ModelBitmapWidget()
|
||||
{
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
void refreshBuffer()
|
||||
{
|
||||
delete buffer;
|
||||
buffer = new BitmapBuffer(BMP_RGB565, zone.w, zone.h);
|
||||
|
||||
if (buffer) {
|
||||
buffer->drawBitmap(0, 0, lcd, zone.x, zone.y, zone.w, zone.h);
|
||||
GET_FILENAME(filename, BITMAPS_PATH, g_model.header.bitmap, "");
|
||||
BitmapBuffer * bitmap = BitmapBuffer::load(filename);
|
||||
if (zone.h >= 96 && zone.w >= 120) {
|
||||
buffer->drawFilledRect(0, 0, zone.w, zone.h, SOLID, MAINVIEW_PANES_COLOR | OPACITY(5));
|
||||
static BitmapBuffer * icon = BitmapBuffer::loadMask(getThemePath("mask_menu_model.png"));
|
||||
buffer->drawMask(6, 4, icon, MAINVIEW_GRAPHICS_COLOR);
|
||||
buffer->drawSizedText(45, 10, g_model.header.name, LEN_MODEL_NAME, ZCHAR | SMLSIZE);
|
||||
buffer->drawSolidFilledRect(39, 27, zone.w - 48, 2, MAINVIEW_GRAPHICS_COLOR);
|
||||
if (bitmap) {
|
||||
buffer->drawScaledBitmap(bitmap, 0, 38, zone.w, zone.h - 38);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (bitmap) {
|
||||
buffer->drawScaledBitmap(bitmap, 0, 0, zone.w, zone.h);
|
||||
}
|
||||
}
|
||||
delete bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
virtual void refresh()
|
||||
{
|
||||
uint32_t new_hash = hash(g_model.header.bitmap, sizeof(g_model.header.bitmap));
|
||||
new_hash ^= hash(g_model.header.name, sizeof(g_model.header.name));
|
||||
new_hash ^= hash(g_eeGeneral.themeName, sizeof(g_eeGeneral.themeName));
|
||||
if (new_hash != deps_hash) {
|
||||
deps_hash = new_hash;
|
||||
refreshBuffer();
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
lcd->drawBitmap(zone.x, zone.y, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
BitmapBuffer * buffer;
|
||||
uint32_t deps_hash;
|
||||
};
|
||||
|
||||
BaseWidgetFactory<ModelBitmapWidget> modelBitmapWidget("ModelBmp", NULL);
|
||||
const WidgetFactory * defaultWidget = &modelBitmapWidget;
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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 RECT_BORDER 1
|
||||
#define ROW_HEIGHT 17
|
||||
|
||||
#define VIEW_CHANNELS_LIMIT_PCT (g_model.extendedLimits ? LIMIT_EXT_PERCENT : 100)
|
||||
|
||||
class OutputsWidget: public Widget
|
||||
{
|
||||
public:
|
||||
OutputsWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
|
||||
uint8_t drawChannels(const uint16_t & x, const uint16_t & y, const uint16_t & w, const uint16_t & h, const uint8_t & firstChan, const bool & bg_shown, const uint16_t & bg_color)
|
||||
{
|
||||
const uint8_t numChan = h / ROW_HEIGHT;
|
||||
const uint8_t lastChan = firstChan + numChan;
|
||||
const uint8_t rowH = (h - numChan * ROW_HEIGHT >= numChan ? ROW_HEIGHT + 1 : ROW_HEIGHT);
|
||||
const uint16_t barW = w - RECT_BORDER * 2;
|
||||
const uint8_t barH = rowH - RECT_BORDER;
|
||||
const uint16_t barLft = x + RECT_BORDER;
|
||||
const uint16_t barMid = barLft + barW / 2;
|
||||
|
||||
for (uint8_t curChan = firstChan; curChan < lastChan && curChan <= MAX_OUTPUT_CHANNELS; curChan++) {
|
||||
const int16_t chanVal = calcRESXto100(channelOutputs[curChan-1]);
|
||||
const uint16_t rowTop = y + (curChan - firstChan) * rowH;
|
||||
const uint16_t barTop = rowTop + RECT_BORDER;
|
||||
const uint16_t fillW = divRoundClosest(barW * limit<int16_t>(0, abs(chanVal), VIEW_CHANNELS_LIMIT_PCT), VIEW_CHANNELS_LIMIT_PCT * 2);
|
||||
|
||||
if (bg_shown) {
|
||||
lcdSetColor(bg_color);
|
||||
lcdDrawSolidFilledRect(barLft, barTop, barW , barH, CUSTOM_COLOR);
|
||||
}
|
||||
if (fillW)
|
||||
lcdDrawSolidFilledRect((chanVal > 0 ? barMid : barMid - fillW), barTop, fillW, barH, MAINVIEW_GRAPHICS_COLOR);
|
||||
lcd->drawSolidVerticalLine(barMid, barTop, barH, MAINVIEW_GRAPHICS_COLOR);
|
||||
lcdDrawRect(x, rowTop, w, rowH + 1);
|
||||
lcdDrawNumber(x + barW - 10, barTop, chanVal, SMLSIZE | TEXT_COLOR | RIGHT, 0, NULL, "%");
|
||||
if (g_model.limitData[curChan - 1].name[0] != 0) {
|
||||
lcdDrawNumber(barLft + 1, barTop, curChan, SMLSIZE | TEXT_COLOR | LEFT | LEADING0, 2);
|
||||
lcdDrawSizedText(barLft + 23, barTop, g_model.limitData[curChan - 1].name, sizeof(g_model.limitData[curChan - 1].name), SMLSIZE | TEXT_COLOR | LEFT | ZCHAR);
|
||||
}
|
||||
else {
|
||||
putsChn(barLft + 1, barTop, curChan, SMLSIZE | TEXT_COLOR | LEFT);
|
||||
}
|
||||
}
|
||||
return lastChan - 1;
|
||||
}
|
||||
|
||||
void twoColumns()
|
||||
{
|
||||
uint8_t endColumn = drawChannels(zone.x, zone.y, zone.w / 2, zone.h, persistentData->options[0].unsignedValue, persistentData->options[1].boolValue, persistentData->options[2].unsignedValue);
|
||||
drawChannels(zone.x + zone.w / 2 + 2, zone.y, zone.w / 2, zone.h, endColumn + 1, persistentData->options[1].boolValue, persistentData->options[2].unsignedValue);
|
||||
}
|
||||
|
||||
void oneColumn()
|
||||
{
|
||||
drawChannels(zone.x, zone.y, zone.w, zone.h, persistentData->options[0].unsignedValue, persistentData->options[1].boolValue, persistentData->options[2].unsignedValue);
|
||||
}
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption OutputsWidget::options[] = {
|
||||
{ "First channel", ZoneOption::Integer, OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(1), OPTION_VALUE_UNSIGNED(32) },
|
||||
{ "Fill Background?", ZoneOption::Bool, OPTION_VALUE_BOOL(false) },
|
||||
{ "BG Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(LIGHTGREY) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
|
||||
void OutputsWidget::refresh()
|
||||
{
|
||||
if (zone.w > 300 && zone.h > 20)
|
||||
twoColumns();
|
||||
else if (zone.w > 150 && zone.h > 20)
|
||||
oneColumn();
|
||||
};
|
||||
|
||||
BaseWidgetFactory<OutputsWidget> outputsWidget("Outputs", OutputsWidget::options);
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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 TEXT_WIDGET_DEFAULT_LABEL '\15', '\347', '\0', '\14', '\377', '\376', '\373', '\364' // "My Label"
|
||||
|
||||
class TextWidget: public Widget
|
||||
{
|
||||
public:
|
||||
TextWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption TextWidget::options[] = {
|
||||
{ "Text", ZoneOption::String, OPTION_VALUE_STRING(TEXT_WIDGET_DEFAULT_LABEL) },
|
||||
{ "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(RED) },
|
||||
{ "Size", ZoneOption::TextSize, OPTION_VALUE_UNSIGNED(0) },
|
||||
{ "Shadow", ZoneOption::Bool, OPTION_VALUE_BOOL(false) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
void TextWidget::refresh()
|
||||
{
|
||||
lcdSetColor(persistentData->options[1].unsignedValue);
|
||||
LcdFlags fontsize = FONTSIZE(persistentData->options[2].unsignedValue << 8);
|
||||
if(persistentData->options[3].boolValue) {
|
||||
lcdDrawSizedText(zone.x+1, zone.y+1, persistentData->options[0].stringValue, sizeof(persistentData->options[0].stringValue), ZCHAR|fontsize|BLACK);
|
||||
}
|
||||
lcdDrawSizedText(zone.x, zone.y, persistentData->options[0].stringValue, sizeof(persistentData->options[0].stringValue), ZCHAR|fontsize|CUSTOM_COLOR);
|
||||
}
|
||||
|
||||
BaseWidgetFactory<TextWidget> textWidget("Text", TextWidget::options);
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 TimerWidget: public Widget
|
||||
{
|
||||
public:
|
||||
TimerWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption TimerWidget::options[] = {
|
||||
{ "Timer source", ZoneOption::Timer, OPTION_VALUE_UNSIGNED(0) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
void TimerWidget::refresh()
|
||||
{
|
||||
uint32_t index = persistentData->options[0].unsignedValue;
|
||||
TimerData & timerData = g_model.timers[index];
|
||||
TimerState & timerState = timersStates[index];
|
||||
|
||||
if (zone.w >= 180 && zone.h >= 70) {
|
||||
if (timerState.val >= 0 || !(timerState.val % 2)) {
|
||||
lcdDrawBitmapPattern(zone.x, zone.y, LBM_TIMER_BACKGROUND, MAINVIEW_PANES_COLOR);
|
||||
}
|
||||
else {
|
||||
lcdDrawBitmapPattern(zone.x, zone.y, LBM_TIMER_BACKGROUND, HEADER_BGCOLOR);
|
||||
}
|
||||
if (timerData.start && timerState.val >= 0) {
|
||||
lcdDrawBitmapPatternPie(
|
||||
zone.x + 2,
|
||||
zone.y + 3, LBM_RSCALE, MAINVIEW_GRAPHICS_COLOR, 0,
|
||||
timerState.val <= 0 ? 360 : 360 * (timerData.start - timerState.val) / timerData.start);
|
||||
}
|
||||
else {
|
||||
lcdDrawBitmapPattern(zone.x + 3, zone.y + 4, LBM_TIMER, MAINVIEW_GRAPHICS_COLOR);
|
||||
}
|
||||
if (abs(timerState.val) >= 3600) {
|
||||
drawTimer(zone.x + 70, zone.y + 31, abs(timerState.val), TEXT_COLOR | MIDSIZE | LEFT | TIMEHOUR);
|
||||
}
|
||||
else {
|
||||
drawTimer(zone.x + 76, zone.y + 31, abs(timerState.val), TEXT_COLOR | DBLSIZE | LEFT);
|
||||
}
|
||||
if (ZLEN(timerData.name) > 0) {
|
||||
lcdDrawSizedText(zone.x + 78, zone.y + 20, timerData.name, LEN_TIMER_NAME, ZCHAR | SMLSIZE | TEXT_COLOR);
|
||||
}
|
||||
else {
|
||||
drawStringWithIndex(zone.x + 137, zone.y + 17, "TMR", index + 1, SMLSIZE | TEXT_COLOR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (timerState.val < 0 && timerState.val % 2) {
|
||||
lcdDrawSolidFilledRect(zone.x, zone.y, zone.w, zone.h, HEADER_ICON_BGCOLOR);
|
||||
}
|
||||
drawStringWithIndex(zone.x + 2, zone.y, "TMR", index + 1, SMLSIZE | TEXT_INVERTED_COLOR);
|
||||
if (zone.w > 100 && zone.h > 40) {
|
||||
if (abs(timerState.val) >= 3600) {
|
||||
drawTimer(zone.x + 3, zone.y + 16, abs(timerState.val), TEXT_INVERTED_COLOR | LEFT | TIMEHOUR);
|
||||
}
|
||||
else {
|
||||
drawTimer(zone.x + 3, zone.y + 16, abs(timerState.val), TEXT_INVERTED_COLOR | LEFT | MIDSIZE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (abs(timerState.val) >= 3600) {
|
||||
drawTimer(zone.x + 3, zone.y + 14, abs(timerState.val), TEXT_INVERTED_COLOR | LEFT | SMLSIZE | TIMEHOUR);
|
||||
}
|
||||
else {
|
||||
drawTimer(zone.x + 3, zone.y + 14, abs(timerState.val), TEXT_INVERTED_COLOR | LEFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BaseWidgetFactory<TimerWidget> timerWidget("Timer", TimerWidget::options);
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 ValueWidget: public Widget
|
||||
{
|
||||
public:
|
||||
ValueWidget(const WidgetFactory * factory, const Zone & zone, Widget::PersistentData * persistentData):
|
||||
Widget(factory, zone, persistentData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void refresh();
|
||||
|
||||
static const ZoneOption options[];
|
||||
};
|
||||
|
||||
const ZoneOption ValueWidget::options[] = {
|
||||
{ "Source", ZoneOption::Source, OPTION_VALUE_UNSIGNED(MIXSRC_Rud) },
|
||||
{ "Color", ZoneOption::Color, OPTION_VALUE_UNSIGNED(WHITE) },
|
||||
{ "Shadow", ZoneOption::Bool, OPTION_VALUE_BOOL(false) },
|
||||
{ NULL, ZoneOption::Bool }
|
||||
};
|
||||
|
||||
void ValueWidget::refresh()
|
||||
{
|
||||
const int NUMBERS_PADDING = 4;
|
||||
|
||||
mixsrc_t field = persistentData->options[0].unsignedValue;
|
||||
lcdSetColor(persistentData->options[1].unsignedValue);
|
||||
|
||||
int x = zone.x;
|
||||
int y = zone.y;
|
||||
|
||||
// TRACE("w=%d, h=%d", zone.w, zone.h);
|
||||
|
||||
// lcdDrawFilledRect(zone.x, zone.y, zone.w, zone.h, SOLID, MAINVIEW_PANES_COLOR | OPACITY(5));
|
||||
|
||||
int xValue, yValue, xLabel, yLabel;
|
||||
LcdFlags attrValue, attrLabel=0;
|
||||
if (zone.w < 120 && zone.h < 50) {
|
||||
xValue = x;
|
||||
yValue = y+14;
|
||||
xLabel = x;
|
||||
yLabel = y;
|
||||
attrValue = LEFT | NO_UNIT | MIDSIZE;
|
||||
attrLabel = SMLSIZE;
|
||||
}
|
||||
else if (zone.h < 50) {
|
||||
xValue = x+zone.w-NUMBERS_PADDING;
|
||||
yValue = y-2;
|
||||
xLabel = x+NUMBERS_PADDING;
|
||||
yLabel = y+2;
|
||||
attrValue = RIGHT | NO_UNIT | DBLSIZE;
|
||||
}
|
||||
else {
|
||||
xValue = x+NUMBERS_PADDING;
|
||||
yValue = y+18;
|
||||
xLabel = x+NUMBERS_PADDING;
|
||||
yLabel = y+2;
|
||||
if (field >= MIXSRC_FIRST_TELEM) {
|
||||
if (isGPSSensor(1+(field-MIXSRC_FIRST_TELEM)/3)) {
|
||||
attrValue = LEFT | MIDSIZE | EXPANDED;
|
||||
}
|
||||
else {
|
||||
attrValue = LEFT | DBLSIZE;
|
||||
}
|
||||
}
|
||||
#if defined(INTERNAL_GPS)
|
||||
else if (field == MIXSRC_TX_GPS) {
|
||||
attrValue = LEFT | MIDSIZE | EXPANDED;
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
attrValue = LEFT | DBLSIZE;
|
||||
}
|
||||
}
|
||||
|
||||
if (field >= MIXSRC_FIRST_TIMER && field <= MIXSRC_LAST_TIMER) {
|
||||
TimerState & timerState = timersStates[field-MIXSRC_FIRST_TIMER];
|
||||
if (timerState.val < 0) {
|
||||
lcdSetColor(ALARM_COLOR_INDEX);
|
||||
}
|
||||
drawSource(x+NUMBERS_PADDING, y+2, field, CUSTOM_COLOR);
|
||||
drawSource(x+NUMBERS_PADDING + 1, y + 3, field, BLACK);
|
||||
drawTimer(xValue, yValue, abs(timerState.val), attrValue|DBLSIZE|CUSTOM_COLOR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (field >= MIXSRC_FIRST_TELEM) {
|
||||
TelemetryItem & telemetryItem = telemetryItems[(field-MIXSRC_FIRST_TELEM)/3]; // TODO macro to convert a source to a telemetry index
|
||||
if (!telemetryItem.isAvailable() || telemetryItem.isOld()) {
|
||||
lcdSetColor(ALARM_COLOR_INDEX);
|
||||
}
|
||||
}
|
||||
|
||||
if(persistentData->options[2].boolValue) {
|
||||
drawSource(xLabel + 1, yLabel + 1, field, attrLabel|BLACK);
|
||||
drawSourceValue(xValue + 1, yValue + 1, field, attrValue|BLACK);
|
||||
}
|
||||
drawSource(xLabel, yLabel, field, attrLabel|CUSTOM_COLOR);
|
||||
drawSourceValue(xValue, yValue, field, attrValue|CUSTOM_COLOR);
|
||||
|
||||
}
|
||||
|
||||
BaseWidgetFactory<ValueWidget> ValueWidget("Value", ValueWidget::options);
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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 _WIDGETS_CONTAINER_H_
|
||||
#define _WIDGETS_CONTAINER_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "widget.h"
|
||||
|
||||
class WidgetsContainerInterface
|
||||
{
|
||||
public:
|
||||
virtual unsigned int getZonesCount() const = 0;
|
||||
|
||||
virtual Zone getZone(unsigned int index) const = 0;
|
||||
|
||||
inline Widget * getWidget(unsigned int index)
|
||||
{
|
||||
return widgets[index];
|
||||
}
|
||||
|
||||
inline void setWidget(unsigned int index, Widget * widget)
|
||||
{
|
||||
widgets[index] = widget;
|
||||
}
|
||||
|
||||
virtual void createWidget(unsigned int index, const WidgetFactory * factory) = 0;
|
||||
|
||||
protected:
|
||||
Widget ** widgets;
|
||||
};
|
||||
|
||||
#define WIDGET_NAME_LEN 10
|
||||
|
||||
template<int N, int O>
|
||||
class WidgetsContainer: public WidgetsContainerInterface
|
||||
{
|
||||
public:
|
||||
struct ZonePersistentData {
|
||||
char widgetName[WIDGET_NAME_LEN];
|
||||
Widget::PersistentData widgetData;
|
||||
};
|
||||
|
||||
struct PersistentData {
|
||||
ZonePersistentData zones[N];
|
||||
ZoneOptionValue options[O];
|
||||
};
|
||||
|
||||
public:
|
||||
WidgetsContainer(PersistentData * persistentData):
|
||||
persistentData(persistentData)
|
||||
{
|
||||
widgets = (Widget **)calloc(N, sizeof(Widget *));
|
||||
}
|
||||
|
||||
virtual ~WidgetsContainer()
|
||||
{
|
||||
if (widgets) {
|
||||
for (uint8_t i=0; i<N; i++) {
|
||||
delete widgets[i];
|
||||
}
|
||||
free(widgets);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void createWidget(unsigned int index, const WidgetFactory * factory)
|
||||
{
|
||||
if (widgets) {
|
||||
memset(persistentData->zones[index].widgetName, 0, sizeof(persistentData->zones[index].widgetName));
|
||||
if (factory) {
|
||||
strncpy(persistentData->zones[index].widgetName, factory->getName(), sizeof(persistentData->zones[index].widgetName));
|
||||
widgets[index] = factory->create(getZone(index), &persistentData->zones[index].widgetData);
|
||||
}
|
||||
else {
|
||||
widgets[index] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void create()
|
||||
{
|
||||
memset(persistentData, 0, sizeof(PersistentData));
|
||||
}
|
||||
|
||||
virtual void load()
|
||||
{
|
||||
if (widgets) {
|
||||
unsigned int count = getZonesCount();
|
||||
for (unsigned int i=0; i<count; i++) {
|
||||
delete widgets[i];
|
||||
if (persistentData->zones[i].widgetName[0]) {
|
||||
char name[WIDGET_NAME_LEN + 1];
|
||||
memset(name, 0, sizeof(name));
|
||||
strncpy(name, persistentData->zones[i].widgetName, WIDGET_NAME_LEN);
|
||||
widgets[i] = loadWidget(name, getZone(i), &persistentData->zones[i].widgetData);
|
||||
}
|
||||
else {
|
||||
widgets[i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline ZoneOptionValue * getOptionValue(unsigned int index) const
|
||||
{
|
||||
return &persistentData->options[index];
|
||||
}
|
||||
|
||||
virtual unsigned int getZonesCount() const = 0;
|
||||
|
||||
virtual Zone getZone(unsigned int index) const = 0;
|
||||
|
||||
virtual void refresh()
|
||||
{
|
||||
if (widgets) {
|
||||
for (int i=0; i<N; i++) {
|
||||
if (widgets[i]) {
|
||||
widgets[i]->refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void background()
|
||||
{
|
||||
if (widgets) {
|
||||
for (int i=0; i<N; i++) {
|
||||
if (widgets[i]) {
|
||||
widgets[i]->background();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
PersistentData * persistentData;
|
||||
};
|
||||
|
||||
#endif // _WIDGETS_CONTAINER_H_
|
||||
@@ -0,0 +1,55 @@
|
||||
|
||||
#ifndef _ZONE_H_
|
||||
#define _ZONE_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#define LEN_ZONE_OPTION_STRING 8
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define OPTION_VALUE_UNSIGNED(x) uint32_t(x)
|
||||
#define OPTION_VALUE_SIGNED(x) uint32_t(x)
|
||||
#define OPTION_VALUE_BOOL(x) bool(x)
|
||||
#define OPTION_VALUE_STRING(...) *(ZoneOptionValue *)(const char *) #__VA_ARGS__
|
||||
#else
|
||||
#define OPTION_VALUE_UNSIGNED(x) { .unsignedValue = (x) }
|
||||
#define OPTION_VALUE_SIGNED(x) { .signedValue = (x) }
|
||||
#define OPTION_VALUE_BOOL(x) { .boolValue = (x) }
|
||||
#define OPTION_VALUE_STRING(...) { .stringValue = {__VA_ARGS__} }
|
||||
#endif
|
||||
|
||||
struct Zone
|
||||
{
|
||||
uint16_t x, y, w, h;
|
||||
};
|
||||
|
||||
union ZoneOptionValue
|
||||
{
|
||||
uint32_t unsignedValue;
|
||||
int32_t signedValue;
|
||||
bool boolValue;
|
||||
char stringValue[LEN_ZONE_OPTION_STRING];
|
||||
};
|
||||
|
||||
struct ZoneOption
|
||||
{
|
||||
enum Type {
|
||||
Integer,
|
||||
Source,
|
||||
Bool,
|
||||
String,
|
||||
File,
|
||||
TextSize,
|
||||
Timer,
|
||||
Switch,
|
||||
Color
|
||||
};
|
||||
|
||||
const char * name;
|
||||
Type type;
|
||||
ZoneOptionValue deflt;
|
||||
ZoneOptionValue min;
|
||||
ZoneOptionValue max;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user