diff --git a/radio/src/gui/colorlcd/CMakeLists.txt b/radio/src/gui/colorlcd/CMakeLists.txt index 087fb0c14..33a077f36 100644 --- a/radio/src/gui/colorlcd/CMakeLists.txt +++ b/radio/src/gui/colorlcd/CMakeLists.txt @@ -17,7 +17,6 @@ file(GLOB WIDGETS_SRC RELATIVE ${RADIO_SRC_DIR}/gui/colorlcd set(GUI_SRC ${GUI_SRC} - str_functions.cpp colors.cpp lcd.cpp splash.cpp diff --git a/radio/src/gui/colorlcd/model_select.cpp b/radio/src/gui/colorlcd/model_select.cpp index 25906de83..ba342008a 100644 --- a/radio/src/gui/colorlcd/model_select.cpp +++ b/radio/src/gui/colorlcd/model_select.cpp @@ -33,7 +33,6 @@ #include "model_templates.h" #include "opentx.h" #include "standalone_lua.h" -#include "str_functions.h" #include "view_channels.h" // bitmaps for toolbar diff --git a/radio/src/gui/colorlcd/model_telemetry.cpp b/radio/src/gui/colorlcd/model_telemetry.cpp index 254dabfef..a415202cc 100644 --- a/radio/src/gui/colorlcd/model_telemetry.cpp +++ b/radio/src/gui/colorlcd/model_telemetry.cpp @@ -19,9 +19,8 @@ * GNU General Public License for more details. */ -#include -#include #include "model_telemetry.h" + #include "opentx.h" #include "libopenui.h" @@ -610,9 +609,12 @@ class SensorEditWindow : public Page { num->setWidth((lv_pct(28))); #endif num->setDisplayHandler([](int32_t value) { - std::stringstream stream; - stream << std::hex << value; - return stream.str(); + char buf[4]; + buf[0] = hex2char((value & 0xf000) >> 12); + buf[1] = hex2char((value & 0x0f00) >> 8); + buf[2] = hex2char((value & 0x00f0) >> 4); + buf[3] = hex2char((value & 0x000f) >> 0); + return std::string(buf, sizeof(buf)); }); num = new NumberEdit(paramLines[P_ID], rect_t{}, 0, 0xff, GET_SET_DEFAULT(sensor->instance)); #if LCD_H > LCD_W diff --git a/radio/src/gui/colorlcd/model_templates.cpp b/radio/src/gui/colorlcd/model_templates.cpp index d2c46ef20..c35e529a1 100644 --- a/radio/src/gui/colorlcd/model_templates.cpp +++ b/radio/src/gui/colorlcd/model_templates.cpp @@ -22,7 +22,6 @@ #include "model_templates.h" #include "standalone_lua.h" -#include "str_functions.h" static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST}; diff --git a/radio/src/gui/colorlcd/radio_theme.cpp b/radio/src/gui/colorlcd/radio_theme.cpp index aeeac8b8b..0b94911c0 100644 --- a/radio/src/gui/colorlcd/radio_theme.cpp +++ b/radio/src/gui/colorlcd/radio_theme.cpp @@ -522,6 +522,17 @@ void ThemeSetupPage::checkEvents() } } +static void removeAllWhiteSpace(char *str) +{ + int len = strlen(str); + int origLen = len; + while(len) { + if (isspace(str[len])) + memmove(str + len, str + len + 1, origLen - len); + len--; + } +} + void ThemeSetupPage::displayThemeMenu(Window *window, ThemePersistance *tp) { auto menu = new Menu(listBox,false); diff --git a/radio/src/gui/colorlcd/str_functions.cpp b/radio/src/gui/colorlcd/str_functions.cpp deleted file mode 100644 index d6e9bafb9..000000000 --- a/radio/src/gui/colorlcd/str_functions.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (C) EdgeTX - * - * Based on code named - * opentx - https://github.com/opentx/opentx - * 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 -#include -#include -#include -#include "str_functions.h" - -static const char splitChars[] = { " -\t" }; - -void removeAllWhiteSpace(char *str) -{ - int len = strlen(str); - int origLen = len; - while(len) { - if (iswspace(str[len])) - memmove(str + len, str + len + 1, origLen - len); - len--; - } -} - -char *trim(char *str) -{ - char *end; - - // Trim leading space - while(isspace((unsigned char)*str)) str++; - - if(*str == 0) // All spaces? - return str; - - // Trim trailing space - end = str + strlen(str) - 1; - while(end > str && isspace((unsigned char)*end)) end--; - - // Write new null terminator character - end[1] = '\0'; - - return str; -} - -std::string trim_start(std::string str) -{ - uint32_t i; - for (i = 0; i < str.length(); i++) - if (!iswspace(str[i])) - break; - - return str.substr(i); -} - -std::vector Explode(std::string str, const char *splitChars) -{ - std::vector parts; - int startIndex = 0; - while (true) - { - size_t index = str.find_first_of(splitChars, startIndex); - - if (index == std::string::npos) - { - parts.emplace_back(str.substr(startIndex)); - return parts; - } - - std::string word = str.substr(startIndex, index - startIndex); - char nextChar = str.substr(index, 1)[0]; - - // Dashes and the likes should stick to the word occuring before it. Whitespace doesn't have to. - if (iswspace(nextChar)) - { - parts.emplace_back(word); - parts.emplace_back(std::string(&nextChar, 1)); - } - else - { - parts.emplace_back(word + nextChar); - } - - startIndex = index + 1; - } -} - -std::string wrap(std::string str, uint32_t width) -{ - std::vector words = Explode(str, splitChars); - - uint32_t curLineLength = 0; - std::ostringstream strBuilder; - - for(uint32_t i = 0; i < words.size(); i++) - { - std::string word = words[i]; - // If adding the new word to the current line would be too long, - // then put it on a new line (and split it up if it's too long). - if (curLineLength + word.length() > width) - { - // Only move down to a new line if we have text on the current line. - // Avoids situation where wrapped whitespace causes emptylines in text. - if (curLineLength > 0) - { - strBuilder << "\n"; - curLineLength = 0; - } - - // If the current word is too long to fit on a line even on it's own then - // split the word up. - while (word.length() > width) - { - strBuilder << word.substr(0, width - 1) + "-"; - word = word.substr(width - 1); - - strBuilder << "\n"; - } - - // Remove leading whitespace from the word so the new line starts flush to the left. - word = trim_start(word); - } - - strBuilder << word; - curLineLength += word.length(); - } - - return strBuilder.str(); -} diff --git a/radio/src/gui/colorlcd/str_functions.h b/radio/src/gui/colorlcd/str_functions.h deleted file mode 100644 index 5d9c64559..000000000 --- a/radio/src/gui/colorlcd/str_functions.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) EdgeTX - * - * Based on code named - * opentx - https://github.com/opentx/opentx - * 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. - */ -#pragma once -#include -#include -#include -#include -#include - -extern char *trim(char *str); -extern void removeAllWhiteSpace(char *str); -extern std::string trim_start(std::string str); -extern std::string wrap(std::string str, uint32_t width); diff --git a/radio/src/gui/colorlcd/theme_manager.h b/radio/src/gui/colorlcd/theme_manager.h index c81e48fb5..c719d8e03 100644 --- a/radio/src/gui/colorlcd/theme_manager.h +++ b/radio/src/gui/colorlcd/theme_manager.h @@ -27,7 +27,6 @@ #include "debug.h" #include "opentx.h" #include "sdcard.h" -#include "str_functions.h" #define COLOR_COUNT 13 diff --git a/radio/src/lua/api_filesystem.cpp b/radio/src/lua/api_filesystem.cpp index 47cf67bd3..79e9dd62e 100644 --- a/radio/src/lua/api_filesystem.cpp +++ b/radio/src/lua/api_filesystem.cpp @@ -75,7 +75,8 @@ int luaDir(lua_State* L) FRESULT res = f_opendir(dir, path); if (res != FR_OK) { - printf("luaDir cannot open %s\n", path); + TRACE("luaDir cannot open %s\n", path); + return 0; } lua_pushcclosure(L, dir_iter, 1); @@ -129,7 +130,7 @@ int luaFstat(lua_State* L) res = f_stat(path, &info); if (res != FR_OK) { - printf("luaFstat cannot open %s\n", path); + TRACE("luaFstat cannot open %s\n", path); return 0; } @@ -174,7 +175,8 @@ int luaDelete(lua_State* L) FRESULT res = f_unlink(filename); if (res != FR_OK) { - printf("luaDelete cannot delete file/folder %s\n", filename); + TRACE("luaDelete cannot delete file/folder %s\n", filename); + return 0; } lua_pushunsigned(L, res); diff --git a/radio/src/storage/modelslist.cpp b/radio/src/storage/modelslist.cpp index 1fa3e28d9..f42137d44 100644 --- a/radio/src/storage/modelslist.cpp +++ b/radio/src/storage/modelslist.cpp @@ -442,15 +442,25 @@ std::string ModelMap::toCSV(const LabelsVector &labels) * @return vector of all labels */ -LabelsVector ModelMap::fromCSV(const char *str) +LabelsVector ModelMap::fromCSV(const char* str) { LabelsVector lbls; - std::istringstream f(str); - std::string lbl; - while (std::getline(f, lbl, ',')) { + const char* prev_c = str; + const char* c = strchr(prev_c, ','); + while(c != nullptr) { + std::string lbl(prev_c, c - prev_c); + unEscapeCSV(lbl); + lbls.push_back(lbl); + prev_c = ++c; + c = strchr(c, ','); + } + + { + std::string lbl(prev_c); unEscapeCSV(lbl); lbls.push_back(lbl); } + return lbls; } diff --git a/radio/src/thirdparty/Lua/src/lauxlib.c b/radio/src/thirdparty/Lua/src/lauxlib.c index b3ef28d4a..452e8dd06 100644 --- a/radio/src/thirdparty/Lua/src/lauxlib.c +++ b/radio/src/thirdparty/Lua/src/lauxlib.c @@ -216,6 +216,20 @@ LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) { LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { +#if defined(USE_FATFS) + if (stat) { + lua_pushboolean(L, 1); + return 1; + } + else { + lua_pushnil(L); + if (fname) + lua_pushfstring(L, "%s: file error", fname); + else + lua_pushstring(L, "file error"); + return 2; + } +#else int en = errno; /* calls to Lua API may change this value */ if (stat) { lua_pushboolean(L, 1); @@ -230,6 +244,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { lua_pushinteger(L, en); return 3; } +#endif } @@ -619,9 +634,14 @@ static const char *getF (lua_State *L, void *ud, size_t *size) { static int errfile (lua_State *L, const char *what, int fnameindex) { +#if defined(USE_FATFS) + const char *filename = lua_tostring(L, fnameindex) + 1; + lua_pushfstring(L, "cannot %s %s", what, filename); +#else const char *serr = strerror(errno); const char *filename = lua_tostring(L, fnameindex) + 1; lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); +#endif lua_remove(L, fnameindex); return LUA_ERRFILE; } diff --git a/radio/src/thirdparty/Lua/src/luaconf.h b/radio/src/thirdparty/Lua/src/luaconf.h index 1e9d544a0..3c3d74822 100644 --- a/radio/src/thirdparty/Lua/src/luaconf.h +++ b/radio/src/thirdparty/Lua/src/luaconf.h @@ -18,6 +18,9 @@ // force ANSI mode: lua_number2integer() behaves the same way on all platforms (#3826) #define LUA_ANSI +// prevent localeconv() +#define getlocaledecpoint() ('.') + /* ** ================================================================== ** Search for "@@" to find all configurable definitions.