accel trim support

10.3.x-maintenance
cTn 2013-04-15 10:03:34 +02:00
parent 0a1b8c5d03
commit 53eecaba14
4 changed files with 134 additions and 30 deletions

View File

@ -317,7 +317,9 @@ a:hover {
-webkit-transform: rotateX(90deg) translateZ(100px);
background-color: silver;
}
.tab-initial_setup .GPS_info {
.tab-initial_setup .GPS_info,
.tab-initial_setup .battery,
.tab-initial_setup .acc-trim {
float: left;
display: block;
@ -328,7 +330,9 @@ a:hover {
border: 1px solid silver;
}
.tab-initial_setup .GPS_info .head {
.tab-initial_setup .GPS_info .head,
.tab-initial_setup .battery .head,
.tab-initial_setup .acc-trim .head {
display: block;
text-align: center;
@ -342,37 +346,62 @@ a:hover {
padding: 5px;
line-height: 18px;
}
.tab-initial_setup .battery {
float: left;
display: block;
margin-top: 10px;
margin-left: 20px;
width: 145px;
border: 1px solid silver;
}
.tab-initial_setup .battery .head {
display: block;
text-align: center;
line-height: 20px;
font-weight: bold;
border-bottom: 1px solid silver;
background-color: #ececec;
}
.tab-initial_setup .battery .fields {
padding: 5px;
}
.tab-initial_setup .battery .bat-voltage {
padding-left: 20px;
}
.tab-initial_setup .acc-trim dl {
padding: 5px;
}
.tab-initial_setup .acc-trim dt {
float: left;
width: 50px;
margin-bottom: 4px;
}
.tab-initial_setup .acc-trim dd {
margin-left: 50px;
margin-bottom: 4px;
}
.tab-initial_setup .acc-trim input {
width: 80px;
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: 18px;
line-height: 18px;
color: white;
text-align: center;
border: 1px solid silver;
background-color: #6f1515;
}
.tab-initial_setup .acc-trim a.update:hover {
cursor: default;
}
.tab-initial_setup .acc-trim a.update.active {
background-color: #0fab16;
}
.tab-initial_setup .acc-trim a.update.active:hover {
cursor: pointer;
background-color: #13d81d;
}
.tab-initial_setup .compass-wrapper {
float: left;
margin-top: 100px;
margin-top: 60px;
margin-left: 80px;
border: 1px solid silver;

View File

@ -38,7 +38,12 @@ var MSP_codes = {
MSP_EEPROM_WRITE: 250,
MSP_DEBUGMSG: 253,
MSP_DEBUG: 254
MSP_DEBUG: 254,
// Additional baseflight commands that are not compatible with MultiWii
MSP_UID: 160,
MSP_ACC_TRIM: 240,
MSP_SET_ACC_TRIM: 239
}
var CONFIG = {
@ -47,7 +52,10 @@ var CONFIG = {
cycleTime: 0,
i2cError: 0,
activeSensors: 0,
mode: 0
mode: 0,
uid: [0, 0, 0],
accelerometerTrims: [0, 0]
}
var PIDs = new Array(10);
@ -207,7 +215,11 @@ function onOpen(openInfo) {
// start polling
serial_poll = setInterval(readPoll, 10);
port_usage_poll = setInterval(port_usage, 1000);
// baseflight specific
send_message(MSP_codes.MSP_UID, MSP_codes.MSP_UID);
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM);
// request configuration data
send_message(MSP_codes.MSP_IDENT, MSP_codes.MSP_IDENT);
send_message(MSP_codes.MSP_STATUS, MSP_codes.MSP_STATUS);
@ -603,13 +615,19 @@ function process_message(code, data) {
send_message(MSP_codes.MSP_RC_TUNING, MSP_codes.MSP_RC_TUNING);
send_message(MSP_codes.MSP_BOXNAMES, MSP_codes.MSP_BOXNAMES);
send_message(MSP_codes.MSP_BOX, MSP_codes.MSP_BOX);
// baseflight specific
send_message(MSP_codes.MSP_UID, MSP_codes.MSP_UID);
send_message(MSP_codes.MSP_ACC_TRIM, MSP_codes.MSP_ACC_TRIM);
break;
case MSP_codes.MSP_SELECT_SETTING:
console.log(data);
break;
break;
/* disabled (find out why ???)
case MSP_codes.MSP_BIND:
console.log(data);
break;
break;
*/
case MSP_codes.MSP_EEPROM_WRITE:
console.log('Settings Saved in EEPROM');
break;
@ -618,7 +636,24 @@ function process_message(code, data) {
break;
case MSP_codes.MSP_DEBUG:
console.log(data);
break;
break;
// Additional baseflight commands that are not compatible with MultiWii
case MSP_codes.MSP_UID:
if (data.byteLength > 0) {
CONFIG.uid[0] = view.getUint32(0, 1);
CONFIG.uid[1] = view.getUint32(4, 1);
CONFIG.uid[2] = view.getUint32(8, 1);
}
break;
case MSP_codes.MSP_ACC_TRIM:
if (data.byteLength > 0) {
CONFIG.accelerometerTrims[0] = view.getInt16(0, 1); // pitch
CONFIG.accelerometerTrims[1] = view.getInt16(2, 1); // roll
}
break;
case MSP_codes.MSP_SET_ACC_TRIM:
console.log('Accelerometer trimms saved.');
break;
}
}

View File

@ -70,6 +70,16 @@
Voltage: <span class="bat-voltage">0 V</span>
</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>
</dl>
<a class="update" href="#">Update</a>
</div>
</div>
<div class="compass-wrapper">
<div id="compass">
<span>N</span>

View File

@ -1,6 +1,11 @@
var yaw_fix = 0.0;
function tab_initialize_initial_setup() {
// Fill in the accel trimms from CONFIG object
$('input[name="pitch"]').val(CONFIG.accelerometerTrims[0]);
$('input[name="roll"]').val(CONFIG.accelerometerTrims[1]);
// UI Hooks
$('a.calibrateAccel').click(function() {
send_message(MSP_codes.MSP_ACC_CALIBRATION, MSP_codes.MSP_ACC_CALIBRATION);
});
@ -11,8 +16,33 @@ function tab_initialize_initial_setup() {
$('a.resetSettings').click(function() {
send_message(MSP_codes.MSP_RESET_CONF, MSP_codes.MSP_RESET_CONF);
});
$('input[name="pitch"], input[name="roll"]').change(function() {
// if any of the fields changed, unlock update button
$('a.update').addClass('active');
});
$('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);
// remove the active status
$(this).removeClass('active');
});
// reset yaw button hook
$('div#interactive_block > a.reset').click(function() {