[Companion] Show custom control names throughout the UI (& internal refactoring) (#4693)

* [Companion] Introduce new Boards class to further consolidate hardware metadata and remove some globals.

* [Companion] * RawSource::toString() and RawSwitch::toString() can now return custom hardware names (if given a GeneralSettings object) for the following types (respectively):
    SOURCE_TYPE_STICK, SOURCE_TYPE_SWITCH, SWITCH_TYPE_SWITCH, & SWITCH_TYPE_MULTIPOS_POT;
* RawSource::isPot() and isSlider() can now return their own index position in potConfig[]/sliderConfig[];
* Switch indicator strings can be localized if necessary.

* [Companion] Refactor model printers to use new RawSource/RawSwitch capabilities; Simplify model-to-printer mapping scheme in multimodelprinter; Use const ModelData pointer.

* [Companion] Refactor how RawSource and RawSwitch selection combo boxes are populated, using cache-able data models instead of direct manipulation; Refactor some other Helpers function into their own namespace.

* Cosmetics & forgotten qualifier.
This commit is contained in:
Max Paperno
2017-03-27 19:02:19 +02:00
committed by Bertrand Songis
parent 627347a48c
commit f5ab145d2f
40 changed files with 886 additions and 747 deletions
@@ -116,7 +116,7 @@ unsigned long Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, i
std::bitset<NUM_ERRORS> errors;
if (size != getEEpromSize(Board::BOARD_STOCK)) {
if (size != Boards::getEEpromSize(Board::BOARD_STOCK)) {
std::cout << "wrong size\n";
errors.set(WRONG_SIZE);
return errors.to_ulong();
@@ -127,7 +127,7 @@ unsigned long Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, i
errors.set(WRONG_FILE_SYSTEM);
return errors.to_ulong();
}
efile->openRd(FILE_GENERAL);
Er9xGeneral er9xGeneral;
@@ -164,7 +164,7 @@ unsigned long Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, i
}
radioData.generalSettings = er9xGeneral;
for (int i=0; i<getCapability(Models); i++) {
Er9xModelData er9xModel;
efile->openRd(FILE_MODEL(i));
@@ -174,7 +174,7 @@ unsigned long Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, i
else {
applyStickModeToModel(er9xModel, radioData.generalSettings.stickMode+1);
radioData.models[i] = er9xModel;
}
}
}
std::cout << "ok\n";
@@ -329,4 +329,4 @@ int Er9xInterface::getCapability(Capability capability)
default:
return 0;
}
}
}
@@ -158,7 +158,7 @@ unsigned long Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom
std::bitset<NUM_ERRORS> errors;
if (size != EESIZE_SKY9X) {
if (size != Boards::getEEpromSize(Board::BOARD_SKY9X)) {
std::cout << "wrong size\n";
errors.set(WRONG_SIZE);
return errors.to_ulong();
@@ -169,7 +169,7 @@ unsigned long Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom
errors.set(WRONG_FILE_SYSTEM);
return errors.to_ulong();
}
efile->openRd(FILE_GENERAL);
Ersky9xGeneral ersky9xGeneral;
@@ -198,13 +198,13 @@ unsigned long Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom
return errors.to_ulong();
}
radioData.generalSettings = ersky9xGeneral;
for (int i=0; i<getCapability(Models); i++) {
uint8_t buffer[4096];
uint size;
memset(buffer,0,sizeof(buffer));
efile->openRd(FILE_MODEL(i));
// if (!efile->readRlc2((uint8_t*)&ersky9xModel, sizeof(Ersky9xModelData))) {
size = efile->readRlc2(buffer, 4096);
if (!size) {
@@ -222,7 +222,7 @@ unsigned long Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom
applyStickModeToModel(ersky9xModel, radioData.generalSettings.stickMode+1);
radioData.models[i] = ersky9xModel;
}
}
}
}
std::cout << "ok\n";
@@ -382,4 +382,4 @@ int Ersky9xInterface::getCapability(Capability capability)
default:
return 0;
}
}
}
@@ -955,9 +955,9 @@ class FlightModeField: public TransformedField {
Board::Type board;
unsigned int version;
int rotencCount;
int trimBase[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS];
int trimExt[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS];
unsigned int trimMode[CPN_MAX_STICKS+CPN_MAX_AUX_TRIMS];
int trimBase[CPN_MAX_TRIMS];
int trimExt[CPN_MAX_TRIMS];
unsigned int trimMode[CPN_MAX_TRIMS];
};
class MixField: public TransformedField {
@@ -207,7 +207,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *
std::bitset<NUM_ERRORS> errors;
if (size != getEEpromSize(board)) {
if (size != Boards::getEEpromSize(board)) {
if (size == 4096) {
int notnull = false;
for (int i = 2048; i < 4096; i++) {
@@ -227,7 +227,7 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *
}
}
else {
std::cout << " wrong size (" << size << "/" << getEEpromSize(board) << ")\n";
std::cout << " wrong size (" << size << "/" << Boards::getEEpromSize(board) << ")\n";
errors.set(WRONG_SIZE);
return errors.to_ulong();
}
@@ -330,7 +330,7 @@ int OpenTxEepromInterface::save(uint8_t * eeprom, const RadioData & radioData, u
version = getLastDataVersion(board);
}
int size = getEEpromSize(board);
int size = Boards::getEEpromSize(board);
efile->EeFsCreate(eeprom, size, board, version);
@@ -379,8 +379,8 @@ int OpenTxEepromInterface::getSize(const ModelData &model)
if (model.isEmpty())
return 0;
QByteArray tmp(EESIZE_MAX, 0);
efile->EeFsCreate((uint8_t *) tmp.data(), EESIZE_MAX, board, 255/*version max*/);
QByteArray tmp(Boards::getEEpromSize(Board::BOARD_UNKNOWN), 0);
efile->EeFsCreate((uint8_t *) tmp.data(), Boards::getEEpromSize(Board::BOARD_UNKNOWN), board, 255/*version max*/);
OpenTxModelData open9xModel((ModelData &) model, board, 255/*version max*/, getCurrentFirmware()->getVariantNumber());
@@ -398,8 +398,8 @@ int OpenTxEepromInterface::getSize(const GeneralSettings &settings)
if (IS_SKY9X(board))
return 0;
QByteArray tmp(EESIZE_MAX, 0);
efile->EeFsCreate((uint8_t *) tmp.data(), EESIZE_MAX, board, 255);
QByteArray tmp(Boards::getEEpromSize(Board::BOARD_UNKNOWN), 0);
efile->EeFsCreate((uint8_t *) tmp.data(), Boards::getEEpromSize(Board::BOARD_UNKNOWN), board, 255);
OpenTxGeneralData open9xGeneral((GeneralSettings &) settings, board, 255, getCurrentFirmware()->getVariantNumber());
// open9xGeneral.Dump();
@@ -570,7 +570,9 @@ int OpenTxFirmware::getCapability(::Capability capability)
return (IS_ARM(board) ? 1 : 0);
case ExtraInputs:
return 1;
case ExtendedTrims:
case TrimsRange:
return 125;
case ExtendedTrimsRange:
return 500;
case Simulation:
return 1;
@@ -727,7 +729,7 @@ int OpenTxFirmware::getCapability(::Capability capability)
QString OpenTxFirmware::getAnalogInputName(unsigned int index)
{
if (index < 4) {
if ((int)index < getBoardCapability(board, Board::Sticks)) {
const QString sticks[] = {
QObject::tr("Rud"),
QObject::tr("Ele"),
@@ -737,7 +739,7 @@ QString OpenTxFirmware::getAnalogInputName(unsigned int index)
return sticks[index];
}
index -= 4;
index -= getBoardCapability(board, Board::Sticks);
if (IS_9X(board) || IS_2560(board) || IS_SKY9X(board)) {
const QString pots[] = {