chore: Remove some bloat, reduce firmware size (#4288)
This commit is contained in:
@@ -17,7 +17,6 @@ file(GLOB WIDGETS_SRC RELATIVE ${RADIO_SRC_DIR}/gui/colorlcd
|
|||||||
|
|
||||||
set(GUI_SRC
|
set(GUI_SRC
|
||||||
${GUI_SRC}
|
${GUI_SRC}
|
||||||
str_functions.cpp
|
|
||||||
colors.cpp
|
colors.cpp
|
||||||
lcd.cpp
|
lcd.cpp
|
||||||
splash.cpp
|
splash.cpp
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
#include "model_templates.h"
|
#include "model_templates.h"
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "standalone_lua.h"
|
#include "standalone_lua.h"
|
||||||
#include "str_functions.h"
|
|
||||||
#include "view_channels.h"
|
#include "view_channels.h"
|
||||||
|
|
||||||
// bitmaps for toolbar
|
// bitmaps for toolbar
|
||||||
|
|||||||
@@ -19,9 +19,8 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include "model_telemetry.h"
|
#include "model_telemetry.h"
|
||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "libopenui.h"
|
#include "libopenui.h"
|
||||||
|
|
||||||
@@ -610,9 +609,12 @@ class SensorEditWindow : public Page {
|
|||||||
num->setWidth((lv_pct(28)));
|
num->setWidth((lv_pct(28)));
|
||||||
#endif
|
#endif
|
||||||
num->setDisplayHandler([](int32_t value) {
|
num->setDisplayHandler([](int32_t value) {
|
||||||
std::stringstream stream;
|
char buf[4];
|
||||||
stream << std::hex << value;
|
buf[0] = hex2char((value & 0xf000) >> 12);
|
||||||
return stream.str();
|
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));
|
num = new NumberEdit(paramLines[P_ID], rect_t{}, 0, 0xff, GET_SET_DEFAULT(sensor->instance));
|
||||||
#if LCD_H > LCD_W
|
#if LCD_H > LCD_W
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
#include "model_templates.h"
|
#include "model_templates.h"
|
||||||
|
|
||||||
#include "standalone_lua.h"
|
#include "standalone_lua.h"
|
||||||
#include "str_functions.h"
|
|
||||||
|
|
||||||
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
|
static const lv_coord_t col_dsc[] = {LV_GRID_FR(1), LV_GRID_FR(1),
|
||||||
LV_GRID_TEMPLATE_LAST};
|
LV_GRID_TEMPLATE_LAST};
|
||||||
|
|||||||
@@ -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)
|
void ThemeSetupPage::displayThemeMenu(Window *window, ThemePersistance *tp)
|
||||||
{
|
{
|
||||||
auto menu = new Menu(listBox,false);
|
auto menu = new Menu(listBox,false);
|
||||||
|
|||||||
@@ -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 <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <list>
|
|
||||||
#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<std::string> Explode(std::string str, const char *splitChars)
|
|
||||||
{
|
|
||||||
std::vector<std::string> 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<std::string> 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();
|
|
||||||
}
|
|
||||||
@@ -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 <cstdint>
|
|
||||||
#include <wctype.h>
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
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);
|
|
||||||
@@ -27,7 +27,6 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "sdcard.h"
|
#include "sdcard.h"
|
||||||
#include "str_functions.h"
|
|
||||||
|
|
||||||
#define COLOR_COUNT 13
|
#define COLOR_COUNT 13
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ int luaDir(lua_State* L)
|
|||||||
|
|
||||||
FRESULT res = f_opendir(dir, path);
|
FRESULT res = f_opendir(dir, path);
|
||||||
if (res != FR_OK) {
|
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);
|
lua_pushcclosure(L, dir_iter, 1);
|
||||||
@@ -129,7 +130,7 @@ int luaFstat(lua_State* L)
|
|||||||
|
|
||||||
res = f_stat(path, &info);
|
res = f_stat(path, &info);
|
||||||
if (res != FR_OK) {
|
if (res != FR_OK) {
|
||||||
printf("luaFstat cannot open %s\n", path);
|
TRACE("luaFstat cannot open %s\n", path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +175,8 @@ int luaDelete(lua_State* L)
|
|||||||
|
|
||||||
FRESULT res = f_unlink(filename);
|
FRESULT res = f_unlink(filename);
|
||||||
if (res != FR_OK) {
|
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);
|
lua_pushunsigned(L, res);
|
||||||
|
|||||||
@@ -442,15 +442,25 @@ std::string ModelMap::toCSV(const LabelsVector &labels)
|
|||||||
* @return vector of all labels
|
* @return vector of all labels
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LabelsVector ModelMap::fromCSV(const char *str)
|
LabelsVector ModelMap::fromCSV(const char* str)
|
||||||
{
|
{
|
||||||
LabelsVector lbls;
|
LabelsVector lbls;
|
||||||
std::istringstream f(str);
|
const char* prev_c = str;
|
||||||
std::string lbl;
|
const char* c = strchr(prev_c, ',');
|
||||||
while (std::getline(f, lbl, ',')) {
|
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);
|
unEscapeCSV(lbl);
|
||||||
lbls.push_back(lbl);
|
lbls.push_back(lbl);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lbls;
|
return lbls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
@@ -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) {
|
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 */
|
int en = errno; /* calls to Lua API may change this value */
|
||||||
if (stat) {
|
if (stat) {
|
||||||
lua_pushboolean(L, 1);
|
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);
|
lua_pushinteger(L, en);
|
||||||
return 3;
|
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) {
|
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 *serr = strerror(errno);
|
||||||
const char *filename = lua_tostring(L, fnameindex) + 1;
|
const char *filename = lua_tostring(L, fnameindex) + 1;
|
||||||
lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
|
lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
|
||||||
|
#endif
|
||||||
lua_remove(L, fnameindex);
|
lua_remove(L, fnameindex);
|
||||||
return LUA_ERRFILE;
|
return LUA_ERRFILE;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -18,6 +18,9 @@
|
|||||||
// force ANSI mode: lua_number2integer() behaves the same way on all platforms (#3826)
|
// force ANSI mode: lua_number2integer() behaves the same way on all platforms (#3826)
|
||||||
#define LUA_ANSI
|
#define LUA_ANSI
|
||||||
|
|
||||||
|
// prevent localeconv()
|
||||||
|
#define getlocaledecpoint() ('.')
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** ==================================================================
|
** ==================================================================
|
||||||
** Search for "@@" to find all configurable definitions.
|
** Search for "@@" to find all configurable definitions.
|
||||||
|
|||||||
Reference in New Issue
Block a user