Skip to content

Commit

Permalink
Merge pull request #69 from paxo-phone/gabriel_dev
Browse files Browse the repository at this point in the history
  Ajout de l'affichage de la batterie sur le launcher ainsi que de l'ajout du scrool
  • Loading branch information
paxo-rch authored May 21, 2024
2 parents d29c64e + 5f966bd commit 8a6fce9
Show file tree
Hide file tree
Showing 40 changed files with 586 additions and 137 deletions.
21 changes: 17 additions & 4 deletions lib/applications/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace app
std::vector<App> appList;

bool request;
App requestingApp;
AppRequest requestingApp;

void init()
{
Expand All @@ -29,6 +29,19 @@ namespace app
}
}

App getApp(std::string appName)
{
for (auto &app : appList)
{
if(app.name == appName)
{
return app;
}
}

return {"", storage::Path(), storage::Path(), false};
}

bool askPerm(App &app)
{
gui::elements::Window win;
Expand Down Expand Up @@ -95,9 +108,9 @@ namespace app
std::cout << "Error: no such app" << std::endl;
}

void runApp(App app)
void runApp(AppRequest app)
{
LuaFile luaApp(app.path, app.manifest);
luaApp.run();
LuaFile luaApp(app.app.path, app.app.manifest);
luaApp.run(app.parameters);
}
};
11 changes: 9 additions & 2 deletions lib/applications/src/app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ namespace app
bool auth;
};

struct AppRequest
{
App app;
std::vector<std::string> parameters;
};

extern std::vector<App> appList;

extern bool request;
extern App requestingApp;
extern AppRequest requestingApp;

void init();
App getApp(std::string appName);
bool askPerm(App &app);
void runApp(storage::Path path);
void runApp(App app);
void runApp(AppRequest app);
};

#include <launcher.hpp>
Expand Down
10 changes: 9 additions & 1 deletion lib/applications/src/launcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ int launcher()
date->setFontSize(16);
win.addChild(date);

Label *batt = new Label(269, 10, 40, 18);
batt->setText(std::to_string(GSM::getBatteryLevel())); // hour
batt->setVerticalAlignment(Label::Alignement::CENTER);
batt->setHorizontalAlignment(Label::Alignement::CENTER);
batt->setFontSize(18);
win.addChild(batt);

uint32_t evid = eventHandlerApp.setInterval(
new Callback<>([&hour, &date]() {
static int min;
Expand Down Expand Up @@ -85,9 +92,10 @@ int launcher()
if (app::request)
{
app::request = false;
app::runApp(app::requestingApp);
app::runApp({app::requestingApp.app});
}

eventHandlerApp.update();
win.updateAll();
}

Expand Down
10 changes: 10 additions & 0 deletions lib/graphics/src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ void graphics::showSurface(const Surface* surface, int x, int y)
#endif
}

void graphics::setWindow(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
lcd.get()->setWindow(x, y, width, height);
}

void graphics::setWindow()
{
lcd.get()->setWindow(0, 0, getScreenWidth(), getScreenHeight());
}

void graphics::flip()
{
// lcd->display();
Expand Down
2 changes: 2 additions & 0 deletions lib/graphics/src/graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ namespace graphics
bool isRunning();

void showSurface(const Surface *surface, int x = 0, int y = 0);
void setWindow(uint16_t x, uint16_t y, uint16_t width, uint16_t height);
void setWindow();

void flip();

Expand Down
2 changes: 1 addition & 1 deletion lib/gsm/src/contacts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Contacts

std::string file = json.dump();

storage::FileStream stream((Path(CONTACTS_LOCATION) / "list.json").str(), storage::Mode::WRITE, true);
storage::FileStream stream((Path(CONTACTS_LOCATION) / "list.json").str(), storage::Mode::WRITE);
stream.write(file);
stream.close();
}
Expand Down
60 changes: 55 additions & 5 deletions lib/gsm/src/gsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace GSM
std::vector<Message> messages;
State state;
uint16_t seconds, minutes, hours, days, months, years = 0;
float voltage = 0;

namespace ExternalEvents
{
Expand Down Expand Up @@ -321,28 +322,75 @@ namespace GSM
endCall();
}

float getVoltage()
void getVoltage()
{
std::string answer = send("AT+CBC", "OK");

int start = answer.find("+CBC: ") + 6;
int end = answer.find("V", start);

if(start == std::string::npos || end == std::string::npos)
return 0;
if(start == std::string::npos || end == std::string::npos) // maybe wrong
return;

std::string voltage_str = answer.substr(start, end - start);

try
{
return std::stof(voltage_str);
voltage = std::stof(voltage_str);
}
catch (std::exception)
{
return 0;
return;
}
}

int getBatteryLevel()
{
if(voltage>4.12)
return 100;
else if(voltage>4.03)
return 95;
else if(voltage>3.99)
return 90;
else if(voltage>3.94)
return 85;
else if(voltage>3.90)
return 80;
else if(voltage>3.86)
return 75;
else if(voltage>3.82)
return 70;
else if(voltage>3.77)
return 65;
else if(voltage>3.74)
return 60;
else if(voltage>3.70)
return 55;
else if(voltage>3.66)
return 50;
else if(voltage>3.64)
return 45;
else if(voltage>3.63)
return 40;
else if(voltage>3.62)
return 35;
else if(voltage>3.59)
return 30;
else if(voltage>3.58)
return 25;
else if(voltage>3.57)
return 20;
else if(voltage>3.55)
return 15;
else if(voltage>3.52)
return 10;
else if(voltage>3.5)
return 5;
else
return 0;

}

void updateHour()
{
std::string data = send("AT+CCLK?", "+CCLK:");
Expand Down Expand Up @@ -399,6 +447,8 @@ namespace GSM
updateHour();

eventHandlerBack.setInterval(new Callback<>(&GSM::getHour), 5000);
eventHandlerBack.setInterval(new Callback<>([](){ requests.push_back({&GSM::getVoltage, GSM::priority::normal}); }), 5000);

//eventHandlerBack.setInterval(new Callback<>([](){if(send("AT", "AT").find("OK") == std::string::npos) init(); }), 15000);

keys.push_back({"RING", &GSM::onRinging});
Expand Down
3 changes: 2 additions & 1 deletion lib/gsm/src/gsm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace GSM
extern std::vector<Message> pendingMessages; // messages pending
extern State state;
extern uint16_t seconds, minutes, hours, days, months, years;
extern float voltage;

void init();
void reInit();
Expand All @@ -91,7 +92,7 @@ namespace GSM
void endCall();
void acceptCall();
void rejectCall();
float getVoltage();
int getBatteryLevel();
void getHour();
};

Expand Down
Loading

0 comments on commit 8a6fce9

Please sign in to comment.