Files movement continued ...

This commit is contained in:
bsongis
2015-01-10 09:11:28 +01:00
parent bfeab1402c
commit f51d8e1b6c
11 changed files with 107 additions and 35 deletions
+188
View File
@@ -0,0 +1,188 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* 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 (!listSdFiles(SCRIPTS_MIXES_PATH, SCRIPTS_EXT, sizeof(sd.file), NULL)) {
POPUP_WARNING(STR_NO_SCRIPTS_ON_SD);
s_menu_flags = 0;
}
}
else {
// The user choosed a lua file in the list
copySelection(sd.file, result, sizeof(sd.file));
memset(sd.inputs, 0, sizeof(sd.inputs));
eeDirty(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 (12*FW)
#define SCRIPT_ONE_3RD_COLUMN_POS (23*FW)
void menuModelCustomScriptOne(uint8_t event)
{
TITLE(STR_MENUCUSTOMSCRIPT);
ScriptData &sd = g_model.scriptsData[s_currIdx];
putsStrIdx(lcdLastPos+FW, 0, "LUA", s_currIdx+1, 0);
SUBMENU_NOTITLE(3+scriptInputsOutputs[s_currIdx].inputsCount, { 0, 0, LABEL(inputs), 0/*repeated*/ });
int8_t sub = m_posVert;
for (uint8_t k=0; k<LCD_LINES-1; k++) {
coord_t y = MENU_TITLE_HEIGHT + 1 + k*FH;
uint8_t i = k + s_pgOfs;
uint8_t attr = (sub==i ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0);
if (i == ITEM_MODEL_CUSTOMSCRIPT_FILE) {
lcd_putsLeft(y, STR_SCRIPT);
if (ZEXIST(sd.file))
lcd_putsnAtt(SCRIPT_ONE_2ND_COLUMN_POS, y, sd.file, sizeof(sd.file), attr);
else
lcd_putsiAtt(SCRIPT_ONE_2ND_COLUMN_POS, y, STR_VCSWFUNC, 0, attr);
if (attr && event==EVT_KEY_BREAK(KEY_ENTER) && !READ_ONLY()) {
s_editMode = 0;
if (listSdFiles(SCRIPTS_MIXES_PATH, SCRIPTS_EXT, sizeof(sd.file), sd.file, LIST_NONE_SD_FILE)) {
menuHandler = onModelCustomScriptMenu;
}
else {
POPUP_WARNING(STR_NO_SCRIPTS_ON_SD);
s_menu_flags = 0;
}
}
}
else if (i == ITEM_MODEL_CUSTOMSCRIPT_NAME) {
lcd_putsLeft(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) {
lcd_putsLeft(y, STR_INPUTS);
}
else if (i <= ITEM_MODEL_CUSTOMSCRIPT_PARAMS_LABEL+scriptInputsOutputs[s_currIdx].inputsCount) {
int inputIdx = i-ITEM_MODEL_CUSTOMSCRIPT_PARAMS_LABEL-1;
lcd_putsnAtt(INDENT_WIDTH, y, scriptInputsOutputs[s_currIdx].inputs[inputIdx].name, 10, 0);
if (scriptInputsOutputs[s_currIdx].inputs[inputIdx].type == 0) {
lcd_outdezAtt(SCRIPT_ONE_2ND_COLUMN_POS, y, g_model.scriptsData[s_currIdx].inputs[inputIdx]+scriptInputsOutputs[s_currIdx].inputs[inputIdx].def, attr|LEFT);
if (attr) {
CHECK_INCDEC_MODELVAR(event, g_model.scriptsData[s_currIdx].inputs[inputIdx], 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 {
putsMixerSource(SCRIPT_ONE_2ND_COLUMN_POS, y, g_model.scriptsData[s_currIdx].inputs[inputIdx]+scriptInputsOutputs[s_currIdx].inputs[inputIdx].def, attr);
if (attr) {
uint8_t *source = (uint8_t *)&g_model.scriptsData[s_currIdx].inputs[inputIdx];
CHECK_INCDEC_MODELSOURCE(event, *source, scriptInputsOutputs[s_currIdx].inputs[inputIdx].min-scriptInputsOutputs[s_currIdx].inputs[inputIdx].def, scriptInputsOutputs[s_currIdx].inputs[inputIdx].max-scriptInputsOutputs[s_currIdx].inputs[inputIdx].def);
}
}
}
}
if (scriptInputsOutputs[s_currIdx].outputsCount > 0) {
lcd_vline(SCRIPT_ONE_3RD_COLUMN_POS-4, FH+1, LCD_H-FH-1);
lcd_puts(SCRIPT_ONE_3RD_COLUMN_POS, FH+1, STR_OUTPUTS);
for (int i=0; i<scriptInputsOutputs[s_currIdx].outputsCount; i++) {
putsMixerSource(SCRIPT_ONE_3RD_COLUMN_POS+INDENT_WIDTH, FH+1+FH+i*FH, MIXSRC_FIRST_LUA+(s_currIdx*MAX_SCRIPT_OUTPUTS)+i, 0);
lcd_outdezNAtt(SCRIPT_ONE_3RD_COLUMN_POS+11*FW+3, FH+1+FH+i*FH, calcRESXto1000(scriptInputsOutputs[s_currIdx].outputs[i].value), PREC1);
}
}
}
void menuModelCustomScripts(uint8_t event)
{
lcd_outdezAtt(19*FW, 0, luaGetMemUsed(), 0);
lcd_puts(19*FW+1, 0, STR_BYTES);
MENU(STR_MENUCUSTOMSCRIPTS, menuTabModel, e_CustomScripts, MAX_SCRIPTS+1, {0, NAVIGATION_LINE_BY_LINE|3/*repeated*/});
coord_t y;
int8_t sub = m_posVert - 1;
switch (event) {
case EVT_KEY_FIRST(KEY_ENTER):
if (sub >= 0) {
s_currIdx = sub;
pushMenu(menuModelCustomScriptOne);
}
break;
}
for (int i=0, scriptIndex=0; i<MAX_SCRIPTS; i++) {
y = 1 + (i+1)*FH;
ScriptData &sd = g_model.scriptsData[i];
// LUAx header
putsStrIdx(0, y, "LUA", i+1, sub==i ? INVERS : 0);
// LUA script
if (ZEXIST(sd.file)) {
lcd_putsnAtt(5*FW, y, sd.file, sizeof(sd.file), 0);
switch (scriptInternalData[scriptIndex].state) {
case SCRIPT_SYNTAX_ERROR:
lcd_puts(30*FW+2, y, "(error)");
break;
case SCRIPT_KILLED:
lcd_puts(29*FW+2, y, "(killed)");
break;
default:
lcd_outdezAtt(34*FW, y, luaGetCpuUsed(scriptIndex));
lcd_putc(34*FW, y, '%');
break;
}
scriptIndex++;
}
else {
lcd_putsiAtt(5*FW, y, STR_VCSWFUNC, 0, 0);
}
// Script name
lcd_putsnAtt(16*FW, y, sd.name, sizeof(sd.name), ZCHAR);
}
}
+153
View File
@@ -0,0 +1,153 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* 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 onGVARSMenu(const char *result)
{
int8_t sub = m_posVert - 1;
if (result == STR_ENABLE_POPUP) {
g_model.gvars[sub].popup = true;
eeDirty(EE_MODEL);
}
else if (result == STR_DISABLE_POPUP) {
g_model.gvars[sub].popup = false;
eeDirty(EE_MODEL);
}
else if (result == STR_CLEAR) {
for (int i=0; i<MAX_FLIGHT_MODES; i++) {
g_model.flightModeData[i].gvars[sub] = 0;
}
eeDirty(EE_MODEL);
}
}
#define GVARS_FM_COLUMN(p) (12*FW + FWNUM + (p)*(2+3*FWNUM) - 3)
void menuModelGVars(uint8_t event)
{
tmr10ms_t tmr10ms = get_tmr10ms();
const char * menuTitle;
bool first2seconds = (tmr10ms - menuEntryTime > 200); /*2 seconds*/
if (first2seconds) {
menuTitle = STR_GLOBAL_V;
for (int i=0; i<MAX_GVARS; i++) {
putsStrIdx(GVARS_FM_COLUMN(i)-16, 1, STR_FP, i, SMLSIZE|(getFlightMode()==i ? INVERS : 0));
}
}
else {
menuTitle = STR_MENUGLOBALVARS;
}
MENU_FLAGS(menuTitle, menuTabModel, e_GVars, first2seconds ? CHECK_FLAG_NO_SCREEN_INDEX : 0, 1+MAX_GVARS, {0, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES, NAVIGATION_LINE_BY_LINE|MAX_FLIGHT_MODES});
uint8_t sub = m_posVert - 1;
#if MAX_GVARS > 6
for (uint8_t l=0; l<LCD_LINES-1; l++) {
uint8_t i = l+s_pgOfs;
coord_t y = MENU_TITLE_HEIGHT + 1 + l*FH;
#elif MAX_GVARS == 6
for (uint8_t i=0; i<MAX_GVARS; i++) {
coord_t y = MENU_TITLE_HEIGHT + FH + 1 + i*FH;
#else
for (uint8_t i=0; i<MAX_GVARS; i++) {
coord_t y = MENU_TITLE_HEIGHT + 2*FH + 1 + i*FH;
#endif
if (g_model.gvars[i].popup) lcd_putc(3*FW, y, '!');
putsStrIdx(0, y, STR_GV, i+1, (sub==i && m_posHorz<0) ? INVERS : 0);
for (uint8_t j=0; j<1+MAX_FLIGHT_MODES; j++) {
LcdFlags attr = ((sub==i && m_posHorz==j) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
coord_t x = GVARS_FM_COLUMN(j-1);
#if MAX_GVARS == 6
if (i==0 && j!=9) putsStrIdx(x+2, FH+1, STR_FP, j, SMLSIZE);
#elif MAX_GVARS <= 5
if (i==0 && j!=9) putsStrIdx(x+2, 2*FH, STR_FP, j, SMLSIZE);
#endif
switch(j)
{
case 0:
editName(4*FW-3, y, g_model.gvars[i].name, LEN_GVAR_NAME, event, attr);
break;
default:
{
FlightModeData *fm = &g_model.flightModeData[j-1];
int16_t & v = fm->gvars[i];
int16_t vmin, vmax;
if (v > GVAR_MAX) {
uint8_t p = v - GVAR_MAX - 1;
if (p >= j-1) p++;
putsFlightMode(x-15, y, p+1, attr|SMLSIZE);
vmin = GVAR_MAX+1; vmax = GVAR_MAX+MAX_FLIGHT_MODES-1;
}
else {
if (abs(v) >= 100)
lcd_outdezAtt(x, y+1, v, attr | TINSIZE);
else
lcd_outdezAtt(x, y, v, attr);
vmin = -GVAR_MAX; vmax = GVAR_MAX;
}
if (attr) {
if (event == EVT_KEY_LONG(KEY_ENTER)) {
v = (v > GVAR_MAX ? 0 : GVAR_MAX+1);
eeDirty(EE_MODEL);
}
else if (s_editMode>0 || p1valdiff) {
v = checkIncDec(event, v, vmin, vmax, EE_MODEL);
}
}
break;
}
}
}
}
if (m_posVert > 0 && m_posHorz < 0 && event==EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
if (g_model.gvars[sub].popup)
MENU_ADD_ITEM(STR_DISABLE_POPUP);
else
MENU_ADD_ITEM(STR_ENABLE_POPUP);
MENU_ADD_ITEM(STR_CLEAR);
menuHandler = onGVARSMenu;
}
}
+88
View File
@@ -0,0 +1,88 @@
/*
* Authors (alphabetical order)
* - Andre Bernet <bernet.andre@gmail.com>
* - Andreas Weitl
* - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv
* - Gabriel Birkus
* - Jean-Pierre Parisy
* - Karl Szmutny
* - Michael Blandford
* - Michal Hlavinka
* - Pat Mackenzie
* - Philip Moss
* - Rob Thomson
* - Thomas Husterer
*
* opentx is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
*
* 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 menuModelHeliItems {
ITEM_HELI_SWASHTYPE,
ITEM_HELI_COLLECTIVE,
ITEM_HELI_SWASHRING,
ITEM_HELI_ELEDIRECTION,
ITEM_HELI_AILDIRECTION,
ITEM_HELI_COLDIRECTION
};
#define HELI_PARAM_OFS (23*FW)
void menuModelHeli(uint8_t event)
{
SIMPLE_MENU(STR_MENUHELISETUP, menuTabModel, e_Heli, 7);
uint8_t sub = m_posVert - 1;
for (uint8_t i=0; i<6; i++) {
coord_t y = MENU_TITLE_HEIGHT + 1 + i*FH;
uint8_t attr = (sub == i ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0);
switch(i) {
case ITEM_HELI_SWASHTYPE:
g_model.swashR.type = selectMenuItem(HELI_PARAM_OFS, y, STR_SWASHTYPE, STR_VSWASHTYPE, g_model.swashR.type, 0, SWASH_TYPE_MAX, attr, event);
break;
case ITEM_HELI_COLLECTIVE:
lcd_putsLeft(y, STR_COLLECTIVE);
if (attr) CHECK_INCDEC_MODELSOURCE(event, g_model.swashR.collectiveSource, 0, MIXSRC_LAST_CH);
putsMixerSource(HELI_PARAM_OFS, y, g_model.swashR.collectiveSource, attr);
break;
case ITEM_HELI_SWASHRING:
lcd_putsLeft(y, STR_SWASHRING);
lcd_outdezAtt(HELI_PARAM_OFS, y, g_model.swashR.value, LEFT|attr);
if (attr) CHECK_INCDEC_MODELVAR_ZERO(event, g_model.swashR.value, 100);
break;
case ITEM_HELI_ELEDIRECTION:
g_model.swashR.invertELE = selectMenuItem(HELI_PARAM_OFS, y, STR_ELEDIRECTION, STR_MMMINV, g_model.swashR.invertELE, 0, 1, attr, event);
break;
case ITEM_HELI_AILDIRECTION:
g_model.swashR.invertAIL = selectMenuItem(HELI_PARAM_OFS, y, STR_AILDIRECTION, STR_MMMINV, g_model.swashR.invertAIL, 0, 1, attr, event);
break;
case ITEM_HELI_COLDIRECTION:
g_model.swashR.invertCOL = selectMenuItem(HELI_PARAM_OFS, y, STR_COLDIRECTION, STR_MMMINV, g_model.swashR.invertCOL, 0, 1, attr, event);
break;
}
}
}