mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-24 00:35:39 +03:00
Improve OSD g-force display and avoid math when not needed
Previously the g-force element was being display using integer math and truncating the float value. This lead to the g-force displaying 0.9 much of the time. Changed to use rounding to one decimal place. Also avoid the g-force calculation unless the element or post-flight statistic are enabled. This saves unnecessary math including a sqrt().
This commit is contained in:
parent
d0076cf24e
commit
a66d6a2fc7
1 changed files with 16 additions and 9 deletions
|
@ -742,8 +742,11 @@ static bool osdDrawSingleElement(uint8_t item)
|
||||||
}
|
}
|
||||||
|
|
||||||
case OSD_G_FORCE:
|
case OSD_G_FORCE:
|
||||||
tfp_sprintf(buff, "%01d.%01dG", (int)osdGForce, (int)(osdGForce * 10) % 10);
|
{
|
||||||
break;
|
const int gForce = lrintf(osdGForce * 10);
|
||||||
|
tfp_sprintf(buff, "%01d.%01dG", gForce / 10, gForce % 10);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case OSD_ROLL_PIDS:
|
case OSD_ROLL_PIDS:
|
||||||
osdFormatPID(buff, "ROL", ¤tPidProfile->pid[PID_ROLL]);
|
osdFormatPID(buff, "ROL", ¤tPidProfile->pid[PID_ROLL]);
|
||||||
|
@ -1077,13 +1080,16 @@ static void osdDrawElements(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
osdGForce = 0.0f;
|
||||||
if (sensors(SENSOR_ACC)) {
|
if (sensors(SENSOR_ACC)) {
|
||||||
osdGForce = 0.0f;
|
// only calculate the G force if the element is visible or the stat is enabled
|
||||||
for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) {
|
if (VISIBLE(osdConfig()->item_pos[OSD_G_FORCE]) || osdStatGetState(OSD_STAT_MAX_G_FORCE)) {
|
||||||
const float a = accAverage[axis];
|
for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) {
|
||||||
osdGForce += a * a;
|
const float a = accAverage[axis];
|
||||||
|
osdGForce += a * a;
|
||||||
|
}
|
||||||
|
osdGForce = sqrtf(osdGForce) * acc.dev.acc_1G_rec;
|
||||||
}
|
}
|
||||||
osdGForce = sqrtf(osdGForce) * acc.dev.acc_1G_rec;
|
|
||||||
osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON);
|
osdDrawSingleElement(OSD_ARTIFICIAL_HORIZON);
|
||||||
osdDrawSingleElement(OSD_G_FORCE);
|
osdDrawSingleElement(OSD_G_FORCE);
|
||||||
}
|
}
|
||||||
|
@ -1551,8 +1557,9 @@ static void osdShowStats(uint16_t endBatteryVoltage)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (osdStatGetState(OSD_STAT_MAX_G_FORCE)) {
|
if (osdStatGetState(OSD_STAT_MAX_G_FORCE) && sensors(SENSOR_ACC)) {
|
||||||
tfp_sprintf(buff, "%01d.%01dG", (int)stats.max_g_force, (int)(stats.max_g_force * 10) % 10);
|
const int gForce = lrintf(stats.max_g_force * 10);
|
||||||
|
tfp_sprintf(buff, "%01d.%01dG", gForce / 10, gForce % 10);
|
||||||
osdDisplayStatisticLabel(top++, "MAX G-FORCE", buff);
|
osdDisplayStatisticLabel(top++, "MAX G-FORCE", buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue