Skip to content

Commit

Permalink
Add the charging mode feature to the gui
Browse files Browse the repository at this point in the history
  • Loading branch information
reagcz committed Oct 4, 2022
1 parent 564105d commit d5b1402
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
2 changes: 1 addition & 1 deletion IdeapadToolkit/Models/ChargingMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace IdeapadToolkit.Models
{
public enum ChargingMode
{
Conservative = 1,
Conservation = 1,
Normal = 0,
Rapid = 2
}
Expand Down
56 changes: 56 additions & 0 deletions IdeapadToolkit/ViewModels/LenovoSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ public LenovoSettingsViewModel(ILenovoPowerSettingsService lenovoPowerSettingsSe
public void Refresh()
{
Plan = _lenovoPowerSettingsService.GetPowerPlan();
Mode = _lenovoPowerSettingsService.GetChargingMode();
}

[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsEfficientChecked), nameof(IsIntelligentCoolingChecked), nameof(IsExtremePerformanceChecked))]
private PowerPlan _plan;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(IsConservationModeEnabled), nameof(IsNormalModeEnabled), nameof(IsRapidModeEnabled))]
private ChargingMode _mode;
private readonly ILenovoPowerSettingsService _lenovoPowerSettingsService;
private readonly IUEFISettingsService _uEFISettingsService;

#region PowerPlanProperties
public bool IsEfficientChecked
{
get
Expand All @@ -56,7 +61,9 @@ public bool IsExtremePerformanceChecked
}
set { }
}
#endregion

#region OtherProperties
public bool IsFlipToBootEnabled
{
get
Expand Down Expand Up @@ -93,6 +100,55 @@ public bool IsAlwaysOnUsbBatteryEnabled
_lenovoPowerSettingsService.SetAlwaysOnUsbBattery(value);
}
}
#endregion

#region ChargingModeProperties
public bool IsConservationModeEnabled
{
get
{
return _mode == ChargingMode.Conservation;
}
set
{
}
}

public bool IsNormalModeEnabled
{
get
{
return _mode == ChargingMode.Normal;
}
set
{
}
}

public bool IsRapidModeEnabled
{
get
{
return _mode == ChargingMode.Rapid;
}
set
{
}
}

#endregion

[RelayCommand]
private void SetChargingMode(int? mode)
{
if (mode == null) return;
try
{
_lenovoPowerSettingsService.SetChargingMode((ChargingMode)mode);
Refresh();
}
catch { }
}

[RelayCommand]
private void SetPlan(int? plan)
Expand Down
30 changes: 30 additions & 0 deletions IdeapadToolkit/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@
</RadioButton.CommandParameter>
</RadioButton>
</ui:SimpleStackPanel>
<TextBlock FontSize="24" Text="Battery Charging Mode" />
<ui:SimpleStackPanel>
<RadioButton
Command="{Binding SetChargingModeCommand}"
Content="Conservation"
GroupName="ChargingMode"
IsChecked="{Binding IsConservationModeEnabled}">
<RadioButton.CommandParameter>
<system:Int32>1</system:Int32>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
Command="{Binding SetChargingModeCommand}"
Content="Normal"
GroupName="ChargingMode"
IsChecked="{Binding IsNormalModeEnabled}">
<RadioButton.CommandParameter>
<system:Int32>0</system:Int32>
</RadioButton.CommandParameter>
</RadioButton>
<RadioButton
Command="{Binding SetChargingModeCommand}"
Content="Rapid"
GroupName="ChargingMode"
IsChecked="{Binding IsRapidModeEnabled}">
<RadioButton.CommandParameter>
<system:Int32>2</system:Int32>
</RadioButton.CommandParameter>
</RadioButton>
</ui:SimpleStackPanel>
<TextBlock
Margin="0,0,0,0"
FontSize="24"
Expand Down
13 changes: 13 additions & 0 deletions IdeapadToolkitTests/Services/LenovoPowerSettingsServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,18 @@ public void AlwaysOnUsbBattryRandomTest()
var res3 = _service.IsAlwaysOnUsbBatteryEnabled();
Assert.AreEqual(res, res3);
}

[TestMethod()]
private void SetChargingModeRandomTest()
{
_service.SetChargingMode(Models.ChargingMode.Normal);
Assert.IsTrue(_service.GetChargingMode() == Models.ChargingMode.Normal);
_service.SetChargingMode(Models.ChargingMode.Conservation);
Assert.IsTrue(_service.GetChargingMode() == Models.ChargingMode.Conservation);
_service.SetChargingMode(Models.ChargingMode.Rapid);
Assert.IsTrue(_service.GetChargingMode() == Models.ChargingMode.Rapid);
_service.SetChargingMode(Models.ChargingMode.Normal);
Assert.IsTrue(_service.GetChargingMode() == Models.ChargingMode.Normal);
}
}
}

0 comments on commit d5b1402

Please sign in to comment.