added other half of main loop and cleared up cpufreq file mistake

This commit is contained in:
celso 2022-11-19 12:50:19 -03:00
parent 58c0d9f503
commit 4e522dc30b
1 changed files with 12 additions and 4 deletions

View File

@ -4,7 +4,6 @@
#define CURGOV "/sys/devices/system/cpu/cpufreq/policy0/scaling_governor" #define CURGOV "/sys/devices/system/cpu/cpufreq/policy0/scaling_governor"
#define FREQS "/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies" #define FREQS "/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies"
#define MAXSPDPATH "/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq" #define MAXSPDPATH "/sys/devices/system/cpu/cpufreq/policy0/scaling_max_freq"
#define SETSPDPATH "/sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed"
#define CURTEMPPATH "/sys/devices/virtual/thermal/thermal_zone0/temp" #define CURTEMPPATH "/sys/devices/virtual/thermal/thermal_zone0/temp"
int comparestrings(char *a, char *b){ int comparestrings(char *a, char *b){
@ -203,15 +202,24 @@ int main(int argc, char** argv){
getfilec(curtempfile, temperature); getfilec(curtempfile, temperature);
newlinetonullbyte(temperature); newlinetonullbyte(temperature);
if (stringtoint(temperature, stringlength(temperature)) >= maxtemp if (stringtoint(temperature, stringlength(temperature)) >= maxtemp
&& curstep <= stepc){ && curstep < stepc - 1){
curstep++;
curmaxfile = fopen(MAXSPDPATH, "w");
fprintf(curmaxfile, "%s\n", steps[curstep]);
fclose(curmaxfile);
}
if (stringtoint(temperature, stringlength(temperature)) <= mintemp
&& curstep > 0){
curstep--;
curmaxfile = fopen(MAXSPDPATH, "w");
fprintf(curmaxfile, "%s\n", steps[curstep]);
fclose(curmaxfile);
} }
free(temperature); free(temperature);
fclose(curtempfile); fclose(curtempfile);
} }
/* cleanup for graceful exit */ /* cleanup for graceful exit */
free(steps); free(steps);
FILE* setspeedfile = fopen(SETSPDPATH, "w");
fclose(setspeedfile);
fclose(curtempfile); fclose(curtempfile);
return 0; return 0;
} }