diff --git a/radio/src/storage/modelslist.h b/radio/src/storage/modelslist.h index 3a8baa062..3dd25054b 100644 --- a/radio/src/storage/modelslist.h +++ b/radio/src/storage/modelslist.h @@ -229,26 +229,19 @@ class ModelsList bool readNextLine(char * line, int maxlen) { - char c; - unsigned int read; - int len=0; - while (1) { - FRESULT result = f_read(&file, (uint8_t *)&c, 1, &read); - if (result != FR_OK || read != 1) { - line[len] = '\0'; - return false; - } - if (c == '\n') { - if (len > 0) { - // we skip empty lines - line[len] = '\0'; - return true; + if (f_gets(line, maxlen, &file) != NULL) { + int curlen = strlen(line) - 1; + if (line[curlen] == '\n') { // remove unwanted chars if file was edited using windows + if (line[curlen - 1] == '\r') { + line[curlen - 1] = 0; + } + else { + line[curlen] = 0; } } - else if (c != '\r' && len < maxlen) { - line[len++] = c; - } + return true; } + return false; } ModelsCategory * createCategory() diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 6e64a879c..bcaa1a9fe 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -155,7 +155,7 @@ void simuInit() void simuSetKey(uint8_t key, bool state) { // if (state) TRACE("simuSetKey(%d, %d)", key, state); - + switch (key) { #if !defined(PCBHORUS) KEY_CASE(KEY_MENU, KEYS_GPIO_REG_MENU, KEYS_GPIO_PIN_MENU) @@ -219,7 +219,7 @@ void simuSetTrim(uint8_t trim, bool state) void simuSetSwitch(uint8_t swtch, int8_t state) { // TRACE("simuSetSwitch(%d, %d)", swtch, state); - + switch (swtch) { #if defined(PCBFLAMENCO) // SWITCH_3_CASE(0, SWITCHES_GPIO_REG_A_L, SWITCHES_GPIO_REG_A_H, SWITCHES_GPIO_PIN_A_L, SWITCHES_GPIO_PIN_A_H) @@ -694,6 +694,18 @@ FRESULT f_write (FIL* fil, const void* data, UINT size, UINT* written) return FR_OK; } +TCHAR * f_gets (TCHAR* buff, int len, FIL* fil) +{ + if (fil && fil->obj.fs) { + buff = fgets(buff, len, (FILE*)fil->obj.fs); + if (buff != NULL) { + fil->fptr = *buff; + } + // TRACE("fgets(%p) %u, %s", fil->obj.fs, len, buff); + } + return buff; +} + FRESULT f_lseek (FIL* fil, DWORD offset) { if (fil && fil->obj.fs) fseek((FILE*)fil->obj.fs, offset, SEEK_SET);