/* * Authors (alphabetical order) * - Andre Bernet * - Andreas Weitl * - Bertrand Songis * - Bryan J. Rentoul (Gruvin) * - Cameron Weeks * - Erez Raviv * - Gabriel Birkus * - Jean-Pierre Parisy * - Karl Szmutny * - Michael Blandford * - Michal Hlavinka * - Pat Mackenzie * - Philip Moss * - Rob Thomson * - Romolo Manfredini * - Thomas Husterer * * opentx is based on code named * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, * er9x by Erez Raviv: http://code.google.com/p/er9x/, * and the original (and ongoing) project by * Thomas Husterer, th9x: http://code.google.com/p/th9x/ * * 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_FILENAME_MAXLEN 40 #define TEXT_FILE_MAXSIZE 1000 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[2]; 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=s_pgOfs && current_line-s_pgOfs0 && escape<3) { escape_chars[escape-1] = c; if (escape == 2 && !strncmp(escape_chars, "up", 2)) { c = '\300'; } else if (escape == 2 && !strncmp(escape_chars, "dn", 2)) { c = '\301'; } else { escape++; continue; } } escape = 0; s_text_screen[current_line-s_pgOfs][line_length++] = c; } } f_close(&file); } if (lines_count == 0) { lines_count = current_line; } } void menuTextView(uint8_t event) { static int lines_count; switch (event) { case EVT_ENTRY: s_pgOfs = 0; lines_count = 0; readTextFile(lines_count); break; case EVT_KEY_BREAK(KEY_UP): if (s_pgOfs == 0) break; else s_pgOfs--; // no break; case EVT_KEY_BREAK(KEY_DOWN): if (event == EVT_KEY_BREAK(KEY_DOWN)) { if (s_pgOfs+LCD_LINES-1 >= lines_count) break; else ++s_pgOfs; } readTextFile(lines_count); break; case EVT_KEY_BREAK(KEY_EXIT): popMenu(); return; } for (int i=0; i LCD_LINES-1) { displayScrollbar(LCD_W-1, FH, LCD_H-FH, s_pgOfs, lines_count, LCD_LINES-1); } } void pushMenuTextView(const char *filename) { if (strlen(filename) < TEXT_FILENAME_MAXLEN) { strcpy(s_text_file, filename); pushMenu(menuTextView); } }