Skip to content

Commit

Permalink
Macros editor size fix
Browse files Browse the repository at this point in the history
High CPU usage fix
Macros decimals fix
Macros stop on error/alarm
  • Loading branch information
IlyaChernov committed Sep 6, 2020
1 parent 22d74d8 commit 8496083
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 39 deletions.
2 changes: 1 addition & 1 deletion grbl.Master.Model/Attribute/ChangeCommandAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class ChangeCommandAttribute : Attribute

public ChangeCommandAttribute(string command)
{
this.Command = command;
Command = command;
}
}
}
9 changes: 6 additions & 3 deletions grbl.Master.Model/CommandSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ public void StopProcessing()

public bool TryPeekCommand(out Command command)
{
if (State == CommandSourceState.Running && CommandQueue.TryPeek(out var cmdText))
if (!CommandQueue.IsEmpty)
{
command = new Command { Data = cmdText, Source = Type };
return true;
if (State == CommandSourceState.Running && CommandQueue.TryPeek(out var cmdText))
{
command = new Command { Data = cmdText, Source = Type };
return true;
}
}

command = null;
Expand Down
2 changes: 1 addition & 1 deletion grbl.Master.Model/GrblSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void AddOrUpdate(GrblSetting setting)

private GrblSettingType FindType(int index)
{
return this._typeTable.Any(x => x.Value.Any(y => y == index)) ? this._typeTable.FirstOrDefault(x => x.Value.Any(y => y == index)).Key : GrblSettingType.Integer;
return _typeTable.Any(x => x.Value.Any(y => y == index)) ? _typeTable.FirstOrDefault(x => x.Value.Any(y => y == index)).Key : GrblSettingType.Integer;
}
}
}
36 changes: 18 additions & 18 deletions grbl.Master.Service/CommandSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public CommandSender(IComService comService, IGrblResponseTypeFinder responseTyp
private void ProcessQueue()
{
_processing = true;
Observable.Timer(TimeSpan.Zero, TimeSpan.Zero).TakeUntil(_stopSubject).Subscribe(
Observable.Timer(TimeSpan.Zero, TimeSpan.FromMilliseconds(10)).TakeUntil(_stopSubject).Subscribe(
l =>
{
if ((SystemCommands.TryPeekCommand(out var cmd) || ManualCommands.TryPeekCommand(out cmd) || FileCommands.TryPeekCommand(out cmd) || this.FileCommands.State != CommandSourceState.Running && this._waitingCommandQueue.Count == 0 && this.MacroCommands.TryPeekCommand(out cmd)) && cmd != null && cmd.Data.RemoveSpace().Length + CommandQueueLength <= _bufferSizeLimit)
if ((SystemCommands.TryPeekCommand(out var cmd) || ManualCommands.TryPeekCommand(out cmd) || FileCommands.TryPeekCommand(out cmd) || FileCommands.State != CommandSourceState.Running && _waitingCommandQueue.Count == 0 && MacroCommands.TryPeekCommand(out cmd)) && cmd != null && cmd.Data.RemoveSpace().Length + CommandQueueLength <= _bufferSizeLimit)
{
var continueProcess = cmd.Source switch
{
CommandSourceType.System => this.SystemCommands.TryGetCommand(out cmd),
CommandSourceType.Macros => this.MacroCommands.TryGetCommand(out cmd),
CommandSourceType.Manual => this.ManualCommands.TryGetCommand(out cmd),
CommandSourceType.File => this.FileCommands.TryGetCommand(out cmd),
_ => false
};
{
CommandSourceType.System => SystemCommands.TryGetCommand(out cmd),
CommandSourceType.Macros => MacroCommands.TryGetCommand(out cmd),
CommandSourceType.Manual => ManualCommands.TryGetCommand(out cmd),
CommandSourceType.File => FileCommands.TryGetCommand(out cmd),
_ => false
};
if (!continueProcess) return;
Expand Down Expand Up @@ -140,15 +140,6 @@ public void Send(string command, string onResult = null)
}
}

//public Command Prepare(string command)
//{
// var cmd = new Command { Data = command };

// _commandPreProcessor.Process(ref cmd);

// return cmd;
//}

public void SendAsync(string command, string onResult = null)
{
Observable.Start(() => { Send(command, onResult); }).Subscribe();
Expand All @@ -165,6 +156,7 @@ public void PurgeQueues()
SystemCommands.Purge();
ManualCommands.Purge();
FileCommands.Purge();
MacroCommands.Purge();
}

private void ComServiceConnectionStateChanged(object sender, ConnectionState e)
Expand Down Expand Up @@ -242,6 +234,10 @@ private void ComServiceLineReceived(object sender, string e)
{
FileCommands.PauseProcessing();
}
else if (cmd.Source == CommandSourceType.Macros)
{
MacroCommands.Purge();
}
}
else if (type == ResponseType.Alarm)
{
Expand All @@ -252,6 +248,10 @@ private void ComServiceLineReceived(object sender, string e)
{
FileCommands.PauseProcessing();
}
else if (cmd.Source == CommandSourceType.Macros)
{
MacroCommands.Purge();
}
}

if (!string.IsNullOrEmpty(cmd.CommandOnResult))
Expand Down
3 changes: 2 additions & 1 deletion grbl.Master.Service/GrblCommandPreProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace grbl.Master.Service
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
Expand Down Expand Up @@ -121,7 +122,7 @@ private string Evaluate(string line)
{
try
{
return (_evaluator.Execute(line).GetCompletionValue().ToObject() ?? string.Empty).ToString()
return (_evaluator.Execute(line.Replace(',', '.')).GetCompletionValue().ToObject() ?? string.Empty).ToString()
.Replace(',', '.');
}
catch
Expand Down
2 changes: 1 addition & 1 deletion grbl.Master.UI/Input/KeyTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void OnDetaching()
private void OnAssociatedObjectKeyDown(object sender, KeyEventArgs e)
{
var key = e.Key == Key.System ? e.SystemKey : e.Key;
if (key == this.Key && Keyboard.Modifiers == GetActualModifiers(e.Key, this.Modifiers))
if (key == Key && Keyboard.Modifiers == GetActualModifiers(e.Key, Modifiers))
{
InvokeActions(e);
}
Expand Down
2 changes: 1 addition & 1 deletion grbl.Master.UI/ViewModels/COMConnectionViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void ReloadComPorts()

public bool CanChangePortBaud => !_comService.IsConnected;

public bool CanConnect => !string.IsNullOrWhiteSpace(this.SelectedComPort) && this.SelectedBaudRate > 0 || _comService.IsConnected;
public bool CanConnect => !string.IsNullOrWhiteSpace(SelectedComPort) && SelectedBaudRate > 0 || _comService.IsConnected;

public void Connect()
{
Expand Down
4 changes: 2 additions & 2 deletions grbl.Master.UI/ViewModels/MasterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public IHighlightingDefinition GCodeHighlighting
{
get
{
return this._gCodeHighlighting ??= GetHighlightingDefinition();
return _gCodeHighlighting ??= GetHighlightingDefinition();
}
}

Expand Down Expand Up @@ -424,7 +424,7 @@ public void JoggingCommand(string code)
_joggingCount = 0;
_jogStopSubject.OnNext(Unit.Default);

var requestSpeed = this.SelectedJoggingDistance / (this.SelectedFeedRate / 60000) * 0.9;
var requestSpeed = SelectedJoggingDistance / (SelectedFeedRate / 60000) * 0.9;

_commandSender.SendAsync(
"$J=" + string.Format(
Expand Down
32 changes: 21 additions & 11 deletions grbl.Master.UI/Views/MasterView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -892,8 +892,26 @@
</DataTemplate>
</TabItem.Resources>
<DockPanel>
<Grid Height="400" DockPanel.Dock="Bottom"
Visibility="{Binding IsMacrosSelected, Converter={StaticResource BoolToVis}, FallbackValue=Visible}">
<ScrollViewer x:Name="MyScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top">
<ScrollViewer.Resources>
<Style TargetType="ScrollViewer">
<Style.Triggers>
<DataTrigger Binding="{Binding IsMacrosSelected}" Value="True">
<Setter Property="Height" Value="200" />
</DataTrigger>
</Style.Triggers>
</Style>
</ScrollViewer.Resources>
<ItemsControl ItemTemplate="{StaticResource MacrosTemplate}" ItemsSource="{Binding Macroses}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
<Grid DockPanel.Dock="Bottom"
Visibility="{Binding IsMacrosSelected, Converter={StaticResource BoolToVis}, FallbackValue=Visible}" >
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="30" />
Expand Down Expand Up @@ -935,15 +953,7 @@
<materialDesign:PackIcon Width="20" Height="20" Foreground="Red" Kind="CloseCircleOutline" />
</Button>
</Grid>
<ScrollViewer x:Name="MyScrollViewer" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
<ItemsControl ItemTemplate="{StaticResource MacrosTemplate}" ItemsSource="{Binding Macroses}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>

</DockPanel>
</TabItem>
</TabControl>
Expand Down

0 comments on commit 8496083

Please sign in to comment.