Skip to content

Commit

Permalink
add osd profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Oct 20, 2024
1 parent 117c69a commit a024c8f
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 97 deletions.
78 changes: 45 additions & 33 deletions src/core/profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ const profile_t default_profile = {
RACEMODE, // AUX_RACEMODE
HORIZON, // AUX_HORIZON
STICK_BOOST_PROFILE, // AUX_STICK_BOOST_PROFILE
AUX_CHANNEL_OFF, // AUX_RATE_PROFILE
AUX_CHANNEL_OFF, // UNUSED_AUX_HIGH_RATES
#ifdef BUZZER_ENABLE // AUX_BUZZER_ENABLE
BUZZER_ENABLE,
#else
Expand All @@ -427,6 +427,7 @@ const profile_t default_profile = {
#endif
AUX_CHANNEL_OFF, // AUX_BLACKBOX
PREARM, // AUX_PREARM
AUX_CHANNEL_OFF, // AUX_OSD_PROFILE
},
.lqi_source = RX_LQI_SOURCE_PACKET_RATE,
.channel_mapping = RX_MAPPING_AETR,
Expand All @@ -438,39 +439,48 @@ const profile_t default_profile = {
},
},
.osd = {
.callsign = "QUICKSILVER",
.elements = {
ENCODE_OSD_ELEMENT(1, 1, 9, 1), // OSD_CALLSIGN
ENCODE_OSD_ELEMENT(1, 0, 11, 14), // OSD_CELL_COUNT
ENCODE_OSD_ELEMENT(0, 0, 1, 14), // OSD_FUELGAUGE_VOLTS
ENCODE_OSD_ELEMENT(1, 0, 14, 14), // OSD_FILTERED_VOLTS
ENCODE_OSD_ELEMENT(1, 0, 24, 14), // OSD_GYRO_TEMP
ENCODE_OSD_ELEMENT(1, 0, 10, 13), // OSD_FLIGHT_MODE
ENCODE_OSD_ELEMENT(1, 0, 24, 1), // OSD_RSSI
ENCODE_OSD_ELEMENT(1, 0, 24, 13), // OSD_STOPWATCH
ENCODE_OSD_ELEMENT(1, 0, 4, 6), // OSD_SYSTEM_STATUS
ENCODE_OSD_ELEMENT(1, 0, 1, 1), // OSD_THROTTLE
ENCODE_OSD_ELEMENT(0, 0, 1, 1), // OSD_VTX_CHANNEL
ENCODE_OSD_ELEMENT(1, 0, 1, 14), // OSD_CURRENT_DRAW
ENCODE_OSD_ELEMENT(0, 0, 14, 6), // OSD_CROSSHAIR
ENCODE_OSD_ELEMENT(1, 0, 1, 13), // OSD_CURRENT_DRAWN
},
.elements_hd = {
ENCODE_OSD_ELEMENT(1, 1, 19, 0), // OSD_CALLSIGN
ENCODE_OSD_ELEMENT(1, 0, 21, 17), // OSD_CELL_COUNT
ENCODE_OSD_ELEMENT(0, 0, 0, 17), // OSD_FUELGAUGE_VOLTS
ENCODE_OSD_ELEMENT(1, 0, 24, 17), // OSD_FILTERED_VOLTS
ENCODE_OSD_ELEMENT(1, 0, 44, 17), // OSD_GYRO_TEMP
ENCODE_OSD_ELEMENT(1, 0, 20, 16), // OSD_FLIGHT_MODE
ENCODE_OSD_ELEMENT(1, 0, 44, 0), // OSD_RSSI
ENCODE_OSD_ELEMENT(1, 0, 44, 16), // OSD_STOPWATCH
ENCODE_OSD_ELEMENT(1, 0, 14, 8), // OSD_SYSTEM_STATUS
ENCODE_OSD_ELEMENT(1, 0, 0, 0), // OSD_THROTTLE
ENCODE_OSD_ELEMENT(0, 0, 0, 0), // OSD_VTX_CHANNEL
ENCODE_OSD_ELEMENT(1, 0, 0, 17), // OSD_CURRENT_DRAW
ENCODE_OSD_ELEMENT(0, 0, 15, 8), // OSD_CROSSHAIR
ENCODE_OSD_ELEMENT(1, 0, 0, 16), // OSD_CURRENT_DRAWN
.guac_mode = 0,
.profiles = {
[OSD_PROFILE_1] = {
.callsign = "QUICKSILVER",
.elements = {
ENCODE_OSD_ELEMENT(1, 1, 9, 1, 19, 0), // OSD_CALLSIGN
ENCODE_OSD_ELEMENT(1, 0, 11, 14, 21, 17), // OSD_CELL_COUNT
ENCODE_OSD_ELEMENT(0, 0, 1, 14, 0, 17), // OSD_FUELGAUGE_VOLTS
ENCODE_OSD_ELEMENT(1, 0, 14, 14, 24, 17), // OSD_FILTERED_VOLTS
ENCODE_OSD_ELEMENT(1, 0, 24, 14, 44, 17), // OSD_GYRO_TEMP
ENCODE_OSD_ELEMENT(1, 0, 10, 13, 20, 16), // OSD_FLIGHT_MODE
ENCODE_OSD_ELEMENT(1, 0, 24, 1, 44, 0), // OSD_RSSI
ENCODE_OSD_ELEMENT(1, 0, 24, 13, 44, 16), // OSD_STOPWATCH
ENCODE_OSD_ELEMENT(1, 0, 4, 6, 14, 8), // OSD_SYSTEM_STATUS
ENCODE_OSD_ELEMENT(1, 0, 1, 1, 0, 0), // OSD_THROTTLE
ENCODE_OSD_ELEMENT(0, 0, 1, 1, 0, 0), // OSD_VTX_CHANNEL
ENCODE_OSD_ELEMENT(1, 0, 1, 14, 0, 17), // OSD_CURRENT_DRAW
ENCODE_OSD_ELEMENT(0, 0, 14, 6, 15, 8), // OSD_CROSSHAIR
ENCODE_OSD_ELEMENT(1, 0, 1, 13, 0, 16), // OSD_CURRENT_DRAWN
},
},
[OSD_PROFILE_2] = {
.callsign = "QUICKSILVER",
.elements = {
ENCODE_OSD_ELEMENT(0, 1, 9, 1, 19, 0), // OSD_CALLSIGN
ENCODE_OSD_ELEMENT(0, 0, 11, 14, 21, 17), // OSD_CELL_COUNT
ENCODE_OSD_ELEMENT(0, 0, 1, 14, 0, 17), // OSD_FUELGAUGE_VOLTS
ENCODE_OSD_ELEMENT(0, 0, 14, 14, 24, 17), // OSD_FILTERED_VOLTS
ENCODE_OSD_ELEMENT(0, 0, 24, 14, 44, 17), // OSD_GYRO_TEMP
ENCODE_OSD_ELEMENT(0, 0, 10, 13, 20, 16), // OSD_FLIGHT_MODE
ENCODE_OSD_ELEMENT(0, 0, 24, 1, 44, 0), // OSD_RSSI
ENCODE_OSD_ELEMENT(0, 0, 24, 13, 44, 16), // OSD_STOPWATCH
ENCODE_OSD_ELEMENT(0, 0, 4, 6, 14, 8), // OSD_SYSTEM_STATUS
ENCODE_OSD_ELEMENT(0, 0, 1, 1, 0, 0), // OSD_THROTTLE
ENCODE_OSD_ELEMENT(0, 0, 1, 1, 0, 0), // OSD_VTX_CHANNEL
ENCODE_OSD_ELEMENT(0, 0, 1, 14, 0, 17), // OSD_CURRENT_DRAW
ENCODE_OSD_ELEMENT(0, 0, 14, 6, 15, 8), // OSD_CROSSHAIR
ENCODE_OSD_ELEMENT(0, 0, 1, 13, 0, 16), // OSD_CURRENT_DRAWN
},
},
},

},
.blackbox = {
#ifdef BLACKBOX_DEBUG_FLAGS
Expand Down Expand Up @@ -543,6 +553,7 @@ MOTOR_MEMBERS
SERIAL_MEMBERS
FILTER_PARAMETER_MEMBERS
FILTER_MEMBERS
OSD_PROFILE_MEMBERS
OSD_MEMBERS
VOLTAGE_MEMBERS
PID_RATE_MEMBERS
Expand Down Expand Up @@ -617,6 +628,7 @@ MOTOR_MEMBERS
SERIAL_MEMBERS
FILTER_PARAMETER_MEMBERS
FILTER_MEMBERS
OSD_PROFILE_MEMBERS
OSD_MEMBERS
VOLTAGE_MEMBERS
PID_RATE_MEMBERS
Expand Down
31 changes: 22 additions & 9 deletions src/core/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define OSD_NUMBER_ELEMENTS 32

#define PROFILE_VERSION MAKE_SEMVER(0, 2, 4)
#define PROFILE_VERSION MAKE_SEMVER(0, 2, 5)

// Rates
typedef enum {
Expand Down Expand Up @@ -285,19 +285,32 @@ typedef struct {
MEMBER(hdzero, uint8_t) \
END_STRUCT()

typedef enum {
OSD_PROFILE_1,
OSD_PROFILE_2,
OSD_PROFILE_MAX,
} __attribute__((__packed__)) osd_profiles_t;

typedef struct {
uint8_t guac_mode;
uint8_t callsign[36];
uint32_t elements[OSD_NUMBER_ELEMENTS];
uint32_t elements_hd[OSD_NUMBER_ELEMENTS];
} profile_osd_profile_t;

#define OSD_PROFILE_MEMBERS \
START_STRUCT(profile_osd_profile_t) \
TSTR_MEMBER(callsign, 36) \
ARRAY_MEMBER(elements, OSD_NUMBER_ELEMENTS, uint32_t) \
END_STRUCT()

typedef struct {
uint8_t guac_mode;
profile_osd_profile_t profiles[OSD_PROFILE_MAX];
} profile_osd_t;

#define OSD_MEMBERS \
START_STRUCT(profile_osd_t) \
MEMBER(guac_mode, uint8_t) \
TSTR_MEMBER(callsign, 36) \
ARRAY_MEMBER(elements, OSD_NUMBER_ELEMENTS, uint32_t) \
ARRAY_MEMBER(elements_hd, OSD_NUMBER_ELEMENTS, uint32_t) \
#define OSD_MEMBERS \
START_STRUCT(profile_osd_t) \
MEMBER(guac_mode, uint8_t) \
ARRAY_MEMBER(profiles, OSD_PROFILE_MAX, profile_osd_profile_t) \
END_STRUCT()

typedef struct {
Expand Down
2 changes: 0 additions & 2 deletions src/osd/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ typedef struct {

static osd_menu_state_t menu_state;

extern osd_system_t osd_system;

void osd_menu_start() {
menu_state.onscreen_elements = 0;
menu_state.active_elements = 0;
Expand Down
82 changes: 53 additions & 29 deletions src/osd/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "core/profile.h"
#include "core/project.h"
#include "core/scheduler.h"
#include "driver/osd/osd.h"
#include "driver/reset.h"
#include "flight/control.h"
#include "io/blackbox_device.h"
Expand Down Expand Up @@ -121,11 +120,23 @@ uint8_t osd_attr(osd_element_t *el) {
return el->attribute ? OSD_ATTR_INVERT : OSD_ATTR_TEXT;
}

static osd_profiles_t osd_profile_index() {
return rx_aux_on(AUX_OSD_PROFILE) ? OSD_PROFILE_2 : OSD_PROFILE_1;
}

static profile_osd_profile_t *osd_profile() {
return &profile.osd.profiles[osd_profile_index()];
}

static uint32_t *osd_elements() {
if (osd_system == OSD_SYS_HD) {
return profile.osd.elements_hd;
}
return profile.osd.elements;
return osd_profile()->elements;
}

static void osd_start_el(osd_element_t *el) {
if (osd_system == OSD_SYS_HD)
osd_start(osd_attr(el), el->pos_hd_x, el->pos_hd_y);
else
osd_start(osd_attr(el), el->pos_sd_x, el->pos_sd_y);
}

void osd_display_reset() {
Expand Down Expand Up @@ -290,7 +301,7 @@ static void print_osd_flightmode(osd_element_t *el) {
flightmode = 0;
}

osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_data(flightmode_labels[flightmode], 10);
}

Expand All @@ -301,13 +312,13 @@ static void print_osd_rssi(osd_element_t *el) {

lpf(&rx_rssi_filt, state.rx_rssi, lpfcalc(state.looptime * 1e6f * 133.0f, 2e6f)); // 2 second filtertime and 15hz refresh rate @4k, 30hz@ 8k loop

osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_uint(rx_rssi_filt - 0.5f, 4);
osd_write_char(ICON_RSSI);
}

static void print_osd_crosshair(osd_element_t *el) {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_char(ICON_CROSSHAIR_1);
osd_write_char(ICON_CROSSHAIR_2);
osd_write_char(ICON_CROSSHAIR_3);
Expand All @@ -322,7 +333,7 @@ static void print_osd_armtime(osd_element_t *el) {
time_s -= 3600;
}

osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);

const uint32_t minutes = time_s / 60;
osd_write_uint(minutes / 10, 1);
Expand All @@ -338,7 +349,7 @@ static void print_osd_armtime(osd_element_t *el) {
// print the current vtx settings as Band:Channel:Power
static void print_osd_vtx(osd_element_t *el) {
#ifdef USE_VTX
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);

switch (vtx_settings.band) {
case VTX_BAND_A:
Expand Down Expand Up @@ -394,18 +405,18 @@ static void osd_display_regular() {

switch (osd_state.element) {
case OSD_CALLSIGN: {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_write_str((const char *)profile.osd.callsign);
osd_start_el(el);
osd_write_str((const char *)osd_profile()->callsign);

osd_state.element++;
break;
}

case OSD_CELL_COUNT: {
if (!flags.lowbatt) {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
} else {
osd_start(OSD_ATTR_BLINK | OSD_ATTR_INVERT, el->pos_x, el->pos_y);
osd_start(OSD_ATTR_BLINK | OSD_ATTR_INVERT, pos_x(el), pos_y(el));
}
osd_write_uint(state.lipo_cell_count, 1);
osd_write_char('S');
Expand All @@ -415,7 +426,7 @@ static void osd_display_regular() {
}

case OSD_FUELGAUGE_VOLTS: {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_float(state.vbat_compensated_cell_avg, 4, 1);
osd_write_char(ICON_GAUGE);

Expand All @@ -424,7 +435,7 @@ static void osd_display_regular() {
}

case OSD_FILTERED_VOLTS: {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_float(state.vbat_cell_avg, 4, 1);
osd_write_char(ICON_VOLT);

Expand All @@ -433,7 +444,7 @@ static void osd_display_regular() {
}

case OSD_GYRO_TEMP: {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_int(state.gyro_temp, 4);
osd_write_char(ICON_CELSIUS);

Expand Down Expand Up @@ -466,7 +477,7 @@ static void osd_display_regular() {
}

case OSD_THROTTLE: {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
const float throttle = state.rx_filtered.throttle * 100.0f;
if (profile.osd.guac_mode && throttle > 99.0f) {
osd_write_str("GUAC");
Expand All @@ -491,7 +502,7 @@ static void osd_display_regular() {
}

case OSD_CURRENT_DRAW: {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_float(state.ibat_filtered / 1000.0f, 4, 2);
osd_write_char(ICON_AMP);

Expand All @@ -500,7 +511,7 @@ static void osd_display_regular() {
}

case OSD_CURRENT_DRAWN: {
osd_start(osd_attr(el), el->pos_x, el->pos_y);
osd_start_el(el);
osd_write_float(state.ibat_drawn, 4, 2);
osd_write_char(ICON_MAH);

Expand Down Expand Up @@ -660,10 +671,16 @@ void osd_display() {
osd_display_reset();
break;

case OSD_SCREEN_REGULAR:
case OSD_SCREEN_REGULAR: {
static osd_profiles_t last_osd_profile_index = OSD_PROFILE_MAX;
if (last_osd_profile_index != osd_profile_index()) {
last_osd_profile_index = osd_profile_index();
osd_update_screen(OSD_SCREEN_CLEAR);
break;
}
osd_display_regular();
break;

}
case OSD_SCREEN_MAIN_MENU: {
osd_menu_start();
osd_menu_header("MENU");
Expand Down Expand Up @@ -901,12 +918,13 @@ void osd_display() {
osd_menu_select_enum_adjust(4, OSD_AUTO, "STICK BOOST", 17, &profile.receiver.aux[AUX_STICK_BOOST_PROFILE], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);

// PAGE 2
osd_menu_select_enum_adjust(4, OSD_AUTO, "RATE", 17, &profile.receiver.aux[AUX_RATE_PROFILE], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
osd_menu_select_enum_adjust(4, OSD_AUTO, "BUZZER", 17, &profile.receiver.aux[AUX_BUZZER_ENABLE], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
osd_menu_select_enum_adjust(4, OSD_AUTO, "TURTLE", 17, &profile.receiver.aux[AUX_TURTLE], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
osd_menu_select_enum_adjust(4, OSD_AUTO, "MOTOR TEST", 17, &profile.receiver.aux[AUX_MOTOR_TEST], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
osd_menu_select_enum_adjust(4, OSD_AUTO, "FPV SWITCH", 17, &profile.receiver.aux[AUX_FPV_SWITCH], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
osd_menu_select_enum_adjust(4, OSD_AUTO, "BLACKBOX", 17, &profile.receiver.aux[AUX_BLACKBOX], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
osd_menu_select_enum_adjust(4, OSD_AUTO, "PREARM", 17, &profile.receiver.aux[AUX_PREARM], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
osd_menu_select_enum_adjust(4, OSD_AUTO, "OSD PROFILE", 17, &profile.receiver.aux[AUX_OSD_PROFILE], aux_channel_labels, AUX_CHANNEL_0, AUX_CHANNEL_11);
}
osd_menu_scroll_finish(4);

Expand Down Expand Up @@ -1071,11 +1089,17 @@ void osd_display() {
osd_element_t *el = (osd_element_t *)(osd_elements() + i);

osd_menu_select(3, OSD_AUTO, osd_element_labels[i]);
if (osd_menu_select_int(20, OSD_AUTO, el->pos_x, 3)) {
el->pos_x = osd_menu_adjust_int(el->pos_x, 1, 0, osd_system == OSD_SYS_HD ? HD_COLS : SD_COLS);
if (osd_menu_select_int(20, OSD_AUTO, pos_x(el), 3)) {
if (osd_system == OSD_SYS_HD)
el->pos_hd_x = osd_menu_adjust_int(el->pos_hd_x, 1, 0, HD_ROWS);
else
el->pos_sd_x = osd_menu_adjust_int(el->pos_sd_x, 1, 0, SD_ROWS);
}
if (osd_menu_select_int(26, OSD_AUTO, el->pos_y, 3)) {
el->pos_y = osd_menu_adjust_int(el->pos_y, 1, 0, osd_system == OSD_SYS_HD ? HD_ROWS : SD_ROWS);
if (osd_menu_select_int(26, OSD_AUTO, pos_y(el), 3)) {
if (osd_system == OSD_SYS_HD)
el->pos_hd_y = osd_menu_adjust_int(el->pos_hd_y, 1, 0, HD_ROWS);
else
el->pos_sd_y = osd_menu_adjust_int(el->pos_sd_y, 1, 0, SD_ROWS);
}
}
osd_menu_scroll_finish(3);
Expand Down Expand Up @@ -1113,8 +1137,8 @@ void osd_display() {
osd_menu_header("CALLSIGN");

osd_menu_select(1, 5, "EDIT:");
if (osd_menu_select_str(8, 5, (char *)profile.osd.callsign)) {
osd_menu_adjust_str((char *)profile.osd.callsign);
if (osd_menu_select_str(8, 5, (char *)osd_profile()->callsign)) {
osd_menu_adjust_str((char *)osd_profile()->callsign);
}
osd_menu_label(8, 6, "-------------------");

Expand Down
Loading

0 comments on commit a024c8f

Please sign in to comment.