diff --git a/Classes/FanControl.h b/Classes/FanControl.h index ca7dae6..d90124e 100755 --- a/Classes/FanControl.h +++ b/Classes/FanControl.h @@ -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" diff --git a/Classes/FanControl.m b/Classes/FanControl.m index 70219d2..0508033 100755 --- a/Classes/FanControl.m +++ b/Classes/FanControl.m @@ -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 - c_temp = [smcWrapper get_maintemp]; -#endif + if ([self usesIOHIDForTemperature]) { + c_temp = [IOHIDSensor getSOCTemperature]; + } else { + c_temp = [smcWrapper get_maintemp]; + } if ([[defaults objectForKey:PREF_TEMP_UNIT] intValue]==0) { temp = [NSString stringWithFormat:@"%@%CC",@(c_temp),(unsigned short)0xb0]; @@ -543,13 +550,13 @@ NSUserDefaults *defaults; } -(void)setFansToAuto:(bool)is_auto { - for (int fan_index=0;fan_index<[[FavoritesController arrangedObjects][0][PREF_FAN_ARRAY] count];fan_index++) { - [self setFanToAuto:fan_index is_auto:is_auto]; - } + for (int fan_index=0;fan_index<[[FavoritesController arrangedObjects][0][PREF_FAN_ARRAY] count];fan_index++) { + [self setFanToAuto:fan_index is_auto:is_auto]; + } } -(void)setFanToAuto:(int)fan_index is_auto:(bool)is_auto { - [smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",fan_index] value:is_auto ? @"00" : @"01"]; + [smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",fan_index] value:is_auto ? @"00" : @"01"]; } //set the new fan settings @@ -750,8 +757,8 @@ NSUserDefaults *defaults; - (void)systemWillSleep:(id)sender{ #if TARGET_CPU_ARM64 - [FanControl setRights]; - [self setFansToAuto:true]; + [FanControl setRights]; + [self setFansToAuto:true]; #endif } diff --git a/Classes/IOKitSensor.h b/Classes/IOHIDSensor.h similarity index 98% rename from Classes/IOKitSensor.h rename to Classes/IOHIDSensor.h index c87654b..8721f0b 100644 --- a/Classes/IOKitSensor.h +++ b/Classes/IOHIDSensor.h @@ -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; diff --git a/Classes/IOKitSensor.m b/Classes/IOHIDSensor.m similarity index 91% rename from Classes/IOKitSensor.m rename to Classes/IOHIDSensor.m index 2e66daa..efd2a58 100644 --- a/Classes/IOKitSensor.m +++ b/Classes/IOHIDSensor.m @@ -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); } diff --git a/Classes/smcWrapper.m b/Classes/smcWrapper.m index 7828059..83d7419 100755 --- a/Classes/smcWrapper.m +++ b/Classes/smcWrapper.m @@ -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); diff --git a/smcFanControl.xcodeproj/project.pbxproj b/smcFanControl.xcodeproj/project.pbxproj index fb7a42a..0b8b701 100644 --- a/smcFanControl.xcodeproj/project.pbxproj +++ b/smcFanControl.xcodeproj/project.pbxproj @@ -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 = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 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 = ""; }; - B5E84C88293A65840067AEC2 /* IOKitSensor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOKitSensor.h; sourceTree = ""; }; + B5A4D43A293A62F90084C50B /* IOHIDSensor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IOHIDSensor.m; sourceTree = ""; }; + B5E84C88293A65840067AEC2 /* IOHIDSensor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOHIDSensor.h; sourceTree = ""; }; /* 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 = ""; @@ -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; };