From e200d62250fd482748902801dbec9b55e5ad6f2a Mon Sep 17 00:00:00 2001 From: Gus Grubba Date: Thu, 21 Jun 2018 23:00:21 -0400 Subject: [PATCH] Properly handle (unavailable) RX RSSI --- src/FlightDisplay/GuidedActionsController.qml | 2 +- src/Vehicle/Vehicle.cc | 18 +++++++++++++----- src/ui/toolbar/RCRSSIIndicator.qml | 9 +++++---- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/FlightDisplay/GuidedActionsController.qml b/src/FlightDisplay/GuidedActionsController.qml index c62766d2f..b7eb7b1db 100644 --- a/src/FlightDisplay/GuidedActionsController.qml +++ b/src/FlightDisplay/GuidedActionsController.qml @@ -130,7 +130,7 @@ Item { property bool _hideEmergenyStop: !QGroundControl.corePlugin.options.guidedBarShowEmergencyStop property bool _hideOrbit: !QGroundControl.corePlugin.options.guidedBarShowOrbit property bool _vehicleWasFlying: false - property bool _rcRSSIAvailable: _activeVehicle ? _activeVehicle.rcRSSI > 0 && _activeVehicle.rcRSSI < 255 : false + property bool _rcRSSIAvailable: _activeVehicle ? _activeVehicle.rcRSSI > 0 && _activeVehicle.rcRSSI <= 100 : false //Handy code for debugging state problems property bool __debugGuidedStates: false diff --git a/src/Vehicle/Vehicle.cc b/src/Vehicle/Vehicle.cc index cdd1d130d..81984b98c 100644 --- a/src/Vehicle/Vehicle.cc +++ b/src/Vehicle/Vehicle.cc @@ -110,7 +110,7 @@ Vehicle::Vehicle(LinkInterface* link, , _currentMessageType(MessageNone) , _updateCount(0) , _rcRSSI(255) - , _rcRSSIstore(255) + , _rcRSSIstore(255.) , _autoDisconnect(false) , _flying(false) , _landing(false) @@ -303,7 +303,7 @@ Vehicle::Vehicle(MAV_AUTOPILOT firmwareType, , _currentMessageType(MessageNone) , _updateCount(0) , _rcRSSI(255) - , _rcRSSIstore(255) + , _rcRSSIstore(255.) , _autoDisconnect(false) , _flying(false) , _landing(false) @@ -2447,10 +2447,18 @@ void Vehicle::_imageReady(UASInterface*) void Vehicle::_remoteControlRSSIChanged(uint8_t rssi) { - if (_rcRSSIstore < 0 || _rcRSSIstore > 100) { - _rcRSSIstore = rssi; + //-- 0 <= rssi <= 100 - 255 means "invalid/unknown" + if(rssi > 100) { // Anything over 100 doesn't make sense + if(_rcRSSI != 255) { + _rcRSSI = 255; + emit rcRSSIChanged(_rcRSSI); + } + return; + } + //-- Initialize it + if(_rcRSSIstore == 255.) { + _rcRSSIstore = (double)rssi; } - // Low pass to git rid of jitter _rcRSSIstore = (_rcRSSIstore * 0.9f) + ((float)rssi * 0.1); uint8_t filteredRSSI = (uint8_t)ceil(_rcRSSIstore); diff --git a/src/ui/toolbar/RCRSSIIndicator.qml b/src/ui/toolbar/RCRSSIIndicator.qml index baf04b172..aaed4813b 100644 --- a/src/ui/toolbar/RCRSSIIndicator.qml +++ b/src/ui/toolbar/RCRSSIIndicator.qml @@ -26,7 +26,8 @@ Item { anchors.bottom: parent.bottom visible: _activeVehicle ? _activeVehicle.supportsRadio : true - property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle + property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle + property bool _rcRSSIAvailable: _activeVehicle ? _activeVehicle.rcRSSI > 0 && _activeVehicle.rcRSSI <= 100 : false Component { id: rcRSSIInfo @@ -54,7 +55,7 @@ Item { GridLayout { id: rcrssiGrid - visible: _activeVehicle && _activeVehicle.rcRSSI != 255 + visible: _rcRSSIAvailable anchors.margins: ScreenTools.defaultFontPixelHeight columnSpacing: ScreenTools.defaultFontPixelWidth columns: 2 @@ -86,14 +87,14 @@ Item { sourceSize.height: height source: "/qmlimages/RC.svg" fillMode: Image.PreserveAspectFit - opacity: _activeVehicle ? (((_activeVehicle.rcRSSI < 0) || (_activeVehicle.rcRSSI > 100)) ? 0.5 : 1) : 0.5 + opacity: _rcRSSIAvailable ? 1 : 0.5 color: qgcPal.buttonText } SignalStrength { anchors.verticalCenter: parent.verticalCenter size: parent.height * 0.5 - percent: _activeVehicle ? ((_activeVehicle.rcRSSI > 100) ? 0 : _activeVehicle.rcRSSI) : 0 + percent: _rcRSSIAvailable ? _activeVehicle.rcRSSI : 0 } } -- 2.22.0