mirror of
https://github.com/opentx/opentx.git
synced 2025-07-21 15:25:17 +03:00
'next' EEPROM support continued: curves (any number of points, smooth
curves)
This commit is contained in:
parent
f83446cea1
commit
3332cbf051
5 changed files with 181 additions and 149 deletions
|
@ -12,7 +12,8 @@ QString getPhaseName(int val, char * phasename)
|
|||
phaseName.append(phasename);
|
||||
if (phaseName.isEmpty()) {
|
||||
return QString(val < 0 ? "!" : "") + QObject::tr("FM%1").arg(abs(val) - 1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return QString(val < 0 ? "!" : "") + phaseName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@
|
|||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
// TODO Capability CustomCurves to be removed
|
||||
|
||||
#define GFX_MARGIN 16
|
||||
|
||||
static const QColor colors[C9X_MAX_CURVES] = {
|
||||
|
@ -76,9 +74,11 @@ Curves::Curves(QWidget * parent, ModelData & model):
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
lock = true;
|
||||
|
||||
if (!GetEepromInterface()->getCapability(HasCvNames)) {
|
||||
ui->cname_LE->hide();
|
||||
ui->cname_label->hide();
|
||||
ui->curveName->hide();
|
||||
ui->curveNameLabel->hide();
|
||||
}
|
||||
|
||||
QGraphicsScene *scene = new QGraphicsScene(ui->curvePreview);
|
||||
|
@ -132,7 +132,20 @@ Curves::Curves(QWidget * parent, ModelData & model):
|
|||
spnx[i]->setAccelerated(true);
|
||||
connect(spnx[i], SIGNAL(valueChanged(int)), this, SLOT(onPointEdited()));
|
||||
ui->pointsLayout->addWidget(spnx[i], i, 1, 1, 1);
|
||||
|
||||
bool insert;
|
||||
if (GetEepromInterface()->getCapability(EnhancedCurves)) {
|
||||
insert = (i >= 1);
|
||||
}
|
||||
else {
|
||||
insert = (i==2 || i==4 || i==8 || i==16);
|
||||
}
|
||||
if (insert) {
|
||||
ui->curvePoints->addItem(tr("%1 points").arg(i+1), i+1);
|
||||
}
|
||||
}
|
||||
|
||||
lock = false;
|
||||
}
|
||||
|
||||
Curves::~Curves()
|
||||
|
@ -173,7 +186,7 @@ void Curves::update()
|
|||
lock = true;
|
||||
|
||||
if (GetEepromInterface()->getCapability(HasCvNames)) {
|
||||
ui->cname_LE->setText(model.curves[currentCurve].name);
|
||||
ui->curveName->setText(model.curves[currentCurve].name);
|
||||
}
|
||||
|
||||
int count = model.curves[currentCurve].count;
|
||||
|
@ -215,14 +228,27 @@ void Curves::setCurrentCurve(int index)
|
|||
|
||||
void Curves::updateCurveType()
|
||||
{
|
||||
int index = (model.curves[currentCurve].type == CurveData::CURVE_TYPE_CUSTOM ? 1 : 0);
|
||||
if (model.curves[currentCurve].count==5)
|
||||
index += 2;
|
||||
else if (model.curves[currentCurve].count==9)
|
||||
index += 4;
|
||||
else if (model.curves[currentCurve].count==17)
|
||||
index += 6;
|
||||
ui->curvetype_CB->setCurrentIndex(index);
|
||||
lock = true;
|
||||
|
||||
int index = 0;
|
||||
|
||||
if (GetEepromInterface()->getCapability(EnhancedCurves)) {
|
||||
index = model.curves[currentCurve].count - 2;
|
||||
}
|
||||
else {
|
||||
if (model.curves[currentCurve].count == 5)
|
||||
index += 2;
|
||||
else if (model.curves[currentCurve].count == 9)
|
||||
index += 4;
|
||||
else if (model.curves[currentCurve].count == 17)
|
||||
index += 6;
|
||||
}
|
||||
|
||||
ui->curvePoints->setCurrentIndex(index);
|
||||
ui->curveCustom->setCurrentIndex(model.curves[currentCurve].type);
|
||||
ui->curveSmooth->setCurrentIndex(model.curves[currentCurve].smooth);
|
||||
|
||||
lock = false;
|
||||
}
|
||||
|
||||
void Curves::updateCurve()
|
||||
|
@ -333,61 +359,83 @@ void Curves::onNodeUnfocus()
|
|||
updateCurve();
|
||||
}
|
||||
|
||||
void Curves::on_curvetype_CB_currentIndexChanged(int index)
|
||||
bool Curves::allowCurveType(int points, CurveData::CurveType type)
|
||||
{
|
||||
static const int numpoint[] = {3,3,5,5,9,9,17,17};
|
||||
static const CurveData::CurveType types[] = {CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM, CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM, CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM, CurveData::CURVE_TYPE_STANDARD, CurveData::CURVE_TYPE_CUSTOM};
|
||||
int numcurves = GetEepromInterface()->getCapability(NumCurves);
|
||||
|
||||
if (!lock) {
|
||||
lock = true;
|
||||
int totalpoints = 0;
|
||||
for (int i=0; i<numcurves; i++) {
|
||||
int cvPoints = (i==currentCurve ? points : model.curves[i].count);
|
||||
CurveData::CurveType cvType = (i==currentCurve ? type : model.curves[i].type);
|
||||
totalpoints += cvPoints + (cvType==CurveData::CURVE_TYPE_CUSTOM ? cvPoints-2 : 0);
|
||||
}
|
||||
|
||||
int numcurves = GetEepromInterface()->getCapability(NumCurves);
|
||||
// int currpoints = model.curves[currentCurve].count;
|
||||
// bool currcustom = model.curves[currentCurve].custom;
|
||||
|
||||
int totalpoints=0;
|
||||
for (int i=0; i<numcurves; i++) {
|
||||
if (i!=currentCurve) {
|
||||
totalpoints += model.curves[i].count;
|
||||
if (model.curves[i].type == CurveData::CURVE_TYPE_CUSTOM) {
|
||||
totalpoints += model.curves[i].count-2;
|
||||
}
|
||||
}
|
||||
}
|
||||
totalpoints += numpoint[index];
|
||||
if (types[index] == CurveData::CURVE_TYPE_CUSTOM) {
|
||||
totalpoints += numpoint[index]-2;
|
||||
}
|
||||
|
||||
int fwpoints = GetEepromInterface()->getCapability(NumCurvePoints);
|
||||
if (fwpoints!=0) {
|
||||
if (fwpoints < totalpoints) {
|
||||
QMessageBox::warning(this, "companion", tr("Not enough free points in EEPROM to store the curve."));
|
||||
updateCurveType();
|
||||
lock = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
model.curves[currentCurve].count = numpoint[index];
|
||||
model.curves[currentCurve].type = types[index];
|
||||
|
||||
// TODO something better!
|
||||
for (int i=0; i<C9X_MAX_POINTS; i++) {
|
||||
model.curves[currentCurve].points[i].x = (i >= model.curves[currentCurve].count-1 ? +100 : -100 + (200*i)/(numpoint[index]-1));
|
||||
model.curves[currentCurve].points[i].y = 0;
|
||||
}
|
||||
|
||||
update();
|
||||
emit modified();
|
||||
lock = false;
|
||||
int fwpoints = GetEepromInterface()->getCapability(NumCurvePoints);
|
||||
if (totalpoints > fwpoints) {
|
||||
QMessageBox::warning(this, "companion", tr("Not enough free points in EEPROM to store the curve."));
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void Curves::on_cname_LE_editingFinished()
|
||||
void Curves::on_curvePoints_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
int numpoints = ((QComboBox *)sender())->itemData(index).toInt();
|
||||
|
||||
if (allowCurveType(numpoints, model.curves[currentCurve].type)) {
|
||||
model.curves[currentCurve].count = numpoints;
|
||||
|
||||
// TODO something better + reuse!
|
||||
for (int i=0; i<C9X_MAX_POINTS; i++) {
|
||||
model.curves[currentCurve].points[i].x = (i >= model.curves[currentCurve].count-1 ? +100 : -100 + (200*i)/(numpoints-1));
|
||||
model.curves[currentCurve].points[i].y = 0;
|
||||
}
|
||||
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
else {
|
||||
updateCurveType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Curves::on_curveCustom_currentIndexChanged(int index)
|
||||
{
|
||||
if (!lock) {
|
||||
CurveData::CurveType type = (CurveData::CurveType)index;
|
||||
int numpoints = ui->curvePoints->itemData(ui->curvePoints->currentIndex()).toInt();
|
||||
if (allowCurveType(model.curves[currentCurve].count, type)) {
|
||||
model.curves[currentCurve].type = type;
|
||||
|
||||
// TODO something better + reuse!
|
||||
for (int i=0; i<C9X_MAX_POINTS; i++) {
|
||||
model.curves[currentCurve].points[i].x = (i >= model.curves[currentCurve].count-1 ? +100 : -100 + (200*i)/(numpoints-1));
|
||||
model.curves[currentCurve].points[i].y = 0;
|
||||
}
|
||||
|
||||
update();
|
||||
emit modified();
|
||||
}
|
||||
else {
|
||||
updateCurveType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Curves::on_curveSmooth_currentIndexChanged(int index)
|
||||
{
|
||||
model.curves[currentCurve].smooth = index;
|
||||
update();
|
||||
}
|
||||
|
||||
void Curves::on_curveName_editingFinished()
|
||||
{
|
||||
memset(model.curves[currentCurve].name, 0, sizeof(model.curves[currentCurve].name));
|
||||
strcpy(model.curves[currentCurve].name, ui->cname_LE->text().toAscii());
|
||||
strcpy(model.curves[currentCurve].name, ui->curveName->text().toAscii());
|
||||
emit modified();
|
||||
}
|
||||
|
||||
|
@ -621,47 +669,11 @@ void ModelEdit::clearCurves(bool ask)
|
|||
currentCurve=0;
|
||||
curvesLock=false;
|
||||
ui->curvetype_CB->setCurrentIndex(2);
|
||||
ui->cname_LE->clear();
|
||||
ui->curveName->clear();
|
||||
updateSettings();
|
||||
drawCurve();
|
||||
}
|
||||
|
||||
void ModelEdit::setCurve(uint8_t c, int8_t ar[])
|
||||
{
|
||||
int len=sizeof(ar)/sizeof(int8_t);
|
||||
if (GetEepromInterface()->getCapability(CustomCurves)) {
|
||||
if (GetEepromInterface()->getCapability(NumCurves)>c) {
|
||||
if (len<9) {
|
||||
model.curves[c].count=5;
|
||||
model.curves[c].custom=false;
|
||||
for (int i=0; i< 5; i++) {
|
||||
model.curves[c].points[i].y=ar[i];
|
||||
}
|
||||
} else {
|
||||
model.curves[c].count=5;
|
||||
model.curves[c].custom=false;
|
||||
for (int i=0; i< 5; i++) {
|
||||
model.curves[c].points[i].y=ar[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (len<9) {
|
||||
model.curves[c].count=5;
|
||||
model.curves[c].custom=false;
|
||||
for (int i=0; i< 5; i++) {
|
||||
model.curves[c].points[i].y=ar[i];
|
||||
}
|
||||
} else {
|
||||
model.curves[c+8].count=5;
|
||||
model.curves[c+8].custom=false;
|
||||
for (int i=0; i< 5; i++) {
|
||||
model.curves[c+8].points[i].y=ar[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ModelEdit::ControlCurveSignal(bool flag)
|
||||
{
|
||||
foreach(QSpinBox *sb, findChildren<QSpinBox *>(QRegExp("curvePt[0-9]+"))) {
|
||||
|
|
|
@ -22,8 +22,10 @@ class Curves : public ModelPanel
|
|||
void resetCurve();
|
||||
void editCurve();
|
||||
void plotCurve(bool checked);
|
||||
void on_cname_LE_editingFinished();
|
||||
void on_curvetype_CB_currentIndexChanged(int index);
|
||||
void on_curveName_editingFinished();
|
||||
void on_curvePoints_currentIndexChanged(int index);
|
||||
void on_curveCustom_currentIndexChanged(int index);
|
||||
void on_curveSmooth_currentIndexChanged(int index);
|
||||
void onPointEdited();
|
||||
void onNodeMoved(int x, int y);
|
||||
void onNodeFocus();
|
||||
|
@ -41,6 +43,7 @@ class Curves : public ModelPanel
|
|||
void setCurrentCurve(int index);
|
||||
void updateCurve();
|
||||
void updateCurveType();
|
||||
bool allowCurveType(int points, CurveData::CurveType type);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -20,9 +20,47 @@
|
|||
<layout class="QGridLayout" name="curvesLayout"/>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="3">
|
||||
<layout class="QGridLayout" name="gridLayout_8" rowstretch="0,0,0" columnstretch="1,1">
|
||||
<layout class="QGridLayout" name="gridLayout_8" rowstretch="0,0,0" columnstretch="1,0">
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QComboBox" name="curvePoints"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="curveCustom">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Standard</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Custom</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="curveSmooth">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Lines</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Smooth</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="curvetype_label">
|
||||
<widget class="QLabel" name="curveTypeLabel">
|
||||
<property name="text">
|
||||
<string>Curve type</string>
|
||||
</property>
|
||||
|
@ -31,52 +69,8 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="curvetype_CB">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>3 points</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>3 points custom</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>5 points</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>5 points custom</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>9 points</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>9 points custom</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>17 points</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>17 points custom</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="cname_label">
|
||||
<widget class="QLabel" name="curveNameLabel">
|
||||
<property name="text">
|
||||
<string>Curve name</string>
|
||||
</property>
|
||||
|
@ -86,7 +80,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="cname_LE">
|
||||
<widget class="QLineEdit" name="curveName">
|
||||
<property name="maxLength">
|
||||
<number>6</number>
|
||||
</property>
|
||||
|
@ -129,7 +123,7 @@
|
|||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="5">
|
||||
<item row="5" column="0" colspan="5">
|
||||
<spacer name="verticalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
|
|
|
@ -2,6 +2,28 @@
|
|||
#include <QListWidget>
|
||||
#include <QMessageBox>
|
||||
|
||||
void ModelEdit::setCurve(uint8_t c, int8_t ar[])
|
||||
{
|
||||
int len=sizeof(ar)/sizeof(int8_t);
|
||||
|
||||
if (GetEepromInterface()->getCapability(NumCurves)>c) {
|
||||
if (len<9) {
|
||||
model.curves[c].count=5;
|
||||
model.curves[c].custom=false;
|
||||
for (int i=0; i< 5; i++) {
|
||||
model.curves[c].points[i].y=ar[i];
|
||||
}
|
||||
}
|
||||
else {
|
||||
model.curves[c].count=5;
|
||||
model.curves[c].custom=false;
|
||||
for (int i=0; i< 5; i++) {
|
||||
model.curves[c].points[i].y=ar[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Templates::Templates(QWidget * parent, ModelData & model):
|
||||
QWidget(parent),
|
||||
model(model)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue