forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperiodicStatusUpdater.js
128 lines (100 loc) · 3.78 KB
/
periodicStatusUpdater.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
const { GUI } = require('./gui');
const FC = require('./fc');
const CONFIGURATOR = require('./data_storage');
const MSP = require('./msp');
const MSPCodes = require('./msp/MSPCodes');
const mspQueue = require('./serial_queue');
var periodicStatusUpdater = (function () {
var publicScope = {},
privateScope = {};
var stoppped = false;
/**
*
* @param {number=} baudSpeed
* @returns {number}
*/
publicScope.getUpdateInterval = function (baudSpeed) {
if (!baudSpeed) {
baudSpeed = 115200;
}
if (baudSpeed >= 115200) {
return 300;
} else if (baudSpeed >= 57600) {
return 600;
} else if (baudSpeed >= 38400) {
return 800;
} else {
return 1000;
}
};
privateScope.updateView = function () {
var active = ((Date.now() - MSP.analog_last_received_timestamp) < publicScope.getUpdateInterval(CONFIGURATOR.connection.bitrate) * 3);
if (FC.isModeEnabled('ARM'))
$(".armedicon").css({
'background-image': 'url("./images/icons/cf_icon_armed_active.svg")'
});
else
$(".armedicon").css({
'background-image': 'url("./images/icons/cf_icon_armed_grey.svg")'
});
if (FC.isModeEnabled('FAILSAFE'))
$(".failsafeicon").css({
'background-image': 'url("./images/icons/cf_icon_failsafe_active.svg")'
});
else
$(".failsafeicon").css({
'background-image': 'url("./images/icons/cf_icon_failsafe_grey.svg")'
});
if (FC.ANALOG != undefined) {
var nbCells;
nbCells = FC.ANALOG.cell_count;
var min = FC.MISC.vbatmincellvoltage * nbCells;
var max = FC.MISC.vbatmaxcellvoltage * nbCells;
var warn = FC.MISC.vbatwarningcellvoltage * nbCells;
$(".battery-status").css({
width: FC.ANALOG.battery_percentage + "%",
display: 'inline-block'
});
if (active) {
$(".linkicon").css({
'background-image': 'url("./images/icons/cf_icon_link_active.svg")'
});
} else {
$(".linkicon").css({
'background-image': 'url("./images/icons/cf_icon_link_grey.svg")'
});
}
if (((FC.ANALOG.use_capacity_thresholds && FC.ANALOG.battery_remaining_capacity <= FC.MISC.battery_capacity_warning - FC.MISC.battery_capacity_critical) || (!FC.ANALOG.use_capacity_thresholds && FC.ANALOG.voltage < warn)) || FC.ANALOG.voltage < min) {
$(".battery-status").css('background-color', '#D42133');
} else {
$(".battery-status").css('background-color', '#59AA29');
}
$(".battery-legend").text(FC.ANALOG.voltage + " V");
}
$('#quad-status_wrapper').show();
};
publicScope.run = function () {
if (!CONFIGURATOR.connectionValid) {
return;
}
$(".quad-status-contents").css({
display: 'inline-block'
});
if (!stoppped && GUI.active_tab != 'cli') {
MSP.send_message(MSPCodes.MSP_SENSOR_STATUS, false, false);
MSP.send_message(MSPCodes.MSPV2_INAV_STATUS, false, false);
MSP.send_message(MSPCodes.MSP_ACTIVEBOXES, false, false);
MSP.send_message(MSPCodes.MSPV2_INAV_ANALOG, false, false);
privateScope.updateView();
}
};
publicScope.stop = function() {
stoppped = true;
}
publicScope.resume = function() {
stoppped = false;
}
return publicScope;
})();
module.exports = periodicStatusUpdater;