mirror of
https://github.com/hholtmann/smcFanControl.git
synced 2025-11-04 19:49:16 +01:00
Use SMC for temp and only use IOHIDSensor based on a whitelist for when SMC is unavailable
This commit is contained in:
@ -25,7 +25,7 @@
|
||||
#import "NSFileManager+DirectoryLocations.h"
|
||||
#import "smc.h"
|
||||
#import "smcWrapper.h"
|
||||
#import "IOKitSensor.h"
|
||||
#import "IOHIDSensor.h"
|
||||
#import "MachineDefaults.h"
|
||||
|
||||
#import "Power.h"
|
||||
|
||||
@ -151,7 +151,7 @@ NSUserDefaults *defaults;
|
||||
@0, PREF_CHARGING_SELECTION,
|
||||
@0, PREF_MENU_DISPLAYMODE,
|
||||
#if TARGET_CPU_ARM64
|
||||
@"",PREF_TEMPERATURE_SENSOR,
|
||||
@"Tp0D",PREF_TEMPERATURE_SENSOR,
|
||||
#else
|
||||
@"TC0D",PREF_TEMPERATURE_SENSOR,
|
||||
#endif
|
||||
@ -338,6 +338,13 @@ NSUserDefaults *defaults;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)usesIOHIDForTemperature {
|
||||
#if TARGET_CPU_ARM64
|
||||
return [[MachineDefaults computerModel] rangeOfString:@"MacBookPro17"].length > 0;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Called via a timer mechanism. This is where all the temp / RPM reading is done.
|
||||
//reads fan data and updates the gui
|
||||
@ -403,11 +410,11 @@ NSUserDefaults *defaults;
|
||||
|
||||
if (bNeedTemp == true) {
|
||||
// Read current temperature and format text for the menubar.
|
||||
#if TARGET_CPU_ARM64
|
||||
c_temp = [IOKitSensor getSOCTemperature];
|
||||
#else
|
||||
if ([self usesIOHIDForTemperature]) {
|
||||
c_temp = [IOHIDSensor getSOCTemperature];
|
||||
} else {
|
||||
c_temp = [smcWrapper get_maintemp];
|
||||
#endif
|
||||
}
|
||||
|
||||
if ([[defaults objectForKey:PREF_TEMP_UNIT] intValue]==0) {
|
||||
temp = [NSString stringWithFormat:@"%@%CC",@(c_temp),(unsigned short)0xb0];
|
||||
|
||||
@ -49,7 +49,7 @@ void IOHIDEventSystemClientSetMatching(IOHIDEventSystemClientRef, CFDictionaryRe
|
||||
IOHIDEventRef IOHIDServiceClientCopyEvent(IOHIDServiceClientRef, int64_t, int32_t, int64_t);
|
||||
IOHIDFloat IOHIDEventGetFloatValue(IOHIDEventRef event, uint32_t field);
|
||||
|
||||
@interface IOKitSensor : NSObject {
|
||||
@interface IOHIDSensor : NSObject {
|
||||
}
|
||||
|
||||
+ (float) getSOCTemperature;
|
||||
@ -20,13 +20,12 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#import "IOKitSensor.h"
|
||||
#import "IOHIDSensor.h"
|
||||
|
||||
@implementation IOKitSensor
|
||||
@implementation IOHIDSensor
|
||||
|
||||
static BOOL isSOCSensor(CFStringRef sensorName) {
|
||||
return CFStringHasPrefix(sensorName, CFSTR("PMU")) &&
|
||||
!CFStringHasSuffix(sensorName, CFSTR("tcal")); // Ignore "PMU tcal" as it seems static
|
||||
return CFStringFind(sensorName, CFSTR("SOC"), kCFCompareCaseInsensitive).location != kCFNotFound;
|
||||
}
|
||||
|
||||
static float toOneDecimalPlace(float value) {
|
||||
@ -34,7 +33,6 @@ static float toOneDecimalPlace(float value) {
|
||||
}
|
||||
|
||||
+ (float) getSOCTemperature {
|
||||
|
||||
IOHIDEventSystemClientRef eventSystemClient = IOHIDEventSystemClientCreate(kCFAllocatorDefault);
|
||||
CFArrayRef services = IOHIDEventSystemClientCopyServices(eventSystemClient);
|
||||
if (services) {
|
||||
@ -62,7 +60,7 @@ static float toOneDecimalPlace(float value) {
|
||||
CFRelease(services);
|
||||
CFRelease(eventSystemClient);
|
||||
|
||||
float avgSOCTemp = socSensorCount > 0 ? socSensorSum / socSensorCount: 0.0f;
|
||||
float avgSOCTemp = socSensorCount > 0 ? socSensorSum / socSensorCount : 0.0f;
|
||||
return toOneDecimalPlace(avgSOCTemp);
|
||||
}
|
||||
|
||||
@ -70,7 +70,11 @@ NSArray *allSensors;
|
||||
NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:PREF_TEMPERATURE_SENSOR];
|
||||
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
||||
retValue = [self convertToNumber:val];
|
||||
#if TARGET_CPU_ARM64
|
||||
allSensors = [NSArray arrayWithObjects:@"Tp01",@"Tp05",@"Tp09",@"Tp0b",@"Tp0D",@"Tp0H",@"Tp0L",@"Tp0P",@"Tp0T",@"Tp0X",nil];
|
||||
#else
|
||||
allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil];
|
||||
#endif
|
||||
if (retValue<=0 || floor(retValue) == 129 ) { //workaround for some iMac Models
|
||||
for (NSString *sensor in allSensors) {
|
||||
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
|
||||
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
B5A4D43B293A62F90084C50B /* IOKitSensor.m in Sources */ = {isa = PBXBuildFile; fileRef = B5A4D43A293A62F90084C50B /* IOKitSensor.m */; };
|
||||
B5A4D43B293A62F90084C50B /* IOHIDSensor.m in Sources */ = {isa = PBXBuildFile; fileRef = B5A4D43A293A62F90084C50B /* IOHIDSensor.m */; };
|
||||
B5F20EE127FBCC78002EFD11 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 895BDA390B8F8F42003CD894 /* Sparkle.framework */; };
|
||||
B5F20EE227FBCC78002EFD11 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 895BDA390B8F8F42003CD894 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
|
||||
/* End PBXBuildFile section */
|
||||
@ -122,8 +122,8 @@
|
||||
89FE24280B7F4CE900D2713C /* German */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = German; path = German.lproj/MainMenu.nib; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
8D1107320486CEB800E47090 /* smcFanControl.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = smcFanControl.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B5A4D43A293A62F90084C50B /* IOKitSensor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IOKitSensor.m; sourceTree = "<group>"; };
|
||||
B5E84C88293A65840067AEC2 /* IOKitSensor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOKitSensor.h; sourceTree = "<group>"; };
|
||||
B5A4D43A293A62F90084C50B /* IOHIDSensor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IOHIDSensor.m; sourceTree = "<group>"; };
|
||||
B5E84C88293A65840067AEC2 /* IOHIDSensor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOHIDSensor.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -168,8 +168,8 @@
|
||||
892A7F440B10B7700041B493 /* MachineDefaults.m */,
|
||||
8932CF2213D0850F008BC447 /* SystemVersion.h */,
|
||||
8932CF2313D08551008BC447 /* SystemVersion.m */,
|
||||
B5E84C88293A65840067AEC2 /* IOKitSensor.h */,
|
||||
B5A4D43A293A62F90084C50B /* IOKitSensor.m */,
|
||||
B5E84C88293A65840067AEC2 /* IOHIDSensor.h */,
|
||||
B5A4D43A293A62F90084C50B /* IOHIDSensor.m */,
|
||||
);
|
||||
path = Classes;
|
||||
sourceTree = "<group>";
|
||||
@ -388,7 +388,7 @@
|
||||
892A7F450B10B7700041B493 /* MachineDefaults.m in Sources */,
|
||||
8932CF2413D08551008BC447 /* SystemVersion.m in Sources */,
|
||||
89148EA315E2543D00A073EE /* NSFileManager+DirectoryLocations.m in Sources */,
|
||||
B5A4D43B293A62F90084C50B /* IOKitSensor.m in Sources */,
|
||||
B5A4D43B293A62F90084C50B /* IOHIDSensor.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user