-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from RaafatAkkad/master
Add support for Apple Silicon
- Loading branch information
Showing
351 changed files
with
7,702 additions
and
962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* FanControl | ||
* | ||
* Copyright (c) 2006-2012 Hendrik Holtmann | ||
* | ||
* IOHIDSensor.h - MacBook(Pro) FanControl application | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import <IOKit/hidsystem/IOHIDEventSystemClient.h> | ||
#import <IOKit/hidsystem/IOHIDServiceClient.h> | ||
|
||
// https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-1035.70.7/IOHIDFamily/AppleHIDUsageTables.h.auto.html | ||
#define kHIDPage_AppleVendor 0xff00 | ||
#define kHIDUsage_AppleVendor_TemperatureSensor 0x0005 | ||
|
||
// https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-1035.70.7/IOHIDFamily/IOHIDEventTypes.h.auto.html | ||
#ifdef __LP64__ | ||
typedef double IOHIDFloat; | ||
#else | ||
typedef float IOHIDFloat; | ||
#endif | ||
|
||
// https://opensource.apple.com/source/IOHIDFamily/IOHIDFamily-1035.70.7/IOHIDFamily/IOHIDEventTypes.h.auto.html | ||
#define IOHIDEventFieldBase(type) (type << 16) | ||
#define kIOHIDEventTypeTemperature 15 | ||
|
||
|
||
typedef struct __IOHIDEvent *IOHIDEventRef; | ||
typedef struct __IOHIDServiceClient *IOHIDServiceClientRef; | ||
|
||
IOHIDEventSystemClientRef IOHIDEventSystemClientCreate(CFAllocatorRef); | ||
void IOHIDEventSystemClientSetMatching(IOHIDEventSystemClientRef, CFDictionaryRef); | ||
IOHIDEventRef IOHIDServiceClientCopyEvent(IOHIDServiceClientRef, int64_t, int32_t, int64_t); | ||
IOHIDFloat IOHIDEventGetFloatValue(IOHIDEventRef event, uint32_t field); | ||
|
||
@interface IOHIDSensor : NSObject { | ||
} | ||
|
||
+ (float) getSOCTemperature; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* FanControl | ||
* | ||
* Copyright (c) 2006-2012 Hendrik Holtmann | ||
* | ||
* IOHIDSensor.m - MacBook(Pro) FanControl application | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
#import "IOHIDSensor.h" | ||
|
||
@implementation IOHIDSensor | ||
|
||
static BOOL isSOCSensor(CFStringRef sensorName) { | ||
return CFStringFind(sensorName, CFSTR("SOC"), kCFCompareCaseInsensitive).location != kCFNotFound; | ||
} | ||
|
||
static float toOneDecimalPlace(float value) { | ||
return roundf(10.0f * value) / 10.0f; | ||
} | ||
|
||
+ (float) getSOCTemperature { | ||
IOHIDEventSystemClientRef eventSystemClient = IOHIDEventSystemClientCreate(kCFAllocatorDefault); | ||
CFArrayRef services = IOHIDEventSystemClientCopyServices(eventSystemClient); | ||
if (services) { | ||
|
||
float socSensorSum = 0.0f; | ||
int socSensorCount = 0; | ||
|
||
for (int i = 0; i < CFArrayGetCount(services); i++) { | ||
IOHIDServiceClientRef serviceClientRef = (IOHIDServiceClientRef)CFArrayGetValueAtIndex(services, i); | ||
CFStringRef sensorName = IOHIDServiceClientCopyProperty(serviceClientRef, CFSTR("Product")); | ||
if (sensorName) { | ||
if (isSOCSensor(sensorName)) { | ||
IOHIDEventRef event = IOHIDServiceClientCopyEvent(serviceClientRef, kIOHIDEventTypeTemperature, 0, 0); | ||
if (event) { | ||
IOHIDFloat sensorTemperature = IOHIDEventGetFloatValue(event, IOHIDEventFieldBase(kIOHIDEventTypeTemperature)); | ||
CFRelease(event); | ||
socSensorSum += sensorTemperature; | ||
socSensorCount++; | ||
} | ||
} | ||
CFRelease(sensorName); | ||
} | ||
} | ||
|
||
CFRelease(services); | ||
CFRelease(eventSystemClient); | ||
|
||
float avgSOCTemp = socSensorCount > 0 ? socSensorSum / socSensorCount : 0.0f; | ||
return toOneDecimalPlace(avgSOCTemp); | ||
} | ||
|
||
return 0.0f; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.