*** src/battery.h.orig 2012-02-11 18:59:54.000000000 +0100 --- src/battery.h 2012-02-11 18:56:30.000000000 +0100 *************** *** 24,32 **** /******************* * ACPI FEATURES * *********************************************************************************/ ! #define ACPI_ACCESS_TEST "/proc/acpi/info" ! #define ACPI_BATTERY_DIR "/proc/acpi/battery" ! //TODO #define ACPI_BATTERY_DIR "/home/mtc/hisBattery/battery" /* it increments, mallocing, the powerState.batteryVector size, to enable --- 24,32 ---- /******************* * ACPI FEATURES * *********************************************************************************/ ! #define ACPI_ACCESS_TEST "/sys/module/acpi/parameters/acpica_version" ! #define ACPI_BATTERY_DIR "/sys/class/power_supply" ! //#define ACPI_BATTERY_DIR "/home/chris/power_supply" /* it increments, mallocing, the powerState.batteryVector size, to enable *** src/battery.c.orig 2012-02-11 18:59:18.000000000 +0100 --- src/battery.c 2012-02-11 18:56:30.000000000 +0100 *************** *** 115,126 **** { name = batt->d_name; ! /* jump . and .. */ ! if (!strncmp (".", name, 1) || !strncmp ("..", name, 2)) ! continue; ! ! countBattery++; ! /* adding a battery to powerState vector */ if( mallocBatteryVector( ) == ERROR ) return ERROR; --- 115,127 ---- { name = batt->d_name; ! /* keeps only BAT* from power_supply */ ! if (!strncmp ("BAT", name, 3)) ! countBattery++; ! else ! continue; ! ! /* adding a battery to powerState vector */ if( mallocBatteryVector( ) == ERROR ) return ERROR; *************** *** 130,145 **** /* we can find 'status' or even 'state' */ snprintf( path, 52, "%s/%s/status", ACPI_BATTERY_DIR, name ); if (access(path, R_OK) == SUCCESS ) ! snprintf( batPtr -> stateFile, 52, "%s/%s/status",ACPI_BATTERY_DIR, name ); else ! snprintf( batPtr -> stateFile, 52, "%s/%s/state", ACPI_BATTERY_DIR, name ); /* calculating maximum capacity of this battery * reading file infos */ batPtr -> useLFC = ACPI_lfcArgs_get( countBattery ); batPtr -> counter = countBattery; ! snprintf( batPtr -> infoFile, 52, "%s/%s/info", ACPI_BATTERY_DIR, name ); batPtr -> present = ACPI_maxCapacity ( batPtr ); /* THIS IS NOT A BATTERY ! set error field to true: don't use it */ --- 131,146 ---- /* we can find 'status' or even 'state' */ snprintf( path, 52, "%s/%s/status", ACPI_BATTERY_DIR, name ); if (access(path, R_OK) == SUCCESS ) ! snprintf( batPtr -> stateFile, 52, "%s/%s/uevent",ACPI_BATTERY_DIR, name ); else ! snprintf( batPtr -> stateFile, 52, "%s/%s/status", ACPI_BATTERY_DIR, name ); /* calculating maximum capacity of this battery * reading file infos */ batPtr -> useLFC = ACPI_lfcArgs_get( countBattery ); batPtr -> counter = countBattery; ! snprintf( batPtr -> infoFile, 52, "%s/%s/uevent", ACPI_BATTERY_DIR, name ); batPtr -> present = ACPI_maxCapacity ( batPtr ); /* THIS IS NOT A BATTERY ! set error field to true: don't use it */ *************** *** 197,227 **** ptr = buf; while( (!dcTagPointer || !lfcTagPointer) && saltCounter < 492 ) { ! if( !strncmp( ptr, "design capacity:", 16 ) ) ! dcTagPointer = ptr; ! if( !strncmp( ptr, "last full capacity:", 19 ) ) ! lfcTagPointer = ptr; ! ! saltCounter++; ! ptr++; } /* naah.. */ if( saltCounter >= 492 && !dcTagPointer && !lfcTagPointer ) { ! PRINTQ( stderr, "The info file (%s) has not \n'design capacity' and not event 'last full capacity' tag\n%s\n", p -> infoFile, errorMessage ); /* we treat 1111.1111.1111.1111 as error here */ p -> capacity = ~0x00; } if( lfcTagPointer ) { ! lfcTagPointer += 20; sscanf( lfcTagPointer, "%u", &lastFullCapacity ); } if( dcTagPointer ) { ! dcTagPointer += 17; sscanf( dcTagPointer, "%u", &designCapacity ); } --- 198,236 ---- ptr = buf; while( (!dcTagPointer || !lfcTagPointer) && saltCounter < 492 ) { ! ! if( !strncmp( ptr, "POWER_SUPPLY_CHARGE_FULL_DESIGN=", 32 ) ) ! dcTagPointer = ptr; ! ! else if( !strncmp( ptr, "POWER_SUPPLY_ENERGY_FULL_DESIGN=", 32 ) ) ! dcTagPointer = ptr; ! ! ! if( !strncmp( ptr, "POWER_SUPPLY_CHARGE_FULL=", 25 ) ) ! lfcTagPointer = ptr; ! else if ( !strncmp( ptr, "POWER_SUPPLY_ENERGY_FULL=", 25 ) ) ! lfcTagPointer = ptr; ! ! saltCounter++; ! ptr++; } /* naah.. */ if( saltCounter >= 492 && !dcTagPointer && !lfcTagPointer ) { ! PRINTQ( stderr, "The uevent file (%s) has not \n'FULL_DESIGN' and not event 'FULL' tag\n%s\n", p -> infoFile, errorMessage ); /* we treat 1111.1111.1111.1111 as error here */ p -> capacity = ~0x00; } if( lfcTagPointer ) { ! lfcTagPointer += 25; sscanf( lfcTagPointer, "%u", &lastFullCapacity ); } if( dcTagPointer ) { ! dcTagPointer += 32; sscanf( dcTagPointer, "%u", &designCapacity ); } *************** *** 232,239 **** { if( p -> useLFC == false ) { ! PRINTQ( stderr, "'Last full capacity' in <%s>\n", p -> infoFile ); ! PRINTQ( stderr, "is different from 'design capacity' tag:\n" ); PRINTQ( stderr, "If you want to use it pass '--lfc=%d' (%d is the number of this battery)\n", p -> counter, p -> counter ); PRINTQ( stderr, "If you don't want this message to be displayed anymore pass '-q'\n\n" ); } --- 241,248 ---- { if( p -> useLFC == false ) { ! PRINTQ( stderr, "'FULL_DESIGN' in <%s>\n", p -> infoFile ); ! PRINTQ( stderr, "is different from 'FULL' tag:\n" ); PRINTQ( stderr, "If you want to use it pass '--lfc=%d' (%d is the number of this battery)\n", p -> counter, p -> counter ); PRINTQ( stderr, "If you don't want this message to be displayed anymore pass '-q'\n\n" ); } *************** *** 315,335 **** } ptr = buf; ! while( strncmp( ptr, "remaining capacity:", 19 ) && saltCounter < 495) { saltCounter++; ! ptr++; } /* naah.. */ if( saltCounter >= 498 ) { ! fprintf( stderr, "The info file (%s) has not 'remaining capacity' tag", path ); free_and_exit( ERROR ); } ! ptr += 20; ! sscanf( ptr, "%u", &bat -> actualState ); } --- 324,345 ---- } ptr = buf; ! while( strncmp( ptr, "POWER_SUPPLY_CHARGE_NOW=", 24 ) ! && strncmp( ptr, "POWER_SUPPLY_ENERGY_NOW=", 24 ) ! && saltCounter < 495) { saltCounter++; ! *ptr++; } /* naah.. */ if( saltCounter >= 498 ) { ! fprintf( stderr, "The uevent file (%s) has not 'NOW' tag", path ); free_and_exit( ERROR ); } ! ptr += 24; sscanf( ptr, "%u", &bat -> actualState ); } *************** *** 367,391 **** /* battery charger information reading * thanks to wmpower */ ! if (!(fp = fopen ("/proc/acpi/ac_adapter/0/status", "r"))) ! if (!(fp = fopen ("/proc/acpi/ac_adapter/ACAD/state", "r"))) ! if (!(fp = fopen ("/proc/acpi/ac_adapter/AC/state", "r"))) ! if (!(fp = fopen ("/proc/acpi/ac_adapter/ADP1/state", "r"))) ! return; fread_unlocked (buf, 512, 1, fp); fclose(fp); ! if (strncmp(buf, "state:", 6) == 0) ! where = buf + 26; ! if (strncmp(buf, "Status:", 7) == 0) ! where = buf + 26; ! if (where) { ! if (where[0] == 'n') powerState.isCharging = true; ! if (where[0] == 'f') powerState.isCharging = false; } --- 377,401 ---- /* battery charger information reading * thanks to wmpower */ ! if (!(fp = fopen ("/sys/class/power_supply/AC/online", "r"))) ! if (!(fp = fopen ("/sys/class/power_supply/ADP1/online", "r"))) ! return; fread_unlocked (buf, 512, 1, fp); fclose(fp); ! if (strncmp(buf, "state:", 6) == 0) ! where = buf; ! if (strncmp(buf, "0", 1) == 0) ! where = buf; ! if (strncmp(buf, "1", 1) == 0) ! where = buf; ! if (where) { ! if (where[0] == '1') powerState.isCharging = true; ! if (where[0] == '0') powerState.isCharging = false; } *** src/cpu.c.orig 2012-02-11 18:59:30.000000000 +0100 --- src/cpu.c 2012-02-11 18:56:30.000000000 +0100 *************** *** 133,142 **** #ifndef LONGRUN FILE * fp; char red[10]; ! ! if( (fp = fopen( cpuState.setFreqFile, "r" )) == NULL ) { ! fprintf(stderr, "Error reading the info file (%s):\n%s\n", cpuState.setFreqFile, strerror(errno) ); free_and_exit( ERROR ); } --- 133,142 ---- #ifndef LONGRUN FILE * fp; char red[10]; ! ! if( (fp = fopen( cpuState.readFreqFile, "r" )) == NULL ) { ! fprintf(stderr, "Error reading the info file (%s):\n%s\n", cpuState.readFreqFile, strerror(errno) ); free_and_exit( ERROR ); } *************** *** 197,203 **** if(( direction == FREQ_INCREMENT && cpuState.actualFreq == cpuState.maxFreq ) || ( direction == FREQ_DECREMENT && cpuState.actualFreq == cpuState.minFreq )) return; ! switch( speed ) { case FREQ_STEP: --- 197,214 ---- if(( direction == FREQ_INCREMENT && cpuState.actualFreq == cpuState.maxFreq ) || ( direction == FREQ_DECREMENT && cpuState.actualFreq == cpuState.minFreq )) return; ! /* if not userspace, forget about it */ ! if (! cpuState.userspace) ! return; ! /* check we got the permissions */ ! if( (fopen( cpuState.setFreqFile, "w" )) == NULL ) ! { ! fprintf(stderr, "Sorry, you may need priviledge to access into (%s):\n%s\n", \ ! cpuState.setFreqFile, strerror(errno) ); ! cpuState.userspace = false; ! return; ! } ! switch( speed ) { case FREQ_STEP: *************** *** 317,325 **** #ifndef LONGRUN if( (fp = fopen( cpuState.setFreqFile, "w" )) == NULL ) { ! fprintf(stderr, "Error writing the new freq (%d) in the file (%s):\n%s\n", \ cpuState.setFreq, cpuState.setFreqFile, strerror(errno) ); free_and_exit( ERROR ); } fprintf( fp, "%u", cpuState.setFreq ); --- 328,337 ---- #ifndef LONGRUN if( (fp = fopen( cpuState.setFreqFile, "w" )) == NULL ) { ! fprintf(stderr, "Error, cannot write the new freq (%d) into (%s):\n%s\n", \ cpuState.setFreq, cpuState.setFreqFile, strerror(errno) ); free_and_exit( ERROR ); + return; } fprintf( fp, "%u", cpuState.setFreq ); *** src/init.c.orig 2012-02-11 19:01:13.000000000 +0100 --- src/init.c 2012-02-11 18:56:30.000000000 +0100 *************** *** 196,202 **** { char * scaling_governor_path = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"; char * scaling_governor_av_path = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"; ! char * error_msg = "Unable to read <%s>:\n%s\nwmlaptop cannot help you in cpu scaling governor\n"; FILE * sysfp; FILE * sysavfp; char littleBuffer[128]; --- 196,203 ---- { char * scaling_governor_path = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"; char * scaling_governor_av_path = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors"; ! char * error_msg = "Unable to read <%s>\n"; ! char * error_msg_w = "Unable to write <%s>\n"; FILE * sysfp; FILE * sysavfp; char littleBuffer[128]; *************** *** 213,220 **** fclose( sysfp ); if( !strcmp( littleBuffer, "userspace\n" ) ) return; ! if( ( sysavfp = fopen( scaling_governor_av_path, "r" ) ) == NULL ) { PRINTQ( stderr, error_msg, scaling_governor_av_path, strerror(errno) ); return; --- 214,223 ---- fclose( sysfp ); if( !strcmp( littleBuffer, "userspace\n" ) ) + { + cpuState.userspace = true; return; ! } if( ( sysavfp = fopen( scaling_governor_av_path, "r" ) ) == NULL ) { PRINTQ( stderr, error_msg, scaling_governor_av_path, strerror(errno) ); return; *************** *** 228,261 **** { /* ok, module is loaded */ printIt = true; break; } if( printIt == false ) { int s; ! PRINTQ( stderr, "It seems that you do not have 'cpufreq_userspace' module loaded in your kernel\n"); ! PRINTQ( stderr, "I try to call \"/sbin/modprobe cpufreq_userspace\"\n"); ! ! /* ugly.. but very fast */ ! s = system( "/sbin/modprobe cpufreq_userspace" ); ! ! if( s == 0 ) ! PRINTQ( stderr, "..good.\n" ); ! else ! { ! PRINTQ( stderr, "you should do it by yourself (maybe you need to recompile kernel ?)\n"); ! return; ! } } /* All ok here */ if( ( sysfp = fopen( scaling_governor_path, "w" )) == NULL ) ! PRINTQ( stderr, error_msg, scaling_governor_path, strerror(errno)); else { PRINTQ( stderr, "echoing 'userspace' > '%s'\n", scaling_governor_path ); fprintf( sysfp, "userspace" ); fclose( sysfp ); } --- 231,256 ---- { /* ok, module is loaded */ printIt = true; + cpuState.userspace = true; break; } if( printIt == false ) { int s; ! PRINTQ( stderr, "It seems that 'userspace' governor is not set\n"); ! PRINTQ( stderr, "wmlaptop may not control CPU frequency\n"); ! cpuState.userspace = false; } /* All ok here */ if( ( sysfp = fopen( scaling_governor_path, "w" )) == NULL ) ! PRINTQ( stderr, error_msg_w, scaling_governor_path, strerror(errno)); else { PRINTQ( stderr, "echoing 'userspace' > '%s'\n", scaling_governor_path ); fprintf( sysfp, "userspace" ); + cpuState.userspace = true; fclose( sysfp ); } *************** *** 271,277 **** #ifndef LONGRUN FILE * fp; char red[10]; ! char * paths[3][3] = { /* sys proc user */ /* min */ { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq", "/proc/sys/cpu/0/speed-min", --- 266,272 ---- #ifndef LONGRUN FILE * fp; char red[10]; ! char * paths[4][3] = { /* sys proc user */ /* min */ { "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq", "/proc/sys/cpu/0/speed-min", *************** *** 281,287 **** args_useFileMax }, /* set */ { "/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", "/proc/sys/cpu/0/speed", ! args_useFileSet } }; u_int8 idx[3] = { /* the second index */ args_useFileMin ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ), --- 276,285 ---- args_useFileMax }, /* set */ { "/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed", "/proc/sys/cpu/0/speed", ! args_useFileSet }, ! /* read */ { "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", ! "/proc/sys/cpu/0/speed", ! args_useFileSet } }; u_int8 idx[3] = { /* the second index */ args_useFileMin ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ), *************** *** 289,298 **** args_useFileSet ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ) }; - /* auto_freq_state */ cpuState.auto_freq_state = ( args_autoFreq == AUTOFREQ_ON ); ! /* min freq */ if( (fp = fopen( paths[0][idx[0]], "r" )) == NULL ) { --- 287,297 ---- args_useFileSet ? 2 : ( args_useSysProc == USESYSPROC_SYS ? 0 : 1 ) }; /* auto_freq_state */ cpuState.auto_freq_state = ( args_autoFreq == AUTOFREQ_ON ); ! ! /* will be checked later */ ! cpuState.userspace = false; /* min freq */ if( (fp = fopen( paths[0][idx[0]], "r" )) == NULL ) { *************** *** 319,324 **** --- 318,327 ---- /* set freq file */ cpuState.setFreqFile = paths[2][idx[2]]; + /* read freq file */ + cpuState.readFreqFile = paths[3][idx[2]]; + + /* if we have to use the SYS's way to set cpufreq, then ensure that in * scaling_governor there has been put 'userspace'; otherwise let's try * to put it by ourself */ *** src/main.h.orig 2012-02-11 19:00:30.000000000 +0100 --- src/main.h 2012-02-11 18:56:30.000000000 +0100 *************** *** 222,227 **** --- 222,229 ---- u_int32 minFreq; u_int32 maxFreq; char * setFreqFile; + char * readFreqFile; + bool userspace; u_int32 setFreq; u_int32 stepFreq; #else *** src/main.c.orig 2012-02-11 19:00:49.000000000 +0100 --- src/main.c 2012-02-11 18:56:30.000000000 +0100 *************** *** 88,95 **** if( powerState.nBatt == 0 ) { fprintf( stderr, "No batteries found !\n"); ! fprintf( stderr, "(I only can search in /proc/acpi/battery/* and in /proc/apm)\n"); ! free_and_exit( ERROR ); } else if( args_ttyMode == false ) --- 88,95 ---- if( powerState.nBatt == 0 ) { fprintf( stderr, "No batteries found !\n"); ! fprintf( stderr, "(I only can search in /sys/class/power_supply/* and in /proc/apm)\n"); ! /* free_and_exit( ERROR ); */ } else if( args_ttyMode == false )