Skip to content

Commit

Permalink
Add current CPU temperature.
Browse files Browse the repository at this point in the history
  • Loading branch information
t-miyake committed Sep 1, 2017
1 parent 7e7c173 commit d874665
Show file tree
Hide file tree
Showing 13 changed files with 384 additions and 29 deletions.
2 changes: 1 addition & 1 deletion PocketFanController.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PocketFanController", "PocketFanController\PocketFanController.csproj", "{8623A908-1563-46EE-98E5-0539DF3ED417}"
EndProject
Expand Down
248 changes: 248 additions & 0 deletions PocketFanController/AboutWindow.xaml

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions PocketFanController/AboutWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace PocketFanController
{
/// <summary>
/// AboutWindow.xaml の相互作用ロジック
/// </summary>
public partial class AboutWindow : Window
{
public AboutWindow()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}
2 changes: 1 addition & 1 deletion PocketFanController/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:PocketFanController"
mc:Ignorable="d"
Title="Pocket Fan Controller Ver. 0.3.0" Height="100" Width="352" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Icon="Icon.ico" ShowInTaskbar="False">
Title="Pocket Fan Controller" Height="100" Width="352" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" Icon="Icon.ico" ShowInTaskbar="False" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<Window.DataContext>
<local:ViewModel />
</Window.DataContext>
Expand Down
31 changes: 31 additions & 0 deletions PocketFanController/Model.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Win32;
using OpenHardwareMonitor.Hardware;

namespace PocketFanController
{
Expand Down Expand Up @@ -122,5 +125,33 @@ public void RestartService()
};
cmd.Start();
}

public string GetCpuTemp()
{
var computer = new Computer
{
MainboardEnabled = false,
CPUEnabled = true,
RAMEnabled = false,
GPUEnabled = false,
FanControllerEnabled = false,
HDDEnabled = false
};

computer.Open();

var temps = new List<string>();

foreach (var item in computer.Hardware)
{
if (item.HardwareType != HardwareType.CPU) continue;
item.Update();
temps.AddRange(from sensor in item.Sensors where sensor.SensorType == SensorType.Temperature where sensor.Value != null select sensor.Value.Value.ToString(CultureInfo.CurrentCulture));
}

//最初に取得できるのが、現在の温度。
return temps[0];
}

}
}
73 changes: 49 additions & 24 deletions PocketFanController/NotifyIconWrapper.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions PocketFanController/NotifyIconWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public NotifyIconWrapper()

toolStripMenuItem_Exit.Click += Exit;
toolStripMenuItem_OpenWindow.Click += OpenWindow;
toolStripMenuItem_OpenAbout.Click += OpenAbout;

toolStripMenuItem_SetDefault.Click += SetDefault;
toolStripMenuItem_SetFastest.Click += SetFastest;
Expand Down Expand Up @@ -69,8 +70,16 @@ private void OpenWindow(object sender, EventArgs e)
mainWindow.Show();
}

private void OpenAbout(object sender, EventArgs e)
{
var aboutWindow = new AboutWindow();
aboutWindow.Show();
}

private void UpdateCurrentStatus(object sender, EventArgs e)
{
toolStripMenuItem_CpuTemp.Text = "CPU " + Model.GetCpuTemp() + "";

Model.GetCurrentStatus();

switch (Model.CurrentState)
Expand Down
2 changes: 1 addition & 1 deletion PocketFanController/NotifyIconWrapper.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="notifyIcon1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 60</value>
<value>17, 65</value>
</metadata>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>170, 17</value>
Expand Down
Binary file added PocketFanController/OpenHardwareMonitorLib.dll
Binary file not shown.
10 changes: 10 additions & 0 deletions PocketFanController/PocketFanController.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="OpenHardwareMonitorLib">
<HintPath>.\OpenHardwareMonitorLib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
Expand All @@ -63,6 +66,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="AboutWindow.xaml.cs">
<DependentUpon>AboutWindow.xaml</DependentUpon>
</Compile>
<Compile Include="NotifyIconWrapper.cs">
<SubType>Component</SubType>
</Compile>
Expand All @@ -72,6 +78,10 @@
<Compile Include="RelayCommand.cs" />
<Compile Include="ViewModel.cs" />
<Compile Include="ViewModelBase.cs" />
<Page Include="AboutWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
4 changes: 2 additions & 2 deletions PocketFanController/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.0.0")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyVersion("0.4.0.0")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: NeutralResourcesLanguage("en")]

Binary file modified Screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Screenshot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d874665

Please sign in to comment.