Skip to content

Commit

Permalink
Small ajustement for stability and cross compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
paxo-rch committed Jan 20, 2025
1 parent 07da204 commit 7174a53
Show file tree
Hide file tree
Showing 19 changed files with 132 additions and 52 deletions.
56 changes: 30 additions & 26 deletions lib/graphics/src/Encoder/decodeutf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,36 @@ uint16_t decodeUTF8(uint8_t c) {

std::string decodeString(std::string &code)
{
resetUTF8decoder();

std::string code_8;
std::vector<uint16_t> code_16;

for (int i = 0; i < code.size(); i++)
code_16.push_back(decodeUTF8(code[i]));

for (int i = 0; i < code.size(); i++)
{
bool result = false;
for (int j = 0; j < FRCharcount; j++)
resetUTF8decoder();
std::string code_8;
std::vector<uint16_t> code_16;

// First decode UTF8 characters
for (int i = 0; i < code.size(); i++)
code_16.push_back(decodeUTF8(code[i]));

// Process each character
for (int i = 0; i < code.size(); i++)
{
if(code_16[i] == FRCharset[j].UTF)
{
result = true;
code_8.push_back(FRCharset[j].latin);
break;
}
bool result = false;

// Check if character exists in FRCharset table
for (int j = 0; j < FRCharcount; j++)
{
if(code_16[i] == FRCharset[j].UTF)
{
result = true;
code_8.push_back(FRCharset[j].latin);
break;
}
}

// Only add ASCII characters that are printable
if(!result && code_16[i] <= 0x7F && isprint(code_16[i]))
{
code_8.push_back(static_cast<char>(code_16[i]));
}
// Characters above 0x7F that aren't in the table are ignored
}

if(!result && code_16[i] <= 0xFF)
{
code_8.push_back(static_cast<char>(code_16[i]));
}
}

return code_8;
return code_8;
}
30 changes: 29 additions & 1 deletion lib/graphics/src/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <filestream.hpp>
//#include <JPEGENC.h>
#include <iostream>
#include <algorithm>

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

if(m_sprite.getBuffer() == nullptr)
{
std::cerr << "[Error] Unable to write on an invalid sprite: " << w * h * 2 << " bytes" << std::endl;
return;
}

#ifdef ESP_PLATFORM
if(image.getType() == PNG)
{
storage::FileStream stream(image.getPath().str(), storage::Mode::READ);
size_t size = stream.size();

if(!stream.isopen() || size == 0)
{
return;
}

std::cout << "Reading PNG...: " << size << std::endl;
char* buffer = new char[size];
stream.read(buffer, size);
stream.close();

m_sprite.drawPng((uint8_t*) buffer, size, x, y, 0, 0, 0, 0, scaleX, scaleY);

// here is the place to code the decompression

delete[] buffer;
}
switch (image.getType()) // image size with right format
{
case BMP:
m_sprite.drawBmpFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);
break;
case PNG:
m_sprite.drawPngFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);
//m_sprite.drawPngFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);
break;
case JPG:
m_sprite.drawJpgFile(image.getPath().str().c_str(), x, y, 0, 0, 0, 0, scaleX, scaleY);
Expand Down
5 changes: 5 additions & 0 deletions lib/gsm/src/conversation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ namespace Conversations
msg.date = messageItem.at("date").get<std::string>();
conv.messages.push_back(msg);
}

if (conv.messages.size() > 20)
{
conv.messages.erase(conv.messages.begin(), conv.messages.end() - 20);
}
}
catch (const nlohmann::json::exception &e)
{
Expand Down
25 changes: 20 additions & 5 deletions lib/gsm/src/gsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,16 @@ namespace GSM
std::string send(const std::string &message, const std::string &answerKey, uint64_t timeout)
{
#ifdef ESP_PLATFORM
String temp = gsm.readString();
data += temp.c_str();
gsm.println((message + "\r").c_str());

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

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

while (lastChar + timeout > millis()) // save none related messages to data.
/*while (lastChar + timeout > millis()) // save none related messages to data.
{
if (gsm.available())
{
Expand All @@ -172,7 +174,7 @@ namespace GSM
break;
}
}
}
}*/

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

delay(50);

return answer;
#endif

Expand Down Expand Up @@ -793,9 +797,9 @@ namespace GSM
{
send("AT+CMGF=0", "AT+CMGF=0", 100);

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

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

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

Expand Down Expand Up @@ -891,6 +895,12 @@ namespace GSM
catch (const std::out_of_range& e) {
std::cerr << "Erreur : " << e.what() << std::endl;
}

if(pdu.length() > 0)
{
if (ExternalEvents::onNewMessage)
ExternalEvents::onNewMessage();
}
}

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

//PaxOS_Delay(50000);

requests.push_back({[](){ send("AT+CNTP=\"time.google.com\",8", "AT+CNTP"); send("AT+CNTP","AT+CNTP", 1000); }, priority::high});
requests.push_back({[]()
{
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)
send("AT+CNTP","AT+CNTP", 2000);
send("AT+CNMI=2,1,0,0,0", "AT+CNMI");
}, priority::high});

updateHour();
getNetworkQuality();
Expand Down
6 changes: 6 additions & 0 deletions lib/gui/src/ElementBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ gui::ElementBase::~ElementBase()
delete m_children[i];
}
}

if(widgetPressed == this)
{
widgetPressed = nullptr;
globalPressedState = PressedState::NOT_PRESSED;
}
}

void gui::ElementBase::renderAll(bool onScreen)
Expand Down
1 change: 1 addition & 0 deletions lib/gui/src/elements/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <standby.hpp>
#include <threads.hpp>
#include <algorithm>

namespace gui::elements
{
Expand Down
5 changes: 2 additions & 3 deletions lib/gui/src/elements/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ namespace gui::ImagesList

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

// libsystem::log("Image: " + std::to_string(i.getType()) + ", " + std::to_string(i.getWidth()) + ", " + std::to_string(i.getHeight()) + ", " + i.getPath().str());

ImageLoaded img = {
path,
i.getWidth(),
Expand All @@ -40,6 +38,7 @@ namespace gui::ImagesList

// Clear the background if it's a transparent image ?
// I guess so ?

if(i.getType() != graphics::ImageType::BMP) {
img.surface->clear(backgroundColor);
}
Expand All @@ -59,7 +58,7 @@ namespace gui::ImagesList
if (img->surface.unique())
{
img = images.erase(img);
std::cout << "[Image] image deleted" << std::endl;
//std::cout << "[Image] image deleted" << std::endl;
}
else
{
Expand Down
1 change: 1 addition & 0 deletions lib/gui/src/elements/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdio>
#include <graphics.hpp>
#include <Surface.hpp>
#include <algorithm>

namespace gui::elements {
Window::Window()
Expand Down
4 changes: 0 additions & 4 deletions lib/lua/src/lua_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ LuaLabel::LuaLabel(LuaWidget* parent, int x, int y, int width, int height)
}

void LuaLabel::setTextColor(const color_t color) const {
libsystem::log("Color: " + std::to_string(color));

widget->setTextColor(color);
}

void LuaLabel::setTextColorRGB(const uint8_t r, const uint8_t g, const uint8_t b) const {
libsystem::log("Color RGB: " + std::to_string(r) + ", " + std::to_string(g) + ", " + std::to_string(b));

widget->setTextColor(graphics::packRGB565(r, g, b));
}

8 changes: 4 additions & 4 deletions lib/lua/src/lua_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@ bool LuaStorage::legalPath(storage::Path path)

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

if(path[0] == '/') {
std::cout << "Returning path: " << path << std::endl;
//std::cout << "Returning path: " << path << std::endl;
return path;
} else {
storage::Path fullPath = this->lua->directory / path;
std::cout << "Returning full path: " << this->lua->directory.str() << " + " << path << " = " << fullPath.str() << std::endl;
//std::cout << "Returning full path: " << this->lua->directory.str() << " + " << path << " = " << fullPath.str() << std::endl;
return fullPath;
}
}

std::unique_ptr<LuaStorageFile> LuaStorage::file(std::string filename, int mode)
{
storage::Path path(convertPath(filename));
std::cout << "path: " << path.str() << std::endl;
//std::cout << "path: " << path.str() << std::endl;

return std::make_unique<LuaStorageFile>(path, mode);
}
6 changes: 6 additions & 0 deletions lib/storage/filestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ namespace storage
return word;
}

void FileStream::read(char* buffer, std::size_t len)
{
m_stream.read(buffer, len);
}

char FileStream::readchar(void)
{
return m_stream.get();
Expand Down Expand Up @@ -90,6 +95,7 @@ namespace storage
m_stream.seekg(0, std::ios::end);
const auto end = m_stream.tellg();
const auto fsize = (end - begin);
m_stream.seekg(0, std::ios::beg);
return fsize;
}

Expand Down
1 change: 1 addition & 0 deletions lib/storage/filestream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace storage
std::string read(void);
std::string readline(void);
std::string readword(void);
void read(char* buffer, std::size_t len);
char readchar(void);

void write(const std::string &str);
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/src/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <iostream>
#include <clock.hpp>
#include <algorithm>

EventHandler::~EventHandler()
{
Expand Down
10 changes: 8 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib_deps =
lovyan03/LovyanGFX@^1.1.9
bitbank2/FT6236G@^1.0.0
anto/[email protected]
bitbank2/PNGdec@^1.0.3
build_flags =
-std=gnu++17
-DPLATFORM_PAXO_V5
Expand All @@ -34,13 +35,13 @@ build_flags =
-Wno-error=maybe-uninitialized
-Wno-reorder
-DBOARD_HAS_PSRAM
;-mfix-esp32-psram-cache-issue
-DCONFIG_SPIRAM_CACHE_WORKAROUND
-DCONFIG_SPIRAM_USE_MALLOC
-DCORE_DEBUG_LEVEL=5
-DSOL_NO_THREAD_LOCAL=1
-mtext-section-literals
-Wl,--wrap=esp_panic_handler
build_unflags =
build_unflags =
-std=gnu++11
-std=gnu++14
build_type = debug
Expand All @@ -56,6 +57,7 @@ lib_deps =
mbed-babylonica/[email protected]+sha.278f7f125495
bitbank2/FT6236G@^1.0.0
bitbank2/JPEGENC@^1.1.0
bitbank2/PNGdec@^1.0.3
test_framework = googletest
test_testing_command = ${platformio.build_dir}/${this.__env__}/program
build_flags =
Expand Down Expand Up @@ -84,6 +86,7 @@ lib_deps =
mbed-babylonica/[email protected]+sha.278f7f125495
bitbank2/FT6236G@^1.0.0
bitbank2/JPEGENC@^1.1.0
bitbank2/PNGdec@^1.0.3
build_flags =
-std=c++17
-lm
Expand All @@ -109,6 +112,7 @@ lib_deps =
mbed-babylonica/[email protected]+sha.278f7f125495
bitbank2/FT6236G@^1.0.0
bitbank2/JPEGENC@^1.1.0
bitbank2/PNGdec@^1.0.3
test_framework = googletest
build_flags =
-std=c++17
Expand All @@ -128,6 +132,7 @@ lib_deps =
mbed-babylonica/[email protected]+sha.278f7f125495
bitbank2/FT6236G@^1.0.0
bitbank2/JPEGENC@^1.1.0
bitbank2/PNGdec@^1.0.3
test_framework = googletest
build_flags =
-std=c++17
Expand All @@ -153,3 +158,4 @@ lib_deps =
mbed-babylonica/[email protected]+sha.278f7f125495
bitbank2/FT6236G@^1.0.0
bitbank2/JPEGENC@^1.1.0
bitbank2/PNGdec@^1.0.3
Loading

0 comments on commit 7174a53

Please sign in to comment.