Skip to content

Commit 8f679fe

Browse files
committed
r0.2.2
1 parent 5dc8b95 commit 8f679fe

File tree

8 files changed

+521
-69
lines changed

8 files changed

+521
-69
lines changed

AMD Power Gadget/Base.lproj/Main.storyboard

Lines changed: 30 additions & 20 deletions
Large diffs are not rendered by default.

AMD Power Gadget/GraphView.swift

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ class GraphView: NSView {
3838
var viewBottom : CGFloat = 0;
3939
var viewHeight : CGFloat = 100;
4040

41-
let gridDivLines: [Double] = [0, 0.15, 0.25, 0.35, 0.5, 0.6, 0.8, 1]
41+
let gridDivLines: [Double] = [0, 0.15, 0.25, 0.35, 0.5, 0.6, 0.8, 0.9, 1]
4242
let maxDataPoints = 30
4343

4444
let dummyData: [Double] = [1,3,2]
4545
// let dummyData: [Double] = [1,1,1,3,2 ,1]
4646

4747

48+
var dataMax : Double = 0
49+
var dataMin : Double = 0
50+
var dataDiff : Double = 0
51+
4852
override func draw(_ dirtyRect: NSRect) {
4953
super.draw(dirtyRect)
5054

@@ -59,7 +63,7 @@ class GraphView: NSView {
5963
viewBottom = dirtyRect.height * viewBottomPercentage
6064
viewHeight = viewTop - viewBottom;
6165

62-
// dataPoints = dummyData
66+
// fillWithDummyData()
6367

6468
drawBackground(in: dirtyRect, context: context, colorSpace: CGColorSpaceCreateDeviceRGB())
6569

@@ -69,16 +73,25 @@ class GraphView: NSView {
6973
drawLine(in: dirtyRect, context: context, colorSpace: CGColorSpaceCreateDeviceRGB())
7074
drawDataPoint(in: dirtyRect, context: context)
7175
}
76+
77+
self.layer = layer
78+
wantsLayer = true
7279
layer?.cornerRadius = 20
7380
layer?.masksToBounds = true
7481
}
7582

83+
private func fillWithDummyData(){
84+
for d in dummyData {
85+
addData(value: d)
86+
}
87+
}
88+
7689
private func drawBackground(in rect: CGRect, context: CGContext, colorSpace: CGColorSpace?) {
77-
// 1
90+
7891
context.saveGState()
7992
defer { context.restoreGState() }
8093

81-
// 2
94+
8295
let baseColor = backgroundColor1
8396
let middleStop = backgroundColor2
8497

@@ -93,39 +106,45 @@ class GraphView: NSView {
93106
return
94107
}
95108

96-
// 3
97109
let startPoint = CGPoint(x: rect.size.height / 2, y: 0)
98110
let endPoint = CGPoint(x: rect.size.height / 2, y: rect.size.width)
99111
context.drawLinearGradient(gradient, start: startPoint, end: endPoint, options: [])
100112
}
101113

102114
func addData(value: Double){
103115
dataPoints.append(value);
104-
105-
// while dataPoints.count < maxDataPoints{
106-
// dataPoints.append(value )
107-
// }
116+
sortedDataPoint.append(value.rounded())
108117

109118
if dataPoints.count > maxDataPoints {
110119
dataPoints.remove(at: 0)
111120
}
112121

113-
sortedDataPoint = dataPoints.sorted()
122+
if sortedDataPoint.count > maxDataPoints {
123+
let countedSet = NSCountedSet(array: sortedDataPoint)
124+
let mostFrequent = countedSet.max { countedSet.count(for: $0) < countedSet.count(for: $1) }
125+
126+
sortedDataPoint.remove(at: sortedDataPoint.firstIndex(of: mostFrequent as! Double)!)
127+
}
128+
129+
sortedDataPoint = sortedDataPoint.sorted()
130+
131+
dataMax = sortedDataPoint.max()!
132+
dataMin = sortedDataPoint.min()!
133+
134+
//thanks to yurkins for the fix
135+
dataDiff = max(dataMax - dataMin, 1)
136+
114137

115138
setNeedsDisplay(bounds)
116139
}
117140

118141
open override func prepareForInterfaceBuilder() {
119142
super.prepareForInterfaceBuilder()
120-
self.dataPoints = dummyData
143+
fillWithDummyData()
121144
}
122145

123146
private func drawGrid(in rect: CGRect, context: CGContext){
124-
125-
let dataMax = dataPoints.max()!
126-
let dataMin = dataPoints.min()!
127-
let dataDiff = dataMax - dataMin
128-
147+
129148
let attributes = [
130149
NSAttributedString.Key.font: NSFont.systemFont(ofSize: 12.0),
131150
NSAttributedString.Key.foregroundColor: gridColor,
@@ -175,10 +194,6 @@ class GraphView: NSView {
175194
let path = CGMutablePath()
176195
path.move(to: CGPoint(x: 0, y: 0), transform: .identity)
177196

178-
let dataMax = dataPoints.max()!
179-
let dataMin = dataPoints.min()!
180-
let dataDiff = dataMax - dataMin
181-
182197

183198
let xStep : Double = Double(rect.size.width) / Double(dataPoints.count - 1)
184199
var lastPoint = CGPoint(x:0,y:0);
@@ -224,10 +239,6 @@ class GraphView: NSView {
224239

225240
private func drawDataPoint(in rect: CGRect, context: CGContext){
226241

227-
228-
let dataMax = dataPoints.max()!
229-
let dataMin = dataPoints.min()!
230-
let dataDiff = dataMax - dataMin
231242
let xStep : Double = Double(rect.size.width) / Double(dataPoints.count - 1)
232243

233244
for (i, v) in dataPoints.enumerated(){

AMD Power Gadget/ViewController.swift

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class ViewController: NSViewController, NSWindowDelegate {
3333
override func viewDidLoad() {
3434
super.viewDidLoad()
3535
view.window?.delegate = self;
36-
// Do any additional setup after loading the view.
37-
3836

3937
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { (t) in
4038
self.sampleData()
@@ -44,7 +42,6 @@ class ViewController: NSViewController, NSWindowDelegate {
4442
alertAndQuit()
4543
}
4644

47-
// scrollView.documentView?.setFrameSize(NSSize(width: scrollView.frame.size.width - 20, height: 900))
4845

4946
scrollView.scroll(NSPoint(x: 0,y: 0))
5047

@@ -100,38 +97,40 @@ class ViewController: NSViewController, NSWindowDelegate {
10097
}
10198

10299
func sampleData(){
103-
// print("ss")
104100

105101
var numberOfCores: UInt64 = 0
106102
var outputCount: UInt32 = 1
107-
103+
108104
let maxStrLength = 66 //MaxCpu + 2
109105
var outputStr: [Float] = [Float](repeating: 0, count: maxStrLength)
110106
var outputStrCount: Int = 4 * maxStrLength
111107
let res = IOConnectCallMethod(connect, 4, nil, 0, nil, 0,
112108
&numberOfCores, &outputCount,
113109
&outputStr, &outputStrCount)
114-
115-
116-
110+
111+
112+
117113
if res != KERN_SUCCESS {
118114
print(String(cString: mach_error_string(res)))
119115
}
120-
116+
121117
let power = outputStr[0]
122118
let temperature = outputStr[1]
123119
var frequencies : [Float] = []
124120
for i in 0...(numberOfCores-1) {
125121
frequencies.append(outputStr[Int(i + 2)])
126122
}
127-
128-
powerGraphView.addData(value: Double(power))
123+
124+
if power < 1000 {
125+
powerGraphView.addData(value: Double(power))
126+
}
127+
129128
temperatureGraphView.addData(value: Double(temperature))
130-
129+
131130
let meanFre = Double(frequencies.reduce(0, +) / Float(frequencies.count))
132131
frequencyGraphView.addData(value: meanFre)
133132
frequencyLabel.stringValue = String(format: "Average of %d Cores: %.2f Ghz, Max: %.2f Ghz", numberOfCores, meanFre * 0.001, frequencies.max()! * 0.001)
134-
133+
135134
temperatureLabel.stringValue = String(format: "%.2f °C", temperature)
136135
powerLabel.stringValue = String(format: "%.2f Watt", power)
137136
}

SMCAMDProcessor.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
B56162CB2400EF780006A7D8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B56162CA2400EF780006A7D8 /* Assets.xcassets */; };
1313
B56162CE2400EF780006A7D8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B56162CC2400EF780006A7D8 /* Main.storyboard */; };
1414
B561633524010C050006A7D8 /* GraphView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B561633424010C050006A7D8 /* GraphView.swift */; };
15+
B564A5CA240B8256000FF929 /* LegacyIOUserClient.h in Headers */ = {isa = PBXBuildFile; fileRef = B564A5C9240B8256000FF929 /* LegacyIOUserClient.h */; };
1516
B57D280723F66C8E002BC699 /* SMCAMDProcessor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B57D280123F66C8E002BC699 /* SMCAMDProcessor.cpp */; };
1617
B57D280823F66C8E002BC699 /* Keyimplementations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B57D280223F66C8E002BC699 /* Keyimplementations.cpp */; };
1718
B57D280923F66C8E002BC699 /* SMCAMDProcessor.hpp in Headers */ = {isa = PBXBuildFile; fileRef = B57D280323F66C8E002BC699 /* SMCAMDProcessor.hpp */; };
@@ -29,6 +30,7 @@
2930
B56162CF2400EF780006A7D8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3031
B56162D02400EF780006A7D8 /* AMD_Power_Gadget.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AMD_Power_Gadget.entitlements; sourceTree = "<group>"; };
3132
B561633424010C050006A7D8 /* GraphView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphView.swift; sourceTree = "<group>"; };
33+
B564A5C9240B8256000FF929 /* LegacyIOUserClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LegacyIOUserClient.h; sourceTree = "<group>"; };
3234
B57D27F423F66AE7002BC699 /* SMCAMDProcessor.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SMCAMDProcessor.kext; sourceTree = BUILT_PRODUCTS_DIR; };
3335
B57D27FB23F66AE7002BC699 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3436
B57D280123F66C8E002BC699 /* SMCAMDProcessor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SMCAMDProcessor.cpp; sourceTree = "<group>"; };
@@ -57,6 +59,14 @@
5759
/* End PBXFrameworksBuildPhase section */
5860

5961
/* Begin PBXGroup section */
62+
B55E654B240B842400376E9E /* LegacyHeaders */ = {
63+
isa = PBXGroup;
64+
children = (
65+
B564A5C9240B8256000FF929 /* LegacyIOUserClient.h */,
66+
);
67+
path = LegacyHeaders;
68+
sourceTree = "<group>";
69+
};
6070
B56162C52400EF770006A7D8 /* AMD Power Gadget */ = {
6171
isa = PBXGroup;
6272
children = (
@@ -92,6 +102,7 @@
92102
B57D27F623F66AE7002BC699 /* SMCAMDProcessor */ = {
93103
isa = PBXGroup;
94104
children = (
105+
B55E654B240B842400376E9E /* LegacyHeaders */,
95106
B57D280123F66C8E002BC699 /* SMCAMDProcessor.cpp */,
96107
B57D280323F66C8E002BC699 /* SMCAMDProcessor.hpp */,
97108
B57D280523F66C8E002BC699 /* SMCAMDProcessorUserClient.cpp */,
@@ -112,6 +123,7 @@
112123
files = (
113124
B57D280C23F66C8E002BC699 /* SMCAMDProcessorUserClient.hpp in Headers */,
114125
B57D280A23F66C8E002BC699 /* KeyImplementations.hpp in Headers */,
126+
B564A5CA240B8256000FF929 /* LegacyIOUserClient.h in Headers */,
115127
B57D280923F66C8E002BC699 /* SMCAMDProcessor.hpp in Headers */,
116128
);
117129
runOnlyForDeploymentPostprocessing = 0;
@@ -405,7 +417,7 @@
405417
buildSettings = {
406418
CODE_SIGN_STYLE = Manual;
407419
COMBINE_HIDPI_IMAGES = YES;
408-
CURRENT_PROJECT_VERSION = 1.1;
420+
CURRENT_PROJECT_VERSION = 1.1.1;
409421
GCC_PREPROCESSOR_DEFINITIONS = (
410422
"DEBUG=1",
411423
"$(inherited)",
@@ -419,7 +431,7 @@
419431
INFOPLIST_FILE = SMCAMDProcessor/Info.plist;
420432
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/Lilu.kext/Contents/Resources/Library";
421433
MACOSX_DEPLOYMENT_TARGET = 10.13;
422-
MARKETING_VERSION = 1.1;
434+
MARKETING_VERSION = 1.1.1;
423435
MODULE_NAME = wtf.spinach.SMCAMDProcessor;
424436
MODULE_VERSION = 1.0.0d1;
425437
OTHER_CPLUSPLUSFLAGS = "-Wno-inconsistent-missing-override";
@@ -435,7 +447,7 @@
435447
buildSettings = {
436448
CODE_SIGN_STYLE = Manual;
437449
COMBINE_HIDPI_IMAGES = YES;
438-
CURRENT_PROJECT_VERSION = 1.1;
450+
CURRENT_PROJECT_VERSION = 1.1.1;
439451
GCC_PREPROCESSOR_DEFINITIONS = (
440452
"PRODUCT_NAME=$(PRODUCT_NAME)",
441453
"MODULE_VERSION=$(MODULE_VERSION)",
@@ -447,7 +459,7 @@
447459
INFOPLIST_FILE = SMCAMDProcessor/Info.plist;
448460
LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/Lilu.kext/Contents/Resources/Library";
449461
MACOSX_DEPLOYMENT_TARGET = 10.13;
450-
MARKETING_VERSION = 1.1;
462+
MARKETING_VERSION = 1.1.1;
451463
MODULE_NAME = wtf.spinach.SMCAMDProcessor;
452464
MODULE_VERSION = 1.0.0d1;
453465
OTHER_CPLUSPLUSFLAGS = "-Wno-inconsistent-missing-override";

SMCAMDProcessor/Info.plist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@
5858
<key>com.apple.kpi.dsep</key>
5959
<string>12.0.0</string>
6060
<key>com.apple.kpi.iokit</key>
61-
<string>19.3</string>
61+
<string>12.0.0</string>
6262
<key>com.apple.kpi.libkern</key>
63-
<string>19.3</string>
63+
<string>12.0.0</string>
6464
<key>com.apple.kpi.mach</key>
6565
<string>12.0.0</string>
6666
<key>com.apple.kpi.unsupported</key>
67-
<string>19.3</string>
67+
<string>12.0.0</string>
6868
</dict>
6969
<key>OSBundleRequired</key>
7070
<string>Root</string>

0 commit comments

Comments
 (0)