mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
AP_OSD: return a reference from AP::airspeed()
Every firmware which compiles airspeed support in also instantiates an AP_Airspeed object, so the singleton is never null. Returning a reference rather than a pointer says so, and lets the nullptr checks at each call site go away.
This commit is contained in:
committed by
Peter Barker
parent
3ffea9ba40
commit
fdfa57e6e7
@@ -2388,13 +2388,10 @@ void AP_OSD_Screen::draw_btemp(uint8_t x, uint8_t y)
|
||||
void AP_OSD_Screen::draw_atemp(uint8_t x, uint8_t y)
|
||||
{
|
||||
#if AP_AIRSPEED_ENABLED
|
||||
AP_Airspeed *airspeed = AP_Airspeed::get_singleton();
|
||||
if (!airspeed) {
|
||||
return;
|
||||
}
|
||||
const AP_Airspeed &airspeed = AP::airspeed();
|
||||
float temperature = 0;
|
||||
airspeed->get_temperature(temperature);
|
||||
if (airspeed->healthy()) {
|
||||
airspeed.get_temperature(temperature);
|
||||
if (airspeed.healthy()) {
|
||||
backend->write(x, y, false, "%3d%c", (int)u_scale(TEMPERATURE, temperature), u_icon(TEMPERATURE));
|
||||
} else {
|
||||
backend->write(x, y, false, "--%c", u_icon(TEMPERATURE));
|
||||
@@ -2415,12 +2412,9 @@ void AP_OSD_Screen::draw_bat2used(uint8_t x, uint8_t y)
|
||||
void AP_OSD_Screen::draw_aspd1(uint8_t x, uint8_t y)
|
||||
{
|
||||
#if AP_AIRSPEED_ENABLED
|
||||
AP_Airspeed *airspeed = AP_Airspeed::get_singleton();
|
||||
if (!airspeed) {
|
||||
return;
|
||||
}
|
||||
float asp1 = airspeed->get_airspeed();
|
||||
if (airspeed != nullptr && airspeed->healthy()) {
|
||||
const AP_Airspeed &airspeed = AP::airspeed();
|
||||
float asp1 = airspeed.get_airspeed();
|
||||
if (airspeed.healthy()) {
|
||||
backend->write(x, y, false, "%c%4d%c", SYMBOL(SYM_ASPD), (int)u_scale(SPEED, asp1), u_icon(SPEED));
|
||||
} else {
|
||||
backend->write(x, y, false, "%c ---%c", SYMBOL(SYM_ASPD), u_icon(SPEED));
|
||||
@@ -2431,12 +2425,9 @@ void AP_OSD_Screen::draw_aspd1(uint8_t x, uint8_t y)
|
||||
void AP_OSD_Screen::draw_aspd2(uint8_t x, uint8_t y)
|
||||
{
|
||||
#if AP_AIRSPEED_ENABLED
|
||||
AP_Airspeed *airspeed = AP_Airspeed::get_singleton();
|
||||
if (!airspeed) {
|
||||
return;
|
||||
}
|
||||
float asp2 = airspeed->get_airspeed(1);
|
||||
if (airspeed != nullptr && airspeed->healthy(1)) {
|
||||
const AP_Airspeed &airspeed = AP::airspeed();
|
||||
float asp2 = airspeed.get_airspeed(1);
|
||||
if (airspeed.healthy(1)) {
|
||||
backend->write(x, y, false, "%c%4d%c", SYMBOL(SYM_ASPD), (int)u_scale(SPEED, asp2), u_icon(SPEED));
|
||||
} else {
|
||||
backend->write(x, y, false, "%c ---%c", SYMBOL(SYM_ASPD), u_icon(SPEED));
|
||||
|
||||
Reference in New Issue
Block a user