This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
249 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using System; | ||
using System.Windows.Controls; | ||
using Microsoft.Win32; | ||
using WMR_USB_Controller.YUART.Utilities; | ||
|
||
namespace WMR_USB_Controller.YUART.Sleep_Mode | ||
{ | ||
/// <summary> | ||
/// Class, that provide controls for sleep mode of WMR. | ||
/// </summary> | ||
public sealed class SleepModeManager | ||
{ | ||
private const string PathToHololensRegKeys = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Holographic"; | ||
private const string SleepDelayRegkeyName = "IdleTimerDuration"; | ||
private const string ScreensaverModeRegkeyName = "ScreensaverModeEnabled"; | ||
private const int DefaultSleepDelay = 15; | ||
|
||
private readonly RegistryKey _hololensRegKey = Registry.CurrentUser.OpenSubKey(PathToHololensRegKeys, true); | ||
private readonly Label _sleepDelayValueLabel; | ||
private readonly Label _screensaverModeStatusLabel; | ||
private readonly CheckBox _screensaverModeCheckbox; | ||
|
||
public SleepModeManager(Label sleepDelayValueLabel, Label screensaverModeStatusLabel, CheckBox screensaverModeCheckbox) | ||
{ | ||
_sleepDelayValueLabel = sleepDelayValueLabel; | ||
_screensaverModeStatusLabel = screensaverModeStatusLabel; | ||
_screensaverModeCheckbox = screensaverModeCheckbox; | ||
} | ||
|
||
/// <summary> | ||
/// Initialize class and set startup UI values | ||
/// </summary> | ||
public void Initialize() | ||
{ | ||
UpdateUiValues(); | ||
} | ||
|
||
private void UpdateUiValues() | ||
{ | ||
UpdateLabelsValues(); | ||
|
||
SetScreensaverModeCheckboxValue(); | ||
} | ||
|
||
private void UpdateLabelsValues() | ||
{ | ||
SetCurrentSleepDelayValue(); | ||
SetCurrentScreensaverModeStatus(); | ||
} | ||
|
||
private void SetCurrentSleepDelayValue() | ||
{ | ||
_sleepDelayValueLabel.Content = $"{(_hololensRegKey.IsExists(SleepDelayRegkeyName) ? TimeConverter.ConvertMillisecondsIntoMinutes((int) _hololensRegKey.GetValue(SleepDelayRegkeyName)) : DefaultSleepDelay).ToString()} minutes"; | ||
} | ||
|
||
private void SetCurrentScreensaverModeStatus() | ||
{ | ||
_screensaverModeStatusLabel.Content = GetCurrentScreensaverModeStatusFromRegistry(); | ||
} | ||
|
||
private void SetScreensaverModeCheckboxValue() | ||
{ | ||
if (_screensaverModeCheckbox.IsChecked == null) return; | ||
|
||
_screensaverModeCheckbox.IsChecked = GetCurrentScreensaverModeStatusFromRegistry(); | ||
} | ||
|
||
private bool GetCurrentScreensaverModeStatusFromRegistry() | ||
{ | ||
return _hololensRegKey.IsExists(ScreensaverModeRegkeyName) && ((int) _hololensRegKey.GetValue(ScreensaverModeRegkeyName)).ConvertIntToBool(); | ||
} | ||
|
||
/// <summary> | ||
/// Set new value to regkey of sleep delay for WMR. | ||
/// </summary> | ||
/// <param name="newDelayInMinutes">New value of the sleep delay in minutes.</param> | ||
public void SetNewSleepDelay(int newDelayInMinutes) | ||
{ | ||
_hololensRegKey.SetValue(SleepDelayRegkeyName, TimeConverter.ConvertMinutesIntoMilliseconds(newDelayInMinutes)); | ||
|
||
SetCurrentSleepDelayValue(); | ||
} | ||
|
||
/// <summary> | ||
/// Set new value for screensaver regkey. | ||
/// </summary> | ||
/// <param name="newStatus">New status (on/off)</param> | ||
public void SetScreensaverModeStatus(bool newStatus) | ||
{ | ||
_hololensRegKey.SetValue(ScreensaverModeRegkeyName, newStatus.ConvertBoolToInt()); | ||
|
||
SetCurrentScreensaverModeStatus(); | ||
} | ||
|
||
/// <summary> | ||
/// Reset sleep delay value and screensaver mode value (this function will delete keys from the registry) | ||
/// </summary> | ||
public void ResetSleepModeValues() | ||
{ | ||
_hololensRegKey.DeleteValue(SleepDelayRegkeyName); | ||
_hololensRegKey.DeleteValue(ScreensaverModeRegkeyName); | ||
|
||
UpdateUiValues(); | ||
} | ||
} | ||
} |
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,18 @@ | ||
namespace WMR_USB_Controller.YUART.Utilities | ||
{ | ||
/// <summary> | ||
/// Class, that provides tools for int-bool conversion. | ||
/// </summary> | ||
public static class IntBoolConverter | ||
{ | ||
public static bool ConvertIntToBool(this int value) | ||
{ | ||
return value == 1; | ||
} | ||
|
||
public static int ConvertBoolToInt(this bool value) | ||
{ | ||
return value ? 1 : 0; | ||
} | ||
} | ||
} |
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,15 @@ | ||
using Microsoft.Win32; | ||
|
||
namespace WMR_USB_Controller.YUART.Utilities | ||
{ | ||
/// <summary> | ||
/// Class, that provides method to check regkeys. | ||
/// </summary> | ||
public static class RegkeyChecker | ||
{ | ||
public static bool IsExists(this RegistryKey regkey, string keyName) | ||
{ | ||
return regkey.GetValue(keyName) != null; | ||
} | ||
} | ||
} |
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,22 @@ | ||
using System; | ||
|
||
namespace WMR_USB_Controller.YUART.Utilities | ||
{ | ||
/// <summary> | ||
/// Class, that handles methods for time conversion. | ||
/// </summary> | ||
public static class TimeConverter | ||
{ | ||
private const double MillisecondsInMinute = 60000d; | ||
|
||
public static int ConvertMillisecondsIntoMinutes(int milliseconds) | ||
{ | ||
return Convert.ToInt32(Math.Round(milliseconds / MillisecondsInMinute)); | ||
} | ||
|
||
public static int ConvertMinutesIntoMilliseconds(int minutes) | ||
{ | ||
return Convert.ToInt32(minutes * MillisecondsInMinute); | ||
} | ||
} | ||
} |