Skip to content

Commit 7174a53

Browse files
committed
Small ajustement for stability and cross compilation
1 parent 07da204 commit 7174a53

File tree

19 files changed

+132
-52
lines changed

19 files changed

+132
-52
lines changed

lib/graphics/src/Encoder/decodeutf8.cpp

+30-26
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,36 @@ uint16_t decodeUTF8(uint8_t c) {
9494

9595
std::string decodeString(std::string &code)
9696
{
97-
resetUTF8decoder();
98-
99-
std::string code_8;
100-
std::vector<uint16_t> code_16;
101-
102-
for (int i = 0; i < code.size(); i++)
103-
code_16.push_back(decodeUTF8(code[i]));
104-
105-
for (int i = 0; i < code.size(); i++)
106-
{
107-
bool result = false;
108-
for (int j = 0; j < FRCharcount; j++)
97+
resetUTF8decoder();
98+
std::string code_8;
99+
std::vector<uint16_t> code_16;
100+
101+
// First decode UTF8 characters
102+
for (int i = 0; i < code.size(); i++)
103+
code_16.push_back(decodeUTF8(code[i]));
104+
105+
// Process each character
106+
for (int i = 0; i < code.size(); i++)
109107
{
110-
if(code_16[i] == FRCharset[j].UTF)
111-
{
112-
result = true;
113-
code_8.push_back(FRCharset[j].latin);
114-
break;
115-
}
108+
bool result = false;
109+
110+
// Check if character exists in FRCharset table
111+
for (int j = 0; j < FRCharcount; j++)
112+
{
113+
if(code_16[i] == FRCharset[j].UTF)
114+
{
115+
result = true;
116+
code_8.push_back(FRCharset[j].latin);
117+
break;
118+
}
119+
}
120+
121+
// Only add ASCII characters that are printable
122+
if(!result && code_16[i] <= 0x7F && isprint(code_16[i]))
123+
{
124+
code_8.push_back(static_cast<char>(code_16[i]));
125+
}
126+
// Characters above 0x7F that aren't in the table are ignored
116127
}
117-
118-
if(!result && code_16[i] <= 0xFF)
119-
{
120-
code_8.push_back(static_cast<char>(code_16[i]));
121-
}
122-
}
123-
124-
return code_8;
128+
return code_8;
125129
}

lib/graphics/src/Surface.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <filestream.hpp>
1010
//#include <JPEGENC.h>
1111
#include <iostream>
12+
#include <algorithm>
1213

1314
#ifdef ESP_PLATFORM
1415
#include <Arduino.h>
@@ -264,14 +265,41 @@ namespace graphics
264265
float scaleX = static_cast<float>(w) / static_cast<float>(image.getWidth());
265266
float scaleY = static_cast<float>(h) / static_cast<float>(image.getHeight());
266267

268+
if(m_sprite.getBuffer() == nullptr)
269+
{
270+
std::cerr << "[Error] Unable to write on an invalid sprite: " << w * h * 2 << " bytes" << std::endl;
271+
return;
272+
}
273+
267274
#ifdef ESP_PLATFORM
275+
if(image.getType() == PNG)
276+
{
277+
storage::FileStream stream(image.getPath().str(), storage::Mode::READ);
278+
size_t size = stream.size();
279+
280+
if(!stream.isopen() || size == 0)
281+
{
282+
return;
283+
}
284+
285+
std::cout << "Reading PNG...: " << size << std::endl;
286+
char* buffer = new char[size];
287+
stream.read(buffer, size);
288+
stream.close();
289+
290+
m_sprite.drawPng((uint8_t*) buffer, size, x, y, 0, 0, 0, 0, scaleX, scaleY);
291+
292+
// here is the place to code the decompression
293+
294+
delete[] buffer;
295+
}
268296
switch (image.getType()) // image size with right format
269297
{
270298
case BMP:
271299
m_sprite.drawBmpFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);
272300
break;
273301
case PNG:
274-
m_sprite.drawPngFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);
302+
//m_sprite.drawPngFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);
275303
break;
276304
case JPG:
277305
m_sprite.drawJpgFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);

lib/gsm/src/conversation.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ namespace Conversations
5151
msg.date = messageItem.at("date").get<std::string>();
5252
conv.messages.push_back(msg);
5353
}
54+
55+
if (conv.messages.size() > 20)
56+
{
57+
conv.messages.erase(conv.messages.begin(), conv.messages.end() - 20);
58+
}
5459
}
5560
catch (const nlohmann::json::exception &e)
5661
{

lib/gsm/src/gsm.cpp

+20-5
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,16 @@ namespace GSM
151151
std::string send(const std::string &message, const std::string &answerKey, uint64_t timeout)
152152
{
153153
#ifdef ESP_PLATFORM
154+
String temp = gsm.readString();
155+
data += temp.c_str();
154156
gsm.println((message + "\r").c_str());
155157

156158
std::cout << "[GSM] Sending request: " << message << ", " << answerKey << std::endl;
157159

158160
uint64_t lastChar = millis();
159161
std::string answer = "";
160162

161-
while (lastChar + timeout > millis()) // save none related messages to data.
163+
/*while (lastChar + timeout > millis()) // save none related messages to data.
162164
{
163165
if (gsm.available())
164166
{
@@ -172,7 +174,7 @@ namespace GSM
172174
break;
173175
}
174176
}
175-
}
177+
}*/
176178

177179
while (lastChar + timeout > millis() && (answer.find("OK\r\n") == std::string::npos && answer.find("ERROR\r\n") == std::string::npos))
178180
{
@@ -192,6 +194,8 @@ namespace GSM
192194
std::cout << "[GSM] Response: " << answer << std::endl;
193195
}*/
194196

197+
delay(50);
198+
195199
return answer;
196200
#endif
197201

@@ -793,9 +797,9 @@ namespace GSM
793797
{
794798
send("AT+CMGF=0", "AT+CMGF=0", 100);
795799

796-
std::string input = send("AT+CMGL=0", "AT+CMGL", 5000); // read all messages
800+
std::string input = send("AT+CMGL=0", "CMGL", 5000); // read all messages
797801

798-
std::cout << input << std::endl;
802+
std::cout << "AT+CMGL=0 -----------------------------------------: " << input << std::endl;
799803

800804
std::vector<std::string> pdus;
801805

@@ -891,6 +895,12 @@ namespace GSM
891895
catch (const std::out_of_range& e) {
892896
std::cerr << "Erreur : " << e.what() << std::endl;
893897
}
898+
899+
if(pdu.length() > 0)
900+
{
901+
if (ExternalEvents::onNewMessage)
902+
ExternalEvents::onNewMessage();
903+
}
894904
}
895905

896906
send("AT+CMGD=1,1", "AT+CMGD", 1000);
@@ -1232,7 +1242,12 @@ namespace GSM
12321242

12331243
//PaxOS_Delay(50000);
12341244

1235-
requests.push_back({[](){ send("AT+CNTP=\"time.google.com\",8", "AT+CNTP"); send("AT+CNTP","AT+CNTP", 1000); }, priority::high});
1245+
requests.push_back({[]()
1246+
{
1247+
send("AT+CNTP=\"time.google.com\",4", "AT+CNTP"); // the number 4 is the time zone*4, so each 1 is 1 quarter hour (weird)
1248+
send("AT+CNTP","AT+CNTP", 2000);
1249+
send("AT+CNMI=2,1,0,0,0", "AT+CNMI");
1250+
}, priority::high});
12361251

12371252
updateHour();
12381253
getNetworkQuality();

lib/gui/src/ElementBase.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ gui::ElementBase::~ElementBase()
5454
delete m_children[i];
5555
}
5656
}
57+
58+
if(widgetPressed == this)
59+
{
60+
widgetPressed = nullptr;
61+
globalPressedState = PressedState::NOT_PRESSED;
62+
}
5763
}
5864

5965
void gui::ElementBase::renderAll(bool onScreen)

lib/gui/src/elements/Canvas.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <standby.hpp>
44
#include <threads.hpp>
5+
#include <algorithm>
56

67
namespace gui::elements
78
{

lib/gui/src/elements/Image.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ namespace gui::ImagesList
2929

3030
const auto i = graphics::SImage(path);
3131

32-
// libsystem::log("Image: " + std::to_string(i.getType()) + ", " + std::to_string(i.getWidth()) + ", " + std::to_string(i.getHeight()) + ", " + i.getPath().str());
33-
3432
ImageLoaded img = {
3533
path,
3634
i.getWidth(),
@@ -40,6 +38,7 @@ namespace gui::ImagesList
4038

4139
// Clear the background if it's a transparent image ?
4240
// I guess so ?
41+
4342
if(i.getType() != graphics::ImageType::BMP) {
4443
img.surface->clear(backgroundColor);
4544
}
@@ -59,7 +58,7 @@ namespace gui::ImagesList
5958
if (img->surface.unique())
6059
{
6160
img = images.erase(img);
62-
std::cout << "[Image] image deleted" << std::endl;
61+
//std::cout << "[Image] image deleted" << std::endl;
6362
}
6463
else
6564
{

lib/gui/src/elements/Window.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdio>
88
#include <graphics.hpp>
99
#include <Surface.hpp>
10+
#include <algorithm>
1011

1112
namespace gui::elements {
1213
Window::Window()

lib/lua/src/lua_label.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ LuaLabel::LuaLabel(LuaWidget* parent, int x, int y, int width, int height)
1010
}
1111

1212
void LuaLabel::setTextColor(const color_t color) const {
13-
libsystem::log("Color: " + std::to_string(color));
14-
1513
widget->setTextColor(color);
1614
}
1715

1816
void LuaLabel::setTextColorRGB(const uint8_t r, const uint8_t g, const uint8_t b) const {
19-
libsystem::log("Color RGB: " + std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b));
20-
2117
widget->setTextColor(graphics::packRGB565(r, g, b));
2218
}
2319

lib/lua/src/lua_storage.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,24 @@ bool LuaStorage::legalPath(storage::Path path)
6262

6363
storage::Path LuaStorage::convertPath(std::string path)
6464
{
65-
std::cout << "convertPath: " << path << std::endl;
65+
//std::cout << "convertPath: " << path << std::endl;
6666
if (!legalPath(path))
6767
throw libsystem::exceptions::RuntimeError("The app is not allowed to access this path: " + path);
6868

6969
if(path[0] == '/') {
70-
std::cout << "Returning path: " << path << std::endl;
70+
//std::cout << "Returning path: " << path << std::endl;
7171
return path;
7272
} else {
7373
storage::Path fullPath = this->lua->directory / path;
74-
std::cout << "Returning full path: " << this->lua->directory.str() << " + " << path << " = " << fullPath.str() << std::endl;
74+
//std::cout << "Returning full path: " << this->lua->directory.str() << " + " << path << " = " << fullPath.str() << std::endl;
7575
return fullPath;
7676
}
7777
}
7878

7979
std::unique_ptr<LuaStorageFile> LuaStorage::file(std::string filename, int mode)
8080
{
8181
storage::Path path(convertPath(filename));
82-
std::cout << "path: " << path.str() << std::endl;
82+
//std::cout << "path: " << path.str() << std::endl;
8383

8484
return std::make_unique<LuaStorageFile>(path, mode);
8585
}

lib/storage/filestream.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ namespace storage
5959
return word;
6060
}
6161

62+
void FileStream::read(char* buffer, std::size_t len)
63+
{
64+
m_stream.read(buffer, len);
65+
}
66+
6267
char FileStream::readchar(void)
6368
{
6469
return m_stream.get();
@@ -90,6 +95,7 @@ namespace storage
9095
m_stream.seekg(0, std::ios::end);
9196
const auto end = m_stream.tellg();
9297
const auto fsize = (end - begin);
98+
m_stream.seekg(0, std::ios::beg);
9399
return fsize;
94100
}
95101

lib/storage/filestream.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace storage
3333
std::string read(void);
3434
std::string readline(void);
3535
std::string readword(void);
36+
void read(char* buffer, std::size_t len);
3637
char readchar(void);
3738

3839
void write(const std::string &str);

lib/tasks/src/tasks.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <iostream>
44
#include <clock.hpp>
5+
#include <algorithm>
56

67
EventHandler::~EventHandler()
78
{

platformio.ini

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ lib_deps =
2525
lovyan03/LovyanGFX@^1.1.9
2626
bitbank2/FT6236G@^1.0.0
2727
28+
bitbank2/PNGdec@^1.0.3
2829
build_flags =
2930
-std=gnu++17
3031
-DPLATFORM_PAXO_V5
@@ -34,13 +35,13 @@ build_flags =
3435
-Wno-error=maybe-uninitialized
3536
-Wno-reorder
3637
-DBOARD_HAS_PSRAM
37-
;-mfix-esp32-psram-cache-issue
3838
-DCONFIG_SPIRAM_CACHE_WORKAROUND
39+
-DCONFIG_SPIRAM_USE_MALLOC
3940
-DCORE_DEBUG_LEVEL=5
4041
-DSOL_NO_THREAD_LOCAL=1
4142
-mtext-section-literals
4243
-Wl,--wrap=esp_panic_handler
43-
build_unflags =
44+
build_unflags =
4445
-std=gnu++11
4546
-std=gnu++14
4647
build_type = debug
@@ -56,6 +57,7 @@ lib_deps =
5657
mbed-babylonica/[email protected]+sha.278f7f125495
5758
bitbank2/FT6236G@^1.0.0
5859
bitbank2/JPEGENC@^1.1.0
60+
bitbank2/PNGdec@^1.0.3
5961
test_framework = googletest
6062
test_testing_command = ${platformio.build_dir}/${this.__env__}/program
6163
build_flags =
@@ -84,6 +86,7 @@ lib_deps =
8486
mbed-babylonica/[email protected]+sha.278f7f125495
8587
bitbank2/FT6236G@^1.0.0
8688
bitbank2/JPEGENC@^1.1.0
89+
bitbank2/PNGdec@^1.0.3
8790
build_flags =
8891
-std=c++17
8992
-lm
@@ -109,6 +112,7 @@ lib_deps =
109112
mbed-babylonica/[email protected]+sha.278f7f125495
110113
bitbank2/FT6236G@^1.0.0
111114
bitbank2/JPEGENC@^1.1.0
115+
bitbank2/PNGdec@^1.0.3
112116
test_framework = googletest
113117
build_flags =
114118
-std=c++17
@@ -128,6 +132,7 @@ lib_deps =
128132
mbed-babylonica/[email protected]+sha.278f7f125495
129133
bitbank2/FT6236G@^1.0.0
130134
bitbank2/JPEGENC@^1.1.0
135+
bitbank2/PNGdec@^1.0.3
131136
test_framework = googletest
132137
build_flags =
133138
-std=c++17
@@ -153,3 +158,4 @@ lib_deps =
153158
mbed-babylonica/[email protected]+sha.278f7f125495
154159
bitbank2/FT6236G@^1.0.0
155160
bitbank2/JPEGENC@^1.1.0
161+
bitbank2/PNGdec@^1.0.3

0 commit comments

Comments
 (0)