Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fan RPM sensors to Hot #98

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Hot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
05B0DFAA267150F40068FF9B /* TCXCTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 05B0DFA8267150F40068FF9B /* TCXCTemplate.pdf */; };
05BA0BAA26F342DA00AA7BFC /* PressureToString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05BA0BA926F342DA00AA7BFC /* PressureToString.swift */; };
05BA0BAD26F347A500AA7BFC /* PressureTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 05BA0BAC26F347A500AA7BFC /* PressureTemplate.pdf */; };
382CF88F2C4FF77400D9DB3C /* FanSpeedToString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 382CF88E2C4FF77400D9DB3C /* FanSpeedToString.swift */; };
388C8F752C5522FC0057EA05 /* FanViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 388C8F732C5522FC0057EA05 /* FanViewController.xib */; };
388C8F772C5523260057EA05 /* FanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 388C8F762C5523260057EA05 /* FanViewController.swift */; };
38B72A8D2C53DAFF00AD0B87 /* FanTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 38B72A8A2C53DAFF00AD0B87 /* FanTemplate.pdf */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -193,6 +197,10 @@
05B0DFA8267150F40068FF9B /* TCXCTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = TCXCTemplate.pdf; sourceTree = "<group>"; };
05BA0BA926F342DA00AA7BFC /* PressureToString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PressureToString.swift; sourceTree = "<group>"; };
05BA0BAC26F347A500AA7BFC /* PressureTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = PressureTemplate.pdf; sourceTree = "<group>"; };
382CF88E2C4FF77400D9DB3C /* FanSpeedToString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FanSpeedToString.swift; sourceTree = "<group>"; };
388C8F742C5522FC0057EA05 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/FanViewController.xib; sourceTree = "<group>"; };
388C8F762C5523260057EA05 /* FanViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FanViewController.swift; sourceTree = "<group>"; };
38B72A8A2C53DAFF00AD0B87 /* FanTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = FanTemplate.pdf; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -227,6 +235,7 @@
057F8AFF251D22360048F1E1 /* StatusIconTemplate.pdf */,
05BA0BAC26F347A500AA7BFC /* PressureTemplate.pdf */,
052FBCD2251F842C00C4322E /* TemperatureTemplate.pdf */,
38B72A8A2C53DAFF00AD0B87 /* FanTemplate.pdf */,
);
path = Images;
sourceTree = "<group>";
Expand Down Expand Up @@ -414,6 +423,7 @@
057F8B0B251D273E0048F1E1 /* AboutWindowController.swift */,
05AA4079251CF3D200106CEA /* ApplicationDelegate.swift */,
05221E87267009A8007246FF /* SensorViewController.swift */,
388C8F762C5523260057EA05 /* FanViewController.swift */,
055A932A252780FD0070F771 /* GraphView.swift */,
057F8B0E251D274C0048F1E1 /* Hot-Bridging-Header.h */,
055A931F252778C10070F771 /* InfoViewController.swift */,
Expand All @@ -428,6 +438,7 @@
05AA408C251CFA0600106CEA /* ThermalLog.swift */,
05AD458729084FEF00A791C8 /* SelectSensorsWindowController.swift */,
05566A74299195F400E7A5F1 /* GraphWindowController.swift */,
382CF88E2C4FF77400D9DB3C /* FanSpeedToString.swift */,
);
path = Classes;
sourceTree = "<group>";
Expand All @@ -441,6 +452,7 @@
05AA407D251CF3D600106CEA /* MainMenu.xib */,
052FBCA5251EE46700C4322E /* PreferencesWindowController.xib */,
05221E8926700A57007246FF /* SensorViewController.xib */,
388C8F732C5522FC0057EA05 /* FanViewController.xib */,
05AD458E2908505900A791C8 /* SelectSensorsWindowController.xib */,
05566A772991963400E7A5F1 /* GraphWindowController.xib */,
);
Expand Down Expand Up @@ -544,12 +556,14 @@
files = (
052FBCD4251F842C00C4322E /* SpeedTemplate.pdf in Resources */,
05BA0BAD26F347A500AA7BFC /* PressureTemplate.pdf in Resources */,
388C8F752C5522FC0057EA05 /* FanViewController.xib in Resources */,
052FBCD6251F842C00C4322E /* TemperatureTemplate.pdf in Resources */,
057F8B00251D22360048F1E1 /* StatusIconTemplate.pdf in Resources */,
057F8B1B251D2A970048F1E1 /* Icon.icns in Resources */,
052FBCD5251F842C00C4322E /* CPUTemplate.pdf in Resources */,
05221E8B26700A57007246FF /* SensorViewController.xib in Resources */,
05AD459229092CEB00A791C8 /* TCalTemplate.pdf in Resources */,
38B72A8D2C53DAFF00AD0B87 /* FanTemplate.pdf in Resources */,
05AD458C2908505900A791C8 /* SelectSensorsWindowController.xib in Resources */,
055A9323252778D00070F771 /* InfoViewController.xib in Resources */,
05B0DFA526714A830068FF9B /* UnknownTemplate.pdf in Resources */,
Expand Down Expand Up @@ -594,6 +608,8 @@
buildActionMask = 2147483647;
files = (
055A932525277E9E0070F771 /* IntegerToString.swift in Sources */,
388C8F772C5523260057EA05 /* FanViewController.swift in Sources */,
382CF88F2C4FF77400D9DB3C /* FanSpeedToString.swift in Sources */,
055A932725277F6E0070F771 /* TemperatureToString.swift in Sources */,
05221E8626700772007246FF /* DictionaryIsEmpty.swift in Sources */,
052FBCA3251EE43B00C4322E /* PreferencesWindowController.swift in Sources */,
Expand Down Expand Up @@ -670,6 +686,14 @@
name = SelectSensorsWindowController.xib;
sourceTree = "<group>";
};
388C8F732C5522FC0057EA05 /* FanViewController.xib */ = {
isa = PBXVariantGroup;
children = (
388C8F742C5522FC0057EA05 /* Base */,
);
name = FanViewController.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
Expand Down
50 changes: 50 additions & 0 deletions Hot/Classes/ApplicationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
private var sensorsWindowController: SensorsWindowController?
private var selectSensorsWindowController: SelectSensorsWindowController?
private var sensorViewControllers: [ SensorViewController ] = []
private var fanViewControllers: [ FanViewController ] = []
private var graphWindowController: GraphWindowController?
private var exiting = false

@IBOutlet private var menu: NSMenu!
@IBOutlet private var sensorsMenu: NSMenu!
@IBOutlet private var fansMenu: NSMenu!
@IBOutlet private var updater: GitHubUpdater!

@objc public private( set ) dynamic var infoViewController: InfoViewController?
Expand Down Expand Up @@ -82,6 +84,7 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
self?.graphWindowController?.availableCPUs = self?.infoViewController?.availableCPUs ?? 0
self?.graphWindowController?.speedLimit = self?.infoViewController?.speedLimit ?? 0
self?.graphWindowController?.temperature = self?.infoViewController?.temperature ?? 0
self?.graphWindowController?.fanSpeed = self?.infoViewController?.fanSpeed ?? 0
self?.graphWindowController?.thermalPressure = self?.infoViewController?.thermalPressure ?? 0
}

Expand Down Expand Up @@ -357,18 +360,30 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
{
self.sensorsMenu.removeAllItems()
}
if self.fanViewControllers.isEmpty
{
self.fansMenu.removeAllItems()
}

guard let sensors = self.infoViewController?.log.sensors
else
{
return
}
guard let fans = self.infoViewController?.log.fans
else
{
return
}

var controllers = self.sensorViewControllers
var fanControllers = self.fanViewControllers
var items = self.sensorsMenu.items
var fanItems = self.fansMenu.items

controllers.removeAll { item in sensors.contains { $0.key == item.name } == false }
items.removeAll { item in sensors.contains { $0.key == item.title } == false }
fanItems.removeAll { item in fans.contains { $0.key == item.title } == false }

sensors.forEach
{
Expand Down Expand Up @@ -403,6 +418,41 @@ class ApplicationDelegate: NSObject, NSApplicationDelegate, NSWindowDelegate
{
self.sensorsMenu.addItem( $0 )
}

fans.forEach
{
fan in

if let controller = self.fanViewControllers.first( where: { $0.name == fan.key } )
{
controller.value = Int( fan.value )
}
else
{
let controller = FanViewController()
controller.name = fan.key
controller.value = Int( fan.value )
let item = NSMenuItem( title: fan.key, action: nil, keyEquivalent: "" )
item.view = controller.view

fanItems.append( item )
fanControllers.append( controller )
}
}

self.fanViewControllers = fanControllers

self.fansMenu.removeAllItems()


fanItems.sorted
{
$0.title.compare( $1.title, options: [ .numeric, .caseInsensitive ], range: nil, locale: nil ) == .orderedAscending
}
.forEach
{
self.fansMenu.addItem( $0 )
}
}

@IBAction
Expand Down
64 changes: 64 additions & 0 deletions Hot/Classes/FanSpeedToString.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022, Jean-David Gadina - www.xs-labs.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

import Cocoa

@objc( FanSpeedToString )
public class FanSpeedToString: ValueTransformer
{
public override class func transformedValueClass() -> AnyClass
{
return NSString.self
}

public override class func allowsReverseTransformation() -> Bool
{
return false
}

public override func transformedValue( _ value: Any? ) -> Any?
{
let n: Int? =
{
if let n = value as? Int
{
return n
}
else if let n = value as? Double
{
return Int( n )
}

return nil
}()

guard let n = n, n > 0
else
{
return "Off" as NSString
}

return "\( n ) RPM" as NSString
}
}
46 changes: 46 additions & 0 deletions Hot/Classes/FanViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2022, Jean-David Gadina - www.xs-labs.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the Software), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

import Cocoa

public class FanViewController: NSViewController
{
@objc private dynamic var icon = NSImage( named: "Unknown" )
@objc private dynamic var label = "Unknown:"
@objc public dynamic var value = 0
@objc public dynamic var name = "Unknown"
{
didSet
{
self.label = self.name.hasSuffix( ":" ) ? self.name : "\( self.name ):"

self.icon = NSImage( named: "FanTemplate" )
}
}

public override var nibName: NSNib.Name?
{
"FanViewController"
}
}
1 change: 1 addition & 0 deletions Hot/Classes/GraphWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class GraphWindowController: NSWindowController
@objc public dynamic var availableCPUs: Int = 0
@objc public dynamic var speedLimit: Int = 0
@objc public dynamic var temperature: Int = 0
@objc public dynamic var fanSpeed: Int = 0
@objc public dynamic var thermalPressure: Int = 0
@objc public dynamic var showOnAllSpaces: Bool = false
{
Expand Down
8 changes: 8 additions & 0 deletions Hot/Classes/InfoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public class InfoViewController: NSViewController
@objc public private( set ) dynamic var availableCPUs: Int = 0
@objc public private( set ) dynamic var speedLimit: Int = 0
@objc public private( set ) dynamic var temperature: Int = 0
@objc public private( set ) dynamic var fanSpeed: Int = 0
@objc public private( set ) dynamic var thermalPressure: Int = 0
@objc public private( set ) dynamic var hasSensors: Bool = false
@objc public private( set ) dynamic var hasFans: Bool = false

public var onUpdate: ( () -> Void )?

Expand Down Expand Up @@ -117,6 +119,7 @@ public class InfoViewController: NSViewController
private func update()
{
self.hasSensors = self.log.sensors.isEmpty == false
self.hasFans = self.log.fans.isEmpty == false

if let n = self.log.schedulerLimit?.intValue
{
Expand All @@ -138,6 +141,11 @@ public class InfoViewController: NSViewController
self.temperature = n
}

if let n = self.log.fanSpeed?.intValue
{
self.fanSpeed = n
}

if let n = self.log.thermalPressure?.intValue
{
self.thermalPressure = n
Expand Down
Loading