| 1 | /* |
| 2 | * control.c - Fan control daemon for MacBook |
| 3 | * |
| 4 | * Copyright(C) 2010 Mikael Strom <[email protected]> |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <string.h> |
| 20 | #include <sys/types.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <dirent.h> |
| 24 | #include <assert.h> |
| 25 | #include <unistd.h> |
| 26 | #include "config.h"cxx . . $ `<file>/config.h`/ |
| 27 | |
| 28 | //------------------------------------------------------------------------------ |
| 29 | |
| 30 | #define HWMON_DIRcxx . . $ `control.c:30:9`! "/sys/class/hwmon" |
| 31 | #define APPLESMC_IDcxx . . $ `control.c:31:9`! "applesmc" |
| 32 | |
| 33 | structcxx . . $ $anonymous_type_81c162c42d143ee8_0# |
| 34 | { |
| 35 | char *keycxx . . $ $anonymous_type_81c162c42d143ee8_0#key.; |
| 36 | char *desccxx . . $ $anonymous_type_81c162c42d143ee8_0#desc.; |
| 37 | } |
| 38 | sensor_desccxx . . $ sensor_desc.[] = |
| 39 | { |
| 40 | {"TB0T", "Battery TS_MAX Temp"}, |
| 41 | {"TB1T", "Battery TS1 Temp"}, |
| 42 | {"TB2T", "Battery TS2 Temp"}, |
| 43 | {"TB3T", "Battery Temp"}, |
| 44 | {"TC0D", "CPU 0 Die Temp"}, |
| 45 | {"TC0P", "CPU 0 Proximity Temp"}, |
| 46 | {"TG0D", "GPU Die - Digital"}, |
| 47 | {"TG0P", "GPU 0 Proximity Temp"}, |
| 48 | {"TG0T", "GPU 0 Die - Analog Temp"}, |
| 49 | {"TG0H", "Left Heat Pipe/Fin Stack Proximity Temp"}, |
| 50 | {"TG1H", "Left Heat Pipe/Fin Stack Proximity Temp"}, |
| 51 | {"TN0P", "MCP Proximity"}, |
| 52 | {"TN0D", "MCP Die"}, |
| 53 | {"Th2H", "Right Fin Stack Proximity Temp"}, |
| 54 | {"Tm0P", "Battery Charger Proximity Temp"}, |
| 55 | {"Ts0P", "Palm Rest Temp"} |
| 56 | }; |
| 57 | #define N_DESCcxx . . $ `control.c:57:9`! (sizeof(sensor_desc) / sizeof(sensor_desc[0])) |
| 58 | |
| 59 | #define SENSKEY_MAXLENcxx . . $ `control.c:59:9`! 16 |
| 60 | |
| 61 | struct sensorcxx . . $ sensor# |
| 62 | { |
| 63 | int idcxx . . $ sensor#id.; |
| 64 | int excludedcxx . . $ sensor#excluded.; |
| 65 | char namecxx . . $ sensor#name.[SENSKEY_MAXLENcxx . . $ `control.c:59:9`!]; |
| 66 | char fnamecxx . . $ sensor#fname.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 67 | float valuecxx . . $ sensor#value.; |
| 68 | }; |
| 69 | |
| 70 | //------------------------------------------------------------------------------ |
| 71 | |
| 72 | char base_pathcxx . . $ base_path.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 73 | char fan1_mincxx . . $ fan1_min.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 74 | char fan2_mincxx . . $ fan2_min.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 75 | char fan1_mancxx . . $ fan1_man.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 76 | char fan2_mancxx . . $ fan2_man.[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 77 | |
| 78 | int sensor_countcxx . . $ sensor_count. = 0; |
| 79 | int fan_countcxx . . $ fan_count. = 0; |
| 80 | float temp_avgcxx . . $ temp_avg. = 0; |
| 81 | int fan_speedcxx . . $ fan_speed.; |
| 82 | |
| 83 | struct sensorcxx . . $ sensor# *sensorscxx . . $ sensors. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 84 | struct sensorcxx . . $ sensor# *sensor_TC0Pcxx . . $ sensor_TC0P. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 85 | struct sensorcxx . . $ sensor# *sensor_TG0Pcxx . . $ sensor_TG0P. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 86 | |
| 87 | #define CTL_NONEcxx . . $ `control.c:87:9`! 0 // sensor control fan flags |
| 88 | #define CTL_AVGcxx . . $ `control.c:88:9`! 1 |
| 89 | #define CTL_TC0Pcxx . . $ `control.c:89:9`! 2 |
| 90 | #define CTL_TG0Pcxx . . $ `control.c:90:9`! 3 |
| 91 | |
| 92 | int fan_ctlcxx . . $ fan_ctl. = 0; // which sensor controls fan |
| 93 | |
| 94 | //------------------------------------------------------------------------------ |
| 95 | |
| 96 | void find_applesmccxx . . $ find_applesmc(d878ad36e69247c7).() |
| 97 | { |
| 98 | DIRcxx . . $ DIR# *fd_dir; |
| 99 | int ret; |
| 100 | |
| 101 | base_pathcxx . . $ base_path.[0] = 0; |
| 102 | |
| 103 | // find and verify applesmc path in /sys/devices |
| 104 | |
| 105 | fd_dir = opendircxx . . $ opendir(f465d4b65cec8dd2).(HWMON_DIRcxx . . $ `control.c:30:9`!); |
| 106 | |
| 107 | if(fd_dir != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 108 | { |
| 109 | struct direntcxx . . $ dirent# *dir_entry; |
| 110 | |
| 111 | while((dir_entry = readdircxx . . $ readdir(ffbaae344e1a615a).(fd_dir)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && base_pathcxx . . $ base_path.[0] == 0) |
| 112 | { |
| 113 | if(dir_entry->d_namecxx . . $ dirent#d_name.[0] != '.') |
| 114 | { |
| 115 | char name_path[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!]; |
| 116 | int fd_name; |
| 117 | |
| 118 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(name_path, "%s/%s/device/name", HWMON_DIRcxx . . $ `control.c:30:9`!, dir_entry->d_namecxx . . $ dirent#d_name.); |
| 119 | |
| 120 | fd_name = opencxx . . $ open(e156e3aa1e5c4ad1).(name_path, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!); |
| 121 | |
| 122 | if(fd_name > -1) |
| 123 | { |
| 124 | char name[sizeof(APPLESMC_IDcxx . . $ `control.c:31:9`!)]; |
| 125 | |
| 126 | ret = readcxx . . $ read(7e34d0a36f355389).(fd_name, name, sizeof(APPLESMC_IDcxx . . $ `control.c:31:9`!) - 1); |
| 127 | |
| 128 | closecxx . . $ close(7864480464b09eea).(fd_name); |
| 129 | |
| 130 | if(ret == sizeof(APPLESMC_IDcxx . . $ `control.c:31:9`!) - 1) |
| 131 | { |
| 132 | if(strncmpcxx . . $ strncmp(fd278af2f295fa2e).(name, APPLESMC_IDcxx . . $ `control.c:31:9`!, sizeof(APPLESMC_IDcxx . . $ `control.c:31:9`!) - 1) == 0) |
| 133 | { |
| 134 | char *dev_path; |
| 135 | char *last_slash = strrchrcxx . . $ strrchr(2050848944e00d54).(name_path, '/'); |
| 136 | |
| 137 | if(last_slash != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 138 | { |
| 139 | *last_slash = 0; |
| 140 | |
| 141 | dev_path = realpathcxx . . $ realpath(ed8193f262e4eda).(name_path, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 142 | |
| 143 | if(dev_path != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 144 | { |
| 145 | strncpycxx . . $ strncpy(255158a415b673b0).(base_pathcxx . . $ base_path., dev_path, sizeof(base_pathcxx . . $ base_path.) - 1); |
| 146 | base_pathcxx . . $ base_path.[sizeof(base_pathcxx . . $ base_path.) - 1] = 0; |
| 147 | freecxx . . $ free(5d22bdacc48458e8).(dev_path); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | closedircxx . . $ closedir(ac30a447bc7c2f80).(fd_dir); |
| 156 | } |
| 157 | |
| 158 | // create paths to fan and sensor |
| 159 | |
| 160 | if(base_pathcxx . . $ base_path.[0] == 0) |
| 161 | { |
| 162 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't find a applesmc device\n"); |
| 163 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 164 | } |
| 165 | |
| 166 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(fan1_mincxx . . $ fan1_min., "%s/fan1_min", base_pathcxx . . $ base_path.); |
| 167 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(fan2_mincxx . . $ fan2_min., "%s/fan2_min", base_pathcxx . . $ base_path.); |
| 168 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(fan1_mancxx . . $ fan1_man., "%s/fan1_manual", base_pathcxx . . $ base_path.); |
| 169 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(fan2_mancxx . . $ fan2_man., "%s/fan2_manual", base_pathcxx . . $ base_path.); |
| 170 | |
| 171 | printfcxx . . $ printf(581fddd72a8db8fc).("Found applesmc at %s\n", base_pathcxx . . $ base_path.); |
| 172 | } |
| 173 | |
| 174 | //------------------------------------------------------------------------------ |
| 175 | |
| 176 | void read_sensorscxx . . $ read_sensors(d878ad36e69247c7).() |
| 177 | { |
| 178 | int i; |
| 179 | for(i = 0; i < sensor_countcxx . . $ sensor_count.; ++i) |
| 180 | { |
| 181 | if(! sensorscxx . . $ sensors.[i].excludedcxx . . $ sensor#excluded.) |
| 182 | { |
| 183 | // read temp value |
| 184 | |
| 185 | int fd = opencxx . . $ open(e156e3aa1e5c4ad1).(sensorscxx . . $ sensors.[i].fnamecxx . . $ sensor#fname., O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!); |
| 186 | if(fd < 0) |
| 187 | { |
| 188 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't open %s\n", sensorscxx . . $ sensors.[i].fnamecxx . . $ sensor#fname.); |
| 189 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | char val_buf[16]; |
| 194 | int n = readcxx . . $ read(7e34d0a36f355389).(fd, val_buf, sizeof(val_buf)); |
| 195 | if(n < 1) |
| 196 | { |
| 197 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't read %s\n", sensorscxx . . $ sensors.[i].fnamecxx . . $ sensor#fname.); |
| 198 | } |
| 199 | else |
| 200 | { |
| 201 | sensorscxx . . $ sensors.[i].valuecxx . . $ sensor#value. = (float)atoicxx . . $ atoi(5c4306d8553b3696).(val_buf) / 1000.0; |
| 202 | } |
| 203 | closecxx . . $ close(7864480464b09eea).(fd); |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // calc average |
| 209 | |
| 210 | temp_avgcxx . . $ temp_avg. = 0.0; |
| 211 | int active_sensors = 0; |
| 212 | |
| 213 | for(i = 0; i < sensor_countcxx . . $ sensor_count.; ++i) |
| 214 | { |
| 215 | if(! sensorscxx . . $ sensors.[i].excludedcxx . . $ sensor#excluded.) |
| 216 | { |
| 217 | temp_avgcxx . . $ temp_avg. += sensorscxx . . $ sensors.[i].valuecxx . . $ sensor#value.; |
| 218 | ++active_sensors; |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | temp_avgcxx . . $ temp_avg. = temp_avgcxx . . $ temp_avg. / active_sensors; |
| 223 | } |
| 224 | |
| 225 | //------------------------------------------------------------------------------ |
| 226 | |
| 227 | void calc_fancxx . . $ calc_fan(d878ad36e69247c7).() |
| 228 | { |
| 229 | fan_speedcxx . . $ fan_speed. = fan_mincxx . . $ fan_min.; |
| 230 | fan_ctlcxx . . $ fan_ctl. = CTL_NONEcxx . . $ `control.c:87:9`!; |
| 231 | |
| 232 | // calc fan speed on average |
| 233 | |
| 234 | float fan_window = fan_maxcxx . . $ fan_max. - fan_mincxx . . $ fan_min.; |
| 235 | float temp_avg_window = temp_avg_ceilingcxx . . $ temp_avg_ceiling. - temp_avg_floorcxx . . $ temp_avg_floor.; |
| 236 | float normalized_temp =(temp_avgcxx . . $ temp_avg. - temp_avg_floorcxx . . $ temp_avg_floor.) / temp_avg_window; |
| 237 | float fan_avg_speed =(normalized_temp * fan_window); |
| 238 | if(fan_avg_speed > fan_speedcxx . . $ fan_speed.) |
| 239 | { |
| 240 | fan_speedcxx . . $ fan_speed. = fan_avg_speed; |
| 241 | fan_ctlcxx . . $ fan_ctl. = CTL_AVGcxx . . $ `control.c:88:9`!; |
| 242 | } |
| 243 | |
| 244 | // calc fan speed for TC0P |
| 245 | |
| 246 | if(sensor_TC0Pcxx . . $ sensor_TC0P. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 247 | { |
| 248 | float temp_window = temp_TC0P_ceilingcxx . . $ temp_TC0P_ceiling. - temp_TC0P_floorcxx . . $ temp_TC0P_floor.; |
| 249 | float normalized_temp =(sensor_TC0Pcxx . . $ sensor_TC0P.->valuecxx . . $ sensor#value. - temp_TC0P_floorcxx . . $ temp_TC0P_floor.) / temp_window; |
| 250 | float fan_TC0P_speed =(normalized_temp * fan_window); |
| 251 | if(fan_TC0P_speed > fan_speedcxx . . $ fan_speed.) |
| 252 | { |
| 253 | fan_speedcxx . . $ fan_speed. = fan_TC0P_speed; |
| 254 | fan_ctlcxx . . $ fan_ctl. = CTL_TC0Pcxx . . $ `control.c:89:9`!; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // calc fan speed for TG0P |
| 259 | |
| 260 | if(sensor_TG0Pcxx . . $ sensor_TG0P. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 261 | { |
| 262 | float temp_window = temp_TG0P_ceilingcxx . . $ temp_TG0P_ceiling. - temp_TG0P_floorcxx . . $ temp_TG0P_floor.; |
| 263 | float normalized_temp =(sensor_TG0Pcxx . . $ sensor_TG0P.->valuecxx . . $ sensor#value. - temp_TG0P_floorcxx . . $ temp_TG0P_floor.) / temp_window; |
| 264 | float fan_TG0P_speed =(normalized_temp * fan_window); |
| 265 | if(fan_TG0P_speed > fan_speedcxx . . $ fan_speed.) |
| 266 | { |
| 267 | fan_speedcxx . . $ fan_speed. = fan_TG0P_speed; |
| 268 | fan_ctlcxx . . $ fan_ctl. = CTL_TG0Pcxx . . $ `control.c:90:9`!; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | // finally clamp |
| 273 | |
| 274 | fan_speedcxx . . $ fan_speed. = mincxx . . $ `config.h:40:9`!(fan_max, fan_speed); |
| 275 | } |
| 276 | |
| 277 | //------------------------------------------------------------------------------ |
| 278 | |
| 279 | void set_fancxx . . $ set_fan(d878ad36e69247c7).() |
| 280 | { |
| 281 | char buf[16]; |
| 282 | |
| 283 | // update fan 1 |
| 284 | |
| 285 | int fd = opencxx . . $ open(e156e3aa1e5c4ad1).(fan1_mincxx . . $ fan1_min., O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!); |
| 286 | if(fd < 0) |
| 287 | { |
| 288 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't open %s\n", fan1_mincxx . . $ fan1_min.); |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "%d", fan_speedcxx . . $ fan_speed.); |
| 293 | writecxx . . $ write(41184a59d38b4f65).(fd, buf, strlencxx . . $ strlen(751346f8406fd082).(buf)); |
| 294 | closecxx . . $ close(7864480464b09eea).(fd); |
| 295 | } |
| 296 | |
| 297 | // set fan 1 manual to zero |
| 298 | |
| 299 | fd = opencxx . . $ open(e156e3aa1e5c4ad1).(fan1_mancxx . . $ fan1_man., O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!); |
| 300 | if(fd < 0) |
| 301 | { |
| 302 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't open %s\n", fan1_mancxx . . $ fan1_man.); |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | strcpycxx . . $ strcpy(b7b3a83273496486).(buf, "0"); |
| 307 | writecxx . . $ write(41184a59d38b4f65).(fd, buf, strlencxx . . $ strlen(751346f8406fd082).(buf)); |
| 308 | closecxx . . $ close(7864480464b09eea).(fd); |
| 309 | } |
| 310 | |
| 311 | // update fan 2 |
| 312 | |
| 313 | if(fan_countcxx . . $ fan_count. > 1) |
| 314 | { |
| 315 | fd = opencxx . . $ open(e156e3aa1e5c4ad1).(fan2_mincxx . . $ fan2_min., O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!); |
| 316 | if(fd < 0) |
| 317 | { |
| 318 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't open %s\n", fan2_mincxx . . $ fan2_min.); |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(buf, "%d", fan_speedcxx . . $ fan_speed.); |
| 323 | writecxx . . $ write(41184a59d38b4f65).(fd, buf, strlencxx . . $ strlen(751346f8406fd082).(buf)); |
| 324 | closecxx . . $ close(7864480464b09eea).(fd); |
| 325 | } |
| 326 | |
| 327 | // set fan 2 manual to zero |
| 328 | |
| 329 | fd = opencxx . . $ open(e156e3aa1e5c4ad1).(fan2_mancxx . . $ fan2_man., O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!); |
| 330 | if(fd < 0) |
| 331 | { |
| 332 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't open %s\n", fan2_mancxx . . $ fan2_man.); |
| 333 | } |
| 334 | else |
| 335 | { |
| 336 | strcpycxx . . $ strcpy(b7b3a83273496486).(buf, "0"); |
| 337 | writecxx . . $ write(41184a59d38b4f65).(fd, buf, strlencxx . . $ strlen(751346f8406fd082).(buf)); |
| 338 | closecxx . . $ close(7864480464b09eea).(fd); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 343 | } |
| 344 | |
| 345 | //------------------------------------------------------------------------------ |
| 346 | |
| 347 | void adjustcxx . . $ adjust(d878ad36e69247c7).() |
| 348 | { |
| 349 | read_sensorscxx . . $ read_sensors(d878ad36e69247c7).(); |
| 350 | calc_fancxx . . $ calc_fan(d878ad36e69247c7).(); |
| 351 | set_fancxx . . $ set_fan(d878ad36e69247c7).(); |
| 352 | } |
| 353 | |
| 354 | //------------------------------------------------------------------------------ |
| 355 | |
| 356 | void scan_sensorscxx . . $ scan_sensors(d878ad36e69247c7).() |
| 357 | { |
| 358 | int i; |
| 359 | int j; |
| 360 | struct statcxx . . $ stat# buf; |
| 361 | int result; |
| 362 | |
| 363 | sensor_TC0Pcxx . . $ sensor_TC0P. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 364 | sensor_TG0Pcxx . . $ sensor_TG0P. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 365 | |
| 366 | // get number of fans |
| 367 | |
| 368 | result = statcxx . . $ stat(a9cd1e23e96f423c).(fan1_mincxx . . $ fan1_min., &buf); |
| 369 | if(result != 0) |
| 370 | { |
| 371 | printfcxx . . $ printf(581fddd72a8db8fc).("No fans detected, terminating!\n"); |
| 372 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 373 | } |
| 374 | else |
| 375 | { |
| 376 | fan_countcxx . . $ fan_count. = 1; |
| 377 | } |
| 378 | |
| 379 | result = statcxx . . $ stat(a9cd1e23e96f423c).(fan2_mincxx . . $ fan2_min., &buf); |
| 380 | if(result != 0) |
| 381 | { |
| 382 | printfcxx . . $ printf(581fddd72a8db8fc).("Found 1 fan.\n"); |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | fan_countcxx . . $ fan_count. = 2; |
| 387 | printfcxx . . $ printf(581fddd72a8db8fc).("Found 2 fans.\n"); |
| 388 | } |
| 389 | |
| 390 | // count number of sensors |
| 391 | |
| 392 | int count = 0; |
| 393 | while(count < 100) // more than 100 sensors is an error! |
| 394 | { |
| 395 | char fname[512]; |
| 396 | |
| 397 | // sensor numbering start at 1 |
| 398 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(fname, "%s/temp%d_input", base_pathcxx . . $ base_path., count + 1); |
| 399 | result = statcxx . . $ stat(a9cd1e23e96f423c).(fname, &buf); |
| 400 | |
| 401 | if(result == 0) |
| 402 | { |
| 403 | ++count; |
| 404 | } |
| 405 | else |
| 406 | { |
| 407 | break; // done |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | sensor_countcxx . . $ sensor_count. = count; |
| 412 | |
| 413 | if(sensor_countcxx . . $ sensor_count. > 0) |
| 414 | { |
| 415 | // Get sensor id, labels and descriptions, check exclude list |
| 416 | |
| 417 | if(sensorscxx . . $ sensors. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 418 | { |
| 419 | freecxx . . $ free(5d22bdacc48458e8).(sensorscxx . . $ sensors.); |
| 420 | } |
| 421 | |
| 422 | sensorscxx . . $ sensors. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct sensorcxx . . $ sensor#) * sensor_countcxx . . $ sensor_count.); |
| 423 | assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(sensors != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 424 | |
| 425 | printfcxx . . $ printf(581fddd72a8db8fc).("Found %d sensors:\n", sensor_countcxx . . $ sensor_count.); |
| 426 | |
| 427 | for(i = 0; i < sensor_countcxx . . $ sensor_count.; ++i) |
| 428 | { |
| 429 | char fname[512]; |
| 430 | |
| 431 | // set id, check exclude list and save file name |
| 432 | sensorscxx . . $ sensors.[i].idcxx . . $ sensor#id. = i + 1; |
| 433 | sensorscxx . . $ sensors.[i].excludedcxx . . $ sensor#excluded. = 0; |
| 434 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(sensorscxx . . $ sensors.[i].fnamecxx . . $ sensor#fname., "%s/temp%d_input", base_pathcxx . . $ base_path., sensorscxx . . $ sensors.[i].idcxx . . $ sensor#id.); |
| 435 | |
| 436 | for(j = 0; j < MAX_EXCLUDEcxx . . $ `config.h:36:9`! && excludecxx . . $ exclude.[j] != 0; ++j) |
| 437 | { |
| 438 | if(excludecxx . . $ exclude.[j] == sensorscxx . . $ sensors.[i].idcxx . . $ sensor#id.) |
| 439 | { |
| 440 | sensorscxx . . $ sensors.[i].excludedcxx . . $ sensor#excluded. = 1; |
| 441 | break; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | // read label |
| 446 | sprintfcxx . . $ sprintf(26c8642d26409d6d).(fname, "%s/temp%d_label", base_pathcxx . . $ base_path., sensorscxx . . $ sensors.[i].idcxx . . $ sensor#id.); |
| 447 | |
| 448 | sensorscxx . . $ sensors.[i].namecxx . . $ sensor#name.[0] = 0; // set zero length |
| 449 | |
| 450 | FILEcxx . . $ FILE# *fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(fname, "r"); |
| 451 | if(fp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 452 | { |
| 453 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't open %s\n", fname); |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | char key_buf[SENSKEY_MAXLENcxx . . $ `control.c:59:9`!]; |
| 458 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(key_buf, 0, SENSKEY_MAXLENcxx . . $ `control.c:59:9`!); |
| 459 | |
| 460 | int n = freadcxx . . $ fread(738fc8ac1d711e58).(key_buf, 1, SENSKEY_MAXLENcxx . . $ `control.c:59:9`! - 1, fp); |
| 461 | if(n < 1) |
| 462 | { |
| 463 | printfcxx . . $ printf(581fddd72a8db8fc).("Error: Can't read %s\n", fname); |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | char *p_endl = strrchrcxx . . $ strrchr(2050848944e00d54).(key_buf, '\n'); |
| 468 | if(p_endl) |
| 469 | { |
| 470 | *p_endl = 0; // remove '\n' |
| 471 | } |
| 472 | strncpycxx . . $ strncpy(255158a415b673b0).(sensorscxx . . $ sensors.[i].namecxx . . $ sensor#name., key_buf, SENSKEY_MAXLENcxx . . $ `control.c:59:9`!); |
| 473 | } |
| 474 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp); |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | for(i = 0; i < sensor_countcxx . . $ sensor_count.; ++i) // for each label found |
| 479 | { |
| 480 | if(! sensorscxx . . $ sensors.[i].excludedcxx . . $ sensor#excluded.) |
| 481 | { |
| 482 | // try to find TC0P and TG0P |
| 483 | // if found, assign sensor_TC0P and sensor_TG0P for later use |
| 484 | |
| 485 | if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(sensorscxx . . $ sensors.[i].namecxx . . $ sensor#name., "TC0P") == 0) |
| 486 | { |
| 487 | sensor_TC0Pcxx . . $ sensor_TC0P. = &sensorscxx . . $ sensors.[i]; |
| 488 | } |
| 489 | else if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(sensorscxx . . $ sensors.[i].namecxx . . $ sensor#name., "TG0P") == 0) |
| 490 | { |
| 491 | sensor_TG0Pcxx . . $ sensor_TG0P. = &sensorscxx . . $ sensors.[i]; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | // print out sensor information. |
| 496 | |
| 497 | printfcxx . . $ printf(581fddd72a8db8fc).("\t%2d: ", sensorscxx . . $ sensors.[i].idcxx . . $ sensor#id.); |
| 498 | |
| 499 | int found = 0; |
| 500 | for(j = 0; j < N_DESCcxx . . $ `control.c:57:9`! && ! found; ++j) // find in descriptions table |
| 501 | { |
| 502 | if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(sensorscxx . . $ sensors.[i].namecxx . . $ sensor#name., sensor_desccxx . . $ sensor_desc.[j].keycxx . . $ $anonymous_type_81c162c42d143ee8_0#key.) == 0) |
| 503 | { |
| 504 | found = 1; |
| 505 | printfcxx . . $ printf(581fddd72a8db8fc).("%s - %s", sensor_desccxx . . $ sensor_desc.[j].keycxx . . $ $anonymous_type_81c162c42d143ee8_0#key., sensor_desccxx . . $ sensor_desc.[j].desccxx . . $ $anonymous_type_81c162c42d143ee8_0#desc.); |
| 506 | } |
| 507 | } |
| 508 | if(! found) |
| 509 | { |
| 510 | printfcxx . . $ printf(581fddd72a8db8fc).("%s - ?", sensorscxx . . $ sensors.[i].namecxx . . $ sensor#name.); |
| 511 | } |
| 512 | |
| 513 | printfcxx . . $ printf(581fddd72a8db8fc).(" %s\n", sensorscxx . . $ sensors.[i].excludedcxx . . $ sensor#excluded. ? " ***EXCLUDED***" : ""); |
| 514 | } |
| 515 | } |
| 516 | else |
| 517 | { |
| 518 | printfcxx . . $ printf(581fddd72a8db8fc).("No sensors detected, terminating!\n"); |
| 519 | exitcxx . . $ exit(3ca292c338df9bb3).(-1); |
| 520 | } |
| 521 | |
| 522 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 523 | } |
| 524 | |
| 525 | //------------------------------------------------------------------------------ |
| 526 | |
| 527 | void loggercxx . . $ logger(d878ad36e69247c7).() |
| 528 | { |
| 529 | int i; |
| 530 | |
| 531 | if(log_levelcxx . . $ log_level. > 0) |
| 532 | { |
| 533 | printfcxx . . $ printf(581fddd72a8db8fc).("Speed: %d, %sAVG: %.1fC" , |
| 534 | fan_speedcxx . . $ fan_speed., |
| 535 | fan_ctlcxx . . $ fan_ctl. == CTL_AVGcxx . . $ `control.c:88:9`! ? "*" : " ", |
| 536 | temp_avgcxx . . $ temp_avg.); |
| 537 | |
| 538 | if(sensor_TC0Pcxx . . $ sensor_TC0P. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 539 | { |
| 540 | printfcxx . . $ printf(581fddd72a8db8fc).(", %sTC0P: %.1fC" , |
| 541 | fan_ctlcxx . . $ fan_ctl. == CTL_TC0Pcxx . . $ `control.c:89:9`! ? "*" : " ", |
| 542 | sensor_TC0Pcxx . . $ sensor_TC0P.->valuecxx . . $ sensor#value.); |
| 543 | } |
| 544 | |
| 545 | if(sensor_TG0Pcxx . . $ sensor_TG0P. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 546 | { |
| 547 | printfcxx . . $ printf(581fddd72a8db8fc).(", %sTG0P: %.1fC" , |
| 548 | fan_ctlcxx . . $ fan_ctl. == CTL_TG0Pcxx . . $ `control.c:90:9`! ? "*" : " ", |
| 549 | sensor_TG0Pcxx . . $ sensor_TG0P.->valuecxx . . $ sensor#value.); |
| 550 | } |
| 551 | |
| 552 | if(log_levelcxx . . $ log_level. > 1) |
| 553 | { |
| 554 | printfcxx . . $ printf(581fddd72a8db8fc).(", Sensors: "); |
| 555 | for(i = 0; i < sensor_countcxx . . $ sensor_count.; ++i) |
| 556 | { |
| 557 | if(! sensorscxx . . $ sensors.[i].excludedcxx . . $ sensor#excluded.) |
| 558 | { |
| 559 | printfcxx . . $ printf(581fddd72a8db8fc).("%s:%.0f ", sensorscxx . . $ sensors.[i].namecxx . . $ sensor#name., sensorscxx . . $ sensors.[i].valuecxx . . $ sensor#value.); |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 565 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | //------------------------------------------------------------------------------ |
| 570 |