Skip to content

Commit

Permalink
Saving
Browse files Browse the repository at this point in the history
  • Loading branch information
buldo committed May 24, 2024
1 parent 6c3b321 commit 1ac90e3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
16 changes: 16 additions & 0 deletions src/EfuseManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<GroupBox Grid.Row="0" Header="Device">
<Grid Margin="0, 2, 0,2">
Expand Down Expand Up @@ -63,5 +64,20 @@
<views:EfuseView
Grid.Row="2"
DataContext="{Binding EfuseMap}"/>
<StatusBar Grid.Row="3" Height="24">
<StatusBar.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
</Grid>
</ItemsPanelTemplate>
</StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="0">
<TextBlock Text="{Binding Status}" d:DesignWidth="40"/>
</StatusBarItem>
</StatusBar>
</Grid>
</Window>
5 changes: 5 additions & 0 deletions src/EfuseManager/ViewModels/EfuseMapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,9 @@ public void LoadData(byte[] efuseMap)
{
_originalData = efuseMap;
}

public byte[] GetData()
{
return _originalData;
}
}
31 changes: 26 additions & 5 deletions src/EfuseManager/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -14,6 +15,7 @@
using Microsoft.Extensions.Logging.Abstractions;

using MvvmDialogs;
using MvvmDialogs.FrameworkDialogs.SaveFile;

using Rtl8812auNet;
using Rtl8812auNet.Rtl8812au.Enumerations;
Expand All @@ -25,6 +27,7 @@ internal class MainViewModel : ObservableObject, IDisposable
private readonly IDialogService _dialogService;
private readonly WiFiDriver _driver;
private DeviceViewModel? _selectedDevice;
private string _status = "";

public MainViewModel(IDialogService dialogService)
{
Expand Down Expand Up @@ -59,6 +62,12 @@ public DeviceViewModel? SelectedDevice

public EfuseMapViewModel EfuseMap { get; } = new();

public string Status
{
get => _status;
set => SetProperty(ref _status, value);
}

private void ExecuteWrite()
{
_dialogService.ShowMessageBox(
Expand All @@ -73,9 +82,11 @@ private void ExecuteRead()
{
if (SelectedDevice == null)
{
Status = "Error: No device selected";
return;
}

Status = "Start read";
var device = SelectedDevice.RealDevice;
var rtlDevice = _driver.CreateRtlDevice(device);
rtlDevice.NetDevOpen(new()
Expand All @@ -87,16 +98,26 @@ private void ExecuteRead()
});
var efuseMap = rtlDevice.ReadEfuse();
EfuseMap.LoadData(efuseMap);
Status = "Ready. OK.";
}

private void ExecuteWriteFile()
{
_dialogService.ShowMessageBox(
var efuseMap = EfuseMap.GetData();
var saveFileDialogSettings = new SaveFileDialogSettings()
{
AddExtension = true,
DefaultExt = ".bin"
};
var isOk = _dialogService.ShowSaveFileDialog(
this,
"Not implemented",
"Not implemented",
MessageBoxButton.OK,
MessageBoxImage.Warning);
saveFileDialogSettings);
if (isOk == true)
{
File.WriteAllBytes(
saveFileDialogSettings.FileName,
efuseMap);
}
}

private void ExecuteReadFile()
Expand Down

0 comments on commit 1ac90e3

Please sign in to comment.