Skip to content

Commit

Permalink
Add battery temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Sep 1, 2020
1 parent e3b4463 commit 42dc1aa
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
40 changes: 24 additions & 16 deletions applications/oxide/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,15 @@ void Controller::killXochitl(){
system("systemctl stop xochtil");
}
}
int readInt(std::string path) {

int readInt(std::string path){
QFile file(path.c_str());
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
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;
return std::stoi(text);
}
void rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
Expand Down Expand Up @@ -306,11 +303,13 @@ void Controller::updateBatteryLevel() {
ui->setProperty("warning", warning);
}
}
auto temperature = readInt("/sys/class/power_supply/bq27441-0/temp") / 10;
if(batteryTemperature != temperature){
batteryTemperature = temperature;
if(ui){
ui->setProperty("temperature", temperature);
if(showBatteryTemperature()){
int temperature = readInt("/sys/class/power_supply/bq27441-0/temp") / 10;
if(batteryTemperature != temperature){
batteryTemperature = temperature;
if(ui){
ui->setProperty("temperature", temperature);
}
}
}
return;
Expand Down Expand Up @@ -361,11 +360,13 @@ void Controller::updateWifiState(){
ui->setProperty("link", link);
}
}
auto level = std::stoi(exec("cat /proc/net/wireless | grep wlan0 | awk '{print $4}'"));
if(wifiLevel != level){
wifiLevel = level;
if(ui){
ui->setProperty("level", level);
if(showWifiDb()){
auto level = std::stoi(exec("cat /proc/net/wireless | grep wlan0 | awk '{print $4}'"));
if(wifiLevel != level){
wifiLevel = level;
if(ui){
ui->setProperty("level", level);
}
}
}
}
Expand Down Expand Up @@ -416,6 +417,13 @@ void Controller::setShowBatteryPercent(bool state){
emit showBatteryPercentChanged(state);
}
}
void Controller::setShowBatteryTemperature(bool state){
m_showBatteryTemperature = state;
if(root != nullptr){
qDebug() << "Show Battery Temperature: " << state;
emit showBatteryTemperatureChanged(state);
}
}
void Controller::setSleepAfter(int sleepAfter){
m_sleepAfter= sleepAfter;
if(root != nullptr){
Expand Down
7 changes: 7 additions & 0 deletions applications/oxide/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ class Controller : public QObject
return m_showBatteryPercent;
};
void setShowBatteryPercent(bool);
Q_PROPERTY(bool showBatteryTemperature MEMBER m_showBatteryTemperature WRITE setShowBatteryTemperature NOTIFY showBatteryTemperatureChanged);
bool showBatteryTemperature() const {
return m_showBatteryTemperature;
};
void setShowBatteryTemperature(bool);
Q_PROPERTY(int sleepAfter MEMBER m_sleepAfter WRITE setSleepAfter NOTIFY sleepAfterChanged);
int sleepAfter() const {
return m_sleepAfter;
Expand All @@ -57,13 +62,15 @@ class Controller : public QObject
void fontSizeChanged(int);
void showWifiDbChanged(bool);
void showBatteryPercentChanged(bool);
void showBatteryTemperatureChanged(bool);
void sleepAfterChanged(int);
private:
bool m_automaticSleep = true;
int m_columns = 6;
int m_fontSize = 23;
bool m_showWifiDb = false;
bool m_showBatteryPercent = false;
bool m_showBatteryTemperature = false;
int m_sleepAfter = 5;

bool batteryAlert = false;
Expand Down
17 changes: 16 additions & 1 deletion applications/oxide/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ApplicationWindow {
}
return "qrc:/img/battery/" + icon + ".png";
}
text: controller.showBatteryPercent ? level + "%" : ""
text: (controller.showBatteryPercent ? level + "% " : "") + (controller.showBatteryTemperature ? temperature + "C" : "")
}
CustomMenu {
BetterMenu {
Expand Down Expand Up @@ -336,6 +336,21 @@ ApplicationWindow {
Layout.fillWidth: false
}
}
RowLayout {
Layout.columnSpan: parent.columns
Label {
text: "Show Battery Temperature"
Layout.columnSpan: parent.columns - 1
Layout.fillWidth: true
}
BetterCheckBox {
tristate: false
checkState: controller.showBatteryTemperature ? Qt.Checked : Qt.Unchecked
onClicked: controller.showBatteryTemperature = this.checkState === Qt.Checked
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
Layout.fillWidth: false
}
}
RowLayout {
Layout.columnSpan: parent.columns
Label {
Expand Down

0 comments on commit 42dc1aa

Please sign in to comment.