1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-24 16:55:15 +03:00

Move getElementName to helpers and move timerdata to own files

This commit is contained in:
elecpower 2021-03-12 10:32:56 +11:00
parent f8bd7b7fb8
commit 110e1a5fc7
11 changed files with 159 additions and 83 deletions

View file

@ -23,11 +23,13 @@ set(firmwares_SRCS
rawswitch.cpp
sensordata.cpp
telem_data.cpp
timerdata.cpp
afhds3.cpp
ersky9x/ersky9xeeprom.cpp
ersky9x/ersky9xinterface.cpp
opentx/opentxeeprom.cpp
opentx/opentxinterface.cpp
datahelpers.cpp
)
string(REPLACE ".cpp" ".h" firmwares_HDRS "${firmwares_SRCS}")
@ -35,7 +37,6 @@ string(REPLACE ".cpp" ".h" firmwares_HDRS "${firmwares_SRCS}")
list(APPEND firmwares_HDRS
eepromimportexport.h
moduledata.h
helpersdata.h
)
set(firmwares_QT

View file

@ -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 "datahelpers.h"
QString DataHelpers::getElementName(const QString & prefix, const unsigned int index, const char * name, const bool padding)
{
QString result = prefix;
result.append(padding ? QString("%1").arg(index, 2, 10, QChar('0')) : QString("%1").arg(index));
if (name && QString(name).trimmed().length() > 0)
result.append(":" + QString(name).trimmed());
return result;
}

View file

@ -24,8 +24,6 @@
class FieldRange
{
Q_DECLARE_TR_FUNCTIONS(FieldRange)
public:
FieldRange():
decimals(0),
@ -48,3 +46,9 @@ class FieldRange
QString prefix;
QString unit;
};
namespace DataHelpers
{
QString getElementName(const QString & prefix, const unsigned int index, const char * name = 0, const bool padding = false);
}

View file

@ -27,31 +27,6 @@
#include "helpers.h"
#include "adjustmentreference.h"
/*
* TimerData
*/
void TimerData::convert(RadioDataConversionState & cstate)
{
cstate.setComponent(tr("TMR"), 1);
cstate.setSubComp(tr("Timer %1").arg(cstate.subCompIdx + 1));
mode.convert(cstate);
}
bool TimerData::isEmpty()
{
return (mode == RawSwitch(SWITCH_TYPE_TIMER_MODE, 0) && name[0] == '\0' && minuteBeep == 0 && countdownBeep == COUNTDOWN_SILENT && val == 0 && persistent == 0 /*&& pvalue == 0*/);
}
QString TimerData::nameToString(int index) const
{
return RadioData::getElementName(tr("TMR", "as in Timer"), index + 1, name);
}
/*
* ModelData
*/
ModelData::ModelData()
{
clear();

View file

@ -33,6 +33,7 @@
#include "output_data.h"
#include "sensordata.h"
#include "telem_data.h"
#include "timerdata.h"
#include <QtCore>
@ -55,35 +56,6 @@ class RSSIAlarmData {
}
};
#define TIMER_NAME_LEN 8
class TimerData {
Q_DECLARE_TR_FUNCTIONS(TimerData)
public:
enum CountDownMode {
COUNTDOWN_SILENT,
COUNTDOWN_BEEPS,
COUNTDOWN_VOICE,
COUNTDOWN_HAPTIC
};
TimerData() { clear(); }
RawSwitch mode;
char name[TIMER_NAME_LEN+1];
bool minuteBeep;
unsigned int countdownBeep;
unsigned int val;
unsigned int persistent;
int countdownStart;
unsigned int direction;
int pvalue;
void clear() { memset(reinterpret_cast<void *>(this), 0, sizeof(TimerData)); mode = RawSwitch(SWITCH_TYPE_TIMER_MODE, 0); }
void convert(RadioDataConversionState & cstate);
bool isEmpty();
bool isModeOff() { return mode == RawSwitch(SWITCH_TYPE_TIMER_MODE, 0); }
QString nameToString(int index) const;
};
#define CPN_MAX_SCRIPTS 9
#define CPN_MAX_SCRIPT_INPUTS 10
class ScriptData {

View file

@ -22,23 +22,6 @@
#include "radiodataconversionstate.h"
#include "eeprominterface.h"
// static
QString RadioData::getElementName(const QString & prefix, unsigned int index, const char * name, bool padding)
{
QString result = prefix;
if (padding)
result += QString("%1").arg(index, 2, 10, QChar('0'));
else
result += QString("%1").arg(index);
if (name) {
QString trimmed = QString(name).trimmed();
if (trimmed.length() > 0) {
result += ":" + QString(name).trimmed();
}
}
return result;
}
RadioData::RadioData()
{
models.resize(getCurrentFirmware()->getCapability(Models));

View file

@ -1,9 +1,10 @@
#ifndef _RADIODATA_H_
#define _RADIODATA_H_
#pragma once
#include "generalsettings.h"
#include "modeldata.h"
#include "datahelpers.h" // required for getElementName
#include <QtCore>
class RadioDataConversionState;
@ -32,10 +33,10 @@ class RadioData {
void fixModelFilenames();
QString getNextModelFilename();
static QString getElementName(const QString & prefix, unsigned int index, const char * name = 0, bool padding = false);
// leave here until all calls repointed
static QString getElementName(const QString & prefix, unsigned int index, const char * name = 0, bool padding = false)
{ return DataHelpers::getElementName(prefix, index, name, padding); }
protected:
void fixModelFilename(unsigned int index);
};
#endif // _RADIODATA_H_

View file

@ -19,8 +19,6 @@
*/
#include "sensordata.h"
#include "radiodata.h"
#include "modeldata.h"
#include "eeprominterface.h"
#include "compounditemmodels.h"
@ -35,7 +33,7 @@ void SensorData::updateUnit()
QString SensorData::nameToString(int index) const
{
return RadioData::getElementName(tr("TELE"), index + 1, label);
return DataHelpers::getElementName(tr("TELE"), index + 1, label);
}
QString SensorData::getOrigin(const ModelData * model) const

View file

@ -20,7 +20,7 @@
#pragma once
#include "helpersdata.h"
#include "datahelpers.h"
#include <QtCore>

View file

@ -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.
*/
#include "timerdata.h"
#include "radiodataconversionstate.h"
void TimerData::convert(RadioDataConversionState & cstate)
{
cstate.setComponent(tr("TMR"), 1);
cstate.setSubComp(tr("Timer %1").arg(cstate.subCompIdx + 1));
mode.convert(cstate);
}
void TimerData::clear()
{
memset(reinterpret_cast<void *>(this), 0, sizeof(TimerData));
mode = RawSwitch(SWITCH_TYPE_TIMER_MODE, 0);
}
bool TimerData::isEmpty()
{
return (mode == RawSwitch(SWITCH_TYPE_TIMER_MODE, 0) && name[0] == '\0' && minuteBeep == 0 && countdownBeep == COUNTDOWN_SILENT && val == 0 && persistent == 0 /*&& pvalue == 0*/);
}
bool TimerData::isModeOff()
{
return mode == RawSwitch(SWITCH_TYPE_TIMER_MODE, 0);
}
QString TimerData::nameToString(int index) const
{
return DataHelpers::getElementName(tr("TMR", "as in Timer"), index + 1, name);
}

View file

@ -0,0 +1,61 @@
/*
* 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.
*/
#pragma once
#include "rawswitch.h"
#include "datahelpers.h"
#include <QtCore>
class RadioDataConversionState;
#define TIMER_NAME_LEN 8
class TimerData {
Q_DECLARE_TR_FUNCTIONS(TimerData)
public:
enum CountDownMode {
COUNTDOWN_SILENT,
COUNTDOWN_BEEPS,
COUNTDOWN_VOICE,
COUNTDOWN_HAPTIC,
COUNTDOWN_COUNT
};
TimerData() { clear(); }
RawSwitch mode;
char name[TIMER_NAME_LEN + 1];
bool minuteBeep;
unsigned int countdownBeep;
unsigned int val;
unsigned int persistent;
int countdownStart;
unsigned int direction;
int pvalue;
void convert(RadioDataConversionState & cstate);
void clear();
bool isEmpty();
bool isModeOff();
QString nameToString(int index) const;
};