private static void PublishInfo() { while (Program.ServerIsAlive) { try { var statList = new List <Stat>(); foreach (var hardwareMonitorEntry in _hardwareMonitor.Entries) { statList.Add(new Stat(hardwareMonitorEntry)); _hardwareMonitor.ReloadEntry(hardwareMonitorEntry); } SendMessage(TOPIC_STATS, Newtonsoft.Json.JsonConvert.SerializeObject(statList)); Thread.Sleep(STAT_INTERVAL); } catch (Exception exception) { Console.WriteLine(exception.Message); if (exception.InnerException != null) { Console.WriteLine(exception.InnerException.Message); } } } }
public string function1(string param1, string param2) { try { HardwareMonitor mahm = new HardwareMonitor(); if (param1 == "Framerate") { HardwareMonitorEntry framerate = mahm.GetEntry(HardwareMonitor.GPU_GLOBAL_INDEX, MONITORING_SOURCE_ID.FRAMERATE); if (framerate == null) { return("---"); } return(framerate.Data.ToString(param2)); } HardwareMonitorEntry value = mahm.GetEntry(0, param1); mahm.ReloadEntry(value); return(value.Data.ToString(param2)); } catch (MSI.Afterburner.Exceptions.SharedMemoryDead) { return("[Exception: Shared memory dead because Afterburner was closed. You have to restart LCD Smartie."); } //TODO: srsly catch (MSI.Afterburner.Exceptions.SharedMemoryNotFound) { return("[Exception: Couldn't find shared memory. Is Afterburner running?]"); } catch (Exception e) { return(e.ToString()); } }
static void Main(string[] args) { //make sure only one instance is running SharedSettings.CheckForTwins(); //check for device layout and adjust for Mini or Standard StreamDeck if (SettingsSDMonitor.CheckForLayout() != null) { if (SettingsSDMonitor.CheckForLayout() == "Mini") { isMiniDeck = true; } } //clean display and set brightness ImageManager.deck.ClearKeys(); var displayBrightness = Convert.ToByte(SettingsSDMonitor.displayBrightness); ImageManager.deck.SetBrightness(displayBrightness); //create and process necessary header images ImageManager.ProcessHeaderImages(); //check for State setting and start State accodingly if (SharedSettings.CurrentSate() == 1) { StartMonitorState(); } if (SharedSettings.CurrentSate() == 2) { StartClockState(); } //MonitorState void StartMonitorState() { var showFps = false; if (isMiniDeck == true) { if (SettingsSDMonitor.isFpsCounter == "True") { showFps = true; } } try { //check if MSIAfterburner process is running if (SettingsSDMonitor.CheckForAB() == true) { msiAB = new HardwareMonitor(); msiAB.Connect(); isABRunning = true; } else { msiAB = null; } //define Librehardwaremonitor sensors and connect (CPU temp data requires 'highestAvailable' requestedExecutionLevel !!) ohmComputer.Open(); //set static header images ImageManager.SetStaticHeaders(); if (isMiniDeck == false) { showFps = true; //check if using animations or static images string currentProfile = SharedSettings.config.Read("selectedProfile", "Current_Profile"); if (SharedSettings.IsAnimationEnabled(currentProfile) != "True") { foreach (var button in SettingsSDMonitor.BgButtonList()) { ImageManager.SetStaticImg(SettingsSDMonitor.imageName, button); } //start standard loop without the image animations StartMonitor(); } else { //start both loops in parallel Parallel.Invoke(() => ImageManager.StartAnimation(), () => StartMonitor()); } } else { StartMonitor(); } void StartMonitor() { string typeFps; int KeyLocFps; int KeyLocGpuTemp; int KeyLocGpuLoad; int KeyLocCpuTemp; int KeyLocCpuLoad; if (isMiniDeck == true) { typeFps = "fmini"; KeyLocFps = SettingsSDMonitor.KeyLocFpsMini; KeyLocGpuTemp = SettingsSDMonitor.KeyLocGpuTempMini; KeyLocGpuLoad = SettingsSDMonitor.KeyLocGpuLoadMini; KeyLocCpuTemp = SettingsSDMonitor.KeyLocCpuTempMini; KeyLocCpuLoad = SettingsSDMonitor.KeyLocCpuLoadMini; } else { typeFps = "f"; KeyLocFps = SettingsSDMonitor.KeyLocFps; KeyLocGpuTemp = SettingsSDMonitor.KeyLocGpuTemp; KeyLocGpuLoad = SettingsSDMonitor.KeyLocGpuLoad; KeyLocCpuTemp = SettingsSDMonitor.KeyLocCpuTemp; KeyLocCpuLoad = SettingsSDMonitor.KeyLocCpuLoad; } int counterDefault = 1; //start loop while (true) { if (ImageManager.exitflag) { break; } int countValue = counterDefault++; try { //add key press handler, if pressed send exit command ImageManager.deck.KeyStateChanged += DeckKeyPressed; if (showFps == true) { //connect to msi afterburner and reload values if (isABRunning == true) { var framerateEntry = msiAB.GetEntry(HardwareMonitor.GPU_GLOBAL_INDEX, MONITORING_SOURCE_ID.FRAMERATE); msiAB.ReloadEntry(framerateEntry); //get values for framerate and pass to process int framerateInt = (int)Math.Round(framerateEntry.Data); string dataValue = framerateInt.ToString(); string type = typeFps; ImageManager.ProcessValueImg(dataValue, type, KeyLocFps); } else { string dataValue = "0"; string type = typeFps; ImageManager.ProcessValueImg(dataValue, type, KeyLocFps); } } if (isMiniDeck == false) { //get and set time string timeOutput = DateTime.Now.ToString("hh:mm"); if (timeOutput.StartsWith("0")) { timeOutput = timeOutput.Remove(0, 1); } ImageManager.ProcessValueImg(timeOutput, "ti", SettingsSDMonitor.KeyLocTimeHeader); } //search hardware foreach (IHardware hardware in ohmComputer.Hardware) { hardware.Update(); //check for gpu sensor if (hardware.HardwareType == HardwareType.GpuNvidia || hardware.HardwareType == HardwareType.GpuAti) { foreach (ISensor sensor in hardware.Sensors) { //search for temp sensor if (sensor.SensorType == SensorType.Temperature) { string dataValue = sensor.Value.ToString() + "c"; string type = "t"; ImageManager.ProcessValueImg(dataValue, type, KeyLocGpuTemp); } //search for load sensor if (sensor.SensorType == SensorType.Load) { //add gpu load sensors to list string getValues = sensor.Name + sensor.Value.ToString(); List <string> valueList = new List <string> { getValues }; //get values for gpu and pass to process foreach (string value in valueList) { if (value.Contains("GPU Core")) { //get values for gpu and pass to process int gpuLoadInt = (int)Math.Round(sensor.Value.Value); string dataValue = gpuLoadInt.ToString() + "%"; string type = "l"; ImageManager.ProcessValueImg(dataValue, type, KeyLocGpuLoad); } } } } } //check for cpu sensor if (hardware.HardwareType == HardwareType.CPU) { string cpuTempString; if (hardware.Name.Contains("Ryzen")) { cpuTempString = "Core (Tdie)"; } if (hardware.Name.Contains("Intel")) { cpuTempString = "CPU Package"; } else { cpuTempString = "Core #0"; } foreach (ISensor sensor in hardware.Sensors) { //search for temp sensor if (sensor.SensorType == SensorType.Temperature) { //add cpu temp sensors to list string getValues = sensor.Name + sensor.Value.ToString(); List <string> valueList = new List <string> { getValues }; //get values for cpu and pass to process foreach (string value in valueList) { if (value.Contains(cpuTempString)) { string resultPackage = value.Substring(Math.Max(0, value.Length - 2)); if (!resultPackage.Contains("#")) { string dataValue = resultPackage.ToString() + "c"; string type = "t"; ImageManager.ProcessValueImg(dataValue, type, KeyLocCpuTemp); } } } } //search for load sensor if (sensor.SensorType == SensorType.Load) { //add cpu load sensors to list string getValues = sensor.Name + sensor.Value.ToString(); List <string> valueList = new List <string> { getValues }; //get values for cpu and change Stream Deck image foreach (string value in valueList) { if (value.Contains("CPU Total")) { //get values for cpu and pass to process int cpuLoadInt = (int)Math.Round(sensor.Value.Value); string dataValue = cpuLoadInt.ToString() + "%"; string type = "l"; ImageManager.ProcessValueImg(dataValue, type, KeyLocCpuLoad); } } } } } } //wait 1 second before restarting loop System.Threading.Thread.Sleep(1000); //remove handler ImageManager.deck.KeyStateChanged -= DeckKeyPressed; } catch (Exception) { ExitApp(); } } } } catch (Exception ex) { if (ex.InnerException is StreamDeckSharp.Exceptions.StreamDeckNotFoundException) { string deviceNotFound = " 'Stream Deck' Device not found/connected ! "; MessageBox.Show(deviceNotFound); } ExitApp(); } } // ClockState void StartClockState() { if (isMiniDeck == false) { //clear the FPS monitoring button image/animation again seperatly. This is to prevent corrupted images being left on that button when switching to Clock state ImageManager.deck.ClearKey(0); } //start both loops in parallel Parallel.Invoke(() => ImageManager.StartAnimClock(), () => StartClock()); } void StartClock() { //start loop while (true) { if (ImageManager.exitflag) { break; } try { //add key press handler, if pressed send exit command ImageManager.deck.KeyStateChanged += DeckKeyPressed; //get current time DateTime now = DateTime.Now; string hours = now.Hour.ToString(); if (hours.Length < 2) { hours = "0" + hours; } string minutes = now.ToString("mm"); if (isMiniDeck == true) { //send current time to ImageManager ImageManager.ClockStateMini(hours, minutes); } else { //send current time to ImageManager ImageManager.ClockState(hours, minutes); } //wait 10 seconds between getting current time System.Threading.Thread.Sleep(10000); //remove handler ImageManager.deck.KeyStateChanged -= DeckKeyPressed; } catch (Exception) { ExitApp(); } } } }
static void Main(string[] args) { Console.Clear(); Console.TreatControlCAsInput = false; Console.CancelKeyPress += (s, e) => { Console.WriteLine("ctrl+c pressed"); Continue = false; e.Cancel = true; }; try { // connect to MACM shared memory HardwareMonitor mahm = new HardwareMonitor(); // print out current MACM Header values Console.WriteLine("***** MSI AFTERTERBURNER HARDWARE MONITOR HEADER *****"); Console.WriteLine(mahm.Header.ToString().Replace(";", "\n")); Console.WriteLine(); // print out current MAHM GPU Entry values for (int i = 0; i < mahm.Header.GpuEntryCount; i++) { Console.WriteLine("***** MSI AFTERTERBURNER GPU " + i + " *****"); Console.WriteLine(mahm.GpuEntries[i].ToString().Replace(";", "\n")); Console.WriteLine(); } // print out current Entry values for (int i = 0; i < mahm.Header.EntryCount; i++) { if (mahm.Entries[i].SrcName == "CPU usage") { if (cpuUsageIndex == -1) { cpuUsageIndex = i; } } else if (mahm.Entries[i].SrcName == "CPU1 temperature") { if (cpuTempIndex == -1) { cpuTempIndex = i; } } else if (mahm.Entries[i].SrcName == "GPU temperature") { if (gpuTempIndex == -1) { gpuTempIndex = i; } } else if (mahm.Entries[i].SrcName == "Framerate") { if (framerateIndex == -1) { framerateIndex = i; } } else if (mahm.Entries[i].SrcName == "Power") { if (powerIndex == -1) { powerIndex = i; } } else if (mahm.Entries[i].SrcName == "GPU usage") { if (gpuUsageIndex == -1) { gpuUsageIndex = i; } } else if (mahm.Entries[i].SrcName == "Memory usage") { if (memoryUsageIndex == -1) { memoryUsageIndex = i; } } else if (mahm.Entries[i].SrcName == "RAM usage") { if (ramUsageIndex == -1) { ramUsageIndex = i; } } Console.WriteLine("***** MSI AFTERTERBURNER DATA SOURCE " + i + " *****"); Console.WriteLine(mahm.Entries[i].ToString().Replace(";", "\n")); Console.WriteLine(); } Console.WriteLine(mahm.Entries.Length); Console.WriteLine("Enter arduino COM port:"); String comPort = Console.ReadLine(); Console.WriteLine("Enter arduino baudRate:"); int baudRate = Int32.Parse(Console.ReadLine()); Arduino arduino = new Arduino(); arduino.Connect(comPort, baudRate); // show a data source monitor several times HardwareMonitorEntry cpuUsageEntry = mahm.Entries[cpuUsageIndex]; HardwareMonitorEntry cpuTempEntry = mahm.Entries[cpuTempIndex]; HardwareMonitorEntry gpuTempEntry = mahm.Entries[gpuTempIndex]; //mahm.GetEntry(0, MONITORING_SOURCE_ID.GPU_TEMPERATURE); HardwareMonitorEntry framerateEntry = mahm.Entries[framerateIndex]; //mahm.GetEntry(HardwareMonitor.GPU_GLOBAL_INDEX, MONITORING_SOURCE_ID.FRAMERATE); HardwareMonitorEntry powerEntry = mahm.Entries[powerIndex]; HardwareMonitorEntry gpuUsageEntry = mahm.Entries[gpuUsageIndex]; HardwareMonitorEntry memoryUsageEntry = mahm.Entries[memoryUsageIndex]; HardwareMonitorEntry ramUsageEntry = mahm.Entries[ramUsageIndex]; if (framerateEntry != null && cpuUsageEntry != null && cpuTempEntry != null && gpuTempEntry != null) { byte[] data = new byte[16]; UInt16 cpuUsage, gpuUsage, cpuTemp, gpuTemp, memoryUsage, ramUsage, framerate, powerUsage; while (Continue) { cpuUsage = (UInt16)cpuUsageEntry.Data; gpuUsage = (UInt16)gpuUsageEntry.Data; cpuTemp = (UInt16)cpuTempEntry.Data; gpuTemp = (UInt16)gpuTempEntry.Data; memoryUsage = (UInt16)memoryUsageEntry.Data; ramUsage = (UInt16)ramUsageEntry.Data; framerate = (UInt16)framerateEntry.Data; powerUsage = (UInt16)powerEntry.Data; data[0] = (byte)(cpuUsage >> 8); data[1] = (byte)(cpuUsage); data[2] = (byte)(gpuUsage >> 8); data[3] = (byte)(gpuUsage); data[4] = (byte)(cpuTemp >> 8); data[5] = (byte)(cpuTemp); data[6] = (byte)(gpuTemp >> 8); data[7] = (byte)(gpuTemp); data[8] = (byte)(memoryUsage >> 8); data[9] = (byte)(memoryUsage); data[10] = (byte)(ramUsage >> 8); data[11] = (byte)(ramUsage); data[12] = (byte)(framerate >> 8); data[13] = (byte)(framerate); data[14] = (byte)(powerUsage >> 8); data[15] = (byte)(powerUsage); arduino.write(data, 0, 16); System.Threading.Thread.Sleep(500); mahm.ReloadEntry(cpuUsageEntry); mahm.ReloadEntry(gpuUsageEntry); mahm.ReloadEntry(cpuTempEntry); mahm.ReloadEntry(gpuTempEntry); mahm.ReloadEntry(memoryUsageEntry); mahm.ReloadEntry(ramUsageEntry); mahm.ReloadEntry(framerateEntry); mahm.ReloadEntry(powerEntry); } } Console.WriteLine("Closing arduino connection!"); arduino.close(); } catch (Exception e) { Console.WriteLine(e.Message); if (e.InnerException != null) { Console.WriteLine(e.InnerException.Message); } } Console.WriteLine("\nPress any key to exit"); Console.ReadKey(); }