diff --git a/openrtx/include/interfaces/graphics.h b/openrtx/include/interfaces/graphics.h index d9c8815f..6e6e04e6 100644 --- a/openrtx/include/interfaces/graphics.h +++ b/openrtx/include/interfaces/graphics.h @@ -226,13 +226,13 @@ void gfx_drawCircle(point_t start, uint16_t r, color_t color); /** * Prints text on the screen. * @param start: text line start point, in pixel coordinates. - * @param text: text to print. * @param size: text font size, defined as enum. * @param alignment: text alignment type, defined as enum. * @param color: text color, in color_t format. + * @param fmt: printf style format string * @return text width and height as point_t coordinates */ -point_t gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t alignment, color_t color); +point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment, color_t color, const char* fmt, ... ); /** * Prints an error message surrounded by a red box on the screen. diff --git a/openrtx/src/graphics.c b/openrtx/src/graphics.c index c0406797..3b188a92 100644 --- a/openrtx/src/graphics.c +++ b/openrtx/src/graphics.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -381,9 +382,16 @@ static inline uint16_t get_reset_x(textAlign_t alignment, uint16_t line_size, return 0; } -point_t gfx_print(point_t start, const char *text, fontSize_t size, - textAlign_t alignment, color_t color) +point_t gfx_print(point_t start, fontSize_t size, textAlign_t alignment, + color_t color, const char *fmt, ... ) { + va_list ap; + + char text[128]; + + va_start(ap, fmt); + vsnprintf(text, sizeof(text)-1, fmt, ap); + va_end(ap); GFXfont f = fonts[size]; @@ -480,7 +488,7 @@ void gfx_printError(const char *text, fontSize_t size) point_t start = {0, SCREEN_HEIGHT/2 + 5}; // Print the error message - point_t text_size = gfx_print(start, text, size, TEXT_ALIGN_CENTER, white); + point_t text_size = gfx_print(start, size, TEXT_ALIGN_CENTER, white, text); text_size.x += box_padding; text_size.y += box_padding; point_t box_start = {0, 0}; @@ -585,7 +593,6 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, color_t white = {255, 255, 255, 255}; color_t yellow = {250, 180, 19 , 255}; color_t red = {255, 0, 0 , 255}; - char buf[4] = { 0 }; // S-level marks and numbers for(int i = 0; i < 11; i++) @@ -595,11 +602,10 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, point_t pixel_pos = {start.x + i * (width - 1) / 11, start.y}; if (i == 10) { pixel_pos.x -= 8; - snprintf(buf, 4, "+%d", i); + gfx_print(pixel_pos, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, color, "+%d", i); } else - snprintf(buf, 4, "%d", i); - gfx_print(pixel_pos, buf, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, color); + gfx_print(pixel_pos, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, color, "%d", i); if (i == 10) { pixel_pos.x += 8; } @@ -608,7 +614,7 @@ void gfx_drawSmeter(point_t start, uint16_t width, uint16_t height, float rssi, } point_t pixel_pos = {start.x + width - 11, start.y}; - gfx_print(pixel_pos, "+20", FONT_SIZE_5PT, TEXT_ALIGN_LEFT, red); + gfx_print(pixel_pos, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, red, "+20"); pixel_pos.x += 10; pixel_pos.y += height; gfx_setPixel(pixel_pos, red); @@ -656,7 +662,6 @@ void gfx_drawGPSgraph(point_t start, { color_t white = {255, 255, 255, 255}; color_t yellow = {250, 180, 19 , 255}; - char id_buf[5] = { 0 }; // SNR Bars and satellite identifiers uint8_t bar_width = (width - 26) / 12; @@ -668,9 +673,9 @@ void gfx_drawGPSgraph(point_t start, start.y + (height - 8) - bar_height}; color_t bar_color = (active_sats & 1 << (sats[i].id - 1)) ? yellow : white; gfx_drawRect(bar_pos, bar_width, bar_height, bar_color, true); - snprintf(id_buf, 5, "%2d ", sats[i].id); point_t id_pos = {bar_pos.x, start.y + height}; - gfx_print(id_pos, id_buf, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, bar_color); + gfx_print(id_pos, FONT_SIZE_5PT, TEXT_ALIGN_LEFT, + bar_color, "%2d ", sats[i].id); } uint8_t bars_width = 9 + 11 * (bar_width + 2); point_t left_line_end = {start.x, start.y + height - 9}; @@ -714,5 +719,5 @@ void gfx_drawGPScompass(point_t start, } // North indicator point_t n_pos = {start.x + radius - 3, start.y + 7}; - gfx_print(n_pos, "N", FONT_SIZE_6PT, TEXT_ALIGN_LEFT, white); + gfx_print(n_pos, FONT_SIZE_6PT, TEXT_ALIGN_LEFT, white, "N"); } diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 1978c802..7b151f82 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -347,15 +347,13 @@ void ui_drawSplashScreen(bool centered) splash_origin.y = SCREEN_HEIGHT / 2 + 6; else splash_origin.y = SCREEN_HEIGHT / 4; - gfx_print(splash_origin, "OpenRTX", FONT_SIZE_12PT, TEXT_ALIGN_CENTER, - yellow_fab413); + gfx_print(splash_origin, FONT_SIZE_12PT, TEXT_ALIGN_CENTER, yellow_fab413, "OpenRTX"); #else if(centered) splash_origin.y = SCREEN_HEIGHT / 2 - 6; else splash_origin.y = SCREEN_HEIGHT / 5; - gfx_print(splash_origin, "O P N\nR T X", FONT_SIZE_12PT, TEXT_ALIGN_CENTER, - yellow_fab413); + gfx_print(splash_origin, FONT_SIZE_12PT, TEXT_ALIGN_CENTER, yellow_fab413, "O P N\nR T X"); #endif } @@ -370,15 +368,15 @@ void _ui_drawLowBatteryScreen() point_t text_pos_2 = {0, SCREEN_HEIGHT * 2 / 3 + 16}; gfx_print(text_pos_1, - "For emergency use", FONT_SIZE_6PT, TEXT_ALIGN_CENTER, - color_white); + color_white, + "For emergency use"); gfx_print(text_pos_2, - "press any button.", FONT_SIZE_6PT, TEXT_ALIGN_CENTER, - color_white); + color_white, + "press any button."); } freq_t _ui_freq_add_digit(freq_t freq, uint8_t pos, uint8_t number) diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/ui_main.c index 93cf9aaf..3404029e 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/ui_main.c @@ -35,11 +35,9 @@ void _ui_drawMainTop() { #ifdef HAS_RTC // Print clock on top bar - char clock_buf[9] = ""; - snprintf(clock_buf, sizeof(clock_buf), "%02d:%02d:%02d", last_state.time.hour, - last_state.time.minute, last_state.time.second); - gfx_print(layout.top_pos, clock_buf, layout.top_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "%02d:%02d:%02d", last_state.time.hour, + last_state.time.minute, last_state.time.second); #endif // Print battery icon on top bar, use 4 px padding @@ -50,45 +48,41 @@ void _ui_drawMainTop() gfx_drawBattery(bat_pos, bat_width, bat_height, last_state.charge); // Print radio mode on top bar - char mode[4] = ""; switch(last_state.channel.mode) { case FM: - strcpy(mode, "FM"); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_LEFT, + color_white, "FM"); break; case DMR: - strcpy(mode, "DMR"); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_LEFT, + color_white, "DMR"); break; } - gfx_print(layout.top_pos, mode, layout.top_font, TEXT_ALIGN_LEFT, - color_white); } void _ui_drawZoneChannel() { - char zone_buf[20] = ""; - char channel_buf[25] = ""; - if(!last_state.zone_enabled) - snprintf(zone_buf, sizeof(zone_buf), "zone: %.13s", "All channels"); - else - snprintf(zone_buf, sizeof(zone_buf), "zone: %.13s", last_state.zone.name); - snprintf(channel_buf, sizeof(channel_buf), " %03d: %.12s", last_state.channel_index, - last_state.channel.name); // Print Zone name - gfx_print(layout.line1_pos, zone_buf, layout.line1_font, TEXT_ALIGN_LEFT, color_white); + if(!last_state.zone_enabled) + gfx_print(layout.line1_pos, layout.line1_font, TEXT_ALIGN_LEFT, + color_white, "zone: All channels"); + else + gfx_print(layout.line1_pos, layout.line1_font, TEXT_ALIGN_LEFT, + color_white, "zone: %.13s", last_state.zone.name); // Print Channel name - gfx_print(layout.line2_pos, channel_buf, layout.line2_font, TEXT_ALIGN_LEFT, color_white); + gfx_print(layout.line2_pos, layout.line2_font, TEXT_ALIGN_LEFT, + color_white, " %03d: %.12s", + last_state.channel_index, last_state.channel.name); } void _ui_drawFrequency() { // Print big numbers frequency - char freq_buf[15] = ""; - snprintf(freq_buf, sizeof(freq_buf), "%03lu.%05lu", - (unsigned long)last_state.channel.rx_frequency/1000000, - (unsigned long)last_state.channel.rx_frequency%1000000/10); - gfx_print(layout.line3_pos, freq_buf, layout.line3_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line3_pos, layout.line3_font, TEXT_ALIGN_CENTER, + color_white, "%03lu.%05lu", + (unsigned long)last_state.channel.rx_frequency/1000000, + (unsigned long)last_state.channel.rx_frequency%1000000/10); } void _ui_drawVFOMiddleInput(ui_state_t* ui_state) @@ -97,17 +91,15 @@ void _ui_drawVFOMiddleInput(ui_state_t* ui_state) uint8_t insert_pos = ui_state->input_position + 3; if(ui_state->input_position > 3) insert_pos += 1; char input_char = ui_state->input_number + '0'; - char freq_buf[15] = ""; if(ui_state->input_set == SET_RX) { if(ui_state->input_position == 0) { - snprintf(freq_buf, sizeof(freq_buf), ">Rx:%03lu.%05lu", - (unsigned long)ui_state->new_rx_frequency/1000000, - (unsigned long)ui_state->new_rx_frequency%1000000/10); - gfx_print(layout.line2_pos, freq_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line2_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, ">Rx:%03lu.%05lu", + (unsigned long)ui_state->new_rx_frequency/1000000, + (unsigned long)ui_state->new_rx_frequency%1000000/10); } else { @@ -115,38 +107,35 @@ void _ui_drawVFOMiddleInput(ui_state_t* ui_state) if(ui_state->input_position == 1) strcpy(ui_state->new_rx_freq_buf, ">Rx:___._____"); ui_state->new_rx_freq_buf[insert_pos] = input_char; - gfx_print(layout.line2_pos, ui_state->new_rx_freq_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line2_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, ui_state->new_rx_freq_buf); } - snprintf(freq_buf, sizeof(freq_buf), " Tx:%03lu.%05lu", - (unsigned long)last_state.channel.tx_frequency/1000000, - (unsigned long)last_state.channel.tx_frequency%1000000/10); - gfx_print(layout.line3_pos, freq_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line3_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, " Tx:%03lu.%05lu", + (unsigned long)last_state.channel.tx_frequency/1000000, + (unsigned long)last_state.channel.tx_frequency%1000000/10); } else if(ui_state->input_set == SET_TX) { - snprintf(freq_buf, sizeof(freq_buf), " Rx:%03lu.%05lu", - (unsigned long)ui_state->new_rx_frequency/1000000, - (unsigned long)ui_state->new_rx_frequency%1000000/10); - gfx_print(layout.line2_pos, freq_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line2_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, " Rx:%03lu.%05lu", + (unsigned long)ui_state->new_rx_frequency/1000000, + (unsigned long)ui_state->new_rx_frequency%1000000/10); // Replace Rx frequency with underscorses if(ui_state->input_position == 0) { - snprintf(freq_buf, sizeof(freq_buf), ">Tx:%03lu.%05lu", - (unsigned long)ui_state->new_rx_frequency/1000000, - (unsigned long)ui_state->new_rx_frequency%1000000/10); - gfx_print(layout.line3_pos, freq_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line3_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, ">Tx:%03lu.%05lu", + (unsigned long)ui_state->new_rx_frequency/1000000, + (unsigned long)ui_state->new_rx_frequency%1000000/10); } else { if(ui_state->input_position == 1) strcpy(ui_state->new_tx_freq_buf, ">Tx:___._____"); ui_state->new_tx_freq_buf[insert_pos] = input_char; - gfx_print(layout.line3_pos, ui_state->new_tx_freq_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line3_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, ui_state->new_tx_freq_buf); } } } diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index f60bd1b6..f23d1499 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -50,7 +50,7 @@ void _ui_drawMenuList(uint8_t selected, int (*getCurrentEntry)(char *buf, uint8_ point_t rect_pos = {0, pos.y - layout.menu_h + 3}; gfx_drawRect(rect_pos, SCREEN_WIDTH, layout.menu_h, color_white, true); } - gfx_print(pos, entry_buf, layout.menu_font, TEXT_ALIGN_LEFT, text_color); + gfx_print(pos, layout.menu_font, TEXT_ALIGN_LEFT, text_color, entry_buf); pos.y += layout.menu_h; } } @@ -93,8 +93,8 @@ void _ui_drawMenuListValue(ui_state_t* ui_state, uint8_t selected, point_t rect_pos = {0, pos.y - layout.menu_h + 3}; gfx_drawRect(rect_pos, SCREEN_WIDTH, layout.menu_h, color_white, full_rect); } - gfx_print(pos, entry_buf, layout.menu_font, TEXT_ALIGN_LEFT, text_color); - gfx_print(pos, value_buf, layout.menu_font, TEXT_ALIGN_RIGHT, text_color); + gfx_print(pos, layout.menu_font, TEXT_ALIGN_LEFT, text_color, entry_buf); + gfx_print(pos, layout.menu_font, TEXT_ALIGN_RIGHT, text_color, value_buf); pos.y += layout.menu_h; } } @@ -252,8 +252,8 @@ void _ui_drawMenuTop(ui_state_t* ui_state) { gfx_clearScreen(); // Print "Menu" on top bar - gfx_print(layout.top_pos, "Menu", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Menu"); // Print menu entries _ui_drawMenuList(ui_state->menu_selected, _ui_getMenuTopEntryName); } @@ -262,8 +262,8 @@ void _ui_drawMenuZone(ui_state_t* ui_state) { gfx_clearScreen(); // Print "Zone" on top bar - gfx_print(layout.top_pos, "Zone", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Zone"); // Print zone entries _ui_drawMenuList(ui_state->menu_selected, _ui_getZoneName); } @@ -272,8 +272,8 @@ void _ui_drawMenuChannel(ui_state_t* ui_state) { gfx_clearScreen(); // Print "Channel" on top bar - gfx_print(layout.top_pos, "Channels", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Channels"); // Print channel entries _ui_drawMenuList(ui_state->menu_selected, _ui_getChannelName); } @@ -282,8 +282,8 @@ void _ui_drawMenuContacts(ui_state_t* ui_state) { gfx_clearScreen(); // Print "Contacts" on top bar - gfx_print(layout.top_pos, "Contacts", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Contacts"); // Print contact entries _ui_drawMenuList(ui_state->menu_selected, _ui_getContactName); } @@ -292,21 +292,21 @@ void _ui_drawMenuContacts(ui_state_t* ui_state) void _ui_drawMenuGPS() { char *fix_buf, *type_buf; - char lat_buf[12] = { 0 }; - char lon_buf[12] = { 0 }; - char data_buf[25] = { 0 }; gfx_clearScreen(); // Print "GPS" on top bar - gfx_print(layout.top_pos, "GPS", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "GPS"); point_t fix_pos = {layout.line2_pos.x, SCREEN_HEIGHT * 2 / 5}; // Print GPS status, if no fix, hide details if(!last_state.settings.gps_enabled) - gfx_print(fix_pos, "GPS OFF", layout.line3_font, TEXT_ALIGN_CENTER, color_white); + gfx_print(fix_pos, layout.line3_font, TEXT_ALIGN_CENTER, + color_white, "GPS OFF"); else if (last_state.gps_data.fix_quality == 0) - gfx_print(fix_pos, "No Fix", layout.line3_font, TEXT_ALIGN_CENTER, color_white); + gfx_print(fix_pos, layout.line3_font, TEXT_ALIGN_CENTER, + color_white, "No Fix"); else if (last_state.gps_data.fix_quality == 6) - gfx_print(fix_pos, "Fix Lost", layout.line3_font, TEXT_ALIGN_CENTER, color_white); + gfx_print(fix_pos, layout.line3_font, TEXT_ALIGN_CENTER, + color_white, "Fix Lost"); else { switch(last_state.gps_data.fix_quality) @@ -340,29 +340,26 @@ void _ui_drawMenuGPS() type_buf = "ERROR"; break; } - gfx_print(layout.line1_pos, fix_buf, layout.top_font, TEXT_ALIGN_LEFT, - color_white); - gfx_print(layout.line1_pos, "N ", layout.top_font, TEXT_ALIGN_CENTER, - color_white); - snprintf(lat_buf, 12, "%8.6f", last_state.gps_data.latitude); - gfx_print(layout.line1_pos, lat_buf, layout.top_font, TEXT_ALIGN_RIGHT, - color_white); - gfx_print(layout.line2_pos, type_buf, layout.top_font, TEXT_ALIGN_LEFT, - color_white); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_LEFT, + color_white, fix_buf); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "N "); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_RIGHT, + color_white, "%8.6f", last_state.gps_data.latitude); + gfx_print(layout.line2_pos, layout.top_font, TEXT_ALIGN_LEFT, + color_white, type_buf); // Convert from signed longitude, to unsigned + direction float longitude = last_state.gps_data.longitude; char *direction = (longitude < 0) ? "W " : "E "; longitude = (longitude < 0) ? -longitude : longitude; - gfx_print(layout.line2_pos, direction, layout.top_font, TEXT_ALIGN_CENTER, - color_white); - snprintf(lon_buf, 12, "%8.6f", longitude); - gfx_print(layout.line2_pos, lon_buf, layout.top_font, TEXT_ALIGN_RIGHT, - color_white); - snprintf(data_buf, 25, "S %4.1fkm/h A %4.1fm", - last_state.gps_data.speed, - last_state.gps_data.altitude); - gfx_print(layout.bottom_pos, data_buf, layout.bottom_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line2_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, direction); + gfx_print(layout.line2_pos, layout.top_font, TEXT_ALIGN_RIGHT, + color_white, "%8.6f", longitude); + gfx_print(layout.bottom_pos, layout.bottom_font, TEXT_ALIGN_CENTER, + color_white, "S %4.1fkm/h A %4.1fm", + last_state.gps_data.speed, + last_state.gps_data.altitude); } // Draw compass point_t compass_pos = {layout.horizontal_pad * 2, SCREEN_HEIGHT / 2}; @@ -385,8 +382,8 @@ void _ui_drawMenuSettings(ui_state_t* ui_state) { gfx_clearScreen(); // Print "Settings" on top bar - gfx_print(layout.top_pos, "Settings", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Settings"); // Print menu entries _ui_drawMenuList(ui_state->menu_selected, _ui_getSettingsEntryName); } @@ -395,8 +392,8 @@ void _ui_drawMenuInfo(ui_state_t* ui_state) { gfx_clearScreen(); // Print "Info" on top bar - gfx_print(layout.top_pos, "Info", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Info"); // Print menu entries _ui_drawMenuListValue(ui_state, ui_state->menu_selected, _ui_getInfoEntryName, _ui_getInfoValueName); @@ -409,14 +406,14 @@ void _ui_drawMenuAbout() if(SCREEN_HEIGHT >= 100) ui_drawSplashScreen(false); else - gfx_print(openrtx_pos, "OpenRTX", layout.line3_font, TEXT_ALIGN_CENTER, color_white); - char author_buf[MAX_ENTRY_LEN] = ""; + gfx_print(openrtx_pos, layout.line3_font, TEXT_ALIGN_CENTER, + color_white, "OpenRTX"); uint8_t line_h = layout.menu_h; point_t pos = {SCREEN_WIDTH / 7, SCREEN_HEIGHT - (line_h * (author_num - 1)) - 5}; for(int author = 0; author < author_num; author++) { - snprintf(author_buf, MAX_ENTRY_LEN, "%s", authors[author]); - gfx_print(pos, author_buf, layout.top_font, TEXT_ALIGN_LEFT, color_white); + gfx_print(pos, layout.top_font, TEXT_ALIGN_LEFT, + color_white, "%s", authors[author]); pos.y += line_h; } } @@ -425,8 +422,8 @@ void _ui_drawSettingsDisplay(ui_state_t* ui_state) { gfx_clearScreen(); // Print "Display" on top bar - gfx_print(layout.top_pos, "Display", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Display"); // Print display settings entries _ui_drawMenuListValue(ui_state, ui_state->menu_selected, _ui_getDisplayEntryName, _ui_getDisplayValueName); @@ -437,8 +434,8 @@ void _ui_drawSettingsGPS(ui_state_t* ui_state) { gfx_clearScreen(); // Print "GPS Settings" on top bar - gfx_print(layout.top_pos, "GPS Settings", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "GPS Settings"); // Print display settings entries _ui_drawMenuListValue(ui_state, ui_state->menu_selected, _ui_getSettingsGPSEntryName, @@ -451,19 +448,15 @@ void _ui_drawSettingsTimeDate() { gfx_clearScreen(); // Print "Time&Date" on top bar - gfx_print(layout.top_pos, "Time&Date", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Time&Date"); // Print current time and date - char date_buf[10] = ""; - char time_buf[10] = ""; - snprintf(date_buf, sizeof(date_buf), "%02d/%02d/%02d", - last_state.time.date, last_state.time.month, last_state.time.year); - snprintf(time_buf, sizeof(time_buf), "%02d:%02d:%02d", - last_state.time.hour, last_state.time.minute, last_state.time.second); - gfx_print(layout.line2_pos, date_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); - gfx_print(layout.line3_pos, time_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line2_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, "%02d/%02d/%02d", + last_state.time.date, last_state.time.month, last_state.time.year); + gfx_print(layout.line3_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, "%02d:%02d:%02d", + last_state.time.hour, last_state.time.minute, last_state.time.second); } void _ui_drawSettingsTimeDateSet(ui_state_t* ui_state) @@ -472,8 +465,8 @@ void _ui_drawSettingsTimeDateSet(ui_state_t* ui_state) gfx_clearScreen(); // Print "Time&Date" on top bar - gfx_print(layout.top_pos, "Time&Date", layout.top_font, - TEXT_ALIGN_CENTER, color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Time&Date"); if(ui_state->input_position <= 0) { strcpy(ui_state->new_date_buf, "__/__/__"); @@ -500,27 +493,25 @@ void _ui_drawSettingsTimeDateSet(ui_state_t* ui_state) ui_state->new_time_buf[pos] = input_char; } } - gfx_print(layout.line2_pos, ui_state->new_date_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); - gfx_print(layout.line3_pos, ui_state->new_time_buf, layout.input_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.line2_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, ui_state->new_date_buf); + gfx_print(layout.line3_pos, layout.input_font, TEXT_ALIGN_CENTER, + color_white, ui_state->new_time_buf); } #endif bool _ui_drawMacroMenu() { // Header - gfx_print(layout.top_pos, "Macro Menu", layout.top_font, TEXT_ALIGN_CENTER, - color_white); + gfx_print(layout.top_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, "Macro Menu"); // First row - gfx_print(layout.line1_pos, "1", layout.top_font, TEXT_ALIGN_LEFT, - yellow_fab413); - char code_str[11] = { 0 }; - snprintf(code_str, 11, " %6.1f", - ctcss_tone[last_state.channel.fm.txTone]/10.0f); - gfx_print(layout.line1_pos, code_str, layout.top_font, TEXT_ALIGN_LEFT, - color_white); - gfx_print(layout.line1_pos, "2 ", layout.top_font, TEXT_ALIGN_CENTER, - yellow_fab413); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_LEFT, + yellow_fab413, "1"); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_LEFT, + color_white, " %6.1f", + ctcss_tone[last_state.channel.fm.txTone]/10.0f); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_CENTER, + yellow_fab413, "2 "); char encdec_str[9] = { 0 }; bool tone_tx_enable = last_state.channel.fm.txToneEn; bool tone_rx_enable = last_state.channel.fm.rxToneEn; @@ -532,19 +523,18 @@ bool _ui_drawMacroMenu() { snprintf(encdec_str, 9, " D "); else snprintf(encdec_str, 9, " "); - gfx_print(layout.line1_pos, encdec_str, layout.top_font, TEXT_ALIGN_CENTER, - color_white); - gfx_print(layout.line1_pos, "3 ", layout.top_font, TEXT_ALIGN_RIGHT, - yellow_fab413); - char pow_str[9] = { 0 }; - snprintf(pow_str, 9, "%.1gW", last_state.channel.power); - gfx_print(layout.line1_pos, pow_str, layout.top_font, TEXT_ALIGN_RIGHT, - color_white); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, encdec_str); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_RIGHT, + yellow_fab413, "3 "); + gfx_print(layout.line1_pos, layout.top_font, TEXT_ALIGN_RIGHT, + color_white, "%.1gW", last_state.channel.power); // Second row // Calculate symmetric second row position, line2_pos is asymmetric like main screen - point_t pos_2 = {layout.line1_pos.x, layout.line1_pos.y + (layout.line3_pos.y - layout.line1_pos.y)/2}; - gfx_print(pos_2, "4", layout.top_font, TEXT_ALIGN_LEFT, - yellow_fab413); + point_t pos_2 = {layout.line1_pos.x, layout.line1_pos.y + + (layout.line3_pos.y - layout.line1_pos.y)/2}; + gfx_print(pos_2, layout.top_font, TEXT_ALIGN_LEFT, + yellow_fab413, "4"); char bw_str[8] = { 0 }; switch (last_state.channel.bandwidth) { @@ -558,10 +548,10 @@ bool _ui_drawMacroMenu() { snprintf(bw_str, 8, " 25"); break; } - gfx_print(pos_2, bw_str, layout.top_font, TEXT_ALIGN_LEFT, - color_white); - gfx_print(pos_2, "5 ", layout.top_font, TEXT_ALIGN_CENTER, - yellow_fab413); + gfx_print(pos_2, layout.top_font, TEXT_ALIGN_LEFT, + color_white, bw_str); + gfx_print(pos_2, layout.top_font, TEXT_ALIGN_CENTER, + yellow_fab413, "5 "); char mode_str[9] = ""; switch(last_state.channel.mode) { @@ -572,25 +562,25 @@ bool _ui_drawMacroMenu() { snprintf(mode_str, 9," DMR"); break; } - gfx_print(pos_2, mode_str, layout.top_font, TEXT_ALIGN_CENTER, - color_white); - gfx_print(pos_2, "6 ", layout.top_font, TEXT_ALIGN_RIGHT, - yellow_fab413); - gfx_print(pos_2, "Lck", layout.top_font, TEXT_ALIGN_RIGHT, - color_white); + gfx_print(pos_2, layout.top_font, TEXT_ALIGN_CENTER, + color_white, mode_str); + gfx_print(pos_2, layout.top_font, TEXT_ALIGN_RIGHT, + yellow_fab413, "6 "); + gfx_print(pos_2, layout.top_font, TEXT_ALIGN_RIGHT, + color_white, "Lck"); // Third row - gfx_print(layout.line3_pos, "7", layout.top_font, TEXT_ALIGN_LEFT, - yellow_fab413); - gfx_print(layout.line3_pos, " B+", layout.top_font, TEXT_ALIGN_LEFT, - color_white); - gfx_print(layout.line3_pos, "8 ", layout.top_font, TEXT_ALIGN_CENTER, - yellow_fab413); - gfx_print(layout.line3_pos, " B-", layout.top_font, TEXT_ALIGN_CENTER, - color_white); - gfx_print(layout.line3_pos, "9 ", layout.top_font, TEXT_ALIGN_RIGHT, - yellow_fab413); - gfx_print(layout.line3_pos, "Sav", layout.top_font, TEXT_ALIGN_RIGHT, - color_white); + gfx_print(layout.line3_pos, layout.top_font, TEXT_ALIGN_LEFT, + yellow_fab413, "7"); + gfx_print(layout.line3_pos, layout.top_font, TEXT_ALIGN_LEFT, + color_white, " B+"); + gfx_print(layout.line3_pos, layout.top_font, TEXT_ALIGN_CENTER, + yellow_fab413, "8 "); + gfx_print(layout.line3_pos, layout.top_font, TEXT_ALIGN_CENTER, + color_white, " B-"); + gfx_print(layout.line3_pos, layout.top_font, TEXT_ALIGN_RIGHT, + yellow_fab413, "9 "); + gfx_print(layout.line3_pos, layout.top_font, TEXT_ALIGN_RIGHT, + color_white, "Sav"); // Smeter bar float rssi = last_state.rssi; float squelch = last_state.sqlLevel / 16.0f; diff --git a/tests/platform/MDx_display_benchmark.c b/tests/platform/MDx_display_benchmark.c index fc84d51a..3baf8df6 100644 --- a/tests/platform/MDx_display_benchmark.c +++ b/tests/platform/MDx_display_benchmark.c @@ -79,8 +79,8 @@ uint64_t benchmark(uint32_t n) color_t color_red = {255, 0, 0, 255}; color_t color_white = {255, 255, 255, 255}; gfx_drawRect(origin, 160, 20, color_red, 1); - char *buffer = "KEK"; - gfx_print(origin, buffer, FONT_SIZE_24PT, TEXT_ALIGN_LEFT,color_white); + gfx_print(origin, buffer, FONT_SIZE_24PT, TEXT_ALIGN_LEFT, + color_white, "KEK"); dummy += kbd_getKeys(); diff --git a/tests/platform/gpio_demo.c b/tests/platform/gpio_demo.c index b6990f1c..556c9272 100644 --- a/tests/platform/gpio_demo.c +++ b/tests/platform/gpio_demo.c @@ -37,7 +37,7 @@ void printBits(uint16_t value, point_t pos) } color_t color_white = {255, 255, 255}; - gfx_print(pos, buf, FONT_SIZE_1, TEXT_ALIGN_LEFT, color_white); + gfx_print(pos, FONT_SIZE_1, TEXT_ALIGN_LEFT, color_white, buf); } int main(void) diff --git a/tests/platform/gui_demo.c b/tests/platform/gui_demo.c index b0154267..0e25187c 100644 --- a/tests/platform/gui_demo.c +++ b/tests/platform/gui_demo.c @@ -43,9 +43,9 @@ int main(void) // Print splash screen point_t splash_origin = {0, SCREEN_HEIGHT / 2}; color_t color_yellow_fab413 = {250, 180, 19}; - char *splash_buf = "OpenRTX"; gfx_clearScreen(); - gfx_print(splash_origin, splash_buf, FONT_SIZE_4, TEXT_ALIGN_CENTER, color_yellow_fab413); + gfx_print(splash_origin, FONT_SIZE_4, TEXT_ALIGN_CENTER, + color_yellow_fab413, "OpenRTX"); gfx_render(); while(gfx_renderingInProgress()); OSTimeDlyHMSM(0u, 0u, 1u, 0u, OS_OPT_TIME_HMSM_STRICT, &os_err); diff --git a/tests/platform/kek_demo.c b/tests/platform/kek_demo.c index 0939838f..05c96bb9 100644 --- a/tests/platform/kek_demo.c +++ b/tests/platform/kek_demo.c @@ -98,8 +98,8 @@ static void gfxThread(void *arg) color_t color_red = {255, 0, 0}; color_t color_white = {255, 255, 255}; gfx_drawRect(origin, SCREEN_WIDTH, 20, color_red, 1); - char *buffer = "KEK"; - gfx_print(origin, buffer, FONT_SIZE_4, TEXT_ALIGN_LEFT,color_white); + gfx_print(origin, FONT_SIZE_4, TEXT_ALIGN_LEFT, + color_white, "KEK"); gfx_render(); while(gfx_renderingInProgress()) ; pos += 20; diff --git a/tests/platform/keyboard_demo.c b/tests/platform/keyboard_demo.c index 77ede4ec..fdb05f07 100644 --- a/tests/platform/keyboard_demo.c +++ b/tests/platform/keyboard_demo.c @@ -44,11 +44,10 @@ void *print_keys(keyboard_t keys) { //count set bits to check how many keys are being pressed int i = __builtin_popcount(keys); while (i > 0) { - char *buf[15]; //position of the first set bit int pos = __builtin_ctz(keys); - sprintf(buf, "Pressed: %s", keys_list[pos + 1]); - gfx_print(origin, buf, FONT_SIZE_8PT, TEXT_ALIGN_LEFT, color_green); + gfx_print(origin, FONT_SIZE_8PT, TEXT_ALIGN_LEFT, + color_green, "Pressed: %s", keys_list[pos + 1]); origin.y += 9; //unset the bit we already handled keys &= ~(1 << pos); @@ -78,12 +77,11 @@ int main(void) { point_t title_origin = {0, SCREEN_HEIGHT / 9}; - char *title_buf = "Keyboard demo"; - // UI update infinite loop while (1) { gfx_clearScreen(); - gfx_print(title_origin, title_buf, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, color_red); + gfx_print(title_origin, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, + color_red, "Keyboard demo"); keyboard_t keys = kbd_getKeys(); if (keys != 0) print_keys(keys); diff --git a/tests/platform/platform_demo.c b/tests/platform/platform_demo.c index efb981e2..cd25612a 100644 --- a/tests/platform/platform_demo.c +++ b/tests/platform/platform_demo.c @@ -33,19 +33,18 @@ void platform_test() point_t pos_line2 = {0, 9}; point_t pos_line3 = {0, 17}; color_t color_white = {255, 255, 255}; - char *buf = "Platform Test"; - gfx_print(pos_line1, buf, FONT_SIZE_1, TEXT_ALIGN_LEFT, color_white); + gfx_print(pos_line1, FONT_SIZE_1, TEXT_ALIGN_LEFT, + color_white, "Platform Test"); float vBat = platform_getVbat(); float micLevel = platform_getMicLevel(); float volumeLevel = platform_getVolumeLevel(); uint8_t currentCh = platform_getChSelector(); bool ptt = platform_getPttStatus(); - char buf2[26] = ""; - snprintf(buf2, sizeof(buf2), "bat:%.2f mic:%.2f", vBat, micLevel); - char buf3[26] = ""; - snprintf(buf3, sizeof(buf3), "vol:%.2f ch:%d ptt:%s", volumeLevel, currentCh, ptt?"on":"off"); - gfx_print(pos_line2, buf2, FONT_SIZE_1, TEXT_ALIGN_LEFT, color_white); - gfx_print(pos_line3, buf3, FONT_SIZE_1, TEXT_ALIGN_LEFT, color_white); + gfx_print(pos_line2, FONT_SIZE_1, TEXT_ALIGN_LEFT, + color_white, "bat:%.2f mic:%.2f", vBat, micLevel); + gfx_print(pos_line3, FONT_SIZE_1, TEXT_ALIGN_LEFT, + color_white, "vol:%.2f ch:%d ptt:%s", volumeLevel, + currentCh, ptt?"on":"off"); gfx_render(); while(gfx_renderingInProgress()); OSTimeDlyHMSM(0u, 0u, 0u, 250u, OS_OPT_TIME_HMSM_STRICT, &os_err); @@ -61,7 +60,6 @@ int main(void) point_t origin = {0, SCREEN_HEIGHT / 2}; color_t color_yellow = {250, 180, 19}; - char *buffer = "OpenRTX"; OS_ERR os_err; @@ -69,7 +67,8 @@ int main(void) while(1) { gfx_clearScreen(); - gfx_print(origin, buffer, FONT_SIZE_4, TEXT_ALIGN_CENTER, color_yellow); + gfx_print(origin, FONT_SIZE_4, TEXT_ALIGN_CENTER, + color_yellow, "OpenRTX"); //gfx_render(); //while(gfx_renderingInProgress()); platform_test();