r270 - trunk/software/py-odeviced/odeviced/modules

smartphones-commits at lists.linuxtogo.org smartphones-commits at lists.linuxtogo.org
Mon Apr 28 17:05:12 CEST 2008


Author: mickeylauer
Date: 2008-04-28 17:05:11 +0200 (Mon, 28 Apr 2008)
New Revision: 270

Modified:
   trunk/software/py-odeviced/odeviced/modules/kernel26.py
Log:
odeviced: add PowerClassAPM as fallback, since the power class device is pretty new (kernel >= 2.6.24)


Modified: trunk/software/py-odeviced/odeviced/modules/kernel26.py
===================================================================
--- trunk/software/py-odeviced/odeviced/modules/kernel26.py	2008-04-28 13:43:23 UTC (rev 269)
+++ trunk/software/py-odeviced/odeviced/modules/kernel26.py	2008-04-28 15:05:11 UTC (rev 270)
@@ -146,6 +146,44 @@
             return 100 * int(energy_now) / int(energy_full)
 
 #----------------------------------------------------------------------------#
+class PowerSupplyApm( dbus.service.Object ):
+#----------------------------------------------------------------------------#
+    """A Dbus Object implementing org.freesmartphone.Device.PowerSupply
+    using the kernel apm or acpi facilities"""
+    DBUS_INTERFACE = DBUS_INTERFACE_PREFIX + ".PowerSupply"
+
+    def __init__( self, bus, index, node ):
+        self.interface = self.DBUS_INTERFACE
+        self.path = DBUS_PATH_PREFIX + "/PowerSupply/%s" % index
+        dbus.service.Object.__init__( self, bus, self.path )
+        LOG( LOG_INFO, "%s initialized. Serving %s at %s" % ( self.__class__.__name__, self.interface, self.path ) )
+        self.node = node
+
+    def readApm( self ):
+        return open( self.node, "r" ).read().strip().split()
+
+    #
+    # dbus
+    #
+    @dbus.service.method( DBUS_INTERFACE, "", "s" )
+    def GetName( self ):
+        return "APM"
+
+    @dbus.service.method( DBUS_INTERFACE, "", "a{sv}" )
+    def GetInfo( self ):
+        return {}
+
+    @dbus.service.method( DBUS_INTERFACE, "", "b" )
+    def GetOnBattery( self ):
+        d, b, f, AC, BAT, flags, percentage, time, units = self.readApm()
+        return AC != "0x01"
+
+    @dbus.service.method( DBUS_INTERFACE, "", "i" )
+    def GetChargingPercentage( self ):
+        d, b, f, AC, BAT, flags, percentage, time, units = self.readApm()
+        return int( percentage[:-1] )
+
+#----------------------------------------------------------------------------#
 class RealTimeClock( dbus.service.Object ):
 #----------------------------------------------------------------------------#
     """A Dbus Object implementing org.freesmartphone.Device.RealTimeClock
@@ -215,14 +253,19 @@
             LOG( LOG_DEBUG, "scanning", index, node )
             objects.append( LED( bus, index, "%s/%s" % ( ledpath, node ) ) )
 
-    # scan for power supplies
+    # scan for power supplies (apm first, then power supply [kernel 2.6.24++])
+    powerpath = "/tmp/proc/apm"
+    LOG( LOG_DEBUG, "scanning", powerpath )
+    if os.path.exists( powerpath ):
+        objects.append( PowerSupplyApm( bus, 0, powerpath ) )
+
     powerpath = "/sys/class/power_supply"
     if os.path.exists( powerpath ):
         for ( index, node ) in enumerate( os.listdir( powerpath ) ):
             LOG( LOG_DEBUG, "scanning", index, node )
             objects.append( PowerSupply( bus, index, "%s/%s" % ( powerpath, node ) ) )
 
-    # scan for power supplies
+    # scan for real time clocks
     rtcpath = "/sys/class/rtc"
     if os.path.exists( rtcpath ):
         for ( index, node ) in enumerate( os.listdir( rtcpath ) ):




More information about the Smartphones-commits mailing list