Bsongis/ram saving (#6685)
RAM saving. Stacks reduced to have some more RAM available than 2.2 on all boards
This commit is contained in:
@@ -231,15 +231,11 @@ void drawStatusLine();
|
||||
#define drawStatusLine()
|
||||
#endif
|
||||
|
||||
#define TEXT_FILENAME_MAXLEN 40
|
||||
extern char s_text_file[TEXT_FILENAME_MAXLEN];
|
||||
void menuTextView(event_t event);
|
||||
void pushMenuTextView(const char *filename);
|
||||
void pushModelNotes();
|
||||
void readModelNotes();
|
||||
|
||||
#define LABEL(...) (uint8_t)-1
|
||||
|
||||
#define CURSOR_MOVED_LEFT(event) (IS_ROTARY_LEFT(event) || EVT_KEY_MASK(event) == KEY_LEFT)
|
||||
#define CURSOR_MOVED_RIGHT(event) (IS_ROTARY_RIGHT(event) || EVT_KEY_MASK(event) == KEY_RIGHT)
|
||||
|
||||
|
||||
@@ -22,33 +22,35 @@
|
||||
|
||||
void menuChannelsView(event_t event)
|
||||
{
|
||||
static bool longNames = false;
|
||||
bool newLongNames = false;
|
||||
static bool secondPage = false;
|
||||
static bool mixersView = false;
|
||||
|
||||
uint8_t ch;
|
||||
|
||||
switch(event)
|
||||
{
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
memclear(&reusableBuffer.viewChannels, sizeof(reusableBuffer.viewChannels));
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
popMenu();
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_RIGHT):
|
||||
case EVT_KEY_FIRST(KEY_LEFT):
|
||||
secondPage = !secondPage;
|
||||
reusableBuffer.viewChannels.secondPage = !reusableBuffer.viewChannels.secondPage;
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_ENTER):
|
||||
mixersView = !mixersView;
|
||||
reusableBuffer.viewChannels.mixersView = !reusableBuffer.viewChannels.mixersView;
|
||||
break;
|
||||
}
|
||||
|
||||
if (secondPage)
|
||||
if (reusableBuffer.viewChannels.secondPage)
|
||||
ch = 16;
|
||||
else
|
||||
ch = 0;
|
||||
|
||||
if (mixersView) {
|
||||
if (reusableBuffer.viewChannels.mixersView) {
|
||||
lcdDrawTextAlignedCenter(0, TR_MIXERS_MONITOR);
|
||||
}
|
||||
else {
|
||||
@@ -67,13 +69,13 @@ void menuChannelsView(event_t event)
|
||||
// Channels
|
||||
for (uint8_t line=0; line<8; line++) {
|
||||
uint8_t y = 9+line*7;
|
||||
int32_t val = (mixersView) ? ex_chans[ch] : channelOutputs[ch];
|
||||
int32_t val = (reusableBuffer.viewChannels.mixersView) ? ex_chans[ch] : channelOutputs[ch];
|
||||
uint8_t ofs = (col ? 0 : 1);
|
||||
|
||||
// Channel name if present, number if not
|
||||
uint8_t lenLabel = ZLEN(g_model.limitData[ch].name);
|
||||
if (lenLabel > 4) {
|
||||
newLongNames = longNames = true;
|
||||
newLongNames = reusableBuffer.viewChannels.longNames = true;
|
||||
}
|
||||
|
||||
if (lenLabel > 0)
|
||||
@@ -86,7 +88,7 @@ void menuChannelsView(event_t event)
|
||||
uint8_t wbar = (longNames ? 54 : 64);
|
||||
lcdDrawNumber(x+LCD_W/2-3-wbar-ofs, y+1, PPM_CH_CENTER(ch)+val/2, TINSIZE|RIGHT);
|
||||
#elif defined(PPM_UNIT_PERCENT_PREC1)
|
||||
uint8_t wbar = (longNames ? 48 : 58);
|
||||
uint8_t wbar = (reusableBuffer.viewChannels.longNames ? 48 : 58);
|
||||
lcdDrawNumber(x+LCD_W/2-3-wbar-ofs, y+1, calcRESXto1000(val), PREC1|TINSIZE|RIGHT);
|
||||
#else
|
||||
uint8_t wbar = (longNames ? 54 : 64);
|
||||
@@ -105,5 +107,5 @@ void menuChannelsView(event_t event)
|
||||
}
|
||||
}
|
||||
|
||||
longNames = newLongNames;
|
||||
reusableBuffer.viewChannels.longNames = newLongNames;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ void menuStatisticsDebug(event_t event)
|
||||
if (IS_RESET_REASON_WATCHDOG()) {
|
||||
lcdDrawText(LCD_W-8*FW, 0, "WATCHDOG");
|
||||
}
|
||||
else if (unexpectedShutdown) {
|
||||
else if (globalData.unexpectedShutdown) {
|
||||
lcdDrawText(LCD_W-13*FW, 0, "UNEXP.SHTDOWN");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -264,8 +264,6 @@ extern char statusLineMsg[STATUS_LINE_LENGTH];
|
||||
void showStatusLine();
|
||||
void drawStatusLine();
|
||||
|
||||
#define TEXT_FILENAME_MAXLEN 40
|
||||
extern char s_text_file[TEXT_FILENAME_MAXLEN];
|
||||
void menuTextView(event_t event);
|
||||
void pushMenuTextView(const char *filename);
|
||||
void pushModelNotes();
|
||||
@@ -273,8 +271,6 @@ void readModelNotes();
|
||||
|
||||
void menuChannelsView(event_t event);
|
||||
|
||||
#define LABEL(...) (uint8_t)-1
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
#define CURSOR_MOVED_LEFT(event) (event==EVT_ROTARY_LEFT)
|
||||
#define CURSOR_MOVED_RIGHT(event) (event==EVT_ROTARY_RIGHT)
|
||||
|
||||
@@ -24,46 +24,45 @@ extern uint8_t g_moduleIdx;
|
||||
|
||||
void menuModelFailsafe(event_t event)
|
||||
{
|
||||
static uint8_t maxNameLen = 4;
|
||||
static int8_t lastModel = g_eeGeneral.currModel;
|
||||
const coord_t barH = (LCD_H - FH) / 8 - 1;
|
||||
const int lim = (g_model.extendedLimits ? (512 * LIMIT_EXT_PERCENT / 100) : 512) * 2;
|
||||
const uint8_t channelStart = g_model.moduleData[g_moduleIdx].channelsStart;
|
||||
uint8_t cols = 1;
|
||||
uint8_t colW = LCD_W;
|
||||
|
||||
if (lastModel != g_eeGeneral.currModel) {
|
||||
lastModel = g_eeGeneral.currModel;
|
||||
maxNameLen = 4;
|
||||
}
|
||||
switch(event) {
|
||||
case EVT_ENTRY:
|
||||
reusableBuffer.modelFailsafe.maxNameLen = 4;
|
||||
break;
|
||||
|
||||
if (event == EVT_KEY_LONG(KEY_ENTER)) {
|
||||
killEvents(event);
|
||||
event = 0;
|
||||
case EVT_KEY_LONG(KEY_ENTER):
|
||||
killEvents(event);
|
||||
event = 0;
|
||||
|
||||
if (menuVerticalPosition < sentModuleChannels(g_moduleIdx)) {
|
||||
if (s_editMode) {
|
||||
g_model.failsafeChannels[menuVerticalPosition] = channelOutputs[menuVerticalPosition+channelStart];
|
||||
s_editMode = 0;
|
||||
if (menuVerticalPosition < sentModuleChannels(g_moduleIdx)) {
|
||||
if (s_editMode) {
|
||||
g_model.failsafeChannels[menuVerticalPosition] = channelOutputs[menuVerticalPosition+channelStart];
|
||||
s_editMode = 0;
|
||||
}
|
||||
else {
|
||||
int16_t * failsafe = &g_model.failsafeChannels[menuVerticalPosition];
|
||||
if (*failsafe < FAILSAFE_CHANNEL_HOLD)
|
||||
*failsafe = FAILSAFE_CHANNEL_HOLD;
|
||||
else if (*failsafe == FAILSAFE_CHANNEL_HOLD)
|
||||
*failsafe = FAILSAFE_CHANNEL_NOPULSE;
|
||||
else
|
||||
*failsafe = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int16_t * failsafe = &g_model.failsafeChannels[menuVerticalPosition];
|
||||
if (*failsafe < FAILSAFE_CHANNEL_HOLD)
|
||||
*failsafe = FAILSAFE_CHANNEL_HOLD;
|
||||
else if (*failsafe == FAILSAFE_CHANNEL_HOLD)
|
||||
*failsafe = FAILSAFE_CHANNEL_NOPULSE;
|
||||
else
|
||||
*failsafe = 0;
|
||||
// "Outputs => Failsafe" menu item
|
||||
setCustomFailsafe(g_moduleIdx);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// "Outputs => Failsafe" menu item
|
||||
setCustomFailsafe(g_moduleIdx);
|
||||
}
|
||||
|
||||
storageDirty(EE_MODEL);
|
||||
AUDIO_WARNING1();
|
||||
SEND_FAILSAFE_NOW(g_moduleIdx);
|
||||
storageDirty(EE_MODEL);
|
||||
AUDIO_WARNING1();
|
||||
SEND_FAILSAFE_NOW(g_moduleIdx);
|
||||
break;
|
||||
}
|
||||
|
||||
SIMPLE_SUBMENU_NOTITLE(sentModuleChannels(g_moduleIdx) + 1);
|
||||
@@ -95,7 +94,7 @@ void menuModelFailsafe(event_t event)
|
||||
const int32_t channelValue = channelOutputs[ch+channelStart];
|
||||
int32_t failsafeValue = g_model.failsafeChannels[8*col+line];
|
||||
uint8_t lenLabel = ZLEN(g_model.limitData[ch+channelStart].name);
|
||||
uint8_t barW = colW - FW * maxNameLen - FWNUM * 3; // default bar width
|
||||
uint8_t barW = colW - FW * reusableBuffer.modelFailsafe.maxNameLen - FWNUM * 3; // default bar width
|
||||
|
||||
#if defined(PPM_UNIT_PERCENT_PREC1)
|
||||
barW -= FWNUM + 1;
|
||||
@@ -104,8 +103,8 @@ void menuModelFailsafe(event_t event)
|
||||
|
||||
// Channel name if present, number if not
|
||||
if (lenLabel > 0) {
|
||||
if (lenLabel > maxNameLen)
|
||||
maxNameLen = lenLabel;
|
||||
if (lenLabel > reusableBuffer.modelFailsafe.maxNameLen)
|
||||
reusableBuffer.modelFailsafe.maxNameLen = lenLabel;
|
||||
lcdDrawSizedText(x - colW, y, g_model.limitData[ch+channelStart].name, sizeof(g_model.limitData[ch+channelStart].name), ZCHAR | SMLSIZE);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -22,44 +22,46 @@
|
||||
|
||||
void menuChannelsView(event_t event)
|
||||
{
|
||||
static bool longNames = false;
|
||||
static bool secondPage = false;
|
||||
static bool mixersView = false;
|
||||
uint8_t ch = 0;
|
||||
uint8_t wbar = (longNames ? 54 : 64);
|
||||
uint8_t wbar = (reusableBuffer.viewChannels.longNames ? 54 : 64);
|
||||
int16_t limits = 512 * 2;
|
||||
|
||||
#if defined(PPM_UNIT_PERCENT_PREC1)
|
||||
wbar -= 6;
|
||||
#endif
|
||||
|
||||
switch(event)
|
||||
{
|
||||
switch(event) {
|
||||
case EVT_ENTRY:
|
||||
memclear(&reusableBuffer.viewChannels, sizeof(reusableBuffer.viewChannels));
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
popMenu();
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_RIGHT):
|
||||
case EVT_KEY_FIRST(KEY_LEFT):
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
case EVT_ROTARY_LEFT:
|
||||
case EVT_ROTARY_RIGHT:
|
||||
#endif
|
||||
secondPage = !secondPage;
|
||||
reusableBuffer.viewChannels.secondPage = !reusableBuffer.viewChannels.secondPage;
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_ENTER):
|
||||
mixersView = !mixersView;
|
||||
reusableBuffer.viewChannels.mixersView = !reusableBuffer.viewChannels.mixersView;
|
||||
break;
|
||||
}
|
||||
|
||||
if (secondPage)
|
||||
if (reusableBuffer.viewChannels.secondPage)
|
||||
ch = 16;
|
||||
|
||||
if (mixersView)
|
||||
if (reusableBuffer.viewChannels.mixersView)
|
||||
limits *= 2; // this could be handled nicer, but slower, by checking actual range for this mixer
|
||||
else if (g_model.extendedLimits)
|
||||
limits *= LIMIT_EXT_PERCENT / 100;
|
||||
|
||||
if (mixersView)
|
||||
if (reusableBuffer.viewChannels.mixersView)
|
||||
lcdDrawTextAlignedCenter(0, TR_MIXERS_MONITOR);
|
||||
else
|
||||
lcdDrawTextAlignedCenter(0, TR_CHANNELS_MONITOR);
|
||||
@@ -76,13 +78,13 @@ void menuChannelsView(event_t event)
|
||||
// Channels
|
||||
for (uint8_t line=0; line < 8; line++) {
|
||||
const uint8_t y = 9 + line * 7;
|
||||
const int32_t val = mixersView ? ex_chans[ch] : channelOutputs[ch];
|
||||
const int32_t val = reusableBuffer.viewChannels.mixersView ? ex_chans[ch] : channelOutputs[ch];
|
||||
const uint8_t lenLabel = ZLEN(g_model.limitData[ch].name);
|
||||
|
||||
// Channel name if present, number if not
|
||||
if (lenLabel > 0) {
|
||||
if (lenLabel > 4)
|
||||
longNames = true;
|
||||
reusableBuffer.viewChannels.longNames = true;
|
||||
lcdDrawSizedText(x+1-ofs, y, g_model.limitData[ch].name, sizeof(g_model.limitData[ch].name), ZCHAR | SMLSIZE);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -78,11 +78,11 @@ void readModelNotes()
|
||||
{
|
||||
LED_ERROR_BEGIN();
|
||||
|
||||
strcpy(s_text_file, MODELS_PATH "/");
|
||||
char *buf = strcat_currentmodelname(&s_text_file[sizeof(MODELS_PATH)]);
|
||||
strcpy(reusableBuffer.viewText.filename, MODELS_PATH "/");
|
||||
char *buf = strcat_currentmodelname(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)]);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
if (!isFileAvailable(s_text_file)) {
|
||||
char *buf = strAppendFilename(&s_text_file[sizeof(MODELS_PATH)], g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
|
||||
if (!isFileAvailable(reusableBuffer.viewText.filename)) {
|
||||
char *buf = strAppendFilename(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)], g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
}
|
||||
|
||||
@@ -103,11 +103,11 @@ void readModelNotes()
|
||||
bool menuModelNotes(event_t event)
|
||||
{
|
||||
if (event == EVT_ENTRY) {
|
||||
strcpy(s_text_file, MODELS_PATH "/");
|
||||
char *buf = strcat_currentmodelname(&s_text_file[sizeof(MODELS_PATH)]);
|
||||
strcpy(reusableBuffer.viewText.filename, MODELS_PATH "/");
|
||||
char *buf = strcat_currentmodelname(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)]);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
if (!isFileAvailable(s_text_file)) {
|
||||
char *buf = strAppendFilename(&s_text_file[sizeof(MODELS_PATH)], g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
|
||||
if (!isFileAvailable(reusableBuffer.viewText.filename)) {
|
||||
char * buf = strAppendFilename(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)], g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,14 +589,10 @@ inline void POPUP_CONFIRMATION(const char *s, void (* confirmHandler)(const char
|
||||
popupMenuHandler = confirmHandler;
|
||||
}
|
||||
|
||||
#define TEXT_FILENAME_MAXLEN 40
|
||||
extern char s_text_file[TEXT_FILENAME_MAXLEN];
|
||||
void pushMenuTextView(const char * filename);
|
||||
void pushModelNotes();
|
||||
void readModelNotes();
|
||||
|
||||
#define LABEL(...) (uint8_t)-1
|
||||
|
||||
#define CURSOR_MOVED_LEFT(event) (event==EVT_ROTARY_LEFT || EVT_KEY_MASK(event) == KEY_LEFT)
|
||||
#define CURSOR_MOVED_RIGHT(event) (event==EVT_ROTARY_RIGHT || EVT_KEY_MASK(event) == KEY_RIGHT)
|
||||
#define REPEAT_LAST_CURSOR_MOVE(last, refresh) { if (CURSOR_MOVED_RIGHT(event)) menuHorizontalPosition = (menuHorizontalPosition >= (last) ? 0 : menuHorizontalPosition + 1); else menuHorizontalPosition = (menuHorizontalPosition <= (0) ? last : menuHorizontalPosition - 1); if (refresh) putEvent(EVT_REFRESH); }
|
||||
|
||||
@@ -20,80 +20,6 @@
|
||||
|
||||
#include "opentx.h"
|
||||
|
||||
#define TEXT_FILE_MAXSIZE 2048
|
||||
|
||||
char s_text_file[TEXT_FILENAME_MAXLEN];
|
||||
char s_text_screen[NUM_BODY_LINES][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<TEXT_FILE_MAXSIZE && f_read(&file, &c, 1, &sz)==FR_OK && sz==1 && (lines_count==0 || current_line-menuVerticalOffset<NUM_BODY_LINES); i++) {
|
||||
if (c == '\n') {
|
||||
++current_line;
|
||||
line_length = 0;
|
||||
escape = 0;
|
||||
}
|
||||
else if (c!='\r' && current_line>=menuVerticalOffset && current_line-menuVerticalOffset<NUM_BODY_LINES && line_length<LCD_COLS) {
|
||||
if (c=='\\' && escape==0) {
|
||||
escape = 1;
|
||||
continue;
|
||||
}
|
||||
else if (c!='\\' && escape>0 && 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;
|
||||
}
|
||||
}
|
||||
|
||||
bool menuTextView(event_t event)
|
||||
{
|
||||
static int lines_count;
|
||||
@@ -104,7 +30,7 @@ bool menuTextView(event_t event)
|
||||
case EVT_ENTRY:
|
||||
menuVerticalOffset = 0;
|
||||
lines_count = 0;
|
||||
readTextFile(lines_count);
|
||||
sdReadTextFile(reusableBuffer.viewText.filename, reusableBuffer.viewText.lines, lines_count);
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_LEFT:
|
||||
@@ -112,7 +38,7 @@ bool menuTextView(event_t event)
|
||||
break;
|
||||
else
|
||||
menuVerticalOffset--;
|
||||
readTextFile(lines_count);
|
||||
sdReadTextFile(reusableBuffer.viewText.filename, reusableBuffer.viewText.lines, lines_count);
|
||||
break;
|
||||
|
||||
case EVT_ROTARY_RIGHT:
|
||||
@@ -120,7 +46,7 @@ bool menuTextView(event_t event)
|
||||
break;
|
||||
else
|
||||
++menuVerticalOffset;
|
||||
readTextFile(lines_count);
|
||||
sdReadTextFile(reusableBuffer.viewText.filename, reusableBuffer.viewText.lines, lines_count);
|
||||
break;
|
||||
|
||||
case EVT_KEY_FIRST(KEY_EXIT):
|
||||
@@ -129,7 +55,7 @@ bool menuTextView(event_t event)
|
||||
}
|
||||
|
||||
for (int i=0; i<NUM_BODY_LINES; i++) {
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + i*FH, s_text_screen[i]);
|
||||
lcdDrawText(MENUS_MARGIN_LEFT, MENU_CONTENT_TOP + i*FH, reusableBuffer.viewText.lines[i]);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -148,7 +74,7 @@ bool menuTextView(event_t event)
|
||||
void pushMenuTextView(const char *filename)
|
||||
{
|
||||
if (strlen(filename) < TEXT_FILENAME_MAXLEN) {
|
||||
strcpy(s_text_file, filename);
|
||||
strcpy(reusableBuffer.viewText.filename, filename);
|
||||
pushMenu(menuTextView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
void menuModelNotes(event_t event)
|
||||
{
|
||||
if (event == EVT_ENTRY) {
|
||||
strcpy(s_text_file, MODELS_PATH "/");
|
||||
char *buf = strcat_modelname(&s_text_file[sizeof(MODELS_PATH)], g_eeGeneral.currModel);
|
||||
strcpy(reusableBuffer.viewText.filename, MODELS_PATH "/");
|
||||
char *buf = strcat_modelname(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)], g_eeGeneral.currModel);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,80 +20,6 @@
|
||||
|
||||
#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<TEXT_FILE_MAXSIZE && f_read(&file, &c, 1, &sz)==FR_OK && sz==1 && (lines_count==0 || current_line-menuVerticalOffset<LCD_LINES-1); i++) {
|
||||
if (c == '\n') {
|
||||
++current_line;
|
||||
line_length = 0;
|
||||
escape = 0;
|
||||
}
|
||||
else if (c!='\r' && current_line>=menuVerticalOffset && current_line-menuVerticalOffset<LCD_LINES-1 && line_length<LCD_COLS) {
|
||||
if (c=='\\' && escape==0) {
|
||||
escape = 1;
|
||||
continue;
|
||||
}
|
||||
else if (c!='\\' && escape>0 && 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;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
#define EVT_KEY_NEXT_LINE EVT_ROTARY_RIGHT
|
||||
#define EVT_KEY_PREVIOUS_LINE EVT_ROTARY_LEFT
|
||||
@@ -106,8 +32,8 @@ void readModelNotes()
|
||||
{
|
||||
LED_ERROR_BEGIN();
|
||||
|
||||
strcpy(s_text_file, MODELS_PATH "/");
|
||||
char *buf = strcat_modelname(&s_text_file[sizeof(MODELS_PATH)], g_eeGeneral.currModel);
|
||||
strcpy(reusableBuffer.viewText.filename, MODELS_PATH "/");
|
||||
char *buf = strcat_modelname(&reusableBuffer.viewText.filename[sizeof(MODELS_PATH)], g_eeGeneral.currModel);
|
||||
strcpy(buf, TEXT_EXT);
|
||||
|
||||
waitKeysReleased();
|
||||
@@ -126,13 +52,11 @@ void readModelNotes()
|
||||
|
||||
void menuTextView(event_t event)
|
||||
{
|
||||
static int lines_count;
|
||||
|
||||
switch (event) {
|
||||
case EVT_ENTRY:
|
||||
menuVerticalOffset = 0;
|
||||
lines_count = 0;
|
||||
readTextFile(lines_count);
|
||||
reusableBuffer.viewText.linesCount = 0;
|
||||
sdReadTextFile(reusableBuffer.viewText.filename, reusableBuffer.viewText.lines, reusableBuffer.viewText.linesCount);
|
||||
break;
|
||||
|
||||
case EVT_KEY_PREVIOUS_LINE:
|
||||
@@ -140,15 +64,15 @@ void menuTextView(event_t event)
|
||||
break;
|
||||
else
|
||||
menuVerticalOffset--;
|
||||
readTextFile(lines_count);
|
||||
sdReadTextFile(reusableBuffer.viewText.filename, reusableBuffer.viewText.lines, reusableBuffer.viewText.linesCount);
|
||||
break;
|
||||
|
||||
case EVT_KEY_NEXT_LINE:
|
||||
if (menuVerticalOffset+LCD_LINES-1 >= lines_count)
|
||||
if (menuVerticalOffset+LCD_LINES-1 >= reusableBuffer.viewText.linesCount)
|
||||
break;
|
||||
else
|
||||
++menuVerticalOffset;
|
||||
readTextFile(lines_count);
|
||||
sdReadTextFile(reusableBuffer.viewText.filename, reusableBuffer.viewText.lines, reusableBuffer.viewText.linesCount);
|
||||
break;
|
||||
|
||||
case EVT_KEY_BREAK(KEY_EXIT):
|
||||
@@ -157,10 +81,10 @@ void menuTextView(event_t event)
|
||||
}
|
||||
|
||||
for (int i=0; i<LCD_LINES-1; i++) {
|
||||
lcdDrawText(0, i*FH+FH+1, s_text_screen[i], FIXEDWIDTH);
|
||||
lcdDrawText(0, i*FH+FH+1, reusableBuffer.viewText.lines[i], FIXEDWIDTH);
|
||||
}
|
||||
|
||||
char * title = s_text_file;
|
||||
char * title = reusableBuffer.viewText.filename;
|
||||
#if defined(SIMU)
|
||||
if (!strncmp(title, "./", 2)) title += 2;
|
||||
#else
|
||||
@@ -169,15 +93,15 @@ void menuTextView(event_t event)
|
||||
lcdDrawText(LCD_W/2, 0, getBasename(title), CENTERED);
|
||||
lcdInvertLine(0);
|
||||
|
||||
if (lines_count > LCD_LINES-1) {
|
||||
drawVerticalScrollbar(LCD_W-1, FH, LCD_H-FH, menuVerticalOffset, lines_count, LCD_LINES-1);
|
||||
if (reusableBuffer.viewText.linesCount > LCD_LINES-1) {
|
||||
drawVerticalScrollbar(LCD_W-1, FH, LCD_H-FH, menuVerticalOffset, reusableBuffer.viewText.linesCount, LCD_LINES-1);
|
||||
}
|
||||
}
|
||||
|
||||
void pushMenuTextView(const char *filename)
|
||||
{
|
||||
if (strlen(filename) < TEXT_FILENAME_MAXLEN) {
|
||||
strcpy(s_text_file, filename);
|
||||
strcpy(reusableBuffer.viewText.filename, filename);
|
||||
pushMenu(menuTextView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#define READONLY_ROW ((uint8_t)-1)
|
||||
#define TITLE_ROW READONLY_ROW
|
||||
#define LABEL(...) READONLY_ROW
|
||||
#define HIDDEN_ROW ((uint8_t)-2)
|
||||
|
||||
#if defined(ROTARY_ENCODER_NAVIGATION)
|
||||
|
||||
Reference in New Issue
Block a user