Skip to content

Commit

Permalink
Telemetry gvars cpn side
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower authored and philmoz committed Nov 13, 2023
1 parent 1a087fe commit e5bbed3
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
72 changes: 62 additions & 10 deletions companion/src/datamodels/compounditemmodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,22 +481,74 @@ TelemetrySourceItemModel::TelemetrySourceItemModel(const GeneralSettings * const
if (!modelData)
return;

setUpdateMask(IMUE_TeleSensors | IMUE_Modules);
const int count = firmware->getCapability(Sensors);
setUpdateMask(IMUE_TeleSensors | IMUE_Modules | IMUE_GVars);

for (int i = -count; i <= count; ++i) {
addItems(SOURCE_TYPE_GVAR, -firmware->getCapability(Gvars));
addItems(SOURCE_TYPE_TELEMETRY, -firmware->getCapability(Sensors));
addItems(SOURCE_TYPE_NONE, 1);
addItems(SOURCE_TYPE_TELEMETRY, firmware->getCapability(Sensors));
addItems(SOURCE_TYPE_GVAR, firmware->getCapability(Gvars));
}

void TelemetrySourceItemModel::addItems(const RawSourceType & type, int count)
{
int flags = 0;

if (type == SOURCE_TYPE_GVAR)
flags = RawSource::GVarsGroup;

int i = (count < 0 ? count : 1);
count = (i < 0 ? 0 : count + i);

for ( ; i < count; ++i) {
QStandardItem * modelItem = new QStandardItem();
modelItem->setData(i, IMDR_Id);
modelItem->setData(i < 0 ? IMDG_Negative : i > 0 ? IMDG_Positive : IMDG_None, IMDR_Flags);
setDynamicItemData(modelItem, i);
int id = i;

if (type == SOURCE_TYPE_NONE)
id = 0;

if (type != SOURCE_TYPE_GVAR) {
flags = (i < 0 ? IMDG_Negative : i > 0 ? IMDG_Positive : IMDG_None);
}
else {
id = ((SENSOR_GVAR_START + 1) * (i < 0 ? -1 : 1)) - id;
}

modelItem->setData(id, IMDR_Id);
modelItem->setData((int)type, IMDR_Type);
modelItem->setData(flags , IMDR_Flags);
setDynamicItemData(modelItem);
appendRow(modelItem);
}
}

void TelemetrySourceItemModel::setDynamicItemData(QStandardItem * item, const int value) const
void TelemetrySourceItemModel::setDynamicItemData(QStandardItem * item) const
{
item->setText(SensorData::sourceToString(modelData, value));
item->setData(SensorData::isSourceAvailable(modelData, value), IMDR_Available);
const int type = item->data(IMDR_Type).toInt();
int id = item->data(IMDR_Id).toInt();

switch (type) {
case SOURCE_TYPE_NONE:
{
const RawSource src = RawSource(id);
item->setText(src.toString());
item->setData(true, IMDR_Available);
break;
}
case SOURCE_TYPE_TELEMETRY:
item->setText(SensorData::sourceToString(modelData, id));
item->setData(SensorData::isSourceAvailable(modelData, id), IMDR_Available);
break;
case SOURCE_TYPE_GVAR:
{
int idx = SENSOR_GVAR_START - abs(id);
item->setText((id < 0 ? "-" : "") % modelData->gvarData[idx].nameToString(idx));
item->setData(true, IMDR_Available);
break;
}
default:
break;
}
}

void TelemetrySourceItemModel::update(const int event)
Expand All @@ -505,7 +557,7 @@ void TelemetrySourceItemModel::update(const int event)
emit aboutToBeUpdated();

for (int i = 0; i < rowCount(); ++i) {
setDynamicItemData(item(i), item(i)->data(IMDR_Id).toInt());
setDynamicItemData(item(i));
}

emit updateComplete();
Expand Down
3 changes: 2 additions & 1 deletion companion/src/datamodels/compounditemmodels.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ class TelemetrySourceItemModel: public AbstractDynamicItemModel
virtual void update(const int event = IMUE_SystemRefresh) override;

protected:
virtual void setDynamicItemData(QStandardItem * item, const int value) const;
virtual void setDynamicItemData(QStandardItem * item) const;
void addItems(const RawSourceType & type, int count);
};

class CurveRefTypeItemModel : public AbstractStaticItemModel
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/sensordata.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QtCore>

constexpr int SENSOR_LABEL_LEN { 4 };
constexpr int SENSOR_GVAR_START { 127 };

constexpr int SENSOR_ISCONFIGURABLE { 1 << 1 };
constexpr int SENSOR_HAS_GPS { 1 << 2 };
Expand Down

0 comments on commit e5bbed3

Please sign in to comment.