Files
edgetx-gx12/companion/src/wizarddata.cpp
T
c8693569b0 feat(color): New label based Model Selector (#1374)
* Model Labels Selector

* Portrait Layout

* Receiver ID Check

* Fix Labels .yml format

* Companion Initial Commit

commit 967ddf3979b4954402fe62c858faba4b7a416bba
Author: dlktdr <cblackburn320@gmail.com>
Date:   Mon Aug 29 01:49:15 2022 -0700

    Fix Labels .yml format

commit 534221cad9e01146c47a9ac1080a655e04f1f6c8
Author: dlktdr <cblackburn320@gmail.com>
Date:   Mon Aug 29 01:20:57 2022 -0700

    Receiver ID Check

commit f32c0939d44e9ae60bc0705a9176354c23fec198
Author: dlktdr <cblackburn320@gmail.com>
Date:   Sun Aug 28 23:13:25 2022 -0700

    Portrait Layout

commit 961181217c7841ff3f21299ac6aa419b810f80e9
Author: dlktdr <cblackburn320@gmail.com>
Date:   Sat Dec 11 16:56:13 2021 -0800

    Model Labels Selector

commit dc99dd40d2
Author: David PHAM-VAN <1387855+DavBfr@users.noreply.github.com>
Date:   Fri Aug 26 03:04:34 2022 -0300

    feat: Allow Lua widget to override built-in widget with same name (#2208)

    * Allow CPP Widgets Override with LUA

    * Reset a widget option it the type differs

commit 4b747caff9
Author: eshifri <46511024+eshifri@users.noreply.github.com>
Date:   Thu Aug 25 19:47:53 2022 -0700

    fix: Write model name into models.yml when duplicating model (#2224)

    * Update model name in the models.yml file (#2214)

    * Fix the length of the name.

commit e97f23a305
Author: eshifri <46511024+eshifri@users.noreply.github.com>
Date:   Wed Aug 24 21:19:52 2022 -0700

    fix(cpn): Fix full path to model notes for Simulator (#2223)

* Correct Highlighted Column

* labels .yml indentation

* Update da.h

New defines translated to Danish

* Update dataconstants.h

Omit warnings due to difference of LEN_MODEL_FILENAME and LEN_MODEL_NAME in modellist.cpp

* Update modelslist.cpp

Wonder if this are the right file in PR #1374 (?), seems a lot are changed to the better in #1374

* Update dataconstants.h

Restore #define for LEN_MODEL_FILENAME to 16

* Rebase, Correct Issues

Delete now deletes instead of select
New model stores correct information
Duplicate save all information in cell
Rework items to use cell over button
Reword function variables

* CMPN: Add context menu

Fix output not functional. Removed Yaml::null at some point :)
Fix some compiler warnings

* CMPN: Compiler warning, replace ,->_ in list

* FW: Various Changes

Change view to a grid
Don't allow comma in label name
Add scroll indicators
Save sort order

Co-authored-by: HThuren <99370924+HThuren@users.noreply.github.com>
2022-09-03 09:01:19 +10:00

150 lines
4.8 KiB
C++

/*
* 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 <string.h>
#include "eeprominterface.h"
#include "wizarddata.h"
Channel::Channel()
{
clear();
}
void Channel::clear()
{
page = Page_None;
prebooked = false;
input1 = NO_INPUT;
input2 = NO_INPUT;
weight1 = 0;
weight2 = 0;
}
WizMix::WizMix(const GeneralSettings & settings, unsigned int modelId, const ModelData & modelData):
complete(false),
modelId(modelId),
settings(settings),
originalModelData(modelData),
vehicle(NOVEHICLE)
{
memset(name, 0, sizeof(name));
strncpy(name, originalModelData.name, sizeof(name)-1);
}
void WizMix::maxMixSwitch(char *name, MixData &mix, int channel, int sw, int weight)
{
memset(mix.name, 0, sizeof(mix.name));
strncpy(mix.name, name, sizeof(mix.name)-1);
mix.destCh = channel;
mix.srcRaw = RawSource(SOURCE_TYPE_MAX);
mix.swtch = RawSwitch(SWITCH_TYPE_SWITCH, sw);
mix.weight = weight;
}
void WizMix::addMix(ModelData &model, Input input, int weight, int channel, int & mixIndex)
{
if (input != NO_INPUT) {
if (input >= RUDDER_INPUT && input <= AILERONS_INPUT) {
MixData & mix = model.mixData[mixIndex++];
mix.destCh = channel+1;
if (IS_SKY9X(getCurrentBoard())) {
mix.srcRaw = RawSource(SOURCE_TYPE_STICK, input-1);
}
else {
int channel = settings.getDefaultChannel(input-1);
mix.srcRaw = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, channel);
}
mix.weight = weight;
}
else if (input==FLAPS_INPUT){
// There ought to be some kind of constants for switches somewhere...
maxMixSwitch((char *)"Flaps Up", model.mixData[mixIndex++], channel+1, IS_SKY9X(getCurrentBoard()) ? -SWITCH_ELE : SWITCH_SA0, weight); //Taranis-Horus SA-UP, 9X ELE-UP
maxMixSwitch((char *)"Flaps Dn", model.mixData[mixIndex++], channel+1, IS_SKY9X(getCurrentBoard()) ? SWITCH_ELE : SWITCH_SA2, -weight); //Taranis-Horus SA-DOWN, 9X ELE-DOWN
}
else if (input==AIRBRAKES_INPUT){
maxMixSwitch((char *)"AirbkOff", model.mixData[mixIndex++], channel+1, IS_SKY9X(getCurrentBoard()) ? -SWITCH_RUD : SWITCH_SE0, -weight); //Taranis-Horus SE-UP, 9X RUD-UP
maxMixSwitch((char *)"AirbkOn", model.mixData[mixIndex++], channel+1, IS_SKY9X(getCurrentBoard()) ? SWITCH_RUD : SWITCH_SE2, weight); //Tatanis-Horus SE-DOWN, 9X RUD-DOWN
}
}
}
WizMix::operator ModelData()
{
int throttleChannel = -1;
ModelData model;
model.labels[0] = '\0';
model.used = true;
model.moduleData[0].modelId = modelId;
model.setDefaultInputs(settings);
int mixIndex = 0;
int timerIndex = 0;
// Safe copy model name
memset(model.name, 0, sizeof(model.name));
strncpy(model.name, name, sizeof(model.name)-1);
// Add the channel mixes
for (int i=0; i<WIZ_MAX_CHANNELS; i++ )
{
Channel ch = channel[i];
addMix(model, ch.input1, ch.weight1, i, mixIndex);
addMix(model, ch.input2, ch.weight2, i, mixIndex);
if (ch.input1 == THROTTLE_INPUT || ch.input2 == THROTTLE_INPUT) {
throttleChannel++;
if (options[THROTTLE_CUT_OPTION]) {
// Add the Throttle Cut option
MixData & mix = model.mixData[mixIndex++];
mix.destCh = i+1;
mix.srcRaw = SOURCE_TYPE_MAX;
mix.weight = -100;
mix.swtch.type = SWITCH_TYPE_SWITCH;
mix.swtch.index = IS_SKY9X(getCurrentBoard()) ? SWITCH_THR : SWITCH_SF0;
mix.mltpx = MLTPX_REP;
memset(mix.name, 0, sizeof(mix.name));
strncpy(mix.name, "Cut", MIXDATA_NAME_LEN);
}
}
}
// Add the Flight Timer option
if (options[FLIGHT_TIMER_OPTION] && throttleChannel >= 0){
memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
strncpy(model.timers[timerIndex].name, "Flt", sizeof(model.timers[timerIndex].name)-1);
model.timers[timerIndex].mode = TimerData::TIMERMODE_START;
timerIndex++;
}
// Add the Throttle Timer option
if (options[THROTTLE_TIMER_OPTION] && throttleChannel >= 0){
memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
strncpy(model.timers[timerIndex].name, "Thr", sizeof(model.timers[timerIndex].name)-1);
model.timers[timerIndex].mode = TimerData::TIMERMODE_THR;
timerIndex++;
}
return model;
}