Skip to content

Commit

Permalink
Merge pull request #1460 from iNavFlight/dzikuvx-current-meter-config
Browse files Browse the repository at this point in the history
Move current meter config to MSP_CURRENT_METER_CONFIG
  • Loading branch information
DzikuVx authored Feb 23, 2022
2 parents 90ab91b + 7f3dc9f commit 0412582
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
10 changes: 9 additions & 1 deletion js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ var CONFIG,
OUTPUT_MAPPING,
SETTINGS,
BRAKING_CONFIG,
SAFEHOMES;
SAFEHOMES,
CURRENT_METER_CONFIG;

var FC = {
MAX_SERVO_RATE: 125,
Expand Down Expand Up @@ -138,6 +139,13 @@ var FC = {
currentoffset: 0
};

CURRENT_METER_CONFIG = {
scale: 0,
offset: 0,
type: 0,
capacity: 0
};

LED_STRIP = [];
LED_COLORS = [];
LED_MODE_COLORS = [];
Expand Down
2 changes: 2 additions & 0 deletions js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var MSPCodes = {
MSP_SET_CHANNEL_FORWARDING: 33,
MSP_MODE_RANGES: 34,
MSP_SET_MODE_RANGE: 35,
MSP_CURRENT_METER_CONFIG: 40,
MSP_SET_CURRENT_METER_CONFIG: 41,
MSP_RX_CONFIG: 44,
MSP_SET_RX_CONFIG: 45,
MSP_LED_COLORS: 46,
Expand Down
31 changes: 31 additions & 0 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ var mspHelper = (function (gui) {
case MSPCodes.MSP_SET_RX_MAP:
console.log('RCMAP saved');
break;

case MSPCodes.MSP_BF_CONFIG:
BF_CONFIG.mixerConfiguration = data.getUint8(0);
BF_CONFIG.features = data.getUint32(1, true);
Expand All @@ -744,9 +745,22 @@ var mspHelper = (function (gui) {
BF_CONFIG.currentscale = data.getInt16(12, true);
BF_CONFIG.currentoffset = data.getInt16(14, true);
break;

case MSPCodes.MSP_SET_BF_CONFIG:
console.log('BF_CONFIG saved');
break;

case MSPCodes.MSP_CURRENT_METER_CONFIG:
CURRENT_METER_CONFIG.scale = data.getInt16(0, true);
CURRENT_METER_CONFIG.offset = data.getInt16(2, true);
CURRENT_METER_CONFIG.type = data.getUint8(4);
CURRENT_METER_CONFIG.capacity = data.getInt16(5, true);
break;

case MSPCodes.MSP_SET_CURRENT_METER_CONFIG:
console.log('MSP_SET_CURRENT_METER_CONFIG saved');
break;

case MSPCodes.MSP_SET_REBOOT:
console.log('Reboot request accepted');
break;
Expand Down Expand Up @@ -1536,6 +1550,15 @@ var mspHelper = (function (gui) {
i;

switch (code) {
case MSPCodes.MSP_SET_CURRENT_METER_CONFIG:
buffer.push(specificByte(CURRENT_METER_CONFIG.scale, 0));
buffer.push(specificByte(CURRENT_METER_CONFIG.scale, 1));
buffer.push(specificByte(CURRENT_METER_CONFIG.offset, 0));
buffer.push(specificByte(CURRENT_METER_CONFIG.offset, 1));
buffer.push(CURRENT_METER_CONFIG.type);
buffer.push(specificByte(CURRENT_METER_CONFIG.capacity, 0));
buffer.push(specificByte(CURRENT_METER_CONFIG.capacity, 1));
break;
case MSPCodes.MSP_SET_BF_CONFIG:
buffer.push(BF_CONFIG.mixerConfiguration);
buffer.push(specificByte(BF_CONFIG.features, 0));
Expand Down Expand Up @@ -2763,6 +2786,10 @@ var mspHelper = (function (gui) {
MSP.send_message(MSPCodes.MSP_BF_CONFIG, false, false, callback);
};

self.loadCurrentMeterConfig = function (callback) {
MSP.send_message(MSPCodes.MSP_CURRENT_METER_CONFIG, false, false, callback);
};

self.queryFcStatus = function (callback) {
MSP.send_message(MSPCodes.MSPV2_INAV_STATUS, false, false, callback);
};
Expand Down Expand Up @@ -2866,6 +2893,10 @@ var mspHelper = (function (gui) {
self.saveBfConfig = function (callback) {
MSP.send_message(MSPCodes.MSP_SET_BF_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_BF_CONFIG), false, callback);
};

self.saveCurrentMeterConfig = function (callback) {
MSP.send_message(MSPCodes.MSP_SET_CURRENT_METER_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_CURRENT_METER_CONFIG), false, callback);
};

self.saveMisc = function (callback) {
MSP.send_message(MSPCodes.MSP_SET_MISC, mspHelper.crunch(MSPCodes.MSP_SET_MISC), false, callback);
Expand Down
11 changes: 6 additions & 5 deletions tabs/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
mspHelper.loadINAVPidConfig,
mspHelper.loadVTXConfig,
mspHelper.loadMixerConfig,
mspHelper.loadCurrentMeterConfig,
loadCraftName,
mspHelper.loadMiscV2
];
Expand All @@ -59,6 +60,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
mspHelper.saveAdvancedConfig,
mspHelper.saveINAVPidConfig,
mspHelper.saveVTXConfig,
mspHelper.saveCurrentMeterConfig,
saveCraftName,
mspHelper.saveMiscV2,
saveSettings,
Expand Down Expand Up @@ -244,8 +246,8 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
$('#voltagescale').val(MISC.vbatscale);

// fill current
$('#currentscale').val(BF_CONFIG.currentscale);
$('#currentoffset').val(BF_CONFIG.currentoffset / 10);
$('#currentscale').val(CURRENT_METER_CONFIG.scale);
$('#currentoffset').val(CURRENT_METER_CONFIG.offset / 10);

// fill battery capacity
$('#battery_capacity').val(MISC.battery_capacity);
Expand Down Expand Up @@ -347,13 +349,12 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
}


helper.features.reset();
helper.features.fromUI($('.tab-configuration'));
helper.features.execute(function () {
BF_CONFIG.board_align_yaw = Math.round(parseFloat($('input[name="board_align_yaw"]').val()) * 10);
BF_CONFIG.currentscale = parseInt($('#currentscale').val());
BF_CONFIG.currentoffset = Math.round(parseFloat($('#currentoffset').val()) * 10);
CURRENT_METER_CONFIG.scale = parseInt($('#currentscale').val());
CURRENT_METER_CONFIG.offset = Math.round(parseFloat($('#currentoffset').val()) * 10);
saveChainer.execute();
});
});
Expand Down

0 comments on commit 0412582

Please sign in to comment.