1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

Even more optimize FlightMode switch position calculation

This runs in a high frequency loop and should use as little of
floating point as possible. Thanks to Kenn for the idea.
This commit is contained in:
Oleg Semyonov 2012-06-25 11:41:42 +03:00
parent 2c896c9e91
commit 727e67d7fd
2 changed files with 3 additions and 3 deletions

View File

@ -860,7 +860,7 @@ static void processFlightMode(ManualControlSettingsData *settings, float flightM
FlightStatusGet(&flightStatus);
// Convert flightMode value into the switch position in the range [0..N-1]
uint8_t pos = (uint8_t)((flightMode + 1.0f) * settings->FlightModeNumber) >> 1;
uint8_t pos = ((int16_t)(flightMode * 256.0f) + 256) * settings->FlightModeNumber >> 9;
if (pos >= settings->FlightModeNumber)
pos = settings->FlightModeNumber - 1;

View File

@ -1158,8 +1158,8 @@ void ConfigInputWidget::moveFMSlider()
m_config->fmsValue->setText(QString::number(scaledFlightMode * 100.0, 'f', 0));
// Convert flightMode value into the switch position in the range [0..N-1]
// This should use the same logic as flight code to be consistent
uint8_t pos = (uint8_t)((valueScaled + 1.0) * manualSettingsDataPriv.FlightModeNumber) >> 1;
// This uses the same optimized computation as flight code to be consistent
uint8_t pos = ((int16_t)(valueScaled * 256) + 256) * manualSettingsDataPriv.FlightModeNumber >> 9;
if (pos >= manualSettingsDataPriv.FlightModeNumber)
pos = manualSettingsDataPriv.FlightModeNumber - 1;
m_config->fmsSlider->setValue(pos);