diff options
author | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-31 08:29:43 -0400 |
---|---|---|
committer | Michael J. Chudobiak <mjc@avtechpulse.com> | 2012-08-31 08:29:43 -0400 |
commit | 8deceaf5efd69c1f9592deef6b00bd210af38ba3 (patch) | |
tree | d105b7663f927c29dde6067ae69e3e42f0103b8d | |
parent | fae02b5c3a9d5f3cf3e6253cdcd6a0100bdbcd73 (diff) |
added LCD_write_padded_spaces
-rw-r--r-- | lcd.c | 19 | ||||
-rw-r--r-- | lcd.h | 1 | ||||
-rw-r--r-- | menus.c | 31 |
3 files changed, 31 insertions, 20 deletions
@@ -189,7 +189,24 @@ static void LCD_RAM_write(int RAM_start,int row, int col, char *LCD_string) void LCD_write(int row, int col, char *LCD_string) { LCD_RAM_write(LCD_DATA_RAM, row, col, LCD_string); - return; +} + + +void LCD_write_padded_spaces(int row, int col, char *LCD_string, int width) +{ + gchar *padded = NULL; + + int in_len = strlen (LCD_string); + + if (in_len > width) { + padded = g_strdup (LCD_string); + padded[width] = 0; + } else { + padded = g_strdup_printf ("%s%*s", LCD_string, width - in_len, ""); + } + + LCD_write(row, col, padded); + g_free (padded); } @@ -15,4 +15,5 @@ void LCD_display_extended_message(char *response, gboolean show_change_message, gboolean is_error_screen); void LCD_clear(); void LCD_write(int row, int col, char *LCD_string); +void LCD_write_padded_spaces(int row, int col, char *LCD_string, int width); void LCD_initialize(void); @@ -928,31 +928,31 @@ void Menu_Update_Display(void) switch (globals.control_mode) { case REMS_ctrl: - ctrl_str = g_strdup ("GPIB CTRL "); + ctrl_str = g_strdup ("GPIB CTRL"); break; case RWLS_ctrl: - ctrl_str = g_strdup ("GPIB LOCK "); + ctrl_str = g_strdup ("GPIB LOCK"); break; case RS232_ctrl: - ctrl_str = g_strdup ("RS232 CTRL "); + ctrl_str = g_strdup ("RS232 CTRL"); break; case WEB_ctrl: - ctrl_str = g_strdup ("WEB CTRL "); + ctrl_str = g_strdup ("WEB CTRL"); break; case TELNET_ctrl: - ctrl_str = g_strdup ("TELNET CTRL "); + ctrl_str = g_strdup ("TELNET CTRL"); break; case LWLS_ctrl: - ctrl_str = g_strdup ("LOCAL LOCK "); + ctrl_str = g_strdup ("LOCAL LOCK"); break; case LOCS_ctrl: default: - ctrl_str = g_strdup ("LOCAL CTRL "); + ctrl_str = g_strdup ("LOCAL CTRL"); break; } if (globals.Changes.update_whole_main_menu && Menu_Is_Item_Visible(LCD_entry)) { - LCD_write(LCD_row,LCD_col,ctrl_str); + LCD_write_padded_spaces(LCD_row,LCD_col,ctrl_str,LCD_col_width); } g_free (ctrl_str); @@ -968,7 +968,7 @@ void Menu_Update_Display(void) LCD_col=((LCD_entry % LCD_max_entries_per_page) / LCD_rows) * LCD_col_width + 1; if (globals.Changes.update_whole_main_menu && Menu_Is_Item_Visible(LCD_entry)) { - LCD_write(LCD_row,LCD_col,"Memory menu "); + LCD_write_padded_spaces(LCD_row,LCD_col,"Memory menu",LCD_col_width); } @@ -983,7 +983,7 @@ void Menu_Update_Display(void) LCD_col=((LCD_entry % LCD_max_entries_per_page) / LCD_rows) * LCD_col_width + 1; if (globals.Changes.update_whole_main_menu && Menu_Is_Item_Visible(LCD_entry)) { - LCD_write(LCD_row,LCD_col,"Setup menu "); + LCD_write_padded_spaces(LCD_row,LCD_col,"Setup menu",LCD_col_width); } @@ -1011,8 +1011,7 @@ void Menu_Update_Display(void) for (i=(Main_Menu_max_entry%LCD_max_entries_per_page)+ 1; i<12; ++i) { LCD_row=i % LCD_rows; LCD_col=(i / LCD_rows) * LCD_col_width + 1; - /*1234567890123*/ - LCD_write(LCD_row,LCD_col," "); + LCD_write_padded_spaces(LCD_row,LCD_col,"",LCD_col_width); } globals.Changes.update_whole_main_menu=NO; @@ -1225,14 +1224,8 @@ static void Display_Number_on_LCD(int Is_Item_Visible,int LCD_row,int LCD_col,ch strcpy(LCD_string,start_string); } - /* tack on spaces on end of string, but no wider than column */ - for (i=strlen(LCD_string); i<width_of_column; ++i) { - LCD_string[i]=' '; - } - LCD_string[width_of_column]=0; - if (Is_Item_Visible) { - LCD_write(LCD_row,LCD_col,LCD_string); + LCD_write_padded_spaces(LCD_row, LCD_col, LCD_string, width_of_column); } } |