diff --git a/Makefile.dji b/Makefile.dji index be0b669..d9d2a1b 100644 --- a/Makefile.dji +++ b/Makefile.dji @@ -45,9 +45,9 @@ goggle_ipk: install cp -r ipk/goggle/data ipk/goggle/build/ echo "2.0" > ipk/goggle/build/debian-binary cp -r ipk/goggle/control ipk/goggle/build/ - cd ipk/goggle/build/control && tar czvf ../control.tar.gz . - cd ipk/goggle/build/data && tar czvf ../data.tar.gz . - cd ipk/goggle/build && tar czvf "../../${IPK_NAME}" ./control.tar.gz ./data.tar.gz ./debian-binary + cd ipk/goggle/build/control && gtar czvf ../control.tar.gz . + cd ipk/goggle/build/data && gtar czvf ../data.tar.gz . + cd ipk/goggle/build && gtar czvf "../../${IPK_NAME}" ./control.tar.gz ./data.tar.gz ./debian-binary airunit_ipk: install $(eval PKG_NAME := $(shell cat ./ipk/airunit/control/control | grep Package | cut -d" " -f2)) diff --git a/ipk/goggle/control/control b/ipk/goggle/control/control index 62d1e67..bc5f8f4 100644 --- a/ipk/goggle/control/control +++ b/ipk/goggle/control/control @@ -1,5 +1,5 @@ Package: msp-osd -Version: 0.12.1 +Version: 0.12.2 Maintainer: bri3d Description: MSP OSD service for the DJI HD FPV goggles. Architecture: pigeon-glasses diff --git a/jni/font/font.c b/jni/font/font.c index 80fc0c1..c684d23 100644 --- a/jni/font/font.c +++ b/jni/font/font.c @@ -4,6 +4,7 @@ #include #include #include +// #include #include "../libspng/spng.h" #include "font.h" @@ -14,7 +15,7 @@ /* Font helper methods */ -void get_font_path_with_extension(char *font_path_dest, const char *font_path, const char *extension, uint8_t len, uint8_t is_hd, char *font_variant) +void get_font_path_with_extension(char *font_path_dest, const char *font_path, const char *extension, uint8_t len, uint8_t is_hd, const char *font_variant) { char name_buf[len]; char res_buf[len]; @@ -37,7 +38,7 @@ void get_font_path_with_extension(char *font_path_dest, const char *font_path, c DEBUG_PRINT("Font path: %s\n", font_path_dest); } -static int open_font(const char *filename, display_info_t *display_info, char *font_variant) +static int open_font(const char *filename, display_info_t *display_info, const char *font_variant) { char file_path[255]; int is_hd = (display_info->font_width == HD_FONT_WIDTH) ? 1 : 0; @@ -135,7 +136,7 @@ static int open_font(const char *filename, display_info_t *display_info, char *f return -1; } -void load_font(display_info_t *display_info, char *font_variant) { +void load_font(display_info_t *display_info, const char *font_variant) { // Note: load_font will not replace an existing font. if(display_info->fonts[0] == NULL) { @@ -143,11 +144,11 @@ void load_font(display_info_t *display_info, char *font_variant) { DEBUG_PRINT("IN LOAD_FONT\n"); // create a copy of font_variant char font_variant_lower[5] = ""; - if (font_variant != NULL) + if (font_variant != NULL) { DEBUG_PRINT("Lowercasing variant\n"); - int length = sizeof(font_variant) / sizeof(char); - for (int i = 0; i < length; i++) + size_t length = strlen(font_variant); + for (size_t i = 0; i < length && i < 4; i++) // Ensure not to exceed array bounds { font_variant_lower[i] = tolower(font_variant[i]); } @@ -160,12 +161,12 @@ void load_font(display_info_t *display_info, char *font_variant) { DEBUG_PRINT("Loading font %s\n", font_variant_lower); char *fallback_font_variant = ""; - if (font_variant_lower!=NULL && strcmp(font_variant_lower, "btfl") == 0) + if (strcmp(font_variant_lower, "btfl") == 0) { DEBUG_PRINT("Setting fallback font variant to bf\n"); fallback_font_variant = "bf"; } - else if (font_variant_lower != NULL && strcmp(font_variant_lower, "ultr") == 0) + else if (strcmp(font_variant_lower, "ultr") == 0) { DEBUG_PRINT("Setting fallback font variant to ultra\n"); fallback_font_variant = "ultra"; diff --git a/jni/font/font.h b/jni/font/font.h index 6325aa3..b806f0a 100644 --- a/jni/font/font.h +++ b/jni/font/font.h @@ -8,6 +8,8 @@ #define ENTWARE_FONT_PATH "/opt/fonts/font" #define SDCARD_FONT_PATH "/storage/sdcard0/font" +#define FALLBACK_FONT NULL + typedef enum { FONT_VARIANT_GENERIC, @@ -19,6 +21,6 @@ typedef enum FONT_VARIANT_COUNT } font_variant_e; -void load_font(display_info_t *display_info, char *font_variant); +void load_font(display_info_t *display_info, const char *font_variant); void close_font(display_info_t *display_info); -void get_font_path_with_extension(char *font_path_dest, const char *font_path, const char *extension, uint8_t len, uint8_t is_hd, char *font_variant); +void get_font_path_with_extension(char *font_path_dest, const char *font_path, const char *extension, uint8_t len, uint8_t is_hd, const char *font_variant); diff --git a/jni/osd_dji_overlay_udp.c b/jni/osd_dji_overlay_udp.c index 7e8d11c..1824aef 100644 --- a/jni/osd_dji_overlay_udp.c +++ b/jni/osd_dji_overlay_udp.c @@ -245,7 +245,7 @@ static void msp_callback(msp_msg_t *msp_message) displayport_process_message(display_driver, msp_message); } -static void load_fonts(font_variant_e font_variant) { +static void load_fonts(char* font_variant) { char file_path[255]; get_font_path_with_extension(file_path, "font", ".png", 255, 0, font_variant); toast(file_path); @@ -346,7 +346,7 @@ static void process_data_packet(uint8_t *buf, int len, dji_shm_state_t *radio_sh close_all_fonts(); load_fonts(current_fc_variant); // This is not a typo - fill in any missing fonts for the current variant with the generic one. - load_fonts(FONT_VARIANT_GENERIC); + load_fonts(FALLBACK_FONT); } } } @@ -400,9 +400,9 @@ static void rec_msp_draw_complete_hook() .font_width = current_display_info->font_width, .font_height = current_display_info->font_height, .x_offset = current_display_info->x_offset, - .y_offset = current_display_info->y_offset, - .font_variant = current_fc_variant, + .y_offset = current_display_info->y_offset }; + strcpy(config.font_variant, current_fc_variant); rec_start(&config); } @@ -480,7 +480,7 @@ static void rec_pb_timeout_hook() DEBUG_PRINT("msp_osd: playback config, x_offset: %d\n", osd_display_info->x_offset); DEBUG_PRINT("msp_osd: playback config, y_offset: %d\n", osd_display_info->y_offset); - DEBUG_PRINT("msp_osd: gls playing dvr, loading font variant %d\n", rec_config->font_variant); + DEBUG_PRINT("msp_osd: gls playing dvr, loading font variant %s\n", rec_config->font_variant); uint8_t is_hd = osd_display_info->font_width != sd_display_info.font_width; load_font(osd_display_info, rec_config->font_variant); @@ -577,7 +577,7 @@ void osd_directfb(duss_disp_instance_handle_t *disp, duss_hal_obj_handle_t ion_h memset(&last_render, 0, sizeof(last_render)); memset(&now, 0, sizeof(now)); - load_fonts(FONT_VARIANT_GENERIC); + load_fonts(FALLBACK_FONT); open_dji_radio_shm(&radio_shm); start_display(is_v2_goggles, disp, ion_handle); diff --git a/jni/rec/rec.c b/jni/rec/rec.c index f173777..d15ec20 100644 --- a/jni/rec/rec.c +++ b/jni/rec/rec.c @@ -42,6 +42,15 @@ void rec_start(rec_config_t *config) sizeof(rec_file_name)); DEBUG_PRINT("rec_file_name: %s", rec_file_name); + DEBUG_PRINT("Config:\n"); + DEBUG_PRINT(" Char Width: %u\n", config->char_width); + DEBUG_PRINT(" Char Height: %u\n", config->char_height); + DEBUG_PRINT(" Font Width: %u\n", config->font_width); + DEBUG_PRINT(" Font Height: %u\n", config->font_height); + DEBUG_PRINT(" X Offset: %u\n", config->x_offset); + DEBUG_PRINT(" Y Offset: %u\n", config->y_offset); + DEBUG_PRINT(" Font Variant: %.5s\n", config->font_variant); + rec_fd = fopen(rec_file_name, "wb"); if (rec_fd == NULL) { diff --git a/jni/rec/rec.h b/jni/rec/rec.h index 1657959..d75abc0 100644 --- a/jni/rec/rec.h +++ b/jni/rec/rec.h @@ -4,7 +4,7 @@ #include #define REC_MAGIC "MSPOSD" -#define REC_VERSION 1 +#define REC_VERSION 2 typedef struct rec_config_t { @@ -14,7 +14,7 @@ typedef struct rec_config_t uint8_t font_height; uint16_t x_offset; uint16_t y_offset; - uint8_t font_variant; + char font_variant[5]; } __attribute__((packed)) rec_config_t; typedef struct rec_file_header_t @@ -24,6 +24,24 @@ typedef struct rec_file_header_t rec_config_t config; } __attribute__((packed)) rec_file_header_t; +typedef struct rec_config_v1_t +{ + uint8_t char_width; + uint8_t char_height; + uint8_t font_width; + uint8_t font_height; + uint16_t x_offset; + uint16_t y_offset; + uint8_t font_variant; +} __attribute__((packed)) rec_config_v1_t; + +typedef struct rec_file_header_v1_t +{ + char magic[7]; + uint16_t version; + rec_config_v1_t config; +} __attribute__((packed)) rec_file_header_v1_t; + typedef struct rec_frame_header_t { uint32_t frame_idx; diff --git a/jni/rec/rec_pb.c b/jni/rec/rec_pb.c index 8920b63..48cd5bd 100644 --- a/jni/rec/rec_pb.c +++ b/jni/rec/rec_pb.c @@ -11,6 +11,8 @@ #include "rec_pb.h" +#include "../font/font.h" + #define REC_PB_CONFIG_ENABLED_KEY "rec_pb_enabled" #define MAX_X 60 @@ -34,6 +36,7 @@ static bool rec_pb_enabled = false; static FILE *osd_fd = NULL; static rec_config_t osd_config = {0}; +static uint32_t header_size = 0; static int64_t frame_counter = 0; static uint32_t *frame_idxs; @@ -90,7 +93,52 @@ int rec_pb_start() return 1; } - if (file_header.version != REC_VERSION) + if (file_header.version == REC_VERSION) + { + DEBUG_PRINT("header ok!"); + memcpy(&osd_config, &file_header.config, sizeof(rec_config_t)); + header_size = sizeof(rec_file_header_t); + } + else if (file_header.version == 1) + { + DEBUG_PRINT("header is v1"); + rec_file_header_v1_t file_header_v1; + fseek(osd_fd, 0, SEEK_SET); + + fread(&file_header_v1, sizeof(rec_file_header_v1_t), 1, osd_fd); + if (strncmp(file_header_v1.magic, REC_MAGIC, sizeof(REC_MAGIC)) != 0) + { + DEBUG_PRINT("invalid osd file"); + fclose(osd_fd); + osd_fd = NULL; + return 1; + } + + switch (file_header_v1.config.font_variant) + { + case FONT_VARIANT_BETAFLIGHT: + strcpy(file_header.config.font_variant, "BTFL"); + break; + case FONT_VARIANT_INAV: + strcpy(file_header.config.font_variant, "INAV"); + break; + case FONT_VARIANT_ARDUPILOT: + strcpy(file_header.config.font_variant, "ARDU"); + break; + case FONT_VARIANT_KISS_ULTRA: + strcpy(file_header.config.font_variant, "ULTR"); + break; + case FONT_VARIANT_QUICKSILVER: + strcpy(file_header.config.font_variant, "QUIC"); + break; + default: + file_header.config.font_variant[0] = '\0'; // Empty string + } + + memcpy(&osd_config, &file_header.config, sizeof(rec_config_t)); + header_size = sizeof(rec_file_header_v1_t); + } + else { DEBUG_PRINT("invalid osd file version! expected: %d, got: %d", REC_VERSION, file_header.version); fclose(osd_fd); @@ -98,14 +146,11 @@ int rec_pb_start() return 1; } - DEBUG_PRINT("header ok!"); - memcpy(&osd_config, &file_header.config, sizeof(rec_config_t)); - DEBUG_PRINT("loading frame indexes"); fseek(osd_fd, 0, SEEK_END); uint32_t file_size = ftell(osd_fd); - fseek(osd_fd, sizeof(rec_file_header_t), SEEK_SET); + fseek(osd_fd, header_size, SEEK_SET); DEBUG_PRINT("file size: %d", file_size); frame_idx_len = file_size / FRAME_SIZE; @@ -121,7 +166,7 @@ int rec_pb_start() fseek(osd_fd, sizeof(uint16_t) * MAX_T, SEEK_CUR); } - fseek(osd_fd, sizeof(rec_file_header_t), SEEK_SET); + fseek(osd_fd, header_size, SEEK_SET); current_frame_idx = 0; frame_counter = rec_pb_cp_vdec->frames_sent; @@ -179,7 +224,7 @@ int rec_pb_do_next_frame(uint16_t *map_out) fseek( osd_fd, - sizeof(rec_file_header_t) + (closest_frame_idx * FRAME_SIZE) + sizeof(rec_frame_header_t), + header_size + (closest_frame_idx * FRAME_SIZE) + sizeof(rec_frame_header_t), SEEK_SET); fread(map_out, sizeof(uint16_t), MAX_T, osd_fd); @@ -203,3 +248,4 @@ bool rec_pb_is_ready() { return rec_pb_cp_vdec != NULL && rec_pb_vdec_local_player != NULL; } +