From 880216c5446e224ebfe9be0c03e681f50a421f16 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Mon, 19 Dec 2016 17:51:22 +0100 Subject: [PATCH] [X7] Text view fix - #4143 --- radio/src/gui/212x64/view_text.cpp | 153 ------------------ radio/src/gui/common/stdlcd/CMakeLists.txt | 1 + .../{128x64 => common/stdlcd}/view_text.cpp | 15 +- radio/src/targets/sky9x/CMakeLists.txt | 1 - radio/src/targets/taranis/CMakeLists.txt | 1 - 5 files changed, 12 insertions(+), 159 deletions(-) delete mode 100644 radio/src/gui/212x64/view_text.cpp rename radio/src/gui/{128x64 => common/stdlcd}/view_text.cpp (91%) diff --git a/radio/src/gui/212x64/view_text.cpp b/radio/src/gui/212x64/view_text.cpp deleted file mode 100644 index e1719063b..000000000 --- a/radio/src/gui/212x64/view_text.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) OpenTX - * - * Based on code named - * th9x - http://code.google.com/p/th9x - * er9x - http://code.google.com/p/er9x - * gruvin9x - http://code.google.com/p/gruvin9x - * - * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - -#include "opentx.h" - -#define TEXT_FILE_MAXSIZE 2048 - -char s_text_file[TEXT_FILENAME_MAXLEN]; -char s_text_screen[LCD_LINES-1][LCD_COLS+1]; - -void readTextFile(int & lines_count) -{ - FIL file; - int result; - char c; - unsigned int sz; - int line_length = 0; - int escape = 0; - char escape_chars[4] = {0}; - int current_line = 0; - - memset(s_text_screen, 0, sizeof(s_text_screen)); - - result = f_open(&file, s_text_file, FA_OPEN_EXISTING | FA_READ); - if (result == FR_OK) { - for (int i=0; i=menuVerticalOffset && current_line-menuVerticalOffset0 && escape<4) { - escape_chars[escape-1] = c; - if (escape == 2 && !strncmp(escape_chars, "up", 2)) { - c = '\300'; - escape = 0; - } - else if (escape == 2 && !strncmp(escape_chars, "dn", 2)) { - c = '\301'; - escape = 0; - } - else if (escape == 3) { - int val = atoi(escape_chars); - if (val >= 200 && val < 225) { - c = '\200' + val-200; - } - escape = 0; - } - else { - escape++; - continue; - } - } - else if (c=='~') { - c = 'z'+1; - } - else if (c=='\t') { - c = 0x1D; //tab - } - escape = 0; - s_text_screen[current_line-menuVerticalOffset][line_length++] = c; - } - } - if (c != '\n') { - current_line += 1; - } - f_close(&file); - } - - if (lines_count == 0) { - lines_count = current_line; - } -} - -void menuTextView(event_t event) -{ - static int lines_count; - - switch (event) { - case EVT_ENTRY: - menuVerticalOffset = 0; - lines_count = 0; - readTextFile(lines_count); - break; - - case EVT_KEY_FIRST(KEY_UP): - if (menuVerticalOffset == 0) - break; - else - menuVerticalOffset--; - readTextFile(lines_count); - break; - - case EVT_KEY_FIRST(KEY_DOWN): - if (menuVerticalOffset+LCD_LINES-1 >= lines_count) - break; - else - ++menuVerticalOffset; - readTextFile(lines_count); - break; - - case EVT_KEY_BREAK(KEY_EXIT): - popMenu(); - break; - } - - for (int i=0; i LCD_LINES-1) { - drawVerticalScrollbar(LCD_W-1, FH, LCD_H-FH, menuVerticalOffset, lines_count, LCD_LINES-1); - } -} - -void pushMenuTextView(const char *filename) -{ - if (strlen(filename) < TEXT_FILENAME_MAXLEN) { - strcpy(s_text_file, filename); - pushMenu(menuTextView); - } -} diff --git a/radio/src/gui/common/stdlcd/CMakeLists.txt b/radio/src/gui/common/stdlcd/CMakeLists.txt index 5ff8d43ed..32683c307 100644 --- a/radio/src/gui/common/stdlcd/CMakeLists.txt +++ b/radio/src/gui/common/stdlcd/CMakeLists.txt @@ -14,6 +14,7 @@ if(ARCH STREQUAL ARM) ${GUI_SRC} ../common/stdlcd/model_inputs.cpp ../common/stdlcd/model_mixes.cpp + ../common/stdlcd/view_text.cpp ) set(CURVE_EDIT_SRC model_curve_edit.cpp) else() diff --git a/radio/src/gui/128x64/view_text.cpp b/radio/src/gui/common/stdlcd/view_text.cpp similarity index 91% rename from radio/src/gui/128x64/view_text.cpp rename to radio/src/gui/common/stdlcd/view_text.cpp index 9eaca8e29..5d698dd18 100644 --- a/radio/src/gui/128x64/view_text.cpp +++ b/radio/src/gui/common/stdlcd/view_text.cpp @@ -20,7 +20,6 @@ #include "opentx.h" -#define TEXT_FILENAME_MAXLEN 40 #define TEXT_FILE_MAXSIZE 2048 char s_text_file[TEXT_FILENAME_MAXLEN]; @@ -34,7 +33,7 @@ void readTextFile(int & lines_count) unsigned int sz; int line_length = 0; int escape = 0; - char escape_chars[2]; + char escape_chars[4] = {0}; int current_line = 0; memset(s_text_screen, 0, sizeof(s_text_screen)); @@ -52,7 +51,7 @@ void readTextFile(int & lines_count) escape = 1; continue; } - else if (c!='\\' && escape>0 && escape<3) { + else if (c!='\\' && escape>0 && escape<4) { escape_chars[escape-1] = c; if (escape == 2 && !strncmp(escape_chars, "up", 2)) { c = '\300'; @@ -62,6 +61,13 @@ void readTextFile(int & lines_count) c = '\301'; escape = 0; } + else if (escape == 3) { + int val = atoi(escape_chars); + if (val >= 200 && val < 225) { + c = '\200' + val-200; + } + escape = 0; + } else { escape++; continue; @@ -112,7 +118,8 @@ void menuTextView(event_t event) break; else menuVerticalOffset--; - // no break; + readTextFile(lines_count); + break; case EVT_KEY_NEXT_LINE: if (menuVerticalOffset+LCD_LINES-1 >= lines_count) diff --git a/radio/src/targets/sky9x/CMakeLists.txt b/radio/src/targets/sky9x/CMakeLists.txt index 084e19568..9f401810a 100644 --- a/radio/src/targets/sky9x/CMakeLists.txt +++ b/radio/src/targets/sky9x/CMakeLists.txt @@ -53,7 +53,6 @@ set(GUI_SRC radio_diaganas.cpp radio_hardware.cpp view_telemetry.cpp - view_text.cpp view_about.cpp ) diff --git a/radio/src/targets/taranis/CMakeLists.txt b/radio/src/targets/taranis/CMakeLists.txt index 9a68ab83f..456cd57c7 100644 --- a/radio/src/targets/taranis/CMakeLists.txt +++ b/radio/src/targets/taranis/CMakeLists.txt @@ -93,7 +93,6 @@ set(GUI_SRC ${GUI_SRC} radio_hardware.cpp view_channels.cpp view_telemetry.cpp - view_text.cpp view_about.cpp ../screenshot.cpp )