forked from mirror/smcFanControl
Merge pull request #78 from Poopi/master
Added support for MacBookPro15,1 ( Mid 2018 )
This commit is contained in:
@ -42,6 +42,7 @@
|
||||
// Number of fans reported by the hardware.
|
||||
int g_numFans = 0;
|
||||
|
||||
|
||||
NSUserDefaults *defaults;
|
||||
|
||||
#pragma mark **Init-Methods**
|
||||
@ -538,9 +539,22 @@ NSUserDefaults *defaults;
|
||||
int i;
|
||||
[FanControl setRights];
|
||||
[FavoritesController setSelectionIndex:cIndex];
|
||||
|
||||
if ([[MachineDefaults computerModel] rangeOfString:@"MacBookPro15"].location != NSNotFound) {
|
||||
for (i=0;i<[[FavoritesController arrangedObjects][cIndex][PREF_FAN_ARRAY] count];i++) {
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMd",i] value:@"01"];
|
||||
float f_val = [[FanController arrangedObjects][i][PREF_FAN_SELSPEED] floatValue];
|
||||
uint8 *vals = (uint8*)&f_val;
|
||||
//NSString str_val = ;
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dTg",i] value:[NSString stringWithFormat:@"%02x%02x%02x%02x",vals[0],vals[1],vals[2],vals[3]]];
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0;i<[[FavoritesController arrangedObjects][cIndex][PREF_FAN_ARRAY] count];i++) {
|
||||
[smcWrapper setKey_external:[NSString stringWithFormat:@"F%dMn",i] value:[[FanController arrangedObjects][i][PREF_FAN_SELSPEED] tohex]];
|
||||
}
|
||||
}
|
||||
|
||||
NSMenu *submenu = [[NSMenu alloc] init];
|
||||
|
||||
for(i=0;i<[[FavoritesController arrangedObjects] count];i++){
|
||||
@ -659,6 +673,11 @@ NSUserDefaults *defaults;
|
||||
NSLog(@"Error deleting %@",machinesPath);
|
||||
}
|
||||
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"];
|
||||
}
|
||||
}
|
||||
|
||||
NSString *domainName = [[NSBundle mainBundle] bundleIdentifier];
|
||||
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:domainName];
|
||||
|
||||
@ -37,18 +37,44 @@ NSArray *allSensors;
|
||||
SMCClose(conn);
|
||||
}
|
||||
|
||||
+(int)convertToNumber:(SMCVal_t) val
|
||||
{
|
||||
float fval = -1.0f;
|
||||
|
||||
if (strcmp(val.dataType, DATATYPE_FLT) == 0 && val.dataSize == 4) {
|
||||
memcpy(&fval,val.bytes,sizeof(float));
|
||||
}
|
||||
else if (strcmp(val.dataType, DATATYPE_FPE2) == 0 && val.dataSize == 2) {
|
||||
fval = _strtof(val.bytes, val.dataSize, 2);
|
||||
}
|
||||
else if (strcmp(val.dataType, DATATYPE_UINT16) == 0 && val.dataSize == 2) {
|
||||
fval = (float)_strtoul((char *)val.bytes, val.dataSize, 10);
|
||||
}
|
||||
else if (strcmp(val.dataType, DATATYPE_UINT8) == 0 && val.dataSize == 1) {
|
||||
fval = (float)val.bytes[0];
|
||||
}
|
||||
else if (strcmp(val.dataType, DATATYPE_SP78) == 0 && val.dataSize == 2) {
|
||||
fval = ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64;
|
||||
}
|
||||
else {
|
||||
NSLog(@"%@", [NSString stringWithFormat:@"Unknown val:%s size-%d",val.dataType,val.dataSize]);
|
||||
}
|
||||
|
||||
return (int)fval;
|
||||
}
|
||||
|
||||
+(float)readTempSensors
|
||||
{
|
||||
float retValue;
|
||||
SMCVal_t val;
|
||||
NSString *sensor = [[NSUserDefaults standardUserDefaults] objectForKey:PREF_TEMPERATURE_SENSOR];
|
||||
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
||||
retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64;
|
||||
retValue = [self convertToNumber:val];
|
||||
allSensors = [NSArray arrayWithObjects:@"TC0D",@"TC0P",@"TCAD",@"TC0H",@"TC0F",@"TCAH",@"TCBH",nil];
|
||||
if (retValue<=0 || floor(retValue) == 129 ) { //workaround for some iMac Models
|
||||
for (NSString *sensor in allSensors) {
|
||||
SMCReadKey2((char*)[sensor UTF8String], &val,conn);
|
||||
retValue= ((val.bytes[0] * 256 + val.bytes[1]) >> 2)/64;
|
||||
retValue= [self convertToNumber:val];
|
||||
if (retValue>0 && floor(retValue) != 129 ) {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:sensor forKey:PREF_TEMPERATURE_SENSOR];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
@ -86,8 +112,8 @@ NSArray *allSensors;
|
||||
SMCReadKey2(keyA, &valA,conn);
|
||||
sprintf(keyB, "TCBH");
|
||||
SMCReadKey2(keyB, &valB,conn);
|
||||
float c_tempA= ((valA.bytes[0] * 256 + valA.bytes[1]) >> 2)/64.0;
|
||||
float c_tempB= ((valB.bytes[0] * 256 + valB.bytes[1]) >> 2)/64.0;
|
||||
float c_tempA= [self convertToNumber:valA];
|
||||
float c_tempB= [self convertToNumber:valB];
|
||||
int i_tempA, i_tempB;
|
||||
if (c_tempA < c_tempB)
|
||||
{
|
||||
@ -107,7 +133,7 @@ NSArray *allSensors;
|
||||
//kern_return_t result;
|
||||
sprintf(key, "F%dAc", fan_number);
|
||||
SMCReadKey2(key, &val,conn);
|
||||
int running= _strtof(val.bytes, val.dataSize, 2);
|
||||
int running= [self convertToNumber:val];
|
||||
return running;
|
||||
}
|
||||
|
||||
@ -116,7 +142,7 @@ NSArray *allSensors;
|
||||
SMCVal_t val;
|
||||
int totalFans;
|
||||
SMCReadKey2("FNum", &val,conn);
|
||||
totalFans = _strtoul((char *)val.bytes, val.dataSize, 10);
|
||||
totalFans = [self convertToNumber:val];
|
||||
return totalFans;
|
||||
}
|
||||
|
||||
@ -126,10 +152,12 @@ NSArray *allSensors;
|
||||
SMCVal_t val;
|
||||
//kern_return_t result;
|
||||
NSMutableString *desc;
|
||||
// desc=[[NSMutableString alloc] initWithFormat:@"Fan #%d: ",fan_number+1];
|
||||
desc=[[NSMutableString alloc]init];
|
||||
|
||||
sprintf(key, "F%dID", fan_number);
|
||||
SMCReadKey2(key, &val,conn);
|
||||
|
||||
if(val.dataSize>0){
|
||||
desc=[[NSMutableString alloc]init];
|
||||
int i;
|
||||
for (i = 0; i < val.dataSize; i++) {
|
||||
if ((int)val.bytes[i]>32) {
|
||||
@ -137,6 +165,11 @@ NSArray *allSensors;
|
||||
[desc appendFormat:@"%c",temp];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
//On MacBookPro 15.1 descriptions aren't available
|
||||
desc=[[NSMutableString alloc] initWithFormat:@"Fan #%d: ",fan_number+1];
|
||||
}
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -147,7 +180,7 @@ NSArray *allSensors;
|
||||
//kern_return_t result;
|
||||
sprintf(key, "F%dMn", fan_number);
|
||||
SMCReadKey2(key, &val,conn);
|
||||
int min= _strtof(val.bytes, val.dataSize, 2);
|
||||
int min= [self convertToNumber:val];
|
||||
return min;
|
||||
}
|
||||
|
||||
@ -157,7 +190,7 @@ NSArray *allSensors;
|
||||
//kern_return_t result;
|
||||
sprintf(key, "F%dMx", fan_number);
|
||||
SMCReadKey2(key, &val,conn);
|
||||
int max= _strtof(val.bytes, val.dataSize, 2);
|
||||
int max= [self convertToNumber:val];
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
@ -83,6 +83,12 @@ float _strtof(unsigned char *str, int size, int e)
|
||||
return total;
|
||||
}
|
||||
|
||||
void printFLT(SMCVal_t val)
|
||||
{
|
||||
float fval;
|
||||
memcpy(&fval,val.bytes,sizeof(float));
|
||||
printf("%.0f ", fval);
|
||||
}
|
||||
|
||||
void printFP1F(SMCVal_t val)
|
||||
{
|
||||
@ -218,6 +224,8 @@ void printVal(SMCVal_t val)
|
||||
(strcmp(val.dataType, DATATYPE_UINT16) == 0) ||
|
||||
(strcmp(val.dataType, DATATYPE_UINT32) == 0))
|
||||
printUInt(val);
|
||||
else if (strcmp(val.dataType, DATATYPE_FLT) == 0 && val.dataSize == 4)
|
||||
printFLT(val);
|
||||
else if (strcmp(val.dataType, DATATYPE_FP1F) == 0 && val.dataSize == 2)
|
||||
printFP1F(val);
|
||||
else if (strcmp(val.dataType, DATATYPE_FP4C) == 0 && val.dataSize == 2)
|
||||
@ -504,6 +512,31 @@ kern_return_t SMCPrintAll(void)
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
|
||||
|
||||
//Fix me with other types
|
||||
float getFloatFromVal(SMCVal_t val)
|
||||
{
|
||||
float fval = -1.0f;
|
||||
|
||||
if (val.dataSize > 0)
|
||||
{
|
||||
if (strcmp(val.dataType, DATATYPE_FLT) == 0 && val.dataSize == 4) {
|
||||
memcpy(&fval,val.bytes,sizeof(float));
|
||||
}
|
||||
else if (strcmp(val.dataType, DATATYPE_FPE2) == 0 && val.dataSize == 2) {
|
||||
fval = _strtof(val.bytes, val.dataSize, 2);
|
||||
}
|
||||
else if (strcmp(val.dataType, DATATYPE_UINT16) == 0 && val.dataSize == 2) {
|
||||
fval = (float)_strtoul((char *)val.bytes, val.dataSize, 10);
|
||||
}
|
||||
else if (strcmp(val.dataType, DATATYPE_UINT8) == 0 && val.dataSize == 1) {
|
||||
fval = (float)_strtoul((char *)val.bytes, val.dataSize, 10);
|
||||
}
|
||||
}
|
||||
|
||||
return fval;
|
||||
}
|
||||
|
||||
kern_return_t SMCPrintFans(void)
|
||||
{
|
||||
kern_return_t result;
|
||||
@ -523,28 +556,40 @@ kern_return_t SMCPrintFans(void)
|
||||
printf("\nFan #%d:\n", i);
|
||||
sprintf(key, "F%dID", i);
|
||||
SMCReadKey(key, &val);
|
||||
if(val.dataSize > 0) {
|
||||
printf(" Fan ID : %s\n", val.bytes+4);
|
||||
}
|
||||
sprintf(key, "F%dAc", i);
|
||||
SMCReadKey(key, &val);
|
||||
printf(" Actual speed : %.0f\n", _strtof(val.bytes, val.dataSize, 2));
|
||||
printf(" Actual speed : %.0f\n", getFloatFromVal(val));
|
||||
sprintf(key, "F%dMn", i);
|
||||
SMCReadKey(key, &val);
|
||||
printf(" Minimum speed: %.0f\n", _strtof(val.bytes, val.dataSize, 2));
|
||||
printf(" Minimum speed: %.0f\n", getFloatFromVal(val));
|
||||
sprintf(key, "F%dMx", i);
|
||||
SMCReadKey(key, &val);
|
||||
printf(" Maximum speed: %.0f\n", _strtof(val.bytes, val.dataSize, 2));
|
||||
printf(" Maximum speed: %.0f\n", getFloatFromVal(val));
|
||||
sprintf(key, "F%dSf", i);
|
||||
SMCReadKey(key, &val);
|
||||
printf(" Safe speed : %.0f\n", _strtof(val.bytes, val.dataSize, 2));
|
||||
printf(" Safe speed : %.0f\n", getFloatFromVal(val));
|
||||
sprintf(key, "F%dTg", i);
|
||||
SMCReadKey(key, &val);
|
||||
printf(" Target speed : %.0f\n", _strtof(val.bytes, val.dataSize, 2));
|
||||
printf(" Target speed : %.0f\n", getFloatFromVal(val));
|
||||
SMCReadKey("FS! ", &val);
|
||||
if(val.dataSize > 0) {
|
||||
if ((_strtoul((char *)val.bytes, 2, 16) & (1 << i)) == 0)
|
||||
printf(" Mode : auto\n");
|
||||
else
|
||||
printf(" Mode : forced\n");
|
||||
}
|
||||
else {
|
||||
sprintf(key, "F%dMd", i);
|
||||
SMCReadKey(key, &val);
|
||||
if (getFloatFromVal(val))
|
||||
printf(" Mode : forced\n");
|
||||
else
|
||||
printf(" Mode : auto\n");
|
||||
}
|
||||
}
|
||||
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
|
||||
@ -40,6 +40,7 @@
|
||||
#define SMC_CMD_READ_PLIMIT 11
|
||||
#define SMC_CMD_READ_VERS 12
|
||||
|
||||
#define DATATYPE_FLT "flt "
|
||||
#define DATATYPE_FP1F "fp1f"
|
||||
#define DATATYPE_FP4C "fp4c"
|
||||
#define DATATYPE_FP5B "fp5b"
|
||||
|
||||
Reference in New Issue
Block a user