Skip to content

Commit

Permalink
GPS icon now reflect fix state (#3377)
Browse files Browse the repository at this point in the history
* GPS icon now reflect fix state

* Code moved to sensor_helpers.js

* Code moved to sensor_helpers.js

* Minor changes
  • Loading branch information
HThuren committed Mar 13, 2023
1 parent 6ef0046 commit 6cbbaff
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/css/main.less
Expand Up @@ -482,7 +482,11 @@ input[type="number"] {
}
.gpsicon.active {
color: #818181;
background-image: url(../images/icons/sensor_sat_on.png);
background-image: url(../images/icons/sensor_sat_on_no_fix.png);
}
.gpsicon.active_fix {
color: #818181;
background-image: url(../images/icons/sensor_sat_on_with_fix.png);
}
.baroicon.active {
color: #818181;
Expand Down
Binary file added src/images/icons/sensor_sat_on_no_fix.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
4 changes: 2 additions & 2 deletions src/js/msp/MSPHelper.js
Expand Up @@ -191,7 +191,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
FC.CONFIG.mode = data.readU32();
FC.CONFIG.profile = data.readU8();

sensor_status(FC.CONFIG.activeSensors);
sensor_status(FC.CONFIG.activeSensors, FC.GPS_DATA.fix);
break;
case MSPCodes.MSP_STATUS_EX:
FC.CONFIG.cycleTime = data.readU16();
Expand All @@ -213,7 +213,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
FC.CONFIG.armingDisableCount = data.readU8(); // Flag count
FC.CONFIG.armingDisableFlags = data.readU32();

sensor_status(FC.CONFIG.activeSensors);
sensor_status(FC.CONFIG.activeSensors, FC.GPS_DATA.fix);
break;

case MSPCodes.MSP_RAW_IMU:
Expand Down
17 changes: 14 additions & 3 deletions src/js/sensor_helpers.js
Expand Up @@ -19,19 +19,23 @@ export function have_sensor(sensors_detected, sensor_code) {
return false;
}

export function sensor_status(sensors_detected) {
export function sensor_status(sensors_detected = 0, gps_fix_state = 0) {
// initialize variable (if it wasn't)
if (!sensor_status.previous_sensors_detected) {
sensor_status.previous_sensors_detected = -1; // Otherwise first iteration will not be run if sensors_detected == 0
}
if (!sensor_status.previous_gps_fix_state) {
sensor_status.previous_gps_fix_state = -1;
}

// update UI (if necessary)
if (sensor_status.previous_sensors_detected == sensors_detected) {
if (sensor_status.previous_sensors_detected == sensors_detected && sensor_status.previous_gps_fix_state == gps_fix_state) {
return;
}

// set current value
sensor_status.previous_sensors_detected = sensors_detected;
sensor_status.previous_gps_fix_state = gps_fix_state;

const eSensorStatus = $("div#sensor-status");

Expand Down Expand Up @@ -72,10 +76,17 @@ export function sensor_status(sensors_detected) {

if (have_sensor(sensors_detected, "gps")) {
$(".gps", eSensorStatus).addClass("on");
$(".gpsicon", eSensorStatus).addClass("active");
if (gps_fix_state) {
$(".gpsicon", eSensorStatus).removeClass("active");
$(".gpsicon", eSensorStatus).addClass("active_fix");
} else {
$(".gpsicon", eSensorStatus).removeClass("active_fix");
$(".gpsicon", eSensorStatus).addClass("active");
}
} else {
$(".gps", eSensorStatus).removeClass("on");
$(".gpsicon", eSensorStatus).removeClass("active");
$(".gpsicon", eSensorStatus).removeClass("active_fix");
}

if (have_sensor(sensors_detected, "sonar")) {
Expand Down
7 changes: 6 additions & 1 deletion src/js/serial_backend.js
Expand Up @@ -217,7 +217,7 @@ function finishClose(finishedCallback) {
$('div.connect_controls div.connect_state').text(i18n.getMessage('connect'));

// reset active sensor indicators
sensor_status(0);
sensor_status();

if (wasConnected) {
// detach listeners and remove element data
Expand Down Expand Up @@ -683,6 +683,9 @@ async function update_live_status() {
if (GUI.active_tab !== 'cli' && GUI.active_tab !== 'presets') {
await MSP.promise(MSPCodes.MSP_BOXNAMES);
await getStatus();
if (have_sensor(FC.CONFIG.activeSensors, 'gps')) {
await MSP.promise(MSPCodes.MSP_RAW_GPS);
}
await MSP.promise(MSPCodes.MSP_ANALOG);

const active = ((Date.now() - FC.ANALOG.last_received_timestamp) < 300);
Expand Down Expand Up @@ -723,6 +726,8 @@ async function update_live_status() {
}
}

sensor_status(FC.CONFIG.activeSensors, FC.GPS_DATA.fix);

$(".linkicon").toggleClass('active', active);

statuswrapper.show();
Expand Down

0 comments on commit 6cbbaff

Please sign in to comment.