1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

fixing the last bugger in curve/value update event

This commit is contained in:
cTn 2014-09-22 11:06:29 +02:00
parent a8b96a9206
commit 0cb69faf00

View file

@ -142,70 +142,74 @@ TABS.receiver.initialize = function (callback) {
// UI Hooks // UI Hooks
// curves // curves
$('.tunings .throttle input').on('input change', function () { $('.tunings .throttle input').on('input change', function () {
var throttleMidE = $('.tunings .throttle input[name="mid"]'), setTimeout(function () { // let global validation trigger and adjust the values first
throttleExpoE = $('.tunings .throttle input[name="expo"]'), var throttleMidE = $('.tunings .throttle input[name="mid"]'),
mid = parseFloat(throttleMidE.val()), throttleExpoE = $('.tunings .throttle input[name="expo"]'),
expo = parseFloat(throttleExpoE.val()), mid = parseFloat(throttleMidE.val()),
throttle_curve = $('.throttle_curve canvas').get(0), expo = parseFloat(throttleExpoE.val()),
context = throttle_curve.getContext("2d"); throttle_curve = $('.throttle_curve canvas').get(0),
context = throttle_curve.getContext("2d");
// built in validation that executes before global validation // local validation to deal with input event
if (mid >= parseFloat(throttleMidE.prop('min')) && if (mid >= parseFloat(throttleMidE.prop('min')) &&
mid <= parseFloat(throttleMidE.prop('max')) && mid <= parseFloat(throttleMidE.prop('max')) &&
expo >= parseFloat(throttleExpoE.prop('min')) && expo >= parseFloat(throttleExpoE.prop('min')) &&
expo <= parseFloat(throttleExpoE.prop('max'))) { expo <= parseFloat(throttleExpoE.prop('max'))) {
// continue // continue
} else { } else {
return; return;
} }
// math magic by englishman // math magic by englishman
var midx = 220 * mid, var midx = 220 * mid,
midxl = midx * 0.5, midxl = midx * 0.5,
midxr = (((220 - midx) * 0.5) + midx), midxr = (((220 - midx) * 0.5) + midx),
midy = 58 - (midx * (58 / 220)), midy = 58 - (midx * (58 / 220)),
midyl = 58 - ((58 - midy) * 0.5 *(expo + 1)), midyl = 58 - ((58 - midy) * 0.5 *(expo + 1)),
midyr = (midy / 2) * (expo + 1); midyr = (midy / 2) * (expo + 1);
// draw // draw
context.clearRect(0, 0, 220, 58); context.clearRect(0, 0, 220, 58);
context.beginPath(); context.beginPath();
context.moveTo(0, 58); context.moveTo(0, 58);
context.quadraticCurveTo(midxl, midyl, midx, midy); context.quadraticCurveTo(midxl, midyl, midx, midy);
context.moveTo(midx, midy); context.moveTo(midx, midy);
context.quadraticCurveTo(midxr, midyr, 220, 0); context.quadraticCurveTo(midxr, midyr, 220, 0);
context.lineWidth = 2; context.lineWidth = 2;
context.stroke(); context.stroke();
}, 0);
}).trigger('input'); }).trigger('input');
$('.tunings .rate input').on('input change', function () { $('.tunings .rate input').on('input change', function () {
var rateE = $('.tunings .rate input[name="rate"]'), setTimeout(function () { // let global validation trigger and adjust the values first
expoE = $('.tunings .rate input[name="expo"]'), var rateE = $('.tunings .rate input[name="rate"]'),
rate = parseFloat(rateE.val()), expoE = $('.tunings .rate input[name="expo"]'),
expo = parseFloat(expoE.val()), rate = parseFloat(rateE.val()),
pitch_roll_curve = $('.pitch_roll_curve canvas').get(0), expo = parseFloat(expoE.val()),
context = pitch_roll_curve.getContext("2d"); pitch_roll_curve = $('.pitch_roll_curve canvas').get(0),
context = pitch_roll_curve.getContext("2d");
// built in validation that executes before global validation // local validation to deal with input event
if (rate >= parseFloat(rateE.prop('min')) && if (rate >= parseFloat(rateE.prop('min')) &&
rate <= parseFloat(rateE.prop('max')) && rate <= parseFloat(rateE.prop('max')) &&
expo >= parseFloat(expoE.prop('min')) && expo >= parseFloat(expoE.prop('min')) &&
expo <= parseFloat(expoE.prop('max'))) { expo <= parseFloat(expoE.prop('max'))) {
// continue // continue
} else { } else {
return; return;
} }
// math magic by englishman // math magic by englishman
var ratey = 58 * rate; var ratey = 58 * rate;
// draw // draw
context.clearRect(0, 0, 220, 58); context.clearRect(0, 0, 220, 58);
context.beginPath(); context.beginPath();
context.moveTo(0, 58); context.moveTo(0, 58);
context.quadraticCurveTo(110, 58 - ((ratey / 2) * (1 - expo)), 220, 58 - ratey); context.quadraticCurveTo(110, 58 - ((ratey / 2) * (1 - expo)), 220, 58 - ratey);
context.lineWidth = 2; context.lineWidth = 2;
context.stroke(); context.stroke();
}, 0);
}).trigger('input'); }).trigger('input');
$('a.refresh').click(function () { $('a.refresh').click(function () {