Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --osd-custom-message #32

Merged
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ pthread_cond_t video_cond;
int video_zpos = 1;

bool mavlink_dvr_on_arm = false;
bool osd_custom_message = false;

VideoCodec codec = VideoCodec::H265;
Dvr *dvr = NULL;
Expand Down Expand Up @@ -483,6 +484,8 @@ void printHelp() {
"\n"
" --osd-refresh <rate> - Defines the delay between osd refresh (Default: 1000 ms)\n"
"\n"
" --osd-custom-message - Enables the display of /run/pixelpilot.msg (beta feature, may be removed)\n"
"\n"
" --dvr-template <path> - Save the video feed (no osd) to the provided filename template.\n"
" DVR is toggled by SIGUSR1 signal\n"
" Supports placeholders %%Y - year, %%m - month, %%d - day,\n"
Expand Down Expand Up @@ -623,7 +626,12 @@ int main(int argc, char **argv)
osd_vars.telemetry_level = atoi(__ArgValue);
continue;
}


__OnArgument("--osd-custom-message") {
osd_custom_message = true;
continue;
}

__OnArgument("--screen-mode") {
char* mode = const_cast<char*>(__ArgValue);
mode_width = atoi(strtok(mode, "x"));
Expand Down
47 changes: 47 additions & 0 deletions src/osd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ uint32_t stats_rx_bytes = 0;
struct timespec last_timestamp = {0, 0};
float rx_rate = 0;
int hours = 0 , minutes = 0 , seconds = 0 , milliseconds = 0;
char custom_msg[80];
u_int custom_msg_refresh_count = 0;


double getTimeInterval(struct timespec* timestamp, struct timespec* last_meansure_timestamp) {
return (timestamp->tv_sec - last_meansure_timestamp->tv_sec) +
Expand Down Expand Up @@ -161,6 +164,50 @@ void modeset_paint_buffer(struct modeset_buf *buf) {
}
}

//display custom message
if (osd_custom_message) {
FILE *file = fopen("/run/pixelpilot.msg", "r");
if (file != NULL) {

if (fgets(custom_msg, sizeof(custom_msg), file) == NULL) {
perror("Error reading from file");
fclose(file);
}
fclose(file);
if (unlink("/run/pixelpilot.msg") != 0) {
perror("Error deleting the file");
}
custom_msg_refresh_count = 1;
}
if (custom_msg_refresh_count > 0) {

if (custom_msg_refresh_count++ > 5) custom_msg_refresh_count=0;

size_t msg_length = strlen(custom_msg);

// Ensure null termination at the 80th position to prevent overflow
custom_msg[79] = '\0';

// Find the first newline character, if it exists
char *newline_pos = strchr(custom_msg, '\n');
if (newline_pos != NULL) {
*newline_pos = '\0'; // Null-terminate at the newline
}

// Measure the text width
cairo_text_extents_t extents;
cairo_text_extents(cr, custom_msg, &extents);

// Calculate the position to center the text horizontally
double x = (buf->width / 2) - (extents.width / 2);
double y = (buf->height / 2);

// Set the position and draw the text
cairo_move_to(cr, x, y);
cairo_show_text(cr, custom_msg);
}
}

if (!osd_vars.enable_telemetry){
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ struct osd_vars {

extern struct osd_vars osd_vars;
extern int osd_thread_signal;
extern bool osd_custom_message;
extern pthread_mutex_t osd_mutex;

typedef struct {
Expand Down