Skip to content

Commit

Permalink
Autoreset pin states
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaChernov committed Sep 20, 2020
1 parent 73df8ae commit 1a96358
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 6 deletions.
14 changes: 10 additions & 4 deletions grbl.Master.BL/GrblStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class GrblStatus : IGrblStatus
{
private readonly ICommandSender _commandSender;

//private readonly IGrblStatusModel _grblStatusModel;
private readonly IApplicationSettingsService _applicationSettingsService;

private readonly string _decimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;

Expand Down Expand Up @@ -49,9 +49,10 @@ private string TranslateMessageKey(string key)
return Model.Resources.Mssages.ResourceManager.GetString(key);
}

public GrblStatus(IComService comService, ICommandSender commandSender, IGrblStatusModel grblStatusModel)
public GrblStatus(IComService comService, ICommandSender commandSender, IGrblStatusModel grblStatusModel, IApplicationSettingsService applicationSettingsService)
{
_commandSender = commandSender;
_applicationSettingsService = applicationSettingsService;
GrblStatusModel = grblStatusModel;
comService.ConnectionStateChanged += ComServiceConnectionStateChanged;
_commandSender.ResponseReceived += CommandSenderResponseReceived;
Expand Down Expand Up @@ -239,6 +240,7 @@ public GrblStatus(IComService comService, ICommandSender commandSender, IGrblSta
GrblStatusModel.InputPinState.HoldPin = pinParts[1].Contains('H');
GrblStatusModel.InputPinState.SoftResetPin = pinParts[1].Contains('R');
GrblStatusModel.InputPinState.CycleStartPin = pinParts[1].Contains('S');
GrblStatusModel.InputPinState.UpdateDateTime = DateTime.Now;
}
} },
new ResponseProcessor{ TagExpression = "^Ov:\\d+(,\\d+){2}$", Action =
Expand Down Expand Up @@ -499,9 +501,14 @@ private void CommandSenderResponseReceived(object sender, Response e)
processor.ProcessActions.SingleOrDefault(x => x.Regex.IsMatch(part)).Action?.Invoke(part);
}
}

if (DateTime.Now - GrblStatusModel.InputPinState.UpdateDateTime > TimeSpan.FromSeconds(_applicationSettingsService.Settings.PinStateResetTimeout))
{
GrblStatusModel.InputPinState.Reset();
}
}

public IGrblStatusModel GrblStatusModel { get; } //=> _grblStatusModel; // { get; set; } = new GrblStatusModel();
public IGrblStatusModel GrblStatusModel { get; }

private bool _isRunning;

Expand All @@ -519,7 +526,6 @@ public void StartRequesting(TimeSpan positionsInterval, TimeSpan gStateInterval,
public void InitialRequest()
{
_commandSender.Send("$$");
// _commandSender.Send("$#");
}

public void StopRequesting()
Expand Down
2 changes: 2 additions & 0 deletions grbl.Master.Model/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class ApplicationSettings : NotifyPropertyChanged
public ObservableCollection<double> FeedRates { get; set; } = new ObservableCollection<double> { 5, 10, 50, 100, 500, 1000 };
public double SliderLinearity { get; set; }

public int PinStateResetTimeout { get; set; }

public double FeedRate { get; set; }

public ObservableCollection<Macros> Macroses { get; set; } = new ObservableCollection<Macros>();
Expand Down
10 changes: 10 additions & 0 deletions grbl.Master.Model/InputPinState.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace grbl.Master.Model
{
using System;

public class InputPinState : NotifyPropertyChanged
{
public DateTime UpdateDateTime { get; set; }

public bool XLimitPin { get; set; }

public bool YLimitPin { get; set; }
Expand All @@ -17,5 +21,11 @@ public class InputPinState : NotifyPropertyChanged
public bool SoftResetPin { get; set; }

public bool CycleStartPin { get; set; }

public void Reset()
{
XLimitPin = YLimitPin = ZLimitPin = ProbePin = DoorPin = HoldPin = SoftResetPin = CycleStartPin = false;
UpdateDateTime = DateTime.Now;
}
}
}
12 changes: 12 additions & 0 deletions 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 @@ -26,5 +26,8 @@
<Setting Name="SliderLinearity" Type="System.Double" Scope="User">
<Value Profile="(Default)">1</Value>
</Setting>
<Setting Name="PinStateResetTimeout" Type="System.Int32" 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 @@ -51,6 +51,9 @@
<setting name="SliderLinearity" serializeAs="String">
<value>1</value>
</setting>
<setting name="PinStateResetTimeout" 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 @@ -44,6 +44,8 @@ public void Save()

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

Model.Properties.Settings.Default.PinStateResetTimeout = Settings.PinStateResetTimeout;

Model.Properties.Settings.Default.Save();
Model.Properties.Settings.Default.Reload();
}
Expand Down Expand Up @@ -118,6 +120,8 @@ public void Load()
Settings.FeedRate = Model.Properties.Settings.Default.JoggingSpeed;

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

Settings.PinStateResetTimeout = Model.Properties.Settings.Default.PinStateResetTimeout;
}
}
}
12 changes: 12 additions & 0 deletions grbl.Master.UI/ViewModels/MasterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ public double SliderLinearity
}
}

public int PinStateResetTimeout
{
get => _applicationSettingsService.Settings.PinStateResetTimeout;

set
{
_applicationSettingsService.Settings.PinStateResetTimeout = value;
NotifyOfPropertyChange(() => PinStateResetTimeout);
_applicationSettingsService.Save();
}
}


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

Expand Down
7 changes: 5 additions & 2 deletions grbl.Master.UI/Views/MasterView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1454,10 +1454,10 @@
Text="{Binding FeedRates, Converter={StaticResource ListDoubleToString}, UpdateSourceTrigger=LostFocus}"
TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" />
</GroupBox>
<GroupBox Width="200" Margin="2" Padding="2">
<GroupBox Width="240" Margin="2" Padding="2" Header="User Interface">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="160" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
Expand All @@ -1470,6 +1470,9 @@
<Label Content="Linearity power:" />
<xctk:IntegerUpDown Grid.Row="0" Grid.Column="1" Minimum="1"
Value="{Binding SliderLinearity}" />
<Label Grid.Row="1" Grid.Column="0" Content="Pin state reset timeout (sec):" />
<xctk:IntegerUpDown Grid.Row="1" Grid.Column="1" Minimum="1"
Value="{Binding PinStateResetTimeout}" />
</Grid>
</GroupBox>
</WrapPanel>
Expand Down

0 comments on commit 1a96358

Please sign in to comment.