1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 09:45:37 +03:00

Correct switch indentation in osd.c

This commit is contained in:
Dan Nixon 2017-05-26 09:21:27 +01:00
parent 36b1b581fa
commit 79a0f9738c

View file

@ -144,10 +144,10 @@ PG_REGISTER_WITH_RESET_FN(osdConfig_t, osdConfig, PG_OSD_CONFIG, 0);
static char osdGetAltitudeSymbol() static char osdGetAltitudeSymbol()
{ {
switch (osdConfig()->units) { switch (osdConfig()->units) {
case OSD_UNIT_IMPERIAL: case OSD_UNIT_IMPERIAL:
return 0xF; return 0xF;
default: default:
return 0xC; return 0xC;
} }
} }
@ -158,10 +158,10 @@ static char osdGetAltitudeSymbol()
static int32_t osdGetAltitude(int32_t alt) static int32_t osdGetAltitude(int32_t alt)
{ {
switch (osdConfig()->units) { switch (osdConfig()->units) {
case OSD_UNIT_IMPERIAL: case OSD_UNIT_IMPERIAL:
return (alt * 328) / 100; // Convert to feet / 100 return (alt * 328) / 100; // Convert to feet / 100
default: default:
return alt; // Already in metre / 100 return alt; // Already in metre / 100
} }
} }
@ -184,15 +184,15 @@ static void osdDrawSingleElement(uint8_t item)
switch(item) { switch(item) {
case OSD_RSSI_VALUE: case OSD_RSSI_VALUE:
{ {
uint16_t osdRssi = rssi * 100 / 1024; // change range uint16_t osdRssi = rssi * 100 / 1024; // change range
if (osdRssi >= 100) if (osdRssi >= 100)
osdRssi = 99; osdRssi = 99;
buff[0] = SYM_RSSI; buff[0] = SYM_RSSI;
tfp_sprintf(buff + 1, "%d", osdRssi); tfp_sprintf(buff + 1, "%d", osdRssi);
break; break;
} }
case OSD_MAIN_BATT_VOLTAGE: case OSD_MAIN_BATT_VOLTAGE:
buff[0] = SYM_BATT_5; buff[0] = SYM_BATT_5;
@ -200,12 +200,12 @@ static void osdDrawSingleElement(uint8_t item)
break; break;
case OSD_CURRENT_DRAW: case OSD_CURRENT_DRAW:
{ {
int32_t amperage = getAmperage(); int32_t amperage = getAmperage();
buff[0] = SYM_AMP; buff[0] = SYM_AMP;
tfp_sprintf(buff + 1, "%d.%02d", abs(amperage) / 100, abs(amperage) % 100); tfp_sprintf(buff + 1, "%d.%02d", abs(amperage) / 100, abs(amperage) % 100);
break; break;
} }
case OSD_MAH_DRAWN: case OSD_MAH_DRAWN:
buff[0] = SYM_MAH; buff[0] = SYM_MAH;
@ -225,43 +225,43 @@ static void osdDrawSingleElement(uint8_t item)
case OSD_GPS_LAT: case OSD_GPS_LAT:
case OSD_GPS_LON: case OSD_GPS_LON:
{ {
int32_t val; int32_t val;
if (item == OSD_GPS_LAT) { if (item == OSD_GPS_LAT) {
buff[0] = 0x64; // right arrow buff[0] = 0x64; // right arrow
val = GPS_coord[LAT]; val = GPS_coord[LAT];
} else { } else {
buff[0] = 0x60; // down arrow buff[0] = 0x60; // down arrow
val = GPS_coord[LON]; val = GPS_coord[LON];
}
if (val >= 0) {
val += 1000000000;
} else {
val -= 1000000000;
}
itoa(val, &buff[1], 10);
buff[1] = buff[2];
buff[2] = buff[3];
buff[3] = '.';
break;
} }
if (val >= 0) {
val += 1000000000;
} else {
val -= 1000000000;
}
itoa(val, &buff[1], 10);
buff[1] = buff[2];
buff[2] = buff[3];
buff[3] = '.';
break;
}
#endif // GPS #endif // GPS
case OSD_ALTITUDE: case OSD_ALTITUDE:
{ {
int32_t alt = osdGetAltitude(getEstimatedAltitude()); int32_t alt = osdGetAltitude(getEstimatedAltitude());
tfp_sprintf(buff, "%c%d.%01d%c", alt < 0 ? '-' : ' ', abs(alt / 100), abs((alt % 100) / 10), osdGetAltitudeSymbol()); tfp_sprintf(buff, "%c%d.%01d%c", alt < 0 ? '-' : ' ', abs(alt / 100), abs((alt % 100) / 10), osdGetAltitudeSymbol());
break; break;
} }
case OSD_ONTIME: case OSD_ONTIME:
{ {
uint32_t seconds = micros() / 1000000; uint32_t seconds = micros() / 1000000;
buff[0] = SYM_ON_M; buff[0] = SYM_ON_M;
tfp_sprintf(buff + 1, "%02d:%02d", seconds / 60, seconds % 60); tfp_sprintf(buff + 1, "%02d:%02d", seconds / 60, seconds % 60);
break; break;
} }
case OSD_FLYTIME: case OSD_FLYTIME:
buff[0] = SYM_FLY_M; buff[0] = SYM_FLY_M;
@ -274,37 +274,37 @@ static void osdDrawSingleElement(uint8_t item)
break; break;
case OSD_FLYMODE: case OSD_FLYMODE:
{ {
char *p = "ACRO"; char *p = "ACRO";
if (isAirmodeActive()) if (isAirmodeActive())
p = "AIR"; p = "AIR";
if (FLIGHT_MODE(FAILSAFE_MODE)) if (FLIGHT_MODE(FAILSAFE_MODE))
p = "!FS"; p = "!FS";
else if (FLIGHT_MODE(ANGLE_MODE)) else if (FLIGHT_MODE(ANGLE_MODE))
p = "STAB"; p = "STAB";
else if (FLIGHT_MODE(HORIZON_MODE)) else if (FLIGHT_MODE(HORIZON_MODE))
p = "HOR"; p = "HOR";
displayWrite(osdDisplayPort, elemPosX, elemPosY, p); displayWrite(osdDisplayPort, elemPosX, elemPosY, p);
return; return;
}
case OSD_CRAFT_NAME:
{
if (strlen(systemConfig()->name) == 0)
strcpy(buff, "CRAFT_NAME");
else {
for (uint8_t i = 0; i < MAX_NAME_LENGTH; i++) {
buff[i] = toupper((unsigned char)systemConfig()->name[i]);
if (systemConfig()->name[i] == 0)
break;
}
} }
break; case OSD_CRAFT_NAME:
} {
if (strlen(systemConfig()->name) == 0)
strcpy(buff, "CRAFT_NAME");
else {
for (uint8_t i = 0; i < MAX_NAME_LENGTH; i++) {
buff[i] = toupper((unsigned char)systemConfig()->name[i]);
if (systemConfig()->name[i] == 0)
break;
}
}
break;
}
case OSD_THROTTLE_POS: case OSD_THROTTLE_POS:
buff[0] = SYM_THR; buff[0] = SYM_THR;
@ -314,18 +314,18 @@ static void osdDrawSingleElement(uint8_t item)
#if defined(VTX_COMMON) #if defined(VTX_COMMON)
case OSD_VTX_CHANNEL: case OSD_VTX_CHANNEL:
{ {
uint8_t band=0, channel=0; uint8_t band=0, channel=0;
vtxCommonGetBandAndChannel(&band,&channel); vtxCommonGetBandAndChannel(&band,&channel);
uint8_t power = 0; uint8_t power = 0;
vtxCommonGetPowerIndex(&power); vtxCommonGetPowerIndex(&power);
const char vtxBandLetter = vtx58BandLetter[band]; const char vtxBandLetter = vtx58BandLetter[band];
const char *vtxChannelName = vtx58ChannelNames[channel]; const char *vtxChannelName = vtx58ChannelNames[channel];
sprintf(buff, "%c:%s:%d", vtxBandLetter, vtxChannelName, power); sprintf(buff, "%c:%s:%d", vtxBandLetter, vtxChannelName, power);
break; break;
} }
#endif #endif
case OSD_CROSSHAIRS: case OSD_CROSSHAIRS:
@ -341,113 +341,113 @@ static void osdDrawSingleElement(uint8_t item)
break; break;
case OSD_ARTIFICIAL_HORIZON: case OSD_ARTIFICIAL_HORIZON:
{ {
elemPosX = 14; elemPosX = 14;
elemPosY = 6 - 4; // Top center of the AH area elemPosY = 6 - 4; // Top center of the AH area
const int rollAngle = constrain(attitude.values.roll, -AH_MAX_ROLL, AH_MAX_ROLL); const int rollAngle = constrain(attitude.values.roll, -AH_MAX_ROLL, AH_MAX_ROLL);
int pitchAngle = constrain(attitude.values.pitch, -AH_MAX_PITCH, AH_MAX_PITCH); int pitchAngle = constrain(attitude.values.pitch, -AH_MAX_PITCH, AH_MAX_PITCH);
if (displayScreenSize(osdDisplayPort) == VIDEO_BUFFER_CHARS_PAL) { if (displayScreenSize(osdDisplayPort) == VIDEO_BUFFER_CHARS_PAL) {
++elemPosY; ++elemPosY;
}
// Convert pitchAngle to y compensation value
pitchAngle = (pitchAngle / 8) - 41; // 41 = 4 * 9 + 5
for (int x = -4; x <= 4; x++) {
int y = (-rollAngle * x) / 64;
y -= pitchAngle;
// y += 41; // == 4 * 9 + 5
if (y >= 0 && y <= 81) {
displayWriteChar(osdDisplayPort, elemPosX + x, elemPosY + (y / 9), (SYM_AH_BAR9_0 + (y % 9)));
} }
// Convert pitchAngle to y compensation value
pitchAngle = (pitchAngle / 8) - 41; // 41 = 4 * 9 + 5
for (int x = -4; x <= 4; x++) {
int y = (-rollAngle * x) / 64;
y -= pitchAngle;
// y += 41; // == 4 * 9 + 5
if (y >= 0 && y <= 81) {
displayWriteChar(osdDisplayPort, elemPosX + x, elemPosY + (y / 9), (SYM_AH_BAR9_0 + (y % 9)));
}
}
osdDrawSingleElement(OSD_HORIZON_SIDEBARS);
return;
} }
osdDrawSingleElement(OSD_HORIZON_SIDEBARS);
return;
}
case OSD_HORIZON_SIDEBARS: case OSD_HORIZON_SIDEBARS:
{ {
elemPosX = 14; elemPosX = 14;
elemPosY = 6; elemPosY = 6;
if (displayScreenSize(osdDisplayPort) == VIDEO_BUFFER_CHARS_PAL) { if (displayScreenSize(osdDisplayPort) == VIDEO_BUFFER_CHARS_PAL) {
++elemPosY; ++elemPosY;
}
// Draw AH sides
int8_t hudwidth = AH_SIDEBAR_WIDTH_POS;
int8_t hudheight = AH_SIDEBAR_HEIGHT_POS;
for (int8_t y = -hudheight; y <= hudheight; y++) {
displayWriteChar(osdDisplayPort, elemPosX - hudwidth, elemPosY + y, SYM_AH_DECORATION);
displayWriteChar(osdDisplayPort, elemPosX + hudwidth, elemPosY + y, SYM_AH_DECORATION);
}
// AH level indicators
displayWriteChar(osdDisplayPort, elemPosX - hudwidth + 1, elemPosY, SYM_AH_LEFT);
displayWriteChar(osdDisplayPort, elemPosX + hudwidth - 1, elemPosY, SYM_AH_RIGHT);
return;
} }
// Draw AH sides
int8_t hudwidth = AH_SIDEBAR_WIDTH_POS;
int8_t hudheight = AH_SIDEBAR_HEIGHT_POS;
for (int8_t y = -hudheight; y <= hudheight; y++) {
displayWriteChar(osdDisplayPort, elemPosX - hudwidth, elemPosY + y, SYM_AH_DECORATION);
displayWriteChar(osdDisplayPort, elemPosX + hudwidth, elemPosY + y, SYM_AH_DECORATION);
}
// AH level indicators
displayWriteChar(osdDisplayPort, elemPosX - hudwidth + 1, elemPosY, SYM_AH_LEFT);
displayWriteChar(osdDisplayPort, elemPosX + hudwidth - 1, elemPosY, SYM_AH_RIGHT);
return;
}
case OSD_ROLL_PIDS: case OSD_ROLL_PIDS:
{ {
const pidProfile_t *pidProfile = currentPidProfile; const pidProfile_t *pidProfile = currentPidProfile;
osdFormatPID(buff, "ROL", &pidProfile->pid[PID_ROLL]); osdFormatPID(buff, "ROL", &pidProfile->pid[PID_ROLL]);
break; break;
} }
case OSD_PITCH_PIDS: case OSD_PITCH_PIDS:
{ {
const pidProfile_t *pidProfile = currentPidProfile; const pidProfile_t *pidProfile = currentPidProfile;
osdFormatPID(buff, "PIT", &pidProfile->pid[PID_PITCH]); osdFormatPID(buff, "PIT", &pidProfile->pid[PID_PITCH]);
break; break;
} }
case OSD_YAW_PIDS: case OSD_YAW_PIDS:
{ {
const pidProfile_t *pidProfile = currentPidProfile; const pidProfile_t *pidProfile = currentPidProfile;
osdFormatPID(buff, "YAW", &pidProfile->pid[PID_YAW]); osdFormatPID(buff, "YAW", &pidProfile->pid[PID_YAW]);
break; break;
} }
case OSD_POWER: case OSD_POWER:
tfp_sprintf(buff, "%dW", getAmperage() * getBatteryVoltage() / 1000); tfp_sprintf(buff, "%dW", getAmperage() * getBatteryVoltage() / 1000);
break; break;
case OSD_PIDRATE_PROFILE: case OSD_PIDRATE_PROFILE:
{ {
const uint8_t pidProfileIndex = getCurrentPidProfileIndex(); const uint8_t pidProfileIndex = getCurrentPidProfileIndex();
const uint8_t rateProfileIndex = getCurrentControlRateProfileIndex(); const uint8_t rateProfileIndex = getCurrentControlRateProfileIndex();
tfp_sprintf(buff, "%d-%d", pidProfileIndex + 1, rateProfileIndex + 1); tfp_sprintf(buff, "%d-%d", pidProfileIndex + 1, rateProfileIndex + 1);
break; break;
} }
case OSD_MAIN_BATT_WARNING: case OSD_MAIN_BATT_WARNING:
switch(getBatteryState()) { switch(getBatteryState()) {
case BATTERY_WARNING: case BATTERY_WARNING:
tfp_sprintf(buff, "LOW BATTERY"); tfp_sprintf(buff, "LOW BATTERY");
break; break;
case BATTERY_CRITICAL: case BATTERY_CRITICAL:
tfp_sprintf(buff, " LAND NOW"); tfp_sprintf(buff, " LAND NOW");
break; break;
default: default:
return; return;
} }
break; break;
case OSD_AVG_CELL_VOLTAGE: case OSD_AVG_CELL_VOLTAGE:
{ {
const int cellV = getBatteryVoltage() * 10 / getBatteryCellCount(); const int cellV = getBatteryVoltage() * 10 / getBatteryCellCount();
buff[0] = SYM_BATT_5; buff[0] = SYM_BATT_5;
tfp_sprintf(buff + 1, "%d.%02dV", cellV / 100, cellV % 100); tfp_sprintf(buff + 1, "%d.%02dV", cellV / 100, cellV % 100);
break; break;
} }
case OSD_DEBUG: case OSD_DEBUG:
sprintf(buff, "DBG %5d %5d %5d %5d", debug[0], debug[1], debug[2], debug[3]); sprintf(buff, "DBG %5d %5d %5d %5d", debug[0], debug[1], debug[2], debug[3]);
@ -455,41 +455,41 @@ static void osdDrawSingleElement(uint8_t item)
case OSD_PITCH_ANGLE: case OSD_PITCH_ANGLE:
case OSD_ROLL_ANGLE: case OSD_ROLL_ANGLE:
{ {
const int angle = (item == OSD_PITCH_ANGLE) ? attitude.values.pitch : attitude.values.roll; const int angle = (item == OSD_PITCH_ANGLE) ? attitude.values.pitch : attitude.values.roll;
tfp_sprintf(buff, "%c%02d.%01d", angle < 0 ? '-' : ' ', abs(angle / 10), abs(angle % 10)); tfp_sprintf(buff, "%c%02d.%01d", angle < 0 ? '-' : ' ', abs(angle / 10), abs(angle % 10));
break; break;
} }
case OSD_MAIN_BATT_USAGE: case OSD_MAIN_BATT_USAGE:
{ {
//Set length of indicator bar //Set length of indicator bar
#define MAIN_BATT_USAGE_STEPS 10 #define MAIN_BATT_USAGE_STEPS 10
//Calculate constrained value //Calculate constrained value
float value = constrain(batteryConfig()->batteryCapacity - getMAhDrawn(), 0, batteryConfig()->batteryCapacity); float value = constrain(batteryConfig()->batteryCapacity - getMAhDrawn(), 0, batteryConfig()->batteryCapacity);
//Calculate mAh used progress //Calculate mAh used progress
uint8_t mAhUsedProgress = ceil((value / (batteryConfig()->batteryCapacity / MAIN_BATT_USAGE_STEPS))); uint8_t mAhUsedProgress = ceil((value / (batteryConfig()->batteryCapacity / MAIN_BATT_USAGE_STEPS)));
//Create empty battery indicator bar //Create empty battery indicator bar
buff[0] = SYM_PB_START; buff[0] = SYM_PB_START;
for(uint8_t i = 1; i <= MAIN_BATT_USAGE_STEPS; i++) { for(uint8_t i = 1; i <= MAIN_BATT_USAGE_STEPS; i++) {
if (i <= mAhUsedProgress) if (i <= mAhUsedProgress)
buff[i] = SYM_PB_FULL; buff[i] = SYM_PB_FULL;
else else
buff[i] = SYM_PB_EMPTY; buff[i] = SYM_PB_EMPTY;
}
buff[MAIN_BATT_USAGE_STEPS+1] = SYM_PB_CLOSE;
if (mAhUsedProgress > 0 && mAhUsedProgress < MAIN_BATT_USAGE_STEPS) {
buff[1+mAhUsedProgress] = SYM_PB_END;
}
buff[MAIN_BATT_USAGE_STEPS+2] = 0;
break;
} }
buff[MAIN_BATT_USAGE_STEPS+1] = SYM_PB_CLOSE;
if (mAhUsedProgress > 0 && mAhUsedProgress < MAIN_BATT_USAGE_STEPS) {
buff[1+mAhUsedProgress] = SYM_PB_END;
}
buff[MAIN_BATT_USAGE_STEPS+2] = 0;
break;
}
default: default:
return; return;