MISC UI implementation for battery

fixes #15
10.3.x-maintenance
cTn 2014-01-13 17:43:22 +01:00
parent f72a99f327
commit 467b228b34
4 changed files with 249 additions and 194 deletions

View File

@ -417,7 +417,7 @@ function process_data(command, message_buffer, message_length_expected) {
break;
case MSP_codes.MSP_MAG_CALIBRATION:
console.log('Mag calibration executed');
break;
break;
case MSP_codes.MSP_SET_MISC:
console.log('MISC Configuration saved');
break;

View File

@ -162,19 +162,14 @@
margin-left: 10px;
width: 145px;
border: 1px solid silver;
}
.tab-initial_setup .battery {
float: left;
display: block;
margin-left: 10px;
width: 145px;
border: 1px solid silver;
}
.tab-initial_setup .battery .head,
@ -188,14 +183,33 @@
border-bottom: 1px solid silver;
background-color: #ececec;
}
.tab-initial_setup .battery .fields {
padding: 5px;
.tab-initial_setup .battery .fields,
.tab-initial_setup .acc-trim .fields {
padding: 5px 5px 1px 5px;
}
.tab-initial_setup .battery .bat-voltage {
padding-left: 20px;
}
.tab-initial_setup .acc-trim dl {
padding: 5px;
.tab-initial_setup .battery dt {
float: left;
width: 100px;
line-height: 22px;
margin-bottom: 4px;
}
.tab-initial_setup .battery dd {
line-height: 22px;
margin-left: 100px;
margin-bottom: 4px;
}
.tab-initial_setup .battery input {
width: 70px;
height: 20px;
line-height: 20px;
border: 1px solid silver;
text-align: center;
}
.tab-initial_setup .acc-trim dt {
float: left;
@ -209,38 +223,35 @@
margin-bottom: 4px;
}
.tab-initial_setup .acc-trim input {
width: 80px;
width: 70px;
height: 20px;
line-height: 20px;
border: 1px solid silver;
text-align: center;
}
.tab-initial_setup .acc-trim a.update {
display: block;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 55px;
width: 80px;
height: 20px;
line-height: 20px;
text-align: center;
font-weight: bold;
border: 1px solid silver;
background-color: #ececec;
}
.tab-initial_setup .acc-trim a.update:hover {
background-color: #dedcdc;
}
.tab-initial_setup .save_settings {
display: block;
float: right;
width: 80px;
height: 20px;
line-height: 20px;
text-align: center;
font-weight: bold;
border: 1px solid silver;
background-color: #ececec;
}
.tab-initial_setup .save_settings:hover {
background-color: #dedcdc;
}
.tab-initial_setup .compass-wrapper {
position: absolute;
bottom: 60px;
right: 140px;
bottom: 30px;
right: 100px;
border: 1px solid silver;
border-radius: 50%;

View File

@ -42,22 +42,27 @@
</div>
</div>
</div>
<div class="battery">
<span class="head">Battery</span>
<div class="fields">
<dl>
<dt>Voltage:</dt><dd class="bat-voltage">0 V</dd>
<dt>Min Cell Voltage:</dt><dd><input type="number" name="mincellvoltage" step="0.1" value="0" /></dd>
<dt>Max Cell Voltage:</dt><dd><input type="number" name="maxcellvoltage" step="0.1" value="0" /></dd>
<dt>Voltage Scale:</dt><dd><input type="number" name="voltagescale" min="10" max="200" value="0" /></dd>
</dl>
</div>
</div>
<div class="acc-trim">
<span class="head">Accelerometer trims</span>
<div class="fields">
<dl>
<dt>Pitch:</dt><dd><input type="number" name="pitch" value="0" /></dd>
<dt>Roll:</dt><dd><input type="number" name="roll" value="0" /></dd>
<dt>Pitch:</dt><dd><input type="number" name="pitch" min="-300" max="300" value="0" /></dd>
<dt>Roll:</dt><dd><input type="number" name="roll" min="-300" max="300" value="0" /></dd>
</dl>
<a class="update" href="#">Save</a>
</div>
</div>
<div class="battery">
<span class="head">Battery</span>
<div class="fields">
Voltage: <span class="bat-voltage">0 V</span>
</div>
</div>
<a class="save_settings" href="#">Save</a>
<div class="compass-wrapper">
<div id="compass">
<span>N</span>

View File

@ -4,164 +4,203 @@ function tab_initialize_initial_setup() {
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT, false, function() {
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM, false, function() {
var yaw_fix = 0.0;
// Fill in the accel trimms from CONFIG object
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
// Display multiType
var str = '';
switch (CONFIG.multiType) {
case 1: // TRI
str = 'TRI';
break;
case 2: // QUAD +
str = 'Quad +';
break;
case 3: // QUAD X
str = 'Quad X';
break;
case 4: // BI
str = 'BI';
break;
case 5: // GIMBAL
str = 'Gimbal';
break;
case 6: // Y6
str = 'Y6';
break;
case 7: // HEX 6
str = 'HEX 6';
break;
case 8: // FLYING_WING
str = 'Flying Wing';
break;
case 9: // Y4
str = 'Y4';
break;
case 10: // HEX6 X
str = 'HEX6 X';
break;
case 11: // OCTO X8
case 12:
case 13:
str = 'OCTO X8';
break;
case 14: // AIRPLANE
str = 'Airplane';
break;
case 15: // Heli 120
str = 'Heli 120';
break;
case 16: // Heli 90
str = 'Heli 90';
break;
case 17: // Vtail
str = 'Vtail';
break;
case 18: // HEX6 H
str = 'HEX6 H';
break;
case 19: // PPM to SERVO
str = 'PPM to SERVO';
break;
case 20: // Dualcopter
str = 'Dualcopter';
break;
case 21: //
str = 'Singlecopter';
break;
}
$('span.model').html('Model: ' + str);
// UI Hooks
$('a.calibrateAccel').click(function() {
var self = $(this);
send_message(MSP_codes.MSP_MISC, MSP_codes.MSP_MISC, false, function() {
var yaw_fix = 0.0;
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
// During this period MCU won't be able to process any serial commands because its locked in a for/while loop
// until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow
GUI.interval_pause('initial_setup_data_pull');
send_message(MSP_codes.MSP_ACC_CALIBRATION, MSP_codes.MSP_ACC_CALIBRATION);
GUI.timeout_add('button_reset', function() {
GUI.interval_resume('initial_setup_data_pull');
self.removeClass('calibrating');
}, 2000);
// Fill in misc battery stuff
$('input[name="mincellvoltage"]').val(MISC.vbatmincellvoltage);
$('input[name="maxcellvoltage"]').val(MISC.vbatmaxcellvoltage);
$('input[name="voltagescale"]').val(MISC.vbatscale);
// Fill in the accel trimms from CONFIG object
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
// Display multiType
var str = '';
switch (CONFIG.multiType) {
case 1: // TRI
str = 'TRI';
break;
case 2: // QUAD +
str = 'Quad +';
break;
case 3: // QUAD X
str = 'Quad X';
break;
case 4: // BI
str = 'BI';
break;
case 5: // GIMBAL
str = 'Gimbal';
break;
case 6: // Y6
str = 'Y6';
break;
case 7: // HEX 6
str = 'HEX 6';
break;
case 8: // FLYING_WING
str = 'Flying Wing';
break;
case 9: // Y4
str = 'Y4';
break;
case 10: // HEX6 X
str = 'HEX6 X';
break;
case 11: // OCTO X8
case 12:
case 13:
str = 'OCTO X8';
break;
case 14: // AIRPLANE
str = 'Airplane';
break;
case 15: // Heli 120
str = 'Heli 120';
break;
case 16: // Heli 90
str = 'Heli 90';
break;
case 17: // Vtail
str = 'Vtail';
break;
case 18: // HEX6 H
str = 'HEX6 H';
break;
case 19: // PPM to SERVO
str = 'PPM to SERVO';
break;
case 20: // Dualcopter
str = 'Dualcopter';
break;
case 21: //
str = 'Singlecopter';
break;
}
});
$('a.calibrateMag').click(function() {
var self = $(this);
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
$('span.model').html('Model: ' + str);
send_message(MSP_codes.MSP_MAG_CALIBRATION, MSP_codes.MSP_MAG_CALIBRATION);
// UI Hooks
$('a.calibrateAccel').click(function() {
var self = $(this);
GUI.timeout_add('button_reset', function() {
self.removeClass('calibrating');
}, 30000);
}
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
// During this period MCU won't be able to process any serial commands because its locked in a for/while loop
// until this operation finishes, sending more commands through data_poll() will result in serial buffer overflow
GUI.interval_pause('initial_setup_data_pull');
send_message(MSP_codes.MSP_ACC_CALIBRATION, MSP_codes.MSP_ACC_CALIBRATION);
GUI.timeout_add('button_reset', function() {
GUI.interval_resume('initial_setup_data_pull');
self.removeClass('calibrating');
}, 2000);
}
});
$('a.calibrateMag').click(function() {
var self = $(this);
if (!self.hasClass('calibrating')) {
self.addClass('calibrating');
send_message(MSP_codes.MSP_MAG_CALIBRATION, MSP_codes.MSP_MAG_CALIBRATION);
GUI.timeout_add('button_reset', function() {
self.removeClass('calibrating');
}, 30000);
}
});
$('a.resetSettings').click(function() {
send_message(MSP_codes.MSP_RESET_CONF, MSP_codes.MSP_RESET_CONF);
});
$('a.save_settings').click(function() {
CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val());
CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val());
var buffer_out = new Array();
buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]);
buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]);
buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]);
buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]);
// Send over the new trims
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out);
MISC.vbatmincellvoltage = parseFloat($('input[name="mincellvoltage"]').val()) * 10;
MISC.vbatmaxcellvoltage = parseFloat($('input[name="maxcellvoltage"]').val()) * 10;
MISC.vbatscale = parseInt($('input[name="voltagescale"]').val());
// we also have to fill the unsupported bytes
var buffer_out = new Array();
buffer_out[0] = 0; // powerfailmeter
buffer_out[1] = 0;
buffer_out[2] = lowByte(MISC.minthrottle);
buffer_out[3] = highByte(MISC.minthrottle);
buffer_out[4] = 0; // mcfg.maxthrottle, mcfg.mincommand
buffer_out[5] = 0;
buffer_out[6] = 0;
buffer_out[7] = 0;
buffer_out[8] = lowByte(MISC.failsafe_throttle);
buffer_out[9] = highByte(MISC.failsafe_throttle);
buffer_out[10] = 0;
buffer_out[11] = 0;
buffer_out[12] = 0;
buffer_out[13] = 0;
buffer_out[14] = 0;
buffer_out[15] = 0;
buffer_out[16] = lowByte(MISC.mag_declination);
buffer_out[17] = highByte(MISC.mag_declination);
buffer_out[18] = MISC.vbatscale;
buffer_out[19] = MISC.vbatmincellvoltage;
buffer_out[20] = MISC.vbatmaxcellvoltage;
buffer_out[21] = 0; // vbatlevel_crit (unused)
// Send over new misc
send_message(MSP_codes.MSP_SET_MISC, buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
});
// reset yaw button hook
$('div#interactive_block > a.reset').click(function() {
yaw_fix = SENSOR_DATA.kinematicsZ * - 1.0;
console.log("YAW reset to 0");
});
$('#content .backup').click(configuration_backup);
$('#content .restore').click(configuration_restore);
GUI.interval_add('initial_setup_data_pull', function() {
// Update cube
var cube = $('div#cube');
cube.css('-webkit-transform', 'rotateY(' + ((SENSOR_DATA.kinematicsZ * -1.0) - yaw_fix) + 'deg)');
$('#cubePITCH', cube).css('-webkit-transform', 'rotateX(' + SENSOR_DATA.kinematicsY + 'deg)');
$('#cubeROLL', cube).css('-webkit-transform', 'rotateZ(' + SENSOR_DATA.kinematicsX + 'deg)');
// Update Compass
$('div#compass .pointer').css('-webkit-transform', 'rotate(' + (SENSOR_DATA.kinematicsZ) + 'deg)');
$('div#compass .value').html(SENSOR_DATA.kinematicsZ + '&deg;');
// Update voltage indicator
$('.bat-voltage').html(BATTERY.voltage + ' V');
// Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE);
send_message(MSP_codes.MSP_COMP_GPS, MSP_codes.MSP_COMP_GPS);
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG);
}, 50, true);
});
$('a.resetSettings').click(function() {
send_message(MSP_codes.MSP_RESET_CONF, MSP_codes.MSP_RESET_CONF);
});
$('a.update').click(function() {
CONFIG.accelerometerTrims[0] = parseInt($('input[name="pitch"]').val());
CONFIG.accelerometerTrims[1] = parseInt($('input[name="roll"]').val());
var buffer_out = new Array();
buffer_out[0] = lowByte(CONFIG.accelerometerTrims[0]);
buffer_out[1] = highByte(CONFIG.accelerometerTrims[0]);
buffer_out[2] = lowByte(CONFIG.accelerometerTrims[1]);
buffer_out[3] = highByte(CONFIG.accelerometerTrims[1]);
// Send over the new trims
send_message(MSP_codes.MSP_SET_ACC_TRIM, buffer_out);
// Save changes to EEPROM
send_message(MSP_codes.MSP_EEPROM_WRITE, MSP_codes.MSP_EEPROM_WRITE);
});
// reset yaw button hook
$('div#interactive_block > a.reset').click(function() {
yaw_fix = SENSOR_DATA.kinematicsZ * - 1.0;
console.log("YAW reset to 0");
});
$('#content .backup').click(configuration_backup);
$('#content .restore').click(configuration_restore);
GUI.interval_add('initial_setup_data_pull', function() {
// Update cube
var cube = $('div#cube');
cube.css('-webkit-transform', 'rotateY(' + ((SENSOR_DATA.kinematicsZ * -1.0) - yaw_fix) + 'deg)');
$('#cubePITCH', cube).css('-webkit-transform', 'rotateX(' + SENSOR_DATA.kinematicsY + 'deg)');
$('#cubeROLL', cube).css('-webkit-transform', 'rotateZ(' + SENSOR_DATA.kinematicsX + 'deg)');
// Update Compass
$('div#compass .pointer').css('-webkit-transform', 'rotate(' + (SENSOR_DATA.kinematicsZ) + 'deg)');
$('div#compass .value').html(SENSOR_DATA.kinematicsZ + '&deg;');
// Update voltage indicator
$('span.bat-voltage').html(BATTERY.voltage + ' V');
// Request new data
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
send_message(MSP_codes.MSP_ATTITUDE, MSP_codes.MSP_ATTITUDE);
send_message(MSP_codes.MSP_COMP_GPS, MSP_codes.MSP_COMP_GPS);
send_message(MSP_codes.MSP_ANALOG, MSP_codes.MSP_ANALOG);
}, 50, true);
});
});
}