Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display average RPM on motor tab #3371

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/js/tabs/motors.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,6 @@ motors.initialize = async function (callback) {

if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_42) || !(FC.MOTOR_CONFIG.use_dshot_telemetry || FC.MOTOR_CONFIG.use_esc_sensor)) {
$(".motor_testing .telemetry").hide();
} else {
// Hide telemetry from unused motors (to hide the tooltip in an empty blank space)
for (let i = FC.MOTOR_CONFIG.motor_count; i < FC.MOTOR_DATA.length; i++) {
$(`.motor_testing .telemetry .motor-${i}`).hide();
}
}

function setContentButtons(motorsTesting=false) {
Expand Down Expand Up @@ -1062,6 +1057,11 @@ motors.initialize = async function (callback) {
const previousArmState = self.armed;
const blockHeight = $('div.m-block:first').height();
const motorValues = getMotorOutputs();
const MAX_VALUE_SIZE = 6,
AVG_RPM_ROUNDING = 100;
let sumRpm = 0,
isAllMotorValueEqual = motorValues.every((value, _index, arr) => value === arr[0]),
hasTelemetryError = false;

for (let i = 0; i < motorValues.length; i++) {
const motorValue = motorValues[i];
Expand All @@ -1079,23 +1079,25 @@ motors.initialize = async function (callback) {

if (i < FC.MOTOR_CONFIG.motor_count && (FC.MOTOR_CONFIG.use_dshot_telemetry || FC.MOTOR_CONFIG.use_esc_sensor)) {

const MAX_INVALID_PERCENT = 100,
MAX_VALUE_SIZE = 6;
const MAX_INVALID_PERCENT = 100;

let rpmMotorValue = FC.MOTOR_TELEMETRY_DATA.rpm[i];

// Reduce the size of the value if too big
if (rpmMotorValue > 999999) {
rpmMotorValue = `${(rpmMotorValue / 1000000).toFixed(5 - (rpmMotorValue / 1000000).toFixed(0).toString().length)}M`;
}

if (isAllMotorValueEqual) {
sumRpm += Math.round(rpmMotorValue * AVG_RPM_ROUNDING) / AVG_RPM_ROUNDING;
}
rpmMotorValue = rpmMotorValue.toString().padStart(MAX_VALUE_SIZE);
let telemetryText = i18n.getMessage('motorsRPM', {motorsRpmValue: rpmMotorValue});

if (FC.MOTOR_CONFIG.use_dshot_telemetry) {

let invalidPercent = FC.MOTOR_TELEMETRY_DATA.invalidPercent[i];
let classError = (invalidPercent > MAX_INVALID_PERCENT) ? "warning" : "";
hasTelemetryError = invalidPercent > MAX_INVALID_PERCENT;
let classError = hasTelemetryError ? "warning" : "";
invalidPercent = (invalidPercent / 100).toFixed(2).toString().padStart(MAX_VALUE_SIZE);

telemetryText += `<br><span class="${classError}">`;
Expand All @@ -1116,6 +1118,15 @@ motors.initialize = async function (callback) {
}
}

if (FC.MOTOR_CONFIG.use_dshot_telemetry && !hasTelemetryError && isAllMotorValueEqual) {
const avgRpm = (Math.round(sumRpm / motorValues.length * AVG_RPM_ROUNDING) / AVG_RPM_ROUNDING).toFixed(0),
avgRpmMotorValue = avgRpm.toString().padStart(MAX_VALUE_SIZE),
message = i18n.getMessage('motorsRPM', { motorsRpmValue: avgRpmMotorValue });
$(`.motor_testing .telemetry .motor-master`).html(message);
} else {
$(`.motor_testing .telemetry .motor-master`).html("");
}

//keep the following here so at least we get a visual cue of our motor setup
update_arm_status();

Expand Down
4 changes: 2 additions & 2 deletions src/tabs/motors.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
</select>
</div>
</div>

<div class="row">
<div class="left-cell">
<div i18n="sensorsScale"></div>
Expand Down Expand Up @@ -319,7 +319,7 @@
<li><span class="motor-5 cf_tip" i18n_title="motorsTelemetryHelp">&nbsp;</span></li>
<li><span class="motor-6 cf_tip" i18n_title="motorsTelemetryHelp">&nbsp;</span></li>
<li><span class="motor-7 cf_tip" i18n_title="motorsTelemetryHelp">&nbsp;</span></li>
<li>&nbsp;</li>
<li><span class="motor-master cf_tip" i18n_title="motorsTelemetryHelp">&nbsp;</span></li>
</ul>
</div>
<div class="sliders">
Expand Down