Commit 2cfa24ef authored by Radek Polak's avatar Radek Polak

gta04 charging - log to file /var/log/charging

parent 21fb98c6
......@@ -84,7 +84,7 @@ ac(QPowerSource::Wall, "PrimaryAC", this)
, battery(QPowerSource::Battery, "NeoBattery", this)
, batteryVso("/UI/Battery", this)
, vsoPortableHandsfree("/Hardware/Accessories/PortableHandsfree")
, chargeLog("/UI/Battery/charge_log")
, chargeLog("/var/log/charging")
, lastLogDt()
, ueventSocket(this)
, timer(this)
......@@ -172,6 +172,27 @@ static int getIntAttr(const char *name, QByteArray & uevent)
return str.toInt();
}
void NeoHardware::logCharge(QDateTime now, int chargeNow)
{
if (lastLogDt.secsTo(now) < 300)
return;
lastLogDt = now;
if (!chargeLog.exists())
return;
QString newEntry =
now.toString("yyyy-MM-dd hh:mm:ss") + "\t" +
QString::number(chargeNow) + "\n";
if (!chargeLog.open(QIODevice::WriteOnly | QIODevice::Append))
return;
chargeLog.write(newEntry.toLatin1().constData());
chargeLog.close();
}
void NeoHardware::updateStatus()
{
QDateTime now = QDateTime::currentDateTime();
......@@ -187,7 +208,7 @@ void NeoHardware::updateStatus()
ac.setAvailability(QPowerSource::NotAvailable);
battery.setCharging(chargerOn);
// Update battery status
QByteArray uevent =
qReadFile("/sys/class/power_supply/bq27000-battery/uevent");
......@@ -249,18 +270,7 @@ void NeoHardware::updateStatus()
oldChargeNow = chargeNow;
// Charging log
if (lastLogDt.secsTo(now) >= 300) {
lastLogDt = now;
QString newEntry =
now.toString("yyyy-MM-dd hh:mm:ss") + "\t" +
QString::number(chargeNow) + "\n";
QString logContent = chargeLog.value().toString();
if(logContent.length() >= 64000) {
int index = logContent.indexOf('\n', 32000);
logContent = logContent.mid(index + 1);
}
batteryVso.setAttribute("charge_log", logContent + newEntry);
}
logCharge(now, chargeNow);
}
#define UEVENT_BUFFER_SIZE 1024
......@@ -281,8 +291,8 @@ void NeoHardware::uevent()
void NeoHardware::shutdownRequested()
{
qLog(PowerManagement) << __PRETTY_FUNCTION__;
QtopiaServerApplication::instance()->shutdown(QtopiaServerApplication::
ShutdownSystem);
QtopiaServerApplication::instance()->
shutdown(QtopiaServerApplication::ShutdownSystem);
}
void NeoHardware::headphonesInserted(bool b)
......
......@@ -21,6 +21,7 @@
#ifndef NEOHARDWARE_H
#define NEOHARDWARE_H
#include <QFile>
#include <QTimer>
#include <QObject>
#include <QProcess>
......@@ -62,7 +63,7 @@ private:
QPowerSourceProvider battery;
QValueSpaceObject batteryVso;
QValueSpaceObject vsoPortableHandsfree;
QValueSpaceItem chargeLog; // power supply log
QFile chargeLog; // power supply log
QDateTime lastLogDt;
QTcpSocket ueventSocket;
QTimer timer;
......@@ -73,6 +74,7 @@ private:
QtopiaIpcAdaptor *adaptor;
QtopiaIpcAdaptor *audioMgr;
void setMaxChargeCurrent(int newValue);
void logCharge(QDateTime now, int chargeNow);
private slots:
void headphonesInserted(bool);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment