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:
parent
2c896c9e91
commit
727e67d7fd
@ -860,7 +860,7 @@ static void processFlightMode(ManualControlSettingsData *settings, float flightM
|
|||||||
FlightStatusGet(&flightStatus);
|
FlightStatusGet(&flightStatus);
|
||||||
|
|
||||||
// Convert flightMode value into the switch position in the range [0..N-1]
|
// 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)
|
if (pos >= settings->FlightModeNumber)
|
||||||
pos = settings->FlightModeNumber - 1;
|
pos = settings->FlightModeNumber - 1;
|
||||||
|
|
||||||
|
@ -1158,8 +1158,8 @@ void ConfigInputWidget::moveFMSlider()
|
|||||||
m_config->fmsValue->setText(QString::number(scaledFlightMode * 100.0, 'f', 0));
|
m_config->fmsValue->setText(QString::number(scaledFlightMode * 100.0, 'f', 0));
|
||||||
|
|
||||||
// Convert flightMode value into the switch position in the range [0..N-1]
|
// 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
|
// This uses the same optimized computation as flight code to be consistent
|
||||||
uint8_t pos = (uint8_t)((valueScaled + 1.0) * manualSettingsDataPriv.FlightModeNumber) >> 1;
|
uint8_t pos = ((int16_t)(valueScaled * 256) + 256) * manualSettingsDataPriv.FlightModeNumber >> 9;
|
||||||
if (pos >= manualSettingsDataPriv.FlightModeNumber)
|
if (pos >= manualSettingsDataPriv.FlightModeNumber)
|
||||||
pos = manualSettingsDataPriv.FlightModeNumber - 1;
|
pos = manualSettingsDataPriv.FlightModeNumber - 1;
|
||||||
m_config->fmsSlider->setValue(pos);
|
m_config->fmsSlider->setValue(pos);
|
||||||
|
Loading…
Reference in New Issue
Block a user