Skip to content

Commit dc07621

Browse files
committed
Ajout de l'alarme complète ainsi que toutes les dépandances en terme d'application arrière plan, sortie de veille, correction des ../ dans les paths.
Ajout également des thème arrière plan aux paramètres et application réele dans le système
1 parent f76967b commit dc07621

25 files changed

+279
-256
lines changed

lib/applications/src/app.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ namespace AppManager {
226226

227227
std::shared_ptr<App> app;
228228

229+
std::string fullname = prefix.size() ? (prefix + "." + dir) : (dir);
230+
libsystem::log("Loading app \"" + fullname + "\".");
231+
232+
229233
if (root) {
230234
app = std::make_shared<App>(
231235
dir,
@@ -236,21 +240,21 @@ namespace AppManager {
236240
} else if (allowedFiles.find(appPath.str()) != std::string::npos) {
237241
app = std::make_shared<App>(
238242
dir,
239-
storage::Path(APP_DIR) / dir / "app.lua",
240-
storage::Path(PERMS_DIR) / (dir + ".json"),
243+
storage::Path(directory) / dir / "app.lua",
244+
storage::Path(PERMS_DIR) / (fullname + ".json"),
241245
true
242246
);
243247
} else {
244248
app = std::make_shared<App>(
245249
dir,
246-
storage::Path(APP_DIR) / dir / "app.lua",
247-
storage::Path(APP_DIR) / dir / "manifest.json",
250+
storage::Path(directory) / dir / "app.lua",
251+
storage::Path(directory) / fullname / "manifest.json",
248252
false
249253
);
250254
}
251255

252-
app->fullName = prefix.size() ? (prefix + dir) : (dir);
253-
libsystem::log("Loading app \"" + app->fullName + "\".");
256+
app->fullName = fullname;
257+
254258

255259
if (!dir.empty() && dir[0] == '.') {
256260
app->visible = false;
@@ -265,7 +269,6 @@ namespace AppManager {
265269
if(manifest["background"].is_boolean())
266270
{
267271
app->background = manifest["background"];
268-
std::cout << "loading app in the background" << std::endl;
269272
}
270273

271274
if(manifest["subdir"].is_string()) // todo, restrict only for subdirs

lib/applications/src/launcher.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void applications::launcher::draw() {
252252

253253
// Battery icon
254254
const auto batteryIconDarkPath = storage::Path("system/icons/dark/" + getBatteryIconFilename() + "_64px.png");
255-
batteryIcon = new Image(batteryIconDarkPath, 290, 2, 32, 32, COLOR_LIGHT);
255+
batteryIcon = new Image(batteryIconDarkPath, 290, 2, 32, 32);
256256
batteryIcon->load();
257257
launcherWindow->addChild(batteryIcon);
258258

lib/graphics/src/color.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "color.hpp"
77

8+
color_t COLOR_WHITE = 0xFFFF;
9+
810
color_t graphics::packRGB565(const uint8_t r, const uint8_t g, const uint8_t b)
911
{
1012
uint16_t rgb = 0;

lib/graphics/src/color.hpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,7 @@ namespace graphics {
5858
#define COLOR_WARNING 0xFE00
5959
#define COLOR_ERROR 0xD9A8
6060

61-
62-
// #define COLOR_WHITE 0xFFFF
63-
// #define COLOR_BLACK 0x0000
64-
// #define COLOR_GREY 0x8410
65-
66-
#define COLOR_WHITE graphics::constPackRGB565(255, 255, 255)
61+
extern color_t COLOR_WHITE;
6762
#define COLOR_BLACK graphics::constPackRGB565(0, 0, 0)
6863
#define COLOR_RED graphics::constPackRGB565(255, 0, 0)
6964
#define COLOR_GREEN graphics::constPackRGB565(0, 128, 0)

lib/gui/src/elements/Keyboard.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace gui::elements {
5858
m_x = 0;
5959
m_y = 0;
6060

61-
m_backgroundColor = COLOR_LIGHT;
61+
m_backgroundColor = COLOR_WHITE;
6262

6363
m_hasEvents = true;
6464

@@ -251,7 +251,7 @@ namespace gui::elements {
251251
void Keyboard::drawKeys() const {
252252
// Reset default settings
253253
m_keysCanvas->fillRect(0, 0, m_keysCanvas->getWidth(), m_keysCanvas->getHeight(),
254-
COLOR_LIGHT);
254+
COLOR_WHITE);
255255

256256
// Draw every keys
257257
drawKeyRow(0, 10, getLayoutCharMap()[0]);

lib/lua/src/lua_events.cpp

+3-16
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,9 @@ sol::table LuaTime::get(std::string format)
4545
result.push_back(format.substr(start));
4646

4747
std::vector<std::string> identifiers = {"s","mi","h","d","mo","y"};
48-
#ifdef ESP_PLATFORM
49-
std::vector<int> date = {GSM::seconds,GSM::minutes,GSM::hours,GSM::days,GSM::months,GSM::years};
50-
51-
#else
52-
time_t t = std::time(0); // get time now
53-
tm* local_time = std::localtime(&t);
54-
55-
uint16_t years = local_time->tm_year + 1900;
56-
uint16_t months = local_time->tm_mon + 1;
57-
uint16_t days = local_time->tm_mday;
58-
uint16_t hours = local_time->tm_hour;
59-
uint16_t minutes = local_time->tm_min;
60-
uint16_t seconds = local_time->tm_sec;
61-
62-
std::vector<int> date = {seconds,minutes,hours,days,months,years};
63-
#endif
48+
49+
std::vector<int> date = {GSM::seconds,GSM::minutes,GSM::hours,GSM::days,GSM::months,GSM::years};
50+
6451

6552
// ajouter les valeurs aux index des identifiers
6653

lib/lua/src/lua_file.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,8 @@ void LuaFile::load()
304304

305305
lua["require"] = [&](const std::string &filename) -> sol::object
306306
{
307-
storage::Path lib(filename);
308-
309307
// Load the file
310-
sol::load_result chunk = lua.load_file(this->lua_storage.convertPath(lib).str());
308+
sol::load_result chunk = lua.load_file(this->lua_storage.convertPath(filename).str());
311309
if (!chunk.valid())
312310
{
313311
sol::error err = chunk;
@@ -318,16 +316,6 @@ void LuaFile::load()
318316
return chunk();
319317
};
320318

321-
lua["saveTable"] = [&](const std::string &filename, const sol::table &table)
322-
{
323-
save_lua_table(lua, lua_storage.convertPath(filename).str(), table);
324-
};
325-
326-
lua["loadTable"] = [&](const std::string &filename)
327-
{
328-
return load_lua_table(lua, lua_storage.convertPath(filename).str());
329-
};
330-
331319
if (perms.acces_hardware) // si hardware est autorisé
332320
{
333321
lua.new_usertype<LuaHardware>("hardware",
@@ -381,6 +369,16 @@ void LuaFile::load()
381369

382370
lua["Json"] = json_ud;
383371

372+
lua["saveTable"] = [&](const std::string &filename, const sol::table &table)
373+
{
374+
save_lua_table(lua, lua_storage.convertPath(filename).str(), table);
375+
};
376+
377+
lua["loadTable"] = [&](const std::string &filename)
378+
{
379+
return load_lua_table(lua, lua_storage.convertPath(filename).str());
380+
};
381+
384382
lua["storage"] = &lua_storage;
385383
}
386384

@@ -732,6 +730,8 @@ void LuaFile::load()
732730

733731
app.set_function("launch", sol::overload([&](std::string name, std::vector<std::string> arg)
734732
{
733+
std::cout << "launch: " << name << std::endl;
734+
std::cout << "arg: " << arg[0] << std::endl;
735735
try{
736736
AppManager::get(name)->run(arg);
737737
}
@@ -745,6 +745,7 @@ void LuaFile::load()
745745
return true; },
746746
[&](std::string name)
747747
{
748+
std::cout << "launch: " << name << std::endl;
748749
try
749750
{
750751
AppManager::get(name)->run({});
@@ -810,7 +811,7 @@ void LuaFile::load()
810811
systemSettings.set_function("getBackgroundColor", &libsystem::paxoConfig::getBackgroundColor);
811812
systemSettings.set_function("getTextColor", &libsystem::paxoConfig::getTextColor);
812813
systemSettings.set_function("getBorderColor", &libsystem::paxoConfig::getBorderColor);
813-
systemSettings.set_function("setBackgroundColor", &libsystem::paxoConfig::setBackgroundColor);
814+
systemSettings.set_function("setBackgroundColor", [](int color) { libsystem::paxoConfig::setBackgroundColor(color_t(color), true); });
814815
systemSettings.set_function("setTextColor", &libsystem::paxoConfig::setTextColor);
815816
systemSettings.set_function("setBorderColor", &libsystem::paxoConfig::setBorderColor);
816817
}

lib/lua/src/lua_storage.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ bool LuaStorage::legalPath(storage::Path path)
6060
return true;
6161
}
6262

63-
storage::Path LuaStorage::convertPath(storage::Path path)
63+
storage::Path LuaStorage::convertPath(std::string path)
6464
{
65+
std::cout << "convertPath: " << path << std::endl;
6566
if (!legalPath(path))
66-
throw libsystem::exceptions::RuntimeError("The app is not allowed to access this path: " + path.str());
67+
throw libsystem::exceptions::RuntimeError("The app is not allowed to access this path: " + path);
6768

68-
std::cerr << this->lua->directory.str() << " " << path.m_steps[0] << std::endl;
69-
70-
if(path.m_steps[0]=="/")
69+
if(path[0] == '/') {
70+
std::cout << "Returning path: " << path << std::endl;
7171
return path;
72-
else
73-
return this->lua->directory / path;
72+
} else {
73+
storage::Path fullPath = this->lua->directory / path;
74+
std::cout << "Returning full path: " << this->lua->directory.str() << " + " << path << " = " << fullPath.str() << std::endl;
75+
return fullPath;
76+
}
7477
}
7578

7679
std::unique_ptr<LuaStorageFile> LuaStorage::file(std::string filename, int mode)

lib/lua/src/lua_storage.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LuaStorage
2424
std::vector<std::string> listDir(std::string path);
2525

2626
bool legalPath(storage::Path path);
27-
storage::Path convertPath(storage::Path);
27+
storage::Path convertPath(std::string path);
2828

2929
private:
3030
LuaFile* lua = nullptr;

lib/storage/path.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -179,29 +179,31 @@ namespace storage
179179

180180
void Path::simplify(void)
181181
{
182-
std::vector<std::string>::iterator it = m_steps.begin();
183-
184-
while (it != m_steps.end())
182+
std::vector<std::string> simplified_steps;
183+
for (const auto& step : m_steps)
185184
{
186-
if (*it == "..")
185+
if (step == "..")
187186
{
188-
if (it != m_steps.begin())
187+
if (!simplified_steps.empty() && simplified_steps.back() != "..")
189188
{
190-
m_steps.erase(it);
191-
it = m_steps.erase(it - 1);
189+
// Pop the last valid directory
190+
simplified_steps.pop_back();
192191
}
193192
else
194193
{
195-
++it;
194+
// If no valid directory to go up, keep the ".."
195+
simplified_steps.push_back(step);
196196
}
197197
}
198-
else
198+
else if (step != ".")
199199
{
200-
++it;
200+
simplified_steps.push_back(step);
201201
}
202202
}
203+
m_steps = std::move(simplified_steps);
203204
}
204205

206+
205207
void Path::parse(const std::string &raw)
206208
{
207209

lib/system/libsystem.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ color_t libsystem::paxoConfig::getBorderColor()
383383

384384
void libsystem::paxoConfig::setBackgroundColor(color_t color, bool save)
385385
{
386+
COLOR_WHITE = color;
387+
std::cout << COLOR_WHITE << std::endl;
386388
if (save)
387389
{
388390
systemConfig.set<uint16_t>("settings.color.background", static_cast<uint16_t>(color));

src/main.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ void mainLoop(void* data) {
127127
}
128128
}
129129

130+
if(libsystem::getDeviceMode() == libsystem::SLEEP && AppManager::isAnyVisibleApp())
131+
{
132+
setDeviceMode(libsystem::NORMAL);
133+
StandbyMode::disable();
134+
}
135+
130136
if(libsystem::getDeviceMode() != libsystem::SLEEP && StandbyMode::expired())
131137
{
132138
if(launcher)
@@ -143,13 +149,13 @@ void mainLoop(void* data) {
143149
}
144150

145151
#ifdef ESP_PLATFORM
146-
if(Serial.available())
152+
/*if(Serial.available())
147153
{
148154
std::cout << "Main loop" << std::endl;
149155
std::cout << "Launcher: " << launcher << std::endl;
150156
std::cout << "Visible app: " << AppManager::isAnyVisibleApp() << std::endl;
151157
std::cout << "Device mode: " << libsystem::getDeviceMode() << std::endl;
152-
}
158+
}*/
153159
#endif
154160

155161
StandbyMode::wait();
@@ -224,6 +230,13 @@ void setup()
224230
systemConfig.write();
225231
}
226232

233+
if (!systemConfig.has("settings.color.background")) {
234+
libsystem::paxoConfig::setBackgroundColor(0xFFFF, true);
235+
}else
236+
{
237+
COLOR_WHITE = static_cast<color_t>(systemConfig.get<uint16_t>("settings.color.background"));
238+
}
239+
227240
libsystem::log("settings.brightness: " + std::to_string(systemConfig.get<uint8_t>("settings.brightness")));
228241

229242
graphics::setBrightness(systemConfig.get<uint8_t>("settings.brightness"));

storage/apps/alarme/alarms.tab

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{[1]={["time"]="13:14", ["enabled"]=0, }, }

0 commit comments

Comments
 (0)