diff --git a/flight/modules/Battery/battery.c b/flight/modules/Battery/battery.c index e3a495605..9fa030b7d 100644 --- a/flight/modules/Battery/battery.c +++ b/flight/modules/Battery/battery.c @@ -138,6 +138,13 @@ static void onTimer(__attribute__((unused)) UAVObjEvent *ev) const float dT = SAMPLE_PERIOD_MS / 1000.0f; float energyRemaining; + // Reset ConsumedEnergy counter + if (batterySettings.ResetConsumedEnergy) { + flightBatteryData.ConsumedEnergy = 0; + batterySettings.ResetConsumedEnergy = false; + FlightBatterySettingsSet(&batterySettings); + } + // calculate the battery parameters if (voltageADCPin >= 0) { flightBatteryData.Voltage = (PIOS_ADC_PinGetVolt(voltageADCPin) - batterySettings.SensorCalibrations.VoltageZero) * batterySettings.SensorCalibrations.VoltageFactor; // in Volts diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml index 4d34e5037..d1a15e284 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Info.qml @@ -354,6 +354,13 @@ Item { Rectangle { anchors.fill: parent + MouseArea { + id: reset_consumed_energy_mouseArea; + anchors.fill: parent; + cursorShape: Qt.PointingHandCursor; + onClicked: qmlWidget.resetConsumedEnergy(); + } + // Alarm based on FlightBatteryState.EstimatedFlightTime < 120s orange, < 60s red color: (FlightBatteryState.EstimatedFlightTime <= 120 && FlightBatteryState.EstimatedFlightTime > 60 ? "orange" : (FlightBatteryState.EstimatedFlightTime <= 60 ? "red": info.batColors[SystemAlarms.Alarm_Battery])) diff --git a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Panels.qml b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Panels.qml index f8173c9ad..297924e15 100644 --- a/ground/openpilotgcs/share/openpilotgcs/pfd/default/Panels.qml +++ b/ground/openpilotgcs/share/openpilotgcs/pfd/default/Panels.qml @@ -480,6 +480,13 @@ Item { Rectangle { anchors.fill: parent + MouseArea { + id: reset_panel_consumed_energy_mouseArea; + anchors.fill: parent; + cursorShape: Qt.PointingHandCursor; + onClicked: qmlWidget.resetConsumedEnergy(); + } + // Alarm based on FlightBatteryState.EstimatedFlightTime < 120s orange, < 60s red color: (FlightBatteryState.EstimatedFlightTime <= 120 && FlightBatteryState.EstimatedFlightTime > 60 ? "orange" : (FlightBatteryState.EstimatedFlightTime <= 60 ? "red": panels.batColors[SystemAlarms.Alarm_Battery])) @@ -526,6 +533,13 @@ Item { anchors.fill: parent //color: panels.batColors[SystemAlarms.Alarm_Battery] + MouseArea { + id: reset_panel_consumed_energy_mouseArea2; + anchors.fill: parent; + cursorShape: Qt.PointingHandCursor; + onClicked: qmlWidget.resetConsumedEnergy(); + } + // Alarm based on FlightBatteryState.EstimatedFlightTime < 120s orange, < 60s red color: (FlightBatteryState.EstimatedFlightTime <= 120 && FlightBatteryState.EstimatedFlightTime > 60 ? "orange" : (FlightBatteryState.EstimatedFlightTime <= 60 ? "red": panels.batColors[SystemAlarms.Alarm_Battery])) diff --git a/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp index 6a0c650ea..616328091 100644 --- a/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.cpp @@ -18,6 +18,7 @@ #include "extensionsystem/pluginmanager.h" #include "uavobjectmanager.h" #include "uavobject.h" +#include "flightbatterysettings.h" #include "utils/svgimageprovider.h" #ifdef USE_OSG #include "osgearth.h" @@ -81,6 +82,8 @@ PfdQmlGadgetWidget::PfdQmlGadgetWidget(QWindow *parent) : ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); UAVObjectManager *objManager = pm->getObject(); + m_uavoManager = pm->getObject(); + Q_ASSERT(m_uavoManager); foreach(const QString &objectName, objectsToExport) { UAVObject *object = objManager->getObject(objectName); @@ -124,6 +127,14 @@ void PfdQmlGadgetWidget::setQmlFile(QString fn) } } +void PfdQmlGadgetWidget::resetConsumedEnergy() +{ + FlightBatterySettings *mBatterySettings = FlightBatterySettings::GetInstance(m_uavoManager); + + mBatterySettings->setResetConsumedEnergy(true); + mBatterySettings->setData(mBatterySettings->getData()); +} + void PfdQmlGadgetWidget::setEarthFile(QString arg) { if (m_earthFile != arg) { diff --git a/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.h b/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.h index 222fb8ce4..b971942e0 100644 --- a/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/pfdqml/pfdqmlgadgetwidget.h @@ -18,6 +18,7 @@ #define PFDQMLGADGETWIDGET_H_ #include "pfdqmlgadgetconfiguration.h" +#include "uavobjectmanager.h" #include class PfdQmlGadgetWidget : public QQuickView { @@ -84,6 +85,8 @@ public: return m_altitude; } + Q_INVOKABLE void resetConsumedEnergy(); + public slots: void setEarthFile(QString arg); void setTerrainEnabled(bool arg); @@ -119,6 +122,7 @@ protected: void mouseReleaseEvent(QMouseEvent *event); private: + UAVObjectManager *m_uavoManager; QString m_qmlFileName; QString m_earthFile; bool m_openGLEnabled; diff --git a/shared/uavobjectdefinition/flightbatterysettings.xml b/shared/uavobjectdefinition/flightbatterysettings.xml index 16154e5bb..a7fa762f4 100644 --- a/shared/uavobjectdefinition/flightbatterysettings.xml +++ b/shared/uavobjectdefinition/flightbatterysettings.xml @@ -7,6 +7,7 @@ +