Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added extra-files/draft/icons/batteryIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 68 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
#include <QtQuick>
#include <stdio.h>
#include <cstdlib>
//#include <QtGui>
//#include <QtPlugin>
#include <QTimer>
#include <QDebug>
#include "mainview.h"
#include "options.h"
#include "handler.h"

Q_IMPORT_PLUGIN(QsgEpaperPlugin)

MainView *VIEW;
int _qSize = 1404;


int readInt(std::string path) {

QFile file(path.c_str());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Couldn't find the file " << path.c_str();
return 0;
}
QTextStream in(&file);
std::string text = in.readLine().toStdString();
int number = std::stoi(text);

return number;
}


std::string getBatteryLevel() {
int charge_now = readInt(
"/sys/class/power_supply/bq27441-0/charge_now"
);
int charge_full = readInt(
"/sys/class/power_supply/bq27441-0/charge_full_design"
);

int battery_level = 100;
if (charge_now < charge_full) {
battery_level = (charge_now * 100/ charge_full);
}
qDebug() << "Got battery level " << battery_level;
return std::to_string(battery_level) + "%";
}


void setBatteryLevel() {
std::string battery_level = getBatteryLevel();
QQuickItem* root = VIEW->rootObject();
root->setProperty(
"battery_level",
QVariant(getBatteryLevel().c_str())
);
}


int main(int argc, char *argv[])
{
qputenv("QMLSCENE_DEVICE", "epaper");
Expand All @@ -15,18 +65,32 @@ int main(int argc, char *argv[])

system("/usr/bin/button-capture &");

QGuiApplication app(argc, argv);
MainView view;

srand(time(NULL));
QGuiApplication app(argc, argv);
MainView view;
VIEW = &view;

view.rootContext()->setContextProperty("screenGeometry", app.primaryScreen()->geometry());
view.engine()->addImportPath(QStringLiteral(DEPLOYMENT_PATH));
view.setSource(QDir(DEPLOYMENT_PATH).filePath("qml/Main.qml"));

Options options(&view, &app);
Options options(VIEW, &app);

view.show();
QQuickItem* root = view.rootObject();
root->setProperty("battery_icon",QVariant(("file://"+configDir+"/icons/batteryIcon.png").c_str()));
setBatteryLevel();

QTimer *timer = new QTimer();
timer->connect(
timer,
&QTimer::timeout,
VIEW,
QOverload<>::of(setBatteryLevel)
);
// update the battery level every 10min
timer->start(5000);

view.show();
return app.exec();
}
2 changes: 2 additions & 0 deletions options.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <QGuiApplication>
#include "mainview.h"

const extern std::string configDir;

struct OptionItem {
std::string name;
std::string desc;
Expand Down
44 changes: 44 additions & 0 deletions qml/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import QtQuick 2.0
import "../js/Main.js" as MainJS

Rectangle {
property alias battery_level : batteryLevel.text
property alias battery_icon : batteryIcon.source

id: canvas
width: 1404
height: 1872
Expand Down Expand Up @@ -37,6 +40,41 @@ Rectangle {
font.italic:true
}

Image {
x: 19
y: 1837
id: batteryIcon
fillMode: Image.PreserveAspectFit
height: 10
width: 50
anchors.rightMargin: 1335
anchors.bottomMargin: 5
anchors.topMargin: 1841
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom:parent.bottom
anchors.margins:15
source: "../extra-files/draft/icons/batteryIcon.png"
}

Text {
id: batteryLevel
x: 75
y: 1828
width: 428
height: 36
text: "Unable to read battery level"
anchors.rightMargin: 901
anchors.bottomMargin: 8
font.family: "Noto Serif"
anchors.bottom: parent.bottom
font.pixelSize: 30
font.italic: true
anchors.margins: {bottom:10}
anchors.right: parent.right
}


Text {
id: optionsHeading
anchors.left:parent.left
Expand Down Expand Up @@ -84,3 +122,9 @@ Rectangle {
}

}

/*##^##
Designer {
D{i:0;formeditorZoom:0.8999999761581421}
}
##^##*/