Skip to content

Conversation

@shellixyz
Copy link
Collaborator

No description provided.

@shellixyz shellixyz force-pushed the nav_cruise_mode_osd_items branch 3 times, most recently from ebf4b26 to bf53f0e Compare June 21, 2018 16:44
int16_t heading_adjust = lrintf(CENTIDEGREES_TO_DEGREES((float)getCruiseHeadingAdjustment()));

if (ARMING_FLAG(ARMED) && ((!FLIGHT_MODE(NAV_CRUISE_MODE)) || !(isAdjustingPosition() || isAdjustingHeading() || (heading_adjust != 0)))) {
displayWrite(osdDisplayPort, elemPosX, elemPosY, " ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this extra call to displayWrite(). In functions as big as this one, I prefer to avoid early returns when possible. Can you make it write to buff the 5-space string? e.g.

            if (ARMING_FLAG(ARMED) && ((!FLIGHT_MODE(NAV_CRUISE_MODE)) || !(isAdjustingPosition() || isAdjustingHeading() || (heading_adjust != 0)))) {
                strcpy(buff, "     ");
            } else {
                buff[0] = SYM_HEADING;
                if (!ARMING_FLAG(ARMED))
                    buff[1] = buff[2] = buff[3] = buff[4] = '-';
                else if (FLIGHT_MODE(NAV_CRUISE_MODE)) {
                    tfp_sprintf(buff + 1, "%4d", heading_adjust);
                }
                buff[5] = SYM_DEGREES;
            }
            buff[6] = '\0';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a quick test and the early returns save 40 bytes of flash. Given the current state of flash in F3, I guess we're better off taking the flash savings.

@fiam fiam added this to the 2.0 milestone Jun 22, 2018
@shellixyz shellixyz force-pushed the nav_cruise_mode_osd_items branch from bf53f0e to c9a69a6 Compare June 22, 2018 22:06
@fiam fiam merged commit e05d2b3 into iNavFlight:development Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants