Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
gta04 - display current_now on the main screen
  • Loading branch information
radekp committed Jul 24, 2012
1 parent 8ee36f5 commit d4dd894
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions devices/gta04/server/neohardware.cpp
Expand Up @@ -95,6 +95,7 @@ NeoHardware::NeoHardware()
:
ac(QPowerSource::Wall, "PrimaryAC", this)
, battery(QPowerSource::Battery, "NeoBattery", this)
, batteryVso("/UI/Battery", this)
, ueventSocket(this)
, timer(this)
{
Expand Down Expand Up @@ -146,6 +147,11 @@ void NeoHardware::updateStatus()
("/sys/class/power_supply/bq27000-battery/time_to_empty_now");
battery.setTimeRemaining(time.toInt() / 60);
}

QString currentNowStr =
readFile("/sys/class/power_supply/bq27000-battery/current_now");
int currentNow = currentNowStr.toInt() / 1000;
batteryVso.setAttribute("current_now", QString::number(currentNow));
}

#define UEVENT_BUFFER_SIZE 1024
Expand Down
1 change: 1 addition & 0 deletions devices/gta04/server/neohardware.h
Expand Up @@ -48,6 +48,7 @@ class NeoHardware : public QObject
private:
QPowerSourceProvider ac;
QPowerSourceProvider battery;
QValueSpaceObject batteryVso;
QTcpSocket ueventSocket;
QTimer timer;
bool hasSmartBattery;
Expand Down
21 changes: 21 additions & 0 deletions devices/gta04/server/neosuspend.cpp
Expand Up @@ -48,6 +48,7 @@ class NeoSuspend : public SystemSuspendHandler
virtual bool wake();
private:
QProcess resumeScript;
QValueSpaceObject batteryVso;
QDateTime suspendTime;
};

Expand All @@ -56,6 +57,7 @@ QTOPIA_TASK_PROVIDES(NeoSuspend, SystemSuspendHandler);

NeoSuspend::NeoSuspend()
: resumeScript(this)
, batteryVso("/UI/Battery", this)
{
}

Expand Down Expand Up @@ -106,8 +108,27 @@ static void writeFile(const char * path, const char * content)
f.close();
}

static QByteArray readFile(const char *path)
{
QFile f(path);
if (!f.open(QIODevice::ReadOnly)) {
qLog(PowerManagement) << "file open failed" << path << ":" <<
f.errorString();
return QByteArray();
}
QByteArray content = f.readAll();
f.close();
return content;
}

bool NeoSuspend::wake()
{
// Read and update current_now. It should contain the current in suspend
QString currentNowStr =
readFile("/sys/class/power_supply/bq27000-battery/current_now");
int currentNow = currentNowStr.toInt() / 1000;
batteryVso.setAttribute("current_now_in_suspend", QString::number(currentNow));

// Check if resume was too fast. If yes, it might be GPS which wakes the
// device up and prevents suspend. As a workaround we try to turn the gps
// off. For more info see:
Expand Down
7 changes: 5 additions & 2 deletions etc/themes/finxi/home.xml
Expand Up @@ -11,8 +11,11 @@
<text name="profile" size="5" bold="yes" rect="50%,0,48%x12pt" align="right,vcenter" color="#ffffff" outline="#000000" transient="yes" active="expr:@/UI/HomeScreen/ShowProfile &amp;&amp; !@/UI/Profile/Default">
expr:@/UI/Profile/Name . " "
</text>
<text name="pressure" size="5" bold="yes" rect="2%,0,48%x12pt" align="left,vcenter" color="#ffffff" outline="#000000" transient="yes" active="expr:@/UI/HomeScreen/ShowPressure">
expr:@/UI/Pressure/mb . "mb"
<text name="pressure" size="5" bold="yes" rect="2%,0,48%x12pt" align="right,vcenter" color="#ffffff" outline="#000000" transient="yes" active="expr:@/UI/HomeScreen/ShowPressure">
expr:@/UI/Pressure/mb . "mb "
</text>
<text name="current_now" size="5" bold="yes" rect="2%,0,48%x12pt" align="left,vcenter" color="#ffffff" outline="#000000" transient="yes" >
expr:@/UI/Battery/current_now . "/". @/UI/Battery/current_now_in_suspend . "mA"
</text>
</rect>
<layout rect="0,20%,0x45pt" align="hcenter">
Expand Down

0 comments on commit d4dd894

Please sign in to comment.