mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-26 17:55:30 +03:00
Merge pull request #6970 from etracer65/osd_gforce_fix
Improve OSD g-force display and avoid math when not needed
This commit is contained in:
commit
52b876a2a5
1 changed files with 16 additions and 9 deletions
|
@ -745,8 +745,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);
|
{
|
||||||
|
const int gForce = lrintf(osdGForce * 10);
|
||||||
|
tfp_sprintf(buff, "%01d.%01dG", gForce / 10, gForce % 10);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case OSD_ROLL_PIDS:
|
case OSD_ROLL_PIDS:
|
||||||
osdFormatPID(buff, "ROL", ¤tPidProfile->pid[PID_ROLL]);
|
osdFormatPID(buff, "ROL", ¤tPidProfile->pid[PID_ROLL]);
|
||||||
|
@ -1080,13 +1083,16 @@ static void osdDrawElements(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sensors(SENSOR_ACC)) {
|
|
||||||
osdGForce = 0.0f;
|
osdGForce = 0.0f;
|
||||||
|
if (sensors(SENSOR_ACC)) {
|
||||||
|
// only calculate the G force if the element is visible or the stat is enabled
|
||||||
|
if (VISIBLE(osdConfig()->item_pos[OSD_G_FORCE]) || osdStatGetState(OSD_STAT_MAX_G_FORCE)) {
|
||||||
for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) {
|
for (int axis = 0; axis < XYZ_AXIS_COUNT; axis++) {
|
||||||
const float a = accAverage[axis];
|
const float a = accAverage[axis];
|
||||||
osdGForce += a * a;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -1554,8 +1560,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