pndevmapperd: support multiple charge devices
authorGrazvydas Ignotas <notasas@gmail.com>
Sat, 14 Jan 2012 23:19:36 +0000 (01:19 +0200)
committerGrazvydas Ignotas <notasas@gmail.com>
Sat, 14 Jan 2012 23:19:36 +0000 (01:19 +0200)
needed by the new kernel.

apps/pndevmapperd.c
deployment/etc/pandora/conf/eventmap
lib/pnd_device.c

index 273a43c..516b82c 100644 (file)
@@ -130,7 +130,7 @@ unsigned char bc_enable = 1;      // enable charger control
 unsigned char bc_stopcap = 99;    // battery capacity threshold as stop condition 1
 unsigned int bc_stopcur = 80000;  // charge current threshold as stop condition 2, in uA
 unsigned char bc_startcap = 95;   // battery capacity threshold to resume charging
 unsigned char bc_stopcap = 99;    // battery capacity threshold as stop condition 1
 unsigned int bc_stopcur = 80000;  // charge current threshold as stop condition 2, in uA
 unsigned char bc_startcap = 95;   // battery capacity threshold to resume charging
-char *bc_charge_device = NULL;    // charger /sys/class/power_supply/ device, changes between kernel versions
+char *bc_charge_devices = NULL;   // charger /sys/class/power_supply/ devices, changes between kernel versions
 
 /* get to it
  */
 
 /* get to it
  */
@@ -439,9 +439,9 @@ int main ( int argc, char *argv[] ) {
     bc_startcap = pnd_conf_get_as_int ( evmaph, "battery_charge.start_capacity" );
     pnd_log ( pndn_rem, "Battery charge start capacity set to %u", bc_startcap );
   }
     bc_startcap = pnd_conf_get_as_int ( evmaph, "battery_charge.start_capacity" );
     pnd_log ( pndn_rem, "Battery charge start capacity set to %u", bc_startcap );
   }
-  if ( pnd_conf_get_as_char ( evmaph, "battery_charge.device" ) != NULL ) {
-    bc_charge_device = strdup ( pnd_conf_get_as_char ( evmaph, "battery_charge.device" ) );
-    pnd_log ( pndn_rem, "Battery charge device set to %s", bc_charge_device );
+  if ( pnd_conf_get_as_char ( evmaph, "battery_charge.devices" ) != NULL ) {
+    bc_charge_devices = strdup ( pnd_conf_get_as_char ( evmaph, "battery_charge.devices" ) );
+    pnd_log ( pndn_rem, "Battery charge devices set to %s", bc_charge_devices );
   }
 
   /* do we have anything to do?
   }
 
   /* do we have anything to do?
@@ -920,20 +920,20 @@ void sigalrm_handler ( int n ) {
 
   // charge monitoring
   now = time(NULL);
 
   // charge monitoring
   now = time(NULL);
-  if ( bc_enable && bc_charge_device != NULL && (unsigned int)(now - last_charge_check) > 60 ) {
+  if ( bc_enable && bc_charge_devices != NULL && (unsigned int)(now - last_charge_check) > 60 ) {
 
 
-    int charge_enabled = pnd_device_get_charger_enable ( bc_charge_device );
+    int charge_enabled = pnd_device_get_charger_enable ( bc_charge_devices );
     if ( charge_enabled < 0 )
       pnd_log ( pndn_error, "ERROR: Couldn't read charger enable control\n" );
     else {
 
       if ( charge_enabled && batlevel >= bc_stopcap && 0 < uamps && uamps < bc_stopcur ) {
         pnd_log ( pndn_debug, "Charge stop conditions reached, disabling charging\n" );
     if ( charge_enabled < 0 )
       pnd_log ( pndn_error, "ERROR: Couldn't read charger enable control\n" );
     else {
 
       if ( charge_enabled && batlevel >= bc_stopcap && 0 < uamps && uamps < bc_stopcur ) {
         pnd_log ( pndn_debug, "Charge stop conditions reached, disabling charging\n" );
-        pnd_device_set_charger_enable ( bc_charge_device, 0 );
+        pnd_device_set_charger_enable ( bc_charge_devices, 0 );
       }
       else if ( !charge_enabled && batlevel <= bc_startcap ) {
         pnd_log ( pndn_debug, "Charge start conditions reached, enabling charging\n" );
       }
       else if ( !charge_enabled && batlevel <= bc_startcap ) {
         pnd_log ( pndn_debug, "Charge start conditions reached, enabling charging\n" );
-        pnd_device_set_charger_enable ( bc_charge_device, 1 );
+        pnd_device_set_charger_enable ( bc_charge_devices, 1 );
       }
 
       // for some unknown reason it just stops charging randomly (happens once per week or so),
       }
 
       // for some unknown reason it just stops charging randomly (happens once per week or so),
@@ -942,7 +942,7 @@ void sigalrm_handler ( int n ) {
       // by writing to enable. Doing it occasionally should do no harm even with missing charger.
       if ( batlevel <= bc_startcap && (unsigned int)(now - last_charge_worka) > 20*60 ) {
         pnd_log ( pndn_debug, "Charge workaround trigger\n" );
       // by writing to enable. Doing it occasionally should do no harm even with missing charger.
       if ( batlevel <= bc_startcap && (unsigned int)(now - last_charge_worka) > 20*60 ) {
         pnd_log ( pndn_debug, "Charge workaround trigger\n" );
-        pnd_device_set_charger_enable ( bc_charge_device, 1 );
+        pnd_device_set_charger_enable ( bc_charge_devices, 1 );
         last_charge_worka = now;
       }
     }
         last_charge_worka = now;
       }
     }
index 97877eb..3f2272c 100644 (file)
@@ -34,4 +34,4 @@ enable             1            # enable charger control?
 stop_capacity      99           # battery capacity threshold as stop condition 1
 stop_current       80000        # charge current threshold as stop condition 2, in uA
 start_capacity     95           # battery capacity threshold to resume charging
 stop_capacity      99           # battery capacity threshold as stop condition 1
 stop_current       80000        # charge current threshold as stop condition 2, in uA
 start_capacity     95           # battery capacity threshold to resume charging
-device             twl4030_bci_battery
+devices            twl4030_bci_battery twl4030_ac twl4030_usb
index 2e86928..b3cf0c4 100644 (file)
@@ -103,27 +103,49 @@ unsigned char pnd_device_get_charge_current ( int *result ) {
   return ( 0 );
 }
 
   return ( 0 );
 }
 
-int pnd_device_get_charger_enable ( const char *device ) {
+int pnd_device_get_charger_enable ( const char *devices ) {
   char fullname [ 100 ];
   char buffer [ 100 ];
 
   char fullname [ 100 ];
   char buffer [ 100 ];
 
-  snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", device );
+  while ( 1 ) {
+    if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
+      break;
+    }
 
 
-  if ( pnd_device_open_read_close ( fullname, buffer, 100 ) ) {
-    return ( atoi ( buffer ) );
+    while ( isspace ( *devices ) )
+      devices++;
+    devices += strlen ( buffer );
+    snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", buffer );
+
+    /* XXX: only ckecks first good device, but that should be enough for our needs */
+    if ( pnd_device_open_read_close ( fullname, buffer, 100 ) ) {
+      return ( atoi ( buffer ) );
+    }
   }
 
   return ( -1 );
 }
 
   }
 
   return ( -1 );
 }
 
-unsigned char pnd_device_set_charger_enable ( const char *device, unsigned char v ) {
+unsigned char pnd_device_set_charger_enable ( const char *devices, unsigned char v ) {
   char fullname [ 100 ];
   char buffer [ 100 ];
   char fullname [ 100 ];
   char buffer [ 100 ];
+  int ret = 0;
 
 
-  snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", device );
-  sprintf ( buffer, "%u", v );
+  while ( 1 ) {
+    if ( sscanf ( devices, "%99s", buffer ) != 1 ) {
+      break;
+    }
+
+    while ( isspace ( *devices ) )
+      devices++;
+    devices += strlen ( buffer );
+    snprintf ( fullname, sizeof ( fullname ), PND_DEVICE_POWER_BASE "/%s/enable", buffer );
+
+    sprintf ( buffer, "%u", v );
+    ret |= pnd_device_open_write_close ( fullname, buffer );
+  }
 
 
-  return ( pnd_device_open_write_close ( fullname, buffer ) );
+  return ( ret );
 }
 
 unsigned char pnd_device_set_led_power_brightness ( unsigned char v ) {
 }
 
 unsigned char pnd_device_set_led_power_brightness ( unsigned char v ) {