private int ConverWinTemperature(HwmWinApi.MC_COLOR_TEMPERATURE value) { switch (value) { case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_4000K: return(4000); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_5000K: return(5000); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_6500K: return(6500); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_7500K: return(7500); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_8200K: return(8200); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_9300K: return(9300); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_10000K: return(10000); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_11500K: return(11500); case HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_UNKNOWN: return(0); default: throw new ArgumentException(); } }
public HardwareMonitor(IntPtr hMonitor, String name, MonitorManager manager) : base(name, manager) { this.hMonitor = hMonitor; uint monitorCapabilities = 0; uint supportedColorTemperatures = 0; if (!HwmWinApi.GetMonitorCapabilities(hMonitor, ref monitorCapabilities, ref supportedColorTemperatures)) { MainWindow.Win32Error("Monitor " + name + " cannot GetMonitorCapabilities(). However, we'll try to communicate with that monitor anyway."); monitorCapabilities = HwmWinApi.MC_CAPS_BRIGHTNESS | HwmWinApi.MC_CAPS_CONTRAST | HwmWinApi.MC_CAPS_COLOR_TEMPERATURE; supportedColorTemperatures = 0xFFFFFFFF; } if ((monitorCapabilities & HwmWinApi.MC_CAPS_BRIGHTNESS) > 0) { SupportsBrightness = true; uint minBrightness = 0u, currBrightness = 0u, maxBrightness = 0u; if (HwmWinApi.GetMonitorBrightness(hMonitor, ref minBrightness, ref currBrightness, ref maxBrightness)) { MinBrightness = (int)minBrightness; MaxBrightness = (int)maxBrightness; mBrightness = (int)currBrightness; // Don't call property. Just update the value. Monitor's Brightness is already set to that value, so no need to waste time calling monitor API } else { MainWindow.Win32Error("HardwareMonitor Cannot GetMonitorBrightness()"); } } if ((monitorCapabilities & HwmWinApi.MC_CAPS_CONTRAST) > 0) { SupportsContrast = true; uint minContrast = 0u, currContrast = 0u, maxContrast = 0u; if (HwmWinApi.GetMonitorContrast(hMonitor, ref minContrast, ref currContrast, ref maxContrast)) { MinContrast = (int)minContrast; MaxContrast = (int)maxContrast; mContrast = (int)currContrast; // Don't call property. Just update the value. Monitor's Brightness is already set to that value, so no need to waste time calling monitor API } else { MainWindow.Win32Error("HardwareMonitor Cannot GetMonitorContrast()"); } } SupportedColorTemperaturesList = new DoubleCollection(); if ((monitorCapabilities & HwmWinApi.MC_CAPS_COLOR_TEMPERATURE) > 0) { SupportsTemperature = true; HwmWinApi.MC_COLOR_TEMPERATURE currentColorTemperature = HwmWinApi.MC_COLOR_TEMPERATURE.MC_COLOR_TEMPERATURE_UNKNOWN; if (HwmWinApi.GetMonitorColorTemperature(hMonitor, ref currentColorTemperature)) { mTemperature = ConverWinTemperature(currentColorTemperature); } else { MainWindow.Win32Error("HardwareMonitor Cannot GetMonitorColorTemperature()"); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_4000K) > 0) { SupportedColorTemperaturesList.Add(4000); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_5000K) > 0) { SupportedColorTemperaturesList.Add(5000); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_6500K) > 0) { SupportedColorTemperaturesList.Add(6500); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_7500K) > 0) { SupportedColorTemperaturesList.Add(7500); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_8200K) > 0) { SupportedColorTemperaturesList.Add(8200); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_9300K) > 0) { SupportedColorTemperaturesList.Add(9300); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_10000K) > 0) { SupportedColorTemperaturesList.Add(10000); } if ((supportedColorTemperatures & HwmWinApi.MC_SUPPORTED_COLOR_TEMPERATURE_11500K) > 0) { SupportedColorTemperaturesList.Add(11500); } if (SupportedColorTemperaturesList.Count == 0) { SupportsTemperature = false; } } MainWindow.Trace("DBG HWMON CAP STR " + name + ":"); uint capabilitiesStringLength = 0; if (!HwmWinApi.GetCapabilitiesStringLength(hMonitor, ref capabilitiesStringLength)) { MainWindow.Win32Error("Cannot get GetCapabilitiesStringLength()"); return; } StringBuilder capabilities = new StringBuilder((int)capabilitiesStringLength); if (!HwmWinApi.CapabilitiesRequestAndCapabilitiesReply(hMonitor, capabilities, capabilitiesStringLength)) { MainWindow.Win32Error("Cannot get CapabilitiesRequestAndCapabilitiesReply()"); return; } MainWindow.Trace("CAPABILITIES STR --> " + capabilities); MainWindow.Trace(" - " + monitorCapabilities); MainWindow.Trace(" - " + supportedColorTemperatures); }