Skip to content

Commit f75d18d

Browse files
tylerkronqodo-merge-pro[bot]cptkoolbeenzclaude
authored
feat: add delay and re-enable WiFi after network configuration change… (#190)
Signed-off-by: Tyler Kron <[email protected]> Co-authored-by: qodo-merge-pro[bot] <151058649+qodo-merge-pro[bot]@users.noreply.github.com> Co-authored-by: DAQiFi Developer <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent cf2c83b commit f75d18d

File tree

7 files changed

+308
-282
lines changed

7 files changed

+308
-282
lines changed

Daqifi.Desktop/Device/AbstractStreamingDevice.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using ScpiMessageProducer = Daqifi.Core.Communication.Producers.ScpiMessageProducer;
1414
using System.Runtime.InteropServices; // Added for P/Invoke
1515
using CommunityToolkit.Mvvm.ComponentModel; // Added using
16+
using System.Threading;
1617

1718
namespace Daqifi.Desktop.Device;
1819

@@ -541,6 +542,17 @@ public void RefreshSdCardFiles()
541542

542543
// Now request the file list
543544
MessageProducer.Send(ScpiMessageProducer.GetSdFileList);
545+
546+
// Give time for the file list response to be received
547+
Thread.Sleep(500);
548+
549+
// After getting the file list, restore LAN interface if we're in StreamToApp mode
550+
// SD and LAN share the same SPI bus and cannot be enabled simultaneously
551+
if (Mode == DeviceMode.StreamToApp)
552+
{
553+
MessageProducer.Send(ScpiMessageProducer.DisableStorageSd);
554+
MessageProducer.Send(ScpiMessageProducer.EnableNetworkLan);
555+
}
544556
}
545557

546558
public void UpdateSdCardFiles(List<SdCardFile> files)
@@ -866,7 +878,7 @@ private static double ScaleAnalogSample(AnalogChannel channel, double analogValu
866878
channel.InternalScaleMValue + channel.CalibrationBValue;
867879
}
868880

869-
public void UpdateNetworkConfiguration()
881+
public async Task UpdateNetworkConfiguration()
870882
{
871883
if (IsStreaming) { StopStreaming(); }
872884

@@ -898,6 +910,20 @@ public void UpdateNetworkConfiguration()
898910

899911
MessageProducer.Send(ScpiMessageProducer.SetNetworkWifiPassword(NetworkConfiguration.Password));
900912
MessageProducer.Send(ScpiMessageProducer.ApplyNetworkLan);
913+
914+
// Wait for WiFi module to restart after applying settings
915+
await Task.Delay(2000);
916+
917+
// Re-enable WiFi after the module restarts, but only if we're in StreamToApp mode
918+
// The ApplyNetworkLan command causes the WiFi module to restart,
919+
// so we need to re-enable it after the restart completes.
920+
// SD and WiFi share the same SPI bus and cannot be enabled simultaneously.
921+
if (Mode == DeviceMode.StreamToApp)
922+
{
923+
MessageProducer.Send(ScpiMessageProducer.DisableStorageSd);
924+
MessageProducer.Send(ScpiMessageProducer.EnableNetworkLan);
925+
}
926+
901927
MessageProducer.Send(ScpiMessageProducer.SaveNetworkLan);
902928
}
903929

Daqifi.Desktop/Device/HidDevice/HidFirmwareDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void UpdateFirmware(byte[] data)
9191
throw new NotImplementedException();
9292
}
9393

94-
public void UpdateNetworkConfiguration()
94+
public Task UpdateNetworkConfiguration()
9595
{
9696
throw new NotImplementedException();
9797
}

Daqifi.Desktop/Device/IStreamingDevice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ public interface IStreamingDevice : IDevice
7272

7373
void SetChannelDirection(IChannel channel, ChannelDirection direction);
7474

75-
void UpdateNetworkConfiguration();
75+
Task UpdateNetworkConfiguration();
7676
}
Lines changed: 111 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
2-
<UserControl x:Class="Daqifi.Desktop.View.DeviceLogsView"
3-
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4-
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6-
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7-
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
8-
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
9-
xmlns:converters="clr-namespace:Daqifi.Desktop.Converters"
10-
mc:Ignorable="d"
11-
d:DesignHeight="450" d:DesignWidth="800">
12-
<UserControl.Resources>
13-
<converters:ConnectionTypeToColorConverter x:Key="ConnectionTypeToColorConverter"/>
14-
<converters:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter"/>
15-
<BooleanToVisibilityConverter x:Key="BoolToVis"/>
16-
</UserControl.Resources>
17-
<Grid>
18-
<Grid.RowDefinitions>
19-
<RowDefinition Height="Auto"/>
20-
<RowDefinition Height="*"/>
21-
</Grid.RowDefinitions>
22-
23-
<!-- Device Selection -->
24-
<Grid Grid.Row="0" Margin="0,0,0,10">
25-
<Grid.RowDefinitions>
26-
<RowDefinition Height="Auto"/>
27-
<RowDefinition Height="Auto"/>
28-
</Grid.RowDefinitions>
29-
<Grid.ColumnDefinitions>
30-
<ColumnDefinition Width="Auto"/>
31-
<ColumnDefinition Width="*"/>
32-
<ColumnDefinition Width="Auto"/>
33-
</Grid.ColumnDefinitions>
34-
35-
<!-- Device Selection Row -->
36-
<TextBlock Text="Device:"
37-
Grid.Row="0"
38-
VerticalAlignment="Center"
39-
Margin="0,0,10,0"/>
40-
41-
<ComboBox Grid.Row="0"
42-
Grid.Column="1"
43-
ItemsSource="{Binding ConnectedDevices}"
44-
SelectedItem="{Binding SelectedDevice}"
45-
DisplayMemberPath="DeviceSerialNo"
46-
Margin="0,0,10,0"/>
47-
48-
<Button Grid.Row="0"
49-
Grid.Column="2"
50-
Command="{Binding RefreshFilesCommand}"
51-
ToolTip="{Binding ConnectionTypeMessage}"
52-
IsEnabled="{Binding CanAccessSdCard}">
53-
<StackPanel Orientation="Horizontal">
54-
<iconPacks:PackIconMaterial Kind="Refresh" Margin="0,0,5,0"/>
55-
<TextBlock Text="Refresh Files"/>
56-
</StackPanel>
57-
</Button>
58-
59-
<!-- Connection Status Row -->
60-
<TextBlock Grid.Row="1"
61-
Grid.Column="0"
62-
Grid.ColumnSpan="3"
63-
Text="{Binding ConnectionTypeMessage}"
64-
Margin="0,5,0,0"
65-
FontSize="14"
66-
FontWeight="SemiBold"
67-
Foreground="{Binding SelectedDevice.ConnectionType, Converter={StaticResource ConnectionTypeToColorConverter}}"
68-
HorizontalAlignment="Left"
69-
Visibility="{Binding SelectedDevice, Converter={StaticResource NotNullToVisibilityConverter}}"/>
70-
</Grid>
71-
72-
<!-- Device Files List -->
73-
<Grid Grid.Row="1">
74-
<ListView ItemsSource="{Binding DeviceFiles}"
75-
Background="Transparent"
76-
BorderThickness="0"
77-
IsEnabled="{Binding CanAccessSdCard}">
78-
<ListView.View>
79-
<GridView>
80-
<GridViewColumn Header="Name" Width="300">
81-
<GridViewColumn.CellTemplate>
82-
<DataTemplate>
83-
<TextBlock Text="{Binding FileName}" />
84-
</DataTemplate>
85-
</GridViewColumn.CellTemplate>
86-
</GridViewColumn>
87-
<GridViewColumn Header="Created" Width="200">
88-
<GridViewColumn.CellTemplate>
89-
<DataTemplate>
90-
<TextBlock Text="{Binding CreatedDate, StringFormat=\{0:g\}}" />
91-
</DataTemplate>
92-
</GridViewColumn.CellTemplate>
93-
</GridViewColumn>
94-
</GridView>
95-
</ListView.View>
96-
</ListView>
97-
</Grid>
98-
99-
<!-- Loading Overlay -->
100-
<Grid Grid.RowSpan="2" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}">
101-
<Rectangle Fill="White" Opacity="0.75" IsHitTestVisible="False"/>
102-
<StackPanel VerticalAlignment="Center">
103-
<Controls:ProgressRing IsActive="{Binding IsBusy}"/>
104-
<Label Content="{Binding BusyMessage}"
105-
FontSize="14"
106-
HorizontalContentAlignment="Center"
107-
Foreground="#CC119EDA"
108-
FontWeight="Bold"/>
109-
</StackPanel>
110-
</Grid>
111-
</Grid>
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<UserControl x:Class="Daqifi.Desktop.View.DeviceLogsView"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
8+
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
9+
xmlns:converters="clr-namespace:Daqifi.Desktop.Converters"
10+
mc:Ignorable="d"
11+
d:DesignHeight="450" d:DesignWidth="800">
12+
<UserControl.Resources>
13+
<converters:ConnectionTypeToColorConverter x:Key="ConnectionTypeToColorConverter"/>
14+
<converters:NotNullToVisibilityConverter x:Key="NotNullToVisibilityConverter"/>
15+
<BooleanToVisibilityConverter x:Key="BoolToVis"/>
16+
</UserControl.Resources>
17+
<Grid>
18+
<Grid.RowDefinitions>
19+
<RowDefinition Height="Auto"/>
20+
<RowDefinition Height="*"/>
21+
</Grid.RowDefinitions>
22+
23+
<!-- Device Selection -->
24+
<Grid Grid.Row="0" Margin="0,0,0,10">
25+
<Grid.RowDefinitions>
26+
<RowDefinition Height="Auto"/>
27+
<RowDefinition Height="Auto"/>
28+
</Grid.RowDefinitions>
29+
<Grid.ColumnDefinitions>
30+
<ColumnDefinition Width="Auto"/>
31+
<ColumnDefinition Width="*"/>
32+
<ColumnDefinition Width="Auto"/>
33+
</Grid.ColumnDefinitions>
34+
35+
<!-- Device Selection Row -->
36+
<TextBlock Text="Device:"
37+
Grid.Row="0"
38+
VerticalAlignment="Center"
39+
Margin="0,0,10,0"/>
40+
41+
<ComboBox Grid.Row="0"
42+
Grid.Column="1"
43+
ItemsSource="{Binding ConnectedDevices}"
44+
SelectedItem="{Binding SelectedDevice}"
45+
DisplayMemberPath="DeviceSerialNo"
46+
Margin="0,0,10,0"/>
47+
48+
<Button Grid.Row="0"
49+
Grid.Column="2"
50+
Command="{Binding RefreshFilesCommand}"
51+
ToolTip="{Binding ConnectionTypeMessage}"
52+
IsEnabled="{Binding CanAccessSdCard}">
53+
<StackPanel Orientation="Horizontal">
54+
<iconPacks:PackIconMaterial Kind="Refresh" Margin="0,0,5,0"/>
55+
<TextBlock Text="Refresh Files"/>
56+
</StackPanel>
57+
</Button>
58+
59+
<!-- Connection Status Row -->
60+
<TextBlock Grid.Row="1"
61+
Grid.Column="0"
62+
Grid.ColumnSpan="3"
63+
Text="{Binding ConnectionTypeMessage}"
64+
Margin="0,5,0,0"
65+
FontSize="14"
66+
FontWeight="SemiBold"
67+
Foreground="{Binding SelectedDevice.ConnectionType, Converter={StaticResource ConnectionTypeToColorConverter}}"
68+
HorizontalAlignment="Left"
69+
Visibility="{Binding SelectedDevice, Converter={StaticResource NotNullToVisibilityConverter}}"/>
70+
</Grid>
71+
72+
<!-- Device Files List -->
73+
<Grid Grid.Row="1">
74+
<ListView ItemsSource="{Binding DeviceFiles}"
75+
Background="Transparent"
76+
BorderThickness="0"
77+
IsEnabled="{Binding CanAccessSdCard}">
78+
<ListView.View>
79+
<GridView>
80+
<GridViewColumn Header="Name" Width="300">
81+
<GridViewColumn.CellTemplate>
82+
<DataTemplate>
83+
<TextBlock Text="{Binding FileName}" />
84+
</DataTemplate>
85+
</GridViewColumn.CellTemplate>
86+
</GridViewColumn>
87+
<GridViewColumn Header="Created" Width="200">
88+
<GridViewColumn.CellTemplate>
89+
<DataTemplate>
90+
<TextBlock Text="{Binding CreatedDate, StringFormat=\{0:g\}}" />
91+
</DataTemplate>
92+
</GridViewColumn.CellTemplate>
93+
</GridViewColumn>
94+
</GridView>
95+
</ListView.View>
96+
</ListView>
97+
</Grid>
98+
99+
<!-- Loading Overlay -->
100+
<Grid Grid.RowSpan="2" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVis}}">
101+
<Rectangle Fill="White" Opacity="0.75" IsHitTestVisible="False"/>
102+
<StackPanel VerticalAlignment="Center">
103+
<Controls:ProgressRing IsActive="{Binding IsBusy}"/>
104+
<Label Content="{Binding BusyMessage}"
105+
FontSize="14"
106+
HorizontalContentAlignment="Center"
107+
Foreground="#CC119EDA"
108+
FontWeight="Bold"/>
109+
</StackPanel>
110+
</Grid>
111+
</Grid>
112112
</UserControl>
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace Daqifi.Desktop.View;
2-
3-
public partial class DeviceLogsView
4-
{
5-
public DeviceLogsView()
6-
{
7-
InitializeComponent();
8-
}
1+
namespace Daqifi.Desktop.View;
2+
3+
public partial class DeviceLogsView
4+
{
5+
public DeviceLogsView()
6+
{
7+
InitializeComponent();
8+
}
99
}

Daqifi.Desktop/ViewModels/DaqifiViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,9 +707,9 @@ public void Shutdown()
707707
}
708708

709709
[RelayCommand]
710-
public void UpdateNetworkConfiguration()
710+
public async Task UpdateNetworkConfiguration()
711711
{
712-
SelectedDevice.UpdateNetworkConfiguration();
712+
await SelectedDevice.UpdateNetworkConfiguration();
713713
_dialogService.ShowDialog<SuccessDialog>(this, new SuccessDialogViewModel("WiFi settings updated."));
714714
}
715715

0 commit comments

Comments
 (0)