forked from mirror/smcFanControl
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 <Security/AuthorizationTags.h>
|
||||||
#import <Sparkle/SUUpdater.h>
|
#import <Sparkle/SUUpdater.h>
|
||||||
#import "SystemVersion.h"
|
#import "SystemVersion.h"
|
||||||
#include "TargetConditionals.h"
|
|
||||||
|
|
||||||
@interface FanControl ()
|
@interface FanControl ()
|
||||||
+ (void)copyMachinesIfNecessary;
|
+ (void)copyMachinesIfNecessary;
|
||||||
@ -151,11 +150,7 @@ NSUserDefaults *defaults;
|
|||||||
@0, PREF_AC_SELECTION,
|
@0, PREF_AC_SELECTION,
|
||||||
@0, PREF_CHARGING_SELECTION,
|
@0, PREF_CHARGING_SELECTION,
|
||||||
@0, PREF_MENU_DISPLAYMODE,
|
@0, PREF_MENU_DISPLAYMODE,
|
||||||
#if TARGET_CPU_ARM64
|
[MachineDefaults isAppleSilicon] ? @"Tp0D" : @"TC0D", PREF_TEMPERATURE_SENSOR,
|
||||||
@"Tp0D",PREF_TEMPERATURE_SENSOR,
|
|
||||||
#else
|
|
||||||
@"TC0D",PREF_TEMPERATURE_SENSOR,
|
|
||||||
#endif
|
|
||||||
@0, PREF_NUMBEROF_LAUNCHES,
|
@0, PREF_NUMBEROF_LAUNCHES,
|
||||||
@NO,PREF_DONATIONMESSAGE_DISPLAY,
|
@NO,PREF_DONATIONMESSAGE_DISPLAY,
|
||||||
[NSArchiver archivedDataWithRootObject:[NSColor blackColor]],PREF_MENU_TEXTCOLOR,
|
[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
|
//set the new fan settings
|
||||||
|
|
||||||
-(void)apply_settings:(id)sender controllerindex:(int)cIndex{
|
-(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]];
|
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMn",i] value:[[FanController arrangedObjects][i][PREF_FAN_SELSPEED] tohex]];
|
||||||
} else {
|
} else {
|
||||||
bool is_auto = [[FanController arrangedObjects][i][PREF_FAN_AUTO] boolValue];
|
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];
|
float f_val = [[FanController arrangedObjects][i][PREF_FAN_SELSPEED] floatValue];
|
||||||
uint8 *vals = (uint8*)&f_val;
|
uint8 *vals = (uint8*)&f_val;
|
||||||
//NSString str_val = ;
|
//NSString str_val = ;
|
||||||
@ -681,9 +687,7 @@ NSUserDefaults *defaults;
|
|||||||
}
|
}
|
||||||
error = nil;
|
error = nil;
|
||||||
if ([[MachineDefaults computerModel] rangeOfString:@"MacBookPro15"].location != NSNotFound) {
|
if ([[MachineDefaults computerModel] rangeOfString:@"MacBookPro15"].location != NSNotFound) {
|
||||||
for (int i=0;i<[[FavoritesController arrangedObjects][0][PREF_FAN_ARRAY] count];i++) {
|
[self setFansToAuto:true];
|
||||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",i] value:@"00"];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
|
NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
|
||||||
@ -738,6 +742,13 @@ NSUserDefaults *defaults;
|
|||||||
|
|
||||||
#pragma mark **Power Watchdog-Methods**
|
#pragma mark **Power Watchdog-Methods**
|
||||||
|
|
||||||
|
- (void)systemWillSleep:(id)sender{
|
||||||
|
if ([MachineDefaults isAppleSilicon]) {
|
||||||
|
[FanControl setRights];
|
||||||
|
[self setFansToAuto:true];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)systemDidWakeFromSleep:(id)sender{
|
- (void)systemDidWakeFromSleep:(id)sender{
|
||||||
[self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]];
|
[self apply_settings:nil controllerindex:[[defaults objectForKey:PREF_SELECTION_DEFAULT] intValue]];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
int machine_num;
|
int machine_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (BOOL)isAppleSilicon;
|
||||||
+ (NSString *)computerModel;
|
+ (NSString *)computerModel;
|
||||||
- (instancetype)init:(NSString*)p_machine ;
|
- (instancetype)init:(NSString*)p_machine ;
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#import "MachineDefaults.h"
|
#import "MachineDefaults.h"
|
||||||
#import "NSFileManager+DirectoryLocations.h"
|
#import "NSFileManager+DirectoryLocations.h"
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <mach/machine.h>
|
||||||
|
|
||||||
@interface MachineDefaults ()
|
@interface MachineDefaults ()
|
||||||
{
|
{
|
||||||
@ -123,6 +126,14 @@
|
|||||||
return defaultsDict;
|
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
|
+ (NSString *)computerModel
|
||||||
{
|
{
|
||||||
static NSString *computerModel = nil;
|
static NSString *computerModel = nil;
|
||||||
|
|||||||
@ -58,6 +58,8 @@
|
|||||||
//delegate Prototypes
|
//delegate Prototypes
|
||||||
@interface NSObject (PowerDelegate)
|
@interface NSObject (PowerDelegate)
|
||||||
|
|
||||||
|
- (void)systemWillSleep:(id)sender;
|
||||||
|
|
||||||
- (void)systemDidWakeFromSleep:(id)sender;
|
- (void)systemDidWakeFromSleep:(id)sender;
|
||||||
|
|
||||||
- (void)powerChangeToBattery:(id)sender;
|
- (void)powerChangeToBattery:(id)sender;
|
||||||
|
|||||||
@ -101,6 +101,7 @@ static void powerSourceChanged(void * refCon)
|
|||||||
switch (messageType)
|
switch (messageType)
|
||||||
{
|
{
|
||||||
case kIOMessageSystemWillSleep:
|
case kIOMessageSystemWillSleep:
|
||||||
|
[_delegate systemWillSleep:self];
|
||||||
IOAllowPowerChange(root_port, (long)messageArgument);
|
IOAllowPowerChange(root_port, (long)messageArgument);
|
||||||
break;
|
break;
|
||||||
case kIOMessageCanSystemSleep:
|
case kIOMessageCanSystemSleep:
|
||||||
|
|||||||
@ -22,7 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import "smcWrapper.h"
|
#import "smcWrapper.h"
|
||||||
#include "TargetConditionals.h"
|
|
||||||
#import <CommonCrypto/CommonDigest.h>
|
#import <CommonCrypto/CommonDigest.h>
|
||||||
NSString * const smc_checksum=@"4fc00a0979970ee8b55f078a0c793c4d";
|
NSString * const smc_checksum=@"4fc00a0979970ee8b55f078a0c793c4d";
|
||||||
|
|
||||||
@ -71,11 +70,11 @@ NSArray *allSensors;
|
|||||||
NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:PREF_TEMPERATURE_SENSOR];
|
NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:PREF_TEMPERATURE_SENSOR];
|
||||||
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
||||||
retValue = [self convertToNumber:val];
|
retValue = [self convertToNumber:val];
|
||||||
#if TARGET_CPU_ARM64
|
if ([MachineDefaults isAppleSilicon]) {
|
||||||
allSensors = [NSArray arrayWithObjects:@"Tp0D",@"Tp0P",nil];
|
allSensors = [NSArray arrayWithObjects:@"Tp0D",@"Tp0P",nil];
|
||||||
#else
|
} else {
|
||||||
allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil];
|
allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil];
|
||||||
#endif
|
}
|
||||||
if (retValue<=0 || floor(retValue) == 129 ) { //workaround for some iMac Models
|
if (retValue<=0 || floor(retValue) == 129 ) { //workaround for some iMac Models
|
||||||
for (NSString *sensor in allSensors) {
|
for (NSString *sensor in allSensors) {
|
||||||
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
||||||
|
|||||||
Reference in New Issue
Block a user