'next' EEPROM support continued: curves (any number of points, smooth
curves)
This commit is contained in:
@@ -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]+"))) {
|
||||
|
||||
Reference in New Issue
Block a user