Skip to content

Commit

Permalink
fix UI acceleration display bug; save autoconnect & display to config…
Browse files Browse the repository at this point in the history
…file; expose connection status message; let save button indicate config modification status;
  • Loading branch information
comzyh committed Jul 25, 2019
1 parent ce41390 commit 5537f3b
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 45 deletions.
42 changes: 39 additions & 3 deletions WpfDemo/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
Expand All @@ -16,12 +16,14 @@ namespace WpfDemo
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
public partial class App : Application, INotifyPropertyChanged
{

public SensorsPage mainWindow { get; private set; }
public AddSensorPage discoverSensorsWindow { get; private set; }

public bool ConfigModified { get => configStore.Modified; }

public ObservableCollection<IBLEAccelerationSensor> Sensors
{
get { return bleSensors; }
Expand All @@ -35,6 +37,8 @@ public ObservableCollection<IBLEAccelerationSensor> Sensors
private System.Windows.Forms.NotifyIcon notifyIcon;
private HomeWindow homeWindow;

public event PropertyChangedEventHandler PropertyChanged;

public App()
{
ShutdownMode = ShutdownMode.OnExplicitShutdown;
Expand All @@ -44,6 +48,7 @@ protected override void OnStartup(StartupEventArgs e)
base.OnStartup(e);

configStore = new SFConfigStore();
configStore.PropertyChanged += ConfigStorePropertyChanged;

// init sensors
bleSensorsDict = new Dictionary<string, IBLEAccelerationSensor>();
Expand All @@ -56,6 +61,8 @@ protected override void OnStartup(StartupEventArgs e)
Normal = sensorConfig.Normal,
MACAddress = sensorConfig.MACAddress,
};
sensor.AutoConnect = sensorConfig.AutoConnect;
sensor.Binding.MonitorDeviceName = sensorConfig.BindedMonitor;
sensor.PropertyChanged += (object s, PropertyChangedEventArgs ev) =>
{
SyncSensorProperty(sensor, sensorConfig, ev.PropertyName);
Expand Down Expand Up @@ -131,14 +138,23 @@ private void sensorCollectionChanged(object sender, NotifyCollectionChangedEvent
{
throw new NotImplementedException();
}
//System.Diagnostics.Debugger.Break();
configStore.Modified = true;

}
private void SensorPropertyChangedEventHandler(object sender, PropertyChangedEventArgs e)
{

}
private void ConfigStorePropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "Modified")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ConfigModified"));
}
}
private void SyncSensorProperty(IBLEAccelerationSensor sensor, BLEGravitySensorConfig sensorConfig, string propertyName)
{
bool isConfigProperty = true;
switch (propertyName)
{
case "DeviceName":
Expand All @@ -156,6 +172,26 @@ private void SyncSensorProperty(IBLEAccelerationSensor sensor, BLEGravitySensorC
sensorConfig.Normal = sensor.Normal;
break;
}
case "AutoConnect":
{
sensorConfig.AutoConnect = sensor.AutoConnect;
break;
}
case "BindMonitor":
{
sensorConfig.BindedMonitor = sensor.Binding.MonitorDeviceName;
break;
}
default:
{
isConfigProperty = false;
break;
}

}
if (isConfigProperty)
{
configStore.Modified = true;
}
}
public void SaveSettings()
Expand Down
7 changes: 1 addition & 6 deletions WpfDemo/HomeWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@
<Controls:MetroTabItem Header="Add Sensor">
<Frame x:Name="AddSensorFrame"/>
</Controls:MetroTabItem>


</Controls:MetroAnimatedSingleRowTabControl>
<StackPanel Margin="0,0,0,8" Orientation="Horizontal" Height="30" VerticalAlignment="Bottom" Grid.RowSpan="2" HorizontalAlignment="Right" Width="160">
<Button x:Name="btnQuit" Content="Quit" HorizontalAlignment="Left" Margin="10,0,0,0" Click="BtnQuit_Click" Height="28" VerticalAlignment="Bottom" Width="60" />
<Button x:Name="btnSave" Content="Save" HorizontalAlignment="Left" Margin="10,0,0,0" Height="28" VerticalAlignment="Bottom" Click="BtnSave_Click" Width="60"/>
<Button x:Name="btnSave" Content="Save" HorizontalAlignment="Left" Margin="10,0,0,0" Height="28" VerticalAlignment="Bottom" Click="BtnSave_Click" Width="60" IsEnabled="{Binding Path=ConfigModified}"/>
</StackPanel>



</Grid>
</Window>
1 change: 1 addition & 0 deletions WpfDemo/HomeWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public HomeWindow(App app)
SensorsFrame.Content = new SensorsPage(app);
ManualFrame.Content = new ManualPage();
AddSensorFrame.Content = new AddSensorPage(app, this);
btnSave.DataContext = app;
}
private void BtnSave_Click(object sender, RoutedEventArgs e)
{
Expand Down
1 change: 1 addition & 0 deletions WpfDemo/Models/IBLEAccSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public interface IBLEAccelerationSensor : INotifyPropertyChanged

BLESensorConnectionStatus ConnectionStatus { get; }

string StatusMessage { get; }
void Disconnect();

//event AngleChangeHandler AngleChange;
Expand Down
5 changes: 5 additions & 0 deletions WpfDemo/Models/SFSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class BLEGravitySensorConfig
/// </summary>
public Vector3? Normal;

/// <summary>
/// AutoConnect when ScreenFerris starts
/// </summary>
public bool AutoConnect;


/// <summary>
/// Id of binding monitor
Expand Down
22 changes: 21 additions & 1 deletion WpfDemo/SFConfigStore.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,41 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfDemo
{
public class SFConfigStore
public class SFConfigStore : INotifyPropertyChanged
{
public SFSettings settings;
public bool Modified
{
get => modified; set
{
if (value != modified)
{
modified = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Modified"));
}
}
}
private bool modified;
private readonly string configurFilePath;


private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
//ContractResolver = new SettingsReaderContractResolver(),
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};

public event PropertyChangedEventHandler PropertyChanged;

public SFConfigStore(String configurFilePath = null)
{
if (configurFilePath == null)
Expand All @@ -26,6 +44,7 @@ public SFConfigStore(String configurFilePath = null)
}
this.configurFilePath = configurFilePath;
settings = Load(this.configurFilePath) as SFSettings;
Modified = false;
SettingsSanityCheck();
}

Expand Down Expand Up @@ -59,6 +78,7 @@ public string Serialize()
public void Save()
{
File.WriteAllText(configurFilePath, Serialize());
Modified = false;
}

}
Expand Down
Loading

0 comments on commit 5537f3b

Please sign in to comment.