harbour-batterybuddy/application/src/battery.h

107 lines
3.2 KiB
C
Raw Normal View History

/**
* Battery Buddy, a Sailfish application to prolong battery lifetime
*
2020-04-26 19:01:20 +03:00
* Copyright (C) 2019-2020 Matti Viljanen
*
* Battery Buddy is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Battery Buddy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details. You should have received a copy of the GNU
2020-03-24 11:02:30 +03:00
* General Public License along with Battery Buddy. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Matti Viljanen
*/
2020-03-21 04:27:09 +03:00
#ifndef BATTERY_H
#define BATTERY_H
#include <QObject>
2019-01-05 18:14:00 +03:00
#include <QString>
#include <QFile>
2020-03-21 13:32:50 +03:00
#include <QStandardPaths>
#include <QHostInfo>
2020-03-20 21:58:01 +03:00
#include "settings.h"
2020-06-12 01:04:11 +03:00
#include "process.h"
2021-04-17 22:01:19 +03:00
#include "logger.h"
2019-01-05 18:14:00 +03:00
class Battery : public QObject
{
Q_OBJECT
Q_PROPERTY(int charge READ getCharge NOTIFY chargeChanged)
2020-11-15 23:28:00 +03:00
Q_PROPERTY(int current READ getCurrent NOTIFY currentChanged)
Q_PROPERTY(bool chargerConnected READ getChargerConnected NOTIFY chargerConnectedChanged)
Q_PROPERTY(QString state READ getState NOTIFY stateChanged)
2021-04-26 17:13:49 +03:00
Q_PROPERTY(bool chargingEnabled READ getChargingEnabled NOTIFY chargingEnabledChanged)
2019-01-05 18:14:00 +03:00
2021-05-02 11:23:32 +03:00
Q_PROPERTY(QString health READ getHealth NOTIFY healthChanged)
Q_PROPERTY(int temperature READ getTemperature NOTIFY temperatureChanged)
2019-01-05 18:14:00 +03:00
public:
2021-04-17 22:01:19 +03:00
Battery(Settings* newSettings, Logger* newLogger, QObject* parent = nullptr);
2019-01-05 18:14:00 +03:00
~Battery();
int getCharge();
2020-11-15 23:28:00 +03:00
int getCurrent();
2019-01-05 18:14:00 +03:00
bool getCharging();
bool getChargerConnected();
QString getState();
2019-01-05 18:14:00 +03:00
2021-05-02 11:23:32 +03:00
QString getHealth();
int getTemperature();
bool getChargingEnabled();
2019-01-05 22:57:35 +03:00
public slots:
2019-01-05 18:14:00 +03:00
void updateData();
2019-01-05 22:57:35 +03:00
private:
2020-04-26 18:20:54 +03:00
QFile* chargeFile = nullptr;
2020-11-15 23:28:00 +03:00
QFile* currentFile = nullptr;
2020-04-26 18:20:54 +03:00
QFile* chargerConnectedFile = nullptr;
QFile* stateFile = nullptr;
QFile* chargingEnabledFile = nullptr;
Settings* settings = nullptr;
2021-04-17 22:01:19 +03:00
Logger* logger = nullptr;
2019-01-05 18:14:00 +03:00
2021-05-02 11:23:32 +03:00
QFile* temperatureFile = nullptr;
QFile* healthFile = nullptr;
// Default values:
int charge = 100; // 100% full
2020-11-15 23:28:00 +03:00
int current = 0; // Not charging/discharging
bool chargerConnected = false; // Charger plugged in
QString state = "idle"; // dis/charging, idle, unknown
bool chargingEnabled = true; // Only ever disabled manually
2021-05-02 11:23:32 +03:00
QString health = "Good"; // Good, Warm, Overheat. Might have Cold or Overvoltage depending on driver
int temperature = 0; // freezing
int enableChargingValue = 1;
int disableChargingValue = 0;
2020-03-20 21:58:01 +03:00
bool chargerIsEnabled = true;
2019-01-05 18:14:00 +03:00
int nextCharge = charge;
2020-11-15 23:28:00 +03:00
int nextCurrent = current;
bool nextChargerConnected = chargerConnected;
QString nextState = state;
bool nextChargingEnabled = chargingEnabled;
2019-01-05 18:14:00 +03:00
2021-05-02 11:23:32 +03:00
QString nextHealth = health;
int nextTemperature = temperature;
2019-01-05 18:14:00 +03:00
signals:
2020-03-28 11:11:23 +03:00
void chargeChanged(int);
2020-11-15 23:28:00 +03:00
void currentChanged(int);
2020-03-28 11:11:23 +03:00
void stateChanged(QString);
void chargingEnabledChanged(bool);
void chargerConnectedChanged(bool);
2021-05-02 11:23:32 +03:00
void healthChanged(QString);
void temperatureChanged(int);
2019-01-05 18:14:00 +03:00
};
#endif // BATTERY_H