Skip to content

Commit 0b47f63

Browse files
committed
Multiple settings changed to make the system more stable, less spontanious crashes, reduced stack usage, changed the keyboard in asynchronious, added a read function in storage
1 parent 7174a53 commit 0b47f63

File tree

13 files changed

+126
-32
lines changed

13 files changed

+126
-32
lines changed

lib/applications/src/app.cpp

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

33
#include <libsystem.hpp>
44
#include <standby.hpp>
5+
#include <graphics.hpp>
56

67
namespace AppManager {
78
App::App(const std::string& name, const storage::Path& path, const storage::Path& manifest, const bool auth)
@@ -315,8 +316,12 @@ namespace AppManager {
315316
if (!appStack.empty()) {
316317
App* app = appStack.back();
317318

318-
if (app->luaInstance != nullptr) {
319-
app->luaInstance->lua_gui.update();
319+
if (app->luaInstance != nullptr)
320+
{
321+
if(app == Keyboard_manager::app)
322+
Keyboard_manager::update();
323+
else
324+
app->luaInstance->lua_gui.update();
320325
}
321326

322327
if(app->luaInstance->lua_gui.mainWindow == nullptr) // app has no GUI
@@ -466,4 +471,45 @@ namespace AppManager {
466471
}
467472
threadsync.unlock();
468473
}
474+
475+
namespace Keyboard_manager
476+
{
477+
App* app = nullptr;
478+
std::function<void(std::string)> callback;
479+
std::unique_ptr<Keyboard> keyboard;
480+
481+
void open(App* app, const std::string &placeholder, const std::string &defaultText, std::function<void(std::string)> callback) {
482+
graphics::setScreenOrientation(graphics::LANDSCAPE);
483+
Keyboard_manager::app = app;
484+
Keyboard_manager::callback = callback;
485+
keyboard = std::make_unique<Keyboard>(defaultText);
486+
keyboard->setPlaceholder(placeholder);
487+
}
488+
489+
void update()
490+
{
491+
if(keyboard != nullptr)
492+
{
493+
keyboard->updateAll();
494+
495+
if(keyboard->quitting() || hardware::getHomeButton())
496+
{
497+
close();
498+
}
499+
}
500+
}
501+
502+
void close()
503+
{
504+
std::string result = keyboard->getText();
505+
keyboard.reset();
506+
Keyboard_manager::app = nullptr;
507+
graphics::setScreenOrientation(graphics::PORTRAIT);
508+
509+
if(callback)
510+
{
511+
callback(result);
512+
}
513+
}
514+
}
469515
} // namespace AppManager

lib/applications/src/app.hpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,21 @@ namespace AppManager
101101
bool background; // app is in background
102102
};
103103

104-
// TODO : Check if "extern" is needed
105-
106104
extern std::mutex threadsync; // mutex for thread-safe operations between threads
107105

108106
extern std::vector<std::shared_ptr<App>> appList; // list of apps in the apps folder
109107
extern std::vector<App*> appStack; // stack of the apps that are using the GUI, the last one is shown on the screen
108+
109+
// keyboard management
110+
namespace Keyboard_manager
111+
{
112+
void open(App* app, const std::string &placeholder, const std::string &defaultText, std::function<void(std::string)> callback);
113+
void update();
114+
void close();
115+
extern App* app;
116+
extern std::function<void(std::string)> callback;
117+
extern std::unique_ptr<Keyboard> keyboard;
118+
};
110119

111120
int pushError(lua_State* L, sol::optional<const std::exception&> maybe_exception, sol::string_view description);
112121
void addPermission(App* app);

lib/lua/src/lua_file.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ void LuaFile::load()
402402
"del", &LuaGui::del,
403403
"setWindow", &LuaGui::setMainWindow,
404404
"getWindow", &LuaGui::getMainWindow,
405-
"keyboard", &LuaGui::keyboard,
405+
"keyboard_old", &LuaGui::keyboard,
406+
"keyboard", &LuaGui::keyboard_async,
406407
"slider", &LuaGui::slider,
407408
"showInfoMessage", &LuaGui::showInfoMessage,
408409
"showWarningMessage", &LuaGui::showWarningMessage,

lib/lua/src/lua_gui.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <threads.hpp>
55
#include "lua_file.hpp"
66
#include "app.hpp"
7+
#include "libsystem.hpp"
78

89
LuaGui::LuaGui(LuaFile *lua)
910
{
@@ -183,6 +184,7 @@ void LuaGui::update()
183184

184185
std::string LuaGui::keyboard(const std::string &placeholder, const std::string &defaultText)
185186
{
187+
libsystem::log("[WARNING]: Keyboard is deprecated. Use keyboard_async instead.");
186188
graphics::setScreenOrientation(graphics::LANDSCAPE);
187189

188190
auto key = new Keyboard(defaultText);
@@ -202,6 +204,12 @@ std::string LuaGui::keyboard(const std::string &placeholder, const std::string &
202204
return o;
203205
}
204206

207+
void LuaGui::keyboard_async(const std::string &placeholder, const std::string &defaultText, sol::function callback)
208+
{
209+
printf("Calling keyboard_async\n");
210+
AppManager::Keyboard_manager::open(this->lua->app, placeholder, defaultText, callback);
211+
}
212+
205213
void LuaGui::setMainWindow(LuaWindow *window)
206214
{
207215
this->mainWindow = window;

lib/lua/src/lua_gui.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class LuaGui
3535
LuaRadio *radio(LuaWidget *parent, int x, int y);
3636
LuaWindow *window();
3737
LuaSlider *slider(LuaWidget *parent, int x, int y, int width, int height, int minValue, int maxValue, int defaultValue);
38-
std::string keyboard(const std::string &placeholder, const std::string &defaultText);
38+
std::string keyboard(const std::string &placeholder, const std::string &defaultText); // deprecated
39+
void keyboard_async(const std::string &placeholder, const std::string &defaultText, sol::function callback);
3940

4041
void del(LuaWidget *widget);
4142

lib/tasks/src/standby.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ namespace StandbyMode
6666
{
6767
if(powerMode == true)
6868
{
69-
savePower();
69+
//savePower();
7070
}
7171
}
7272
}

lib/tasks/src/threads.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
void ThreadManager::init()
2626
{
27-
new_thread(CORE_BACK, &ThreadManager::simcom_thread, 32*1024);
27+
new_thread(CORE_BACK, &ThreadManager::simcom_thread, 16*1024);
2828
new_thread(CORE_BACK, &ThreadManager::background_thread, 8*1024);
2929
}
3030

@@ -35,7 +35,7 @@ void ThreadManager::new_thread(bool core, void(*func)(void*), int stackSize)
3535
"thread",
3636
stackSize,
3737
nullptr,
38-
0,
38+
core,
3939
nullptr);
4040
#else
4141
std::thread myThread(func, nullptr);

src/main.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <Arduino.h>
1212

13-
SET_LOOP_TASK_STACK_SIZE(10 * 1024);
13+
SET_LOOP_TASK_STACK_SIZE(8 * 1024);
1414

1515
#endif
1616

@@ -168,7 +168,7 @@ void mainLoop(void* data) {
168168
}
169169
}
170170

171-
void setup()
171+
void init(void* data)
172172
{
173173
/**
174174
* Initialisation du hardware, de l'écran, lecture des applications stcokées dans storage
@@ -295,7 +295,7 @@ void setup()
295295
};
296296

297297
#ifdef ESP_PLATFORM
298-
ThreadManager::new_thread(CORE_BACK, &hardware::vibrator::thread, 16000);
298+
ThreadManager::new_thread(CORE_BACK, &hardware::vibrator::thread, 2*1024);
299299
#endif
300300

301301
// gestion de la détection du toucher de l'écran
@@ -309,16 +309,20 @@ void setup()
309309

310310
// Chargement des contacts
311311
std::cout << "[Main] Loading Contacts" << std::endl;
312-
Contacts::load();
313-
314-
std::vector<Contacts::contact> cc = Contacts::listContacts();
312+
eventHandlerApp.setTimeout(new Callback<>([](){Contacts::load();}), 0);
315313

316314
AppManager::init();
317315

318316
hardware::vibrator::play({1, 1, 0, 0, 1, 0, 1});
319317
mainLoop(NULL);
320318
}
321319

320+
void setup()
321+
{
322+
init();
323+
//ThreadManager::new_thread(CORE_APP, &init, 8*1024);
324+
}
325+
322326
void loop(){}
323327

324328
#ifndef ESP_PLATFORM

storage/apps/alarme/alarms.tab

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{[1]={["time"]="15:36", ["enabled"]=0, }, [2]={["time"]="19:05", ["enabled"]=0, }, }
1+
<<<<<<< HEAD
2+
{[1]={["time"]="15:36", ["enabled"]=0, }, [2]={["time"]="19:05", ["enabled"]=0, }, }
3+
=======
4+
{[1]={["time"]="19:50", ["enabled"]=0, }, [2]={["enabled"]=1, ["time"]="00:10", }, }
5+
>>>>>>> d9f4ab7 (Multiple settings changed to make the system more stable, less spontanious crashes, reduced stack usage, changed the keyboard in asynchronious, added a read function in storage)

storage/apps/calendrier/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"defaultView":"week", "displayBusinessWeek":true, "displayWeekNum":true, "day":{"heureDebut":6, "heureFin":18}}
1+
{"defaultView":"week", "displayBusinessWeek":true, "day":{"heureDebut":6, "heureFin":18}, "displayWeekNum":true}

storage/apps/contacts/app.lua

+12-2
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,22 @@ function editContact(contact)
6161
local name = gui:input(win3, 35, 121, 250, 40)
6262
name:setTitle("Nom")
6363
name:setText(contact.name)
64-
name:onClick(function () name:setText(gui:keyboard("Nom", contact.name)) end)
64+
name:onClick(function ()
65+
gui:keyboard("Nom", name:getText(),
66+
function (n)
67+
name:setText(n)
68+
end)
69+
end)
6570

6671
local num = gui:input(win3, 35, 216, 250, 40)
6772
num:setTitle("Numéro")
6873
num:setText(contact.phone)
69-
num:onClick(function () num:setText(gui:keyboard("Numéro", contact.phone)) end)
74+
num:onClick(function ()
75+
gui:keyboard("Nom", num:getText(),
76+
function (number)
77+
num:setText(number)
78+
end)
79+
end)
7080

7181
edit = gui:button(win3, 35, 394, 250, 38);
7282
edit:setText("Modifier")

storage/apps/contacts/list.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"name":"Anna Smith","phone":"123-456-7890"},{"name":"Michael Johnson","phone":"0612345678"},{"name":"Emily Davis","phone":"0612345678"},{"name":"David Wilson","phone":"0612345678"},{"name":"Sarah Thompson","phone":"0612345678"},{"name":"Daniel Anderson","phone":"0612345678"},{"name":"Jacob Thompson","phone":"0612345678"},{"name":"Olivia Taylor","phone":"0612345678"}]
1+
[{"name":"Anna","phone":"123-456-789"},{"name":"Michael Johnson","phone":"0612345678"},{"name":"Emily Davis","phone":"0612345678"},{"name":"David Wilson","phone":"0612345678"},{"name":"Sarah Thompson","phone":"0612345678"},{"name":"Daniel Anderson","phone":"0612345678"},{"name":"Jacob Thompson","phone":"0612345678"},{"name":"Olivia","phone":"0612345678"}]

storage/apps/messages/app.lua

+23-12
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ function openImage(path)
2626
gui:setWindow(win3)
2727
end
2828

29-
function newMessage(number)
30-
local msg = gui:keyboard("Message au " .. number, "")
31-
32-
if(msg ~= "") then
33-
gsm.newMessage(number, msg)
29+
function newMessage(number, callback)
30+
gui:keyboard("Message au " .. number, "",
31+
function (msg)
32+
if(msg ~= "") then
33+
gsm.newMessage(number, msg)
34+
callback()
35+
end
36+
37+
end)
3438
end
35-
36-
return msg
37-
end
38-
39-
function appendMessage(msg, list)
40-
local bull2 = gui:box(list, 0, 0, 184, 30)
4139

42-
label_sent = gui:label(bull2, 0, 0, 184, 0)
40+
function appendMessage(msg, list)
41+
local bull2 = gui:box(list, 0, 0, 184, 30)
42+
43+
label_sent = gui:label(bull2, 0, 0, 184, 0)
4344
label_sent:setHorizontalAlignment(CENTER_ALIGNMENT)
4445
label_sent:setText(msg)
4546
label_sent:setFontSize(18)
@@ -135,12 +136,22 @@ function converation(number)
135136

136137
add:onClick(function ()
137138
-- print("add button clicked")
139+
<<<<<<< HEAD
138140
local msg = newMessage(number)
139141

140142
if(msg ~= "") then
141143
-- print("new message received: " .. msg)
142144
appendMessage(msg, list)
143145
end
146+
=======
147+
local msg = newMessage(number,
148+
function ()
149+
if(msg ~= "") then
150+
-- print("new message received: " .. msg)
151+
appendMessage(msg, list)
152+
end
153+
end)
154+
>>>>>>> d9f4ab7 (Multiple settings changed to make the system more stable, less spontanious crashes, reduced stack usage, changed the keyboard in asynchronious, added a read function in storage)
144155
end)
145156

146157
local back = gui:image(win2, "back.png", 30, 30, 18, 18)

0 commit comments

Comments
 (0)