Skip to content

Commit

Permalink
Merge pull request #423 from emoacht/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emoacht authored Mar 12, 2023
2 parents 51a4069 + 557cd28 commit 92d3942
Show file tree
Hide file tree
Showing 34 changed files with 506 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Source/Installer/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.0.1"
<Product Id="*" Name="Monitorian" Manufacturer="emoacht" Version="4.1.0"
Language="1033" Codepage="1252" UpgradeCode="{81A4D148-75D3-462E-938D-8C208FB48E3C}">
<Package Id="*" InstallerVersion="500" Compressed="yes"
InstallScope="perMachine" InstallPrivileges="elevated"
Expand Down
14 changes: 14 additions & 0 deletions Source/Monitorian.Core/Helper/EnumerableExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,19 @@ public static IEnumerable<TSource[]> Split<TSource>(this IEnumerable<TSource> so
yield return buffer.ToArray();
}
}

public static IEnumerable<TSource> Clip<TSource>(this IEnumerable<TSource> source, TSource start, TSource end) where TSource : IComparable
{
if (source is null)
throw new ArgumentNullException(nameof(source));

// Remove the elements before the start and after the end while keeping the elements
// between intact.
return source
.SkipWhile(x => x.CompareTo(start) < 0)
.Reverse()
.SkipWhile(x => x.CompareTo(end) > 0)
.Reverse();
}
}
}
2 changes: 1 addition & 1 deletion Source/Monitorian.Core/Helper/OsVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal static class OsVersion
private static readonly Dictionary<string, bool> _cache = new();
private static readonly object _lock = new();

private static bool IsEqualToOrGreaterThan(int major, int minor = 0, int build = 0, [CallerMemberName] string propertyName = null)
private static bool IsEqualToOrGreaterThan(in int major, in int minor = 0, in int build = 0, [CallerMemberName] string propertyName = null)
{
lock (_lock)
{
Expand Down
29 changes: 27 additions & 2 deletions Source/Monitorian.Core/Models/Monitor/DdcMonitorItem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
Expand All @@ -19,6 +20,7 @@ internal class DdcMonitorItem : MonitorItem
public override bool IsBrightnessSupported => _capability.IsBrightnessSupported;
public override bool IsContrastSupported => _capability.IsContrastSupported;
public override bool IsPrecleared => _capability.IsPrecleared;
public override bool IsTemperatureSupported => _capability.IsTemperatureSupported;

public DdcMonitorItem(
string deviceInstanceId,
Expand Down Expand Up @@ -63,7 +65,7 @@ public override AccessResult UpdateBrightness(int brightness = -1)
public override AccessResult SetBrightness(int brightness)
{
if (brightness is < 0 or > 100)
throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be within 0 to 100.");
throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be from 0 to 100.");

var buffer = (uint)Math.Round(brightness / 100D * (_maximumBrightness - _minimumBrightness) + _minimumBrightness, MidpointRounding.AwayFromZero);

Expand Down Expand Up @@ -99,7 +101,7 @@ public override AccessResult UpdateContrast()
public override AccessResult SetContrast(int contrast)
{
if (contrast is < 0 or > 100)
throw new ArgumentOutOfRangeException(nameof(contrast), contrast, "The contrast must be within 0 to 100.");
throw new ArgumentOutOfRangeException(nameof(contrast), contrast, "The contrast must be from 0 to 100.");

var buffer = (uint)Math.Round(contrast / 100D * (_maximumContrast - _minimumContrast) + _minimumContrast, MidpointRounding.AwayFromZero);

Expand All @@ -112,6 +114,29 @@ public override AccessResult SetContrast(int contrast)
return result;
}

public override AccessResult ChangeTemperature()
{
var (result, current) = MonitorConfiguration.GetTemperature(_handle);
if (result.Status == AccessStatus.Succeeded)
{
var next = GetNext(_capability.Temperatures, current);
result = MonitorConfiguration.SetTemperature(_handle, next);

Debug.WriteLine($"Color Temperature: {current} -> {next}");
}
return result;

static byte GetNext(IReadOnlyList<byte> source, byte current)
{
for (int i = 0; i < source.Count; i++)
{
if (source[i] == current)
return (i < source.Count - 1) ? source[i + 1] : source[0];
}
return source.First(); // Fallback
}
}

#region IDisposable

private bool _isDisposed = false;
Expand Down
2 changes: 1 addition & 1 deletion Source/Monitorian.Core/Models/Monitor/DeviceInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public InstalledItem(

#endregion

private static readonly Guid GUID_DEVINTERFACE_MONITOR = new Guid("E6F07B5F-EE97-4a90-B076-33F57BF4EAA7");
private static readonly Guid GUID_DEVINTERFACE_MONITOR = new("E6F07B5F-EE97-4a90-B076-33F57BF4EAA7");

public static IEnumerable<InstalledItem> EnumerateInstalledMonitors()
{
Expand Down
8 changes: 4 additions & 4 deletions Source/Monitorian.Core/Models/Monitor/DisplayMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ public class DisplayItem : IDisplayItem
public string DisplayName { get; }

[DataMember(Order = 2)]
public bool IsInternal { get; }
public float PhysicalDiagonalLength { get; }

[DataMember(Order = 3)]
public string ConnectionDescription { get; }
public bool IsInternal { get; }

[DataMember(Order = 4)]
public float PhysicalSize { get; }
public string ConnectionDescription { get; }

public DisplayItem(Monitorian.Supplement.DisplayInformation.DisplayItem item)
{
this.DeviceInstanceId = item.DeviceInstanceId;
this.DisplayName = item.DisplayName;
this.PhysicalDiagonalLength = item.PhysicalDiagonalLength;
this.IsInternal = item.IsInternal;
this.ConnectionDescription = item.ConnectionDescription;
this.PhysicalSize = item.PhysicalSize;
}
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Monitorian.Core/Models/Monitor/IMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface IMonitor : IDisposable
bool IsReachable { get; }
bool IsBrightnessSupported { get; }
bool IsContrastSupported { get; }
bool IsTemperatureSupported { get; }

int Brightness { get; }
int BrightnessSystemAdjusted { get; }
Expand All @@ -29,6 +30,8 @@ public interface IMonitor : IDisposable

AccessResult UpdateContrast();
AccessResult SetContrast(int contrast);

AccessResult ChangeTemperature();
}

public enum AccessStatus
Expand Down
6 changes: 3 additions & 3 deletions Source/Monitorian.Core/Models/Monitor/LightSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ private interface ISensor
uint GetFriendlyName(out string friendlyName);
}

private static uint S_OK = 0x0;
private static uint E_ELEMENTNOTFOUND = 0x80070490; // 0x80070490 means 0x0490 -> 1168 -> ERROR_NOT_FOUND
private const uint S_OK = 0x0;
private const uint E_ELEMENTNOTFOUND = 0x80070490; // 0x80070490 means 0x0490 -> 1168 -> ERROR_NOT_FOUND

#endregion

private static Guid SENSOR_TYPE_AMBIENT_LIGHT => new Guid("97F115C8-599A-4153-8894-D2D12899918A");
private static Guid SENSOR_TYPE_AMBIENT_LIGHT => new("97F115C8-599A-4153-8894-D2D12899918A");

public static bool AmbientLightSensorExists => _ambientLightSensorExists.Value;
private static readonly Lazy<bool> _ambientLightSensorExists = new(() => SensorExists(SENSOR_TYPE_AMBIENT_LIGHT));
Expand Down
2 changes: 1 addition & 1 deletion Source/Monitorian.Core/Models/Monitor/MSMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static bool SetBrightness(string deviceInstanceId, int brightness, int ti
if (string.IsNullOrWhiteSpace(deviceInstanceId))
throw new ArgumentNullException(nameof(deviceInstanceId));
if (brightness is < 0 or > 100)
throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be within 0 to 100.");
throw new ArgumentOutOfRangeException(nameof(brightness), brightness, "The brightness must be from 0 to 100.");

try
{
Expand Down
Loading

0 comments on commit 92d3942

Please sign in to comment.