[Companion] Old EEPROM support removed

This commit is contained in:
Bertrand Songis
2016-11-23 16:40:47 +01:00
parent 9590b5f00e
commit 5f9737fc70
73 changed files with 1309 additions and 9277 deletions
+88 -45
View File
@@ -5,11 +5,9 @@
#include <stdlib.h>
#include "eeprominterface.h"
#include "firmwares/er9x/er9xinterface.h"
#include "firmwares/th9x/th9xinterface.h"
#include "firmwares/gruvin9x/gruvin9xinterface.h"
#include "firmwares/ersky9x/ersky9xinterface.h"
#include "firmwares/opentx/opentxinterface.h"
#include "firmwares/opentx/opentxeeprom.h"
#include "firmwares/ersky9x/ersky9xinterface.h"
#include "appdata.h"
#include "helpers.h"
#include "wizarddata.h"
@@ -24,6 +22,8 @@ const uint8_t chout_ar[] = { // First number is 0..23 -> template setup, Second
4,1,2,3 , 4,1,3,2 , 4,2,1,3 , 4,2,3,1 , 4,3,1,2 , 4,3,2,1
};
static const char specialCharsTab[] = "_-.,";
void setEEPROMString(char *dst, const char *src, int size)
{
memcpy(dst, src, size);
@@ -47,6 +47,52 @@ void getEEPROMString(char *dst, const char *src, int size)
}
}
int8_t char2idx(char c)
{
if (c==' ') return 0;
if (c>='A' && c<='Z') return 1+c-'A';
if (c>='a' && c<='z') return -1-c+'a';
if (c>='0' && c<='9') return 27+c-'0';
for (int8_t i=0;;i++) {
char cc = specialCharsTab[i];
if (cc==0) return 0;
if (cc==c) return 37+i;
}
}
#define ZCHAR_MAX 40
char idx2char(int8_t idx)
{
if (idx == 0) return ' ';
if (idx < 0) {
if (idx > -27) return 'a' - idx - 1;
idx = -idx;
}
if (idx < 27) return 'A' + idx - 1;
if (idx < 37) return '0' + idx - 27;
if (idx <= ZCHAR_MAX) return specialCharsTab[idx-37];
return ' ';
}
void setEEPROMZString(char *dst, const char *src, int size)
{
for (int i=size-1; i>=0; i--)
dst[i] = char2idx(src[i]);
}
void getEEPROMZString(char *dst, const char *src, int size)
{
for (int i=size-1; i>=0; i--)
dst[i] = idx2char(src[i]);
dst[size] = '\0';
for (int i=size-1; i>=0; i--) {
if (dst[i] == ' ')
dst[i] = '\0';
else
break;
}
}
float ValToTim(int value)
{
return ((value < -109 ? 129+value : (value < 7 ? (113+value)*5 : (53+value)*10))/10.0);
@@ -525,15 +571,15 @@ QString RawSource::toString(const ModelData * model) const
bool RawSource::isPot() const
{
return (type == SOURCE_TYPE_STICK &&
index >= NUM_STICKS &&
index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots));
index >= CPN_MAX_STICKS &&
index < CPN_MAX_STICKS+GetCurrentFirmware()->getCapability(Pots));
}
bool RawSource::isSlider() const
{
return (type == SOURCE_TYPE_STICK &&
index >= NUM_STICKS+GetCurrentFirmware()->getCapability(Pots) &&
index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders));
index >= CPN_MAX_STICKS+GetCurrentFirmware()->getCapability(Pots) &&
index < CPN_MAX_STICKS+GetCurrentFirmware()->getCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders));
}
QString RawSwitch::toString() const
@@ -804,7 +850,7 @@ void CustomFunctionData::populateResetParams(const ModelData * model, QComboBox
b->setCurrentIndex(value);
}
if (model && IS_ARM(board)) {
for (int i=0; i<C9X_MAX_SENSORS; ++i) {
for (int i=0; i<CPN_MAX_SENSORS; ++i) {
if (model->sensorData[i].isAvailable()) {
RawSource item = RawSource(SOURCE_TYPE_TELEMETRY, 3*i);
b->addItem(item.toString(model), val+i);
@@ -1005,7 +1051,7 @@ GeneralSettings::GeneralSettings()
contrast = 25;
vBatWarn = 90;
for (int i=0; i<NUM_STICKS+C9X_NUM_POTS; ++i) {
for (int i=0; i<CPN_MAX_STICKS+CPN_MAX_POTS; ++i) {
calibMid[i] = 0x200;
calibSpanNeg[i] = 0x180;
calibSpanPos[i] = 0x180;
@@ -1057,11 +1103,11 @@ GeneralSettings::GeneralSettings()
QString t_SpeakerSet=g.profile[g.id()].speaker();
QString t_CountrySet=g.profile[g.id()].countryCode();
if ((t_calib.length()==(NUM_STICKS+potsnum)*12) && (t_trainercalib.length()==16)) {
if ((t_calib.length()==(CPN_MAX_STICKS+potsnum)*12) && (t_trainercalib.length()==16)) {
QString Byte;
int16_t byte16;
bool ok;
for (int i=0; i<(NUM_STICKS+potsnum); i++) {
for (int i=0; i<(CPN_MAX_STICKS+potsnum); i++) {
Byte=t_calib.mid(i*12,4);
byte16=(int16_t)Byte.toInt(&ok,16);
if (ok)
@@ -1141,7 +1187,7 @@ GeneralSettings::GeneralSettings()
int GeneralSettings::getDefaultStick(unsigned int channel) const
{
if (channel >= NUM_STICKS)
if (channel >= CPN_MAX_STICKS)
return -1;
else
return chout_ar[4*templateSetup + channel] - 1;
@@ -1235,14 +1281,14 @@ ModelData & ModelData::operator = (const ModelData & src)
ExpoData * ModelData::insertInput(const int idx)
{
memmove(&expoData[idx+1], &expoData[idx], (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData));
memmove(&expoData[idx+1], &expoData[idx], (CPN_MAX_EXPOS-(idx+1))*sizeof(ExpoData));
expoData[idx].clear();
return &expoData[idx];
}
bool ModelData::isInputValid(const unsigned int idx) const
{
for (int i=0; i<C9X_MAX_EXPOS; i++) {
for (int i=0; i<CPN_MAX_EXPOS; i++) {
const ExpoData * expo = &expoData[i];
if (expo->mode == 0) break;
if (expo->chn == idx)
@@ -1253,7 +1299,7 @@ bool ModelData::isInputValid(const unsigned int idx) const
bool ModelData::hasExpos(uint8_t inputIdx) const
{
for (int i=0; i<C9X_MAX_EXPOS; i++) {
for (int i=0; i<CPN_MAX_EXPOS; i++) {
const ExpoData & expo = expoData[i];
if (expo.chn==inputIdx && expo.mode!=0) {
return true;
@@ -1265,7 +1311,7 @@ bool ModelData::hasExpos(uint8_t inputIdx) const
bool ModelData::hasMixes(uint8_t channelIdx) const
{
channelIdx += 1;
for (int i=0; i<C9X_MAX_MIXERS; i++) {
for (int i=0; i<CPN_MAX_MIXERS; i++) {
if (mixData[i].destCh == channelIdx) {
return true;
}
@@ -1276,7 +1322,7 @@ bool ModelData::hasMixes(uint8_t channelIdx) const
QVector<const ExpoData *> ModelData::expos(int input) const
{
QVector<const ExpoData *> result;
for (int i=0; i<C9X_MAX_EXPOS; i++) {
for (int i=0; i<CPN_MAX_EXPOS; i++) {
const ExpoData * ed = &expoData[i];
if ((int)ed->chn==input && ed->mode!=0) {
result << ed;
@@ -1288,7 +1334,7 @@ QVector<const ExpoData *> ModelData::expos(int input) const
QVector<const MixData *> ModelData::mixes(int channel) const
{
QVector<const MixData *> result;
for (int i=0; i<C9X_MAX_MIXERS; i++) {
for (int i=0; i<CPN_MAX_MIXERS; i++) {
const MixData * md = &mixData[i];
if ((int)md->destCh == channel+1) {
result << md;
@@ -1301,12 +1347,12 @@ void ModelData::removeInput(const int idx)
{
unsigned int chn = expoData[idx].chn;
memmove(&expoData[idx], &expoData[idx+1], (C9X_MAX_EXPOS-(idx+1))*sizeof(ExpoData));
expoData[C9X_MAX_EXPOS-1].clear();
memmove(&expoData[idx], &expoData[idx+1], (CPN_MAX_EXPOS-(idx+1))*sizeof(ExpoData));
expoData[CPN_MAX_EXPOS-1].clear();
//also remove input name if removing last line for this input
bool found = false;
for (int i=0; i<C9X_MAX_EXPOS; i++) {
for (int i=0; i<CPN_MAX_EXPOS; i++) {
if (expoData[i].mode==0) continue;
if (expoData[i].chn==chn) {
found = true;
@@ -1318,12 +1364,12 @@ void ModelData::removeInput(const int idx)
void ModelData::clearInputs()
{
for (int i=0; i<C9X_MAX_EXPOS; i++)
for (int i=0; i<CPN_MAX_EXPOS; i++)
expoData[i].clear();
//clear all input names
if (GetCurrentFirmware()->getCapability(VirtualInputs)) {
for (int i=0; i<C9X_MAX_INPUTS; i++) {
for (int i=0; i<CPN_MAX_INPUTS; i++) {
inputNames[i][0] = 0;
}
}
@@ -1331,7 +1377,7 @@ void ModelData::clearInputs()
void ModelData::clearMixes()
{
for (int i=0; i<C9X_MAX_MIXERS; i++)
for (int i=0; i<CPN_MAX_MIXERS; i++)
mixData[i].clear();
}
@@ -1357,26 +1403,26 @@ void ModelData::clear()
moduleData[0].protocol = PULSES_PPM;
moduleData[1].protocol = PULSES_OFF;
}
for (int i=0; i<C9X_MAX_FLIGHT_MODES; i++) {
for (int i=0; i<CPN_MAX_FLIGHT_MODES; i++) {
flightModeData[i].clear(i);
}
clearInputs();
clearMixes();
for (int i=0; i<C9X_NUM_CHNOUT; i++)
for (int i=0; i<CPN_MAX_CHNOUT; i++)
limitData[i].clear();
for (int i=0; i<NUM_STICKS; i++)
for (int i=0; i<CPN_MAX_STICKS; i++)
expoData[i].clear();
for (int i=0; i<C9X_NUM_CSW; i++)
for (int i=0; i<CPN_MAX_CSW; i++)
logicalSw[i].clear();
for (int i=0; i<C9X_MAX_CUSTOM_FUNCTIONS; i++)
for (int i=0; i<CPN_MAX_CUSTOM_FUNCTIONS; i++)
customFn[i].clear();
for (int i=0; i<C9X_MAX_CURVES; i++)
for (int i=0; i<CPN_MAX_CURVES; i++)
curves[i].clear(5);
for (int i=0; i<C9X_MAX_TIMERS; i++)
for (int i=0; i<CPN_MAX_TIMERS; i++)
timers[i].clear();
swashRingData.clear();
frsky.clear();
for (int i=0; i<C9X_MAX_SENSORS; i++)
for (int i=0; i<CPN_MAX_SENSORS; i++)
sensorData[i].clear();
}
@@ -1416,7 +1462,7 @@ QString removeAccents(const QString & str)
void ModelData::setDefaultInputs(const GeneralSettings & settings)
{
if (IS_TARANIS(GetEepromInterface()->getBoard())) {
for (int i=0; i<NUM_STICKS; i++) {
for (int i=0; i<CPN_MAX_STICKS; i++) {
ExpoData * expo = &expoData[i];
expo->chn = i;
expo->mode = INPUT_MODE_BOTH;
@@ -1433,7 +1479,7 @@ void ModelData::setDefaultMixes(const GeneralSettings & settings)
setDefaultInputs(settings);
}
for (int i=0; i<NUM_STICKS; i++) {
for (int i=0; i<CPN_MAX_STICKS; i++) {
MixData * mix = &mixData[i];
mix->destCh = i+1;
mix->weight = 100;
@@ -1451,7 +1497,7 @@ void ModelData::setDefaultValues(unsigned int id, const GeneralSettings & settin
clear();
used = true;
sprintf(name, "MODEL%02d", id+1);
for (int i=0; i<C9X_NUM_MODULES; i++) {
for (int i=0; i<CPN_MAX_MODULES; i++) {
moduleData[i].modelId = id+1;
}
setDefaultMixes(settings);
@@ -1460,7 +1506,7 @@ void ModelData::setDefaultValues(unsigned int id, const GeneralSettings & settin
int ModelData::getTrimValue(int phaseIdx, int trimIdx)
{
int result = 0;
for (int i=0; i<C9X_MAX_FLIGHT_MODES; i++) {
for (int i=0; i<CPN_MAX_FLIGHT_MODES; i++) {
FlightModeData & phase = flightModeData[phaseIdx];
if (phase.trimMode[trimIdx] < 0) {
return result;
@@ -1487,7 +1533,7 @@ bool ModelData::isGVarLinked(int phaseIdx, int gvarIdx)
int ModelData::getGVarFieldValue(int phaseIdx, int gvarIdx)
{
int idx = flightModeData[phaseIdx].gvars[gvarIdx];
for (int i=0; idx>1024 && i<C9X_MAX_FLIGHT_MODES; i++) {
for (int i=0; idx>1024 && i<CPN_MAX_FLIGHT_MODES; i++) {
int nextPhase = idx - 1025;
if (nextPhase >= phaseIdx) nextPhase += 1;
phaseIdx = nextPhase;
@@ -1498,7 +1544,7 @@ int ModelData::getGVarFieldValue(int phaseIdx, int gvarIdx)
void ModelData::setTrimValue(int phaseIdx, int trimIdx, int value)
{
for (uint8_t i=0; i<C9X_MAX_FLIGHT_MODES; i++) {
for (uint8_t i=0; i<CPN_MAX_FLIGHT_MODES; i++) {
FlightModeData & phase = flightModeData[phaseIdx];
int mode = phase.trimMode[trimIdx];
int p = phase.trimRef[trimIdx];
@@ -1535,13 +1581,13 @@ ModelData ModelData::removeGlobalVars()
{
ModelData result = *this;
for (int i=0; i<C9X_MAX_MIXERS; i++) {
for (int i=0; i<CPN_MAX_MIXERS; i++) {
removeGlobalVar(mixData[i].weight);
removeGlobalVar(mixData[i].curve.value);
removeGlobalVar(mixData[i].sOffset);
}
for (int i=0; i<C9X_MAX_EXPOS; i++) {
for (int i=0; i<CPN_MAX_EXPOS; i++) {
removeGlobalVar(expoData[i].weight);
removeGlobalVar(expoData[i].curve.value);
}
@@ -1568,10 +1614,7 @@ void registerEEpromInterfaces()
eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS_X9D));
eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS_X9DP));
eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS_X9E));
eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_STOCK));
eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_GRUVIN9X));
eepromInterfaces.push_back(new Ersky9xInterface());
eepromInterfaces.push_back(new Th9xInterface());
eepromInterfaces.push_back(new Er9xInterface());
}
@@ -1795,10 +1838,10 @@ void FlightModeData::clear(const int phase)
{
memset(this, 0, sizeof(FlightModeData));
if (phase != 0) {
for (int idx=0; idx<C9X_MAX_GVARS; idx++) {
for (int idx=0; idx<CPN_MAX_GVARS; idx++) {
gvars[idx] = 1025;
}
for (int idx=0; idx<C9X_MAX_ENCODERS; idx++) {
for (int idx=0; idx<CPN_MAX_ENCODERS; idx++) {
rotaryEncoders[idx] = 1025;
}
}