mirror of
https://github.com/hholtmann/smcFanControl.git
synced 2025-11-04 19:49:16 +01:00
On Apple Silicon set the fan to Auto before sleeping. systemDidWakeFromSleep will set the previous selection on wake
This commit is contained in:
@ -29,7 +29,6 @@
|
||||
#import <Security/AuthorizationTags.h>
|
||||
#import <Sparkle/SUUpdater.h>
|
||||
#import "SystemVersion.h"
|
||||
#include "TargetConditionals.h"
|
||||
|
||||
@interface FanControl ()
|
||||
+ (void)copyMachinesIfNecessary;
|
||||
@ -151,11 +150,7 @@ NSUserDefaults *defaults;
|
||||
@0, PREF_AC_SELECTION,
|
||||
@0, PREF_CHARGING_SELECTION,
|
||||
@0, PREF_MENU_DISPLAYMODE,
|
||||
#if TARGET_CPU_ARM64
|
||||
@"Tp0D",PREF_TEMPERATURE_SENSOR,
|
||||
#else
|
||||
@"TC0D",PREF_TEMPERATURE_SENSOR,
|
||||
#endif
|
||||
[MachineDefaults isAppleSilicon] ? @"Tp0D" : @"TC0D", PREF_TEMPERATURE_SENSOR,
|
||||
@0, PREF_NUMBEROF_LAUNCHES,
|
||||
@NO,PREF_DONATIONMESSAGE_DISPLAY,
|
||||
[NSArchiver archivedDataWithRootObject:[NSColor blackColor]],PREF_MENU_TEXTCOLOR,
|
||||
@ -540,6 +535,17 @@ 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];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setFanToAuto:(int)fan_index is_auto:(bool)is_auto {
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",fan_index] value:is_auto ? @"00" : @"01"];
|
||||
}
|
||||
|
||||
//set the new fan settings
|
||||
|
||||
-(void)apply_settings:(id)sender controllerindex:(int)cIndex{
|
||||
@ -554,7 +560,7 @@ NSUserDefaults *defaults;
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMn",i] value:[[FanController arrangedObjects][i][PREF_FAN_SELSPEED] tohex]];
|
||||
} else {
|
||||
bool is_auto = [[FanController arrangedObjects][i][PREF_FAN_AUTO] boolValue];
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",i] value:is_auto ? @"00" : @"01"];
|
||||
[self setFanToAuto:i is_auto:is_auto];
|
||||
float f_val = [[FanController arrangedObjects][i][PREF_FAN_SELSPEED] floatValue];
|
||||
uint8 *vals = (uint8*)&f_val;
|
||||
//NSString str_val = ;
|
||||
@ -681,9 +687,7 @@ NSUserDefaults *defaults;
|
||||
}
|
||||
error = nil;
|
||||
if ([[MachineDefaults computerModel] rangeOfString:@"MacBookPro15"].location != NSNotFound) {
|
||||
for (int i=0;i<[[FavoritesController arrangedObjects][0][PREF_FAN_ARRAY] count];i++) {
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",i] value:@"00"];
|
||||
}
|
||||
[self setFansToAuto:true];
|
||||
}
|
||||
|
||||
NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
|
||||
@ -738,6 +742,13 @@ NSUserDefaults *defaults;
|
||||
|
||||
#pragma mark **Power Watchdog-Methods**
|
||||
|
||||
- (void)systemWillSleep:(id)sender{
|
||||
if ([MachineDefaults isAppleSilicon]) {
|
||||
[FanControl setRights];
|
||||
[self setFansToAuto:true];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)systemDidWakeFromSleep:(id)sender{
|
||||
[self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]];
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@
|
||||
int machine_num;
|
||||
}
|
||||
|
||||
+ (BOOL)isAppleSilicon;
|
||||
+ (NSString *)computerModel;
|
||||
- (instancetype)init:(NSString*)p_machine ;
|
||||
|
||||
|
||||
@ -22,6 +22,9 @@
|
||||
|
||||
#import "MachineDefaults.h"
|
||||
#import "NSFileManager+DirectoryLocations.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <mach/machine.h>
|
||||
|
||||
@interface MachineDefaults ()
|
||||
{
|
||||
@ -123,6 +126,14 @@
|
||||
return defaultsDict;
|
||||
}
|
||||
|
||||
+ (BOOL)isAppleSilicon
|
||||
{
|
||||
cpu_type_t cpu_type;
|
||||
size_t size = sizeof(cpu_type);
|
||||
sysctlbyname("hw.cputype", &cpu_type, &size, NULL, 0);
|
||||
return cpu_type == CPU_TYPE_ARM64;
|
||||
}
|
||||
|
||||
+ (NSString *)computerModel
|
||||
{
|
||||
static NSString *computerModel = nil;
|
||||
|
||||
@ -58,6 +58,8 @@
|
||||
//delegate Prototypes
|
||||
@interface NSObject (PowerDelegate)
|
||||
|
||||
- (void)systemWillSleep:(id)sender;
|
||||
|
||||
- (void)systemDidWakeFromSleep:(id)sender;
|
||||
|
||||
- (void)powerChangeToBattery:(id)sender;
|
||||
|
||||
@ -101,6 +101,7 @@ static void powerSourceChanged(void * refCon)
|
||||
switch (messageType)
|
||||
{
|
||||
case kIOMessageSystemWillSleep:
|
||||
[_delegate systemWillSleep:self];
|
||||
IOAllowPowerChange(root_port, (long)messageArgument);
|
||||
break;
|
||||
case kIOMessageCanSystemSleep:
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
*/
|
||||
|
||||
#import "smcWrapper.h"
|
||||
#include "TargetConditionals.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
NSString * const smc_checksum=@"4fc00a0979970ee8b55f078a0c793c4d";
|
||||
|
||||
@ -71,11 +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
|
||||
if ([MachineDefaults isAppleSilicon]) {
|
||||
allSensors = [NSArray arrayWithObjects:@"Tp0D",@"Tp0P",nil];
|
||||
#else
|
||||
} 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);
|
||||
|
||||
Reference in New Issue
Block a user