-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fine tuning monitoring lib sample code
- Loading branch information
DevtechProfile
committed
Jan 19, 2022
1 parent
1c3a65a
commit 902b060
Showing
15 changed files
with
220 additions
and
70 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
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
File renamed without changes.
23 changes: 0 additions & 23 deletions
23
source/MonitoringLibTestApp/ConsoleApp1/ConsoleApp1/Program.cs
This file was deleted.
Oops, something went wrong.
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 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Reactive.Linq; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MonitoringLibTestApp | ||
{ | ||
public class Program | ||
{ | ||
private const double SAMPLE_INTERVAL_MS = 1000; | ||
private static ConsoleEventDelegate _handler; | ||
private static IDisposable _sensorUpdateHeartBeat; | ||
private static SensorService _sensorService = new SensorService(); | ||
|
||
static void Main(string[] args) | ||
{ | ||
_handler = new ConsoleEventDelegate(ConsoleEventCallback); | ||
SetConsoleCtrlHandler(_handler, true); | ||
|
||
_sensorService.ActivateAllSensors(); | ||
_sensorUpdateHeartBeat = GetSensorUpdateHeartBeat(); | ||
|
||
Console.ReadKey(); | ||
} | ||
|
||
private static IDisposable GetSensorUpdateHeartBeat() | ||
{ | ||
return Observable | ||
.Timer(DateTimeOffset.UtcNow, TimeSpan.FromMilliseconds(SAMPLE_INTERVAL_MS)) | ||
.Subscribe(x => | ||
{ | ||
_sensorService.UpdateSensors(); | ||
|
||
Console.Clear(); | ||
Console.WriteLine($"{_sensorService.CpuTemp.ToString("F1", CultureInfo.InvariantCulture)} °C"); | ||
Console.WriteLine($"{_sensorService.CPUFrequency.ToString("F0", CultureInfo.InvariantCulture)} MHz"); | ||
Console.WriteLine($"{_sensorService.CpuPPT.ToString("F0", CultureInfo.InvariantCulture)} W"); | ||
Console.WriteLine($"{_sensorService.VCoreVoltage.ToString("F1", CultureInfo.InvariantCulture)} V"); | ||
}); | ||
} | ||
|
||
private delegate bool ConsoleEventDelegate(int eventType); | ||
[DllImport("kernel32.dll", SetLastError = true)] | ||
|
||
private static extern bool SetConsoleCtrlHandler(ConsoleEventDelegate callback, bool add); | ||
|
||
static bool ConsoleEventCallback(int eventType) | ||
{ | ||
if (eventType == 2) | ||
{ | ||
_sensorUpdateHeartBeat?.Dispose(); | ||
_sensorService.Computer?.Close(); | ||
} | ||
return false; | ||
} | ||
} | ||
} |
File renamed without changes.
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.