Skip to content

Commit c0de2e9

Browse files
committed
Reverse can be applied to multiple channels - display for now
1 parent b6070a5 commit c0de2e9

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

src/js/msp/MSPHelper.js

+15
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,20 @@ MspHelper.prototype.process_data = function (dataHandler) {
604604
}
605605
break;
606606
case MSPCodes.MSP_SERVO_MIX_RULES:
607+
FC.SERVO_RULES = []; // empty the array as new data is coming in
608+
const MAX_SERVO_RULES = 8 * 2;
609+
for (let i = 0; i < MAX_SERVO_RULES; i++) {
610+
const array = {
611+
targetChannel: data.readU8(),
612+
inputSource: data.readU8(),
613+
rate: data.readU8(),
614+
speed: data.readU8(),
615+
min: data.readU8(),
616+
max: data.readU8(),
617+
box: data.readU8(),
618+
};
619+
FC.SERVO_RULES.push(array);
620+
}
607621
break;
608622

609623
case MSPCodes.MSP_SERVO_CONFIGURATIONS:
@@ -2521,6 +2535,7 @@ MspHelper.prototype.sendServoConfigurations = function (onCompleteCallback) {
25212535
if (out == undefined) {
25222536
out = 255; // Cleanflight defines "CHANNEL_FORWARDING_DISABLED" as "(uint8_t)0xFF"
25232537
}
2538+
25242539
buffer.push8(out).push32(servoConfiguration.reversedInputSources);
25252540

25262541
// prepare for next iteration

src/js/tabs/servos.js

+26-19
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import { gui_log } from "../gui_log";
88
import $ from "jquery";
99

1010
const servos = {};
11+
12+
// Add clamp function to Number prototype
13+
Number.prototype.clamp = function (min, max) {
14+
return Math.min(Math.max(this, min), max);
15+
};
16+
1117
servos.initialize = function (callback) {
1218
if (GUI.active_tab !== "servos") {
1319
GUI.active_tab = "servos";
@@ -42,20 +48,22 @@ servos.initialize = function (callback) {
4248

4349
$(".tab-servos").addClass("supported");
4450

45-
let servoCheckbox = "";
51+
// setup header
4652
let servoHeader = "";
4753
for (let i = 0; i < FC.RC.active_channels - 4; i++) {
4854
servoHeader += `<th>A${i + 1}</th>`;
4955
}
56+
5057
servoHeader += '<th style="width: 110px" i18n="servosRateAndDirection"></th>';
51-
servoHeader += '<th style="width: 110px" i18n="servosReverse"></th>';
5258

59+
$("div.tab-servos table.fields tr.main").append(servoHeader);
60+
61+
// setup checkboxes
62+
let servoCheckbox = "";
5363
for (let i = 0; i < FC.RC.active_channels; i++) {
54-
servoCheckbox += `<td class="channel"><input type="checkbox"/></td>`;
64+
servoCheckbox += `<td class="channel" id="channel${i}"><input type="checkbox"/></td>`;
5565
}
5666

57-
$("div.tab-servos table.fields tr.main").append(servoHeader);
58-
5967
/*
6068
* function: void process_servos(string, object)
6169
*/
@@ -69,8 +77,7 @@ servos.initialize = function (callback) {
6977
element += `<td class="min">${subElement}${FC.SERVO_CONFIG[obj].min}" /></td>`;
7078
element += `<td class="middle">${subElement}${FC.SERVO_CONFIG[obj].middle}" /></td>`;
7179
element += `<td class="max">${subElement}${FC.SERVO_CONFIG[obj].max}" /></td>`;
72-
element += `${servoCheckbox}<td class="direction"></td>`;
73-
element += `<td class="reverse"></td></tr>`;
80+
element += `${servoCheckbox}<td class="direction"></td></tr>`;
7481

7582
$("div.tab-servos table.fields").append(element);
7683

@@ -95,17 +102,18 @@ servos.initialize = function (callback) {
95102

96103
$("div.tab-servos table.fields tr:last").data("info", { obj: obj });
97104

98-
// adding select box for servo reverse
99-
$("div.tab-servos table.fields tr:last td.reverse").append(
100-
'<select class="reverse" name="reverse"></select>',
101-
);
102-
103-
const reverse = $("div.tab-servos table.fields tr:last td.reverse select");
104-
105-
reverse.append(`<option value="0">${i18n.getMessage("servosNormal")}</option>`);
106-
reverse.append(`<option value="1">${i18n.getMessage("servosReverse")}</option>`);
107-
108-
reverse.val(FC.SERVO_CONFIG[obj].reversedInputSources);
105+
// check if input sources are reversed
106+
for (let i = 0; i < FC.SERVO_RULES.length; i++) {
107+
const inputSource = FC.SERVO_RULES[i].inputSource;
108+
const reversed = FC.SERVO_CONFIG[obj].reversedInputSources & (1 << inputSource);
109+
if (reversed) {
110+
FC.SERVO_CONFIG[obj].reversedInputSources |= 1 << inputSource;
111+
const inputSourceElement = $(`#channel${inputSource}`).find("input");
112+
if (inputSourceElement) {
113+
inputSourceElement.prop("checked", true).parent().css("background-color", "red");
114+
}
115+
}
116+
}
109117

110118
// UI hooks
111119

@@ -138,7 +146,6 @@ servos.initialize = function (callback) {
138146
FC.SERVO_CONFIG[info.obj].max = parseInt($(".max input", this).val());
139147

140148
FC.SERVO_CONFIG[info.obj].rate = parseInt($(".direction select", this).val());
141-
FC.SERVO_CONFIG[info.obj].reversedInputSources = parseInt($(".reverse select", this).val());
142149
});
143150

144151
//

0 commit comments

Comments
 (0)