Skip to content

Commit

Permalink
Fix for app stability
Browse files Browse the repository at this point in the history
Jogging speed and distance selectors replaced with Non linear sliders
  • Loading branch information
IlyaChernov committed Sep 19, 2020
1 parent a66c320 commit 8c23414
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 65 deletions.
1 change: 1 addition & 0 deletions grbl.Master.Model/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class ApplicationSettings : NotifyPropertyChanged
public double JoggingDistance { get; set; }

public ObservableCollection<double> FeedRates { get; set; } = new ObservableCollection<double> { 5, 10, 50, 100, 500, 1000 };
public double SliderLinearity { get; set; }

public double FeedRate { get; set; }

Expand Down
11 changes: 10 additions & 1 deletion grbl.Master.Model/CommandSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;

public class CommandSource : NotifyPropertyChanged
{
private readonly Stopwatch _stopWatch = new Stopwatch();

private bool _needsPurge;

private readonly SynchronizationContext _uiContext;

private ConcurrentQueue<string> CommandQueue { get; } = new ConcurrentQueue<string>();

public TimeSpan Elapsed => _stopWatch.Elapsed;
Expand All @@ -31,6 +34,7 @@ public class CommandSource : NotifyPropertyChanged

public CommandSource(CommandSourceType type, CommandSourceRunMode mode)
{
_uiContext = SynchronizationContext.Current;
Type = type;
Mode = mode;
}
Expand Down Expand Up @@ -107,7 +111,12 @@ public void Purge()
{
CommandQueue.TryDequeue(out var dummy);
}
CommandList.Clear();

_uiContext.Send(
state =>
{
CommandList.Clear();
}, null);

_stopWatch.Reset();
}
Expand Down
14 changes: 13 additions & 1 deletion grbl.Master.Model/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions grbl.Master.Model/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
<Setting Name="JoggingSpeed" Type="System.Double" Scope="User">
<Value Profile="(Default)">1000</Value>
</Setting>
<Setting Name="SliderLinearity" Type="System.Double" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
</Settings>
</SettingsFile>
3 changes: 3 additions & 0 deletions grbl.Master.Model/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<setting name="JoggingSpeed" serializeAs="String">
<value>1000</value>
</setting>
<setting name="SliderLinearity" serializeAs="String">
<value>1</value>
</setting>
</grbl.Master.Model.Properties.Settings>
</userSettings>
</configuration>
4 changes: 4 additions & 0 deletions grbl.Master.Service/ApplicationSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public void Save()

Model.Properties.Settings.Default.JoggingSpeed = Settings.FeedRate;

Model.Properties.Settings.Default.SliderLinearity = Settings.SliderLinearity;

Model.Properties.Settings.Default.Save();
Model.Properties.Settings.Default.Reload();
}
Expand Down Expand Up @@ -114,6 +116,8 @@ public void Load()
Settings.JoggingDistance = Model.Properties.Settings.Default.JoggingDistance;

Settings.FeedRate = Model.Properties.Settings.Default.JoggingSpeed;

Settings.SliderLinearity = Model.Properties.Settings.Default.SliderLinearity;
}
}
}
1 change: 1 addition & 0 deletions grbl.Master.UI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</ResourceDictionary.MergedDictionaries>
<BooleanToVisibilityConverter x:Key="BoolToVis" />
<converters:StringIntegerToBool x:Key="StrIntToBool" />
<converters:NonLinearDouble x:Key="NonLinearDouble" />
<converters:IntegerToBinaryString x:Key="IntegerToBinaryString" />
<converters:IntegerMaskToAxisState x:Key="IntegerMaskToAxisState" />
<converters:IntegerMask3ToDescription x:Key="IntegerMask3ToDescription" />
Expand Down
44 changes: 44 additions & 0 deletions grbl.Master.UI/Converters/NonLinearDouble.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace grbl.Master.UI.Converters
{
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;

public class NonLinearDouble : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (parameter != null && parameter is Label powLbl && powLbl.Content is double pow)
{
pow = pow < 1 ? 1 : pow;
if (value != null)
{
if (value is double val)
{
return Math.Pow(val, 1d / pow);
}

if (value is ObservableCollection<double> vals && vals.Any())
{
return new DoubleCollection(vals.Select(val => Math.Pow(val, 1d / pow)));
}
}
}

return 0d;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null && value is double val && parameter != null && parameter is Label powLbl && powLbl.Content is double pow)
{
return Math.Round(Math.Pow(val, pow), 3);
}
return 0d;
}
}
}
65 changes: 63 additions & 2 deletions grbl.Master.UI/ViewModels/MasterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
using System.Reflection;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Media;
using System.Xml;

using grbl.Master.Common.Enum;
using grbl.Master.Common.Interfaces.BL;
using grbl.Master.Common.Interfaces.Service;
using grbl.Master.Model.Interface;
using grbl.Master.UI.Converters;

using Xceed.Wpf.Toolkit;

Expand All @@ -53,6 +55,8 @@ public class MasterViewModel : Screen

private string _manualCommand;

private NonLinearDouble _nonLinearDoubleConverter = new NonLinearDouble();

public MasterViewModel(
IComService comService,
IGrblStatus grblStatus,
Expand Down Expand Up @@ -119,6 +123,10 @@ public ObservableCollection<double> JoggingDistances
}
}

public double JoggingDistancesFirst => JoggingDistances.Any() ? JoggingDistances.First() : 0;

public double JoggingDistancesLast => JoggingDistances.Any() ? JoggingDistances.Last() : 0;

public ObservableCollection<double> FeedRates
{
get => _applicationSettingsService.Settings.FeedRates;
Expand All @@ -129,6 +137,25 @@ public ObservableCollection<double> FeedRates
}
}

public double FeedRatesFirst => FeedRates.Any() ? FeedRates.First() : 0;

public double FeedRatesLast => FeedRates.Any() ? FeedRates.Last() : 0;

public double SliderLinearity
{
get => _applicationSettingsService.Settings.SliderLinearity < 1 ? 1 : _applicationSettingsService.Settings.SliderLinearity;

set
{
_applicationSettingsService.Settings.SliderLinearity = value;
this.NotifyOfPropertyChange(() => SliderLinearity);
NotifyOfPropertyChange(() => FeedRates);
NotifyOfPropertyChange(() => JoggingDistances);
_applicationSettingsService.Save();
}
}


public ObservableCollection<Macros> Macroses => _applicationSettingsService.Settings.Macroses;

public TimeSpan Elapsed => _commandSender.FileCommands.Elapsed;
Expand Down Expand Up @@ -168,6 +195,40 @@ public double SelectedFeedRate
}
}

/*public DoubleCollection FeedRateTicks
{
get
{
var result = new DoubleCollection();
FeedRates.ToList().ForEach(
item =>
{
result.Add((double)_nonLinearDoubleConverter.Convert(item, null, 3d, CultureInfo.CurrentCulture));
});
return result;
}
}
public DoubleCollection JoggingDistanceTicks
{
get
{
var result = new DoubleCollection();
JoggingDistances.ToList().ForEach(
item =>
{
result.Add((double)_nonLinearDoubleConverter.Convert(item, null, 4d, CultureInfo.CurrentCulture));
});
return result;
}
}*/



public int FileLinesCount => _commandSender.FileCommands.CommandCount;

public int FileLinesProcessed => FileCommandsCollection.Count;
Expand Down Expand Up @@ -368,7 +429,7 @@ public void RefreshMacroLog()

public void RefreshFullLog()
{
_commandSender.CommunicationLog.Clear();;
_commandSender.CommunicationLog.Clear(); ;
}

public void SendEnterCommand()
Expand Down Expand Up @@ -549,7 +610,7 @@ public void CancelMacro()

public void AddMacro()
{
MacrosSelected = new Macros{Command = ""};
MacrosSelected = new Macros { Command = "" };
}

public void UpMacro(Macros macro)
Expand Down

0 comments on commit 8c23414

Please sign in to comment.