private void AxisEnabled_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (AxisEnabled.Value.ToString().Length == 1) { Comms.com.WriteString(string.Format("M122{0}S1\r", AxisEnabled.Value.ToString())); SGValue = GrblSettings.GetInteger(grblHALSetting.StallGuardBase + GrblInfo.AxisLetterToIndex(AxisEnabled.Value.ToString())); } }
private void updateConfig() { grbl.JogStep = jogDistance[(int)JogMode.Step] = AppConfig.Settings.Jog.StepDistance; jogDistance[(int)JogMode.Slow] = AppConfig.Settings.Jog.SlowDistance; jogDistance[(int)JogMode.Fast] = AppConfig.Settings.Jog.SlowDistance; jogSpeed[(int)JogMode.Step] = AppConfig.Settings.Jog.StepFeedrate; jogSpeed[(int)JogMode.Slow] = AppConfig.Settings.Jog.SlowFeedrate; jogSpeed[(int)JogMode.Fast] = AppConfig.Settings.Jog.FastFeedrate; softLimits = GrblSettings.GetInteger(GrblSetting.SoftLimitsEnable) == 1; if (!GrblInfo.IsGrblHAL) { fullJog = AppConfig.Settings.Jog.KeyboardEnable; } }
public void Activate(bool activate, ViewType chgMode) { Comms.com.WriteString(string.Format("M122S{0}H{1}\r", activate ? 1 : 0, SFiltEnabled == true ? 1 : 0)); if (activate) { DataContext = model; model.OnResponseReceived += ProcessSGValue; model.PropertyChanged += OnDataContextPropertyChanged; SGValue = GrblSettings.GetInteger(GrblSetting.StallGuardBase + GrblInfo.AxisLetterToIndex(AxisEnabled.Value.ToString())); } else { model.OnResponseReceived -= ProcessSGValue; model.PropertyChanged -= OnDataContextPropertyChanged; DataContext = null; } model.Poller.SetState(activate ? AppConfig.Settings.Base.PollInterval : 0); }
private void JogControl_Loaded(object sender, RoutedEventArgs e) { if (DataContext is GrblViewModel) { mode = GrblSettings.GetInteger(GrblSetting.ReportInches) == 0 ? "G21" : "G20"; softLimits = !(GrblInfo.IsGrblHAL && GrblSettings.GetInteger(grblHALSetting.SoftLimitJogging) == 1) && GrblSettings.GetInteger(GrblSetting.SoftLimitsEnable) == 1; limitSwitchesClearance = GrblSettings.GetDouble(GrblSetting.HomingPulloff); JogData.SetMetric(mode == "G21"); if (!keyboardMappingsOk) { if (!GrblInfo.HasFirmwareJog || AppConfig.Settings.Jog.LinkStepJogToUI) { JogData.PropertyChanged += JogData_PropertyChanged; } if (softLimits) { (DataContext as GrblViewModel).PropertyChanged += Model_PropertyChanged; } keyboard = (DataContext as GrblViewModel).Keyboard; keyboardMappingsOk = true; if (AppConfig.Settings.Jog.Mode == JogConfig.JogMode.UI) { keyboard.AddHandler(Key.PageUp, ModifierKeys.None, cursorKeyJog, false); keyboard.AddHandler(Key.PageDown, ModifierKeys.None, cursorKeyJog, false); keyboard.AddHandler(Key.Left, ModifierKeys.None, cursorKeyJog, false); keyboard.AddHandler(Key.Up, ModifierKeys.None, cursorKeyJog, false); keyboard.AddHandler(Key.Right, ModifierKeys.None, cursorKeyJog, false); keyboard.AddHandler(Key.Down, ModifierKeys.None, cursorKeyJog, false); } keyboard.AddHandler(xplus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); keyboard.AddHandler(xminus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); keyboard.AddHandler(yplus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); keyboard.AddHandler(yminus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); keyboard.AddHandler(zplus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); keyboard.AddHandler(zminus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); if (GrblInfo.AxisFlags.HasFlag(AxisFlags.A)) { keyboard.AddHandler(aplus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); keyboard.AddHandler(aminus, ModifierKeys.Control | ModifierKeys.Shift, normalKeyJog, false); } if (AppConfig.Settings.Jog.Mode != JogConfig.JogMode.Keypad) { keyboard.AddHandler(Key.End, ModifierKeys.None, endJog, false); keyboard.AddHandler(Key.NumPad0, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad1, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad2, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad3, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad4, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad5, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad6, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad7, ModifierKeys.Control, adjustJog); keyboard.AddHandler(Key.NumPad2, ModifierKeys.None, adjustJog2); keyboard.AddHandler(Key.NumPad4, ModifierKeys.None, adjustJog2); keyboard.AddHandler(Key.NumPad6, ModifierKeys.None, adjustJog2); keyboard.AddHandler(Key.NumPad8, ModifierKeys.None, adjustJog2); } } } }
private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is GrblViewModel) { switch (e.PropertyName) { case nameof(GrblViewModel.GrblState): GrblStateChanged(((GrblViewModel)sender).GrblState); break; case nameof(GrblViewModel.MDI): SendCommand(((GrblViewModel)sender).MDI); break; case nameof(GrblViewModel.IsMPGActive): grblState.MPG = ((GrblViewModel)sender).IsMPGActive == true; ((GrblViewModel)sender).Poller.SetState(grblState.MPG ? 0 : AppConfig.Settings.Base.PollInterval); streamingHandler.Call(grblState.MPG ? StreamingState.Disabled : StreamingState.Idle, false); break; case nameof(GrblViewModel.Signals): { var signals = ((GrblViewModel)sender).Signals.Value; if (JobPending && signals.HasFlag(Signals.CycleStart) && !signals.HasFlag(Signals.Hold) && !cycleStartSignal) { CycleStart(); } holdSignal = signals.HasFlag(Signals.Hold); cycleStartSignal = signals.HasFlag(Signals.CycleStart); } break; case nameof(GrblViewModel.ProgramEnd): if (!GCode.File.IsLoaded) { streamingHandler.Call(job.IsSDFile ? StreamingState.JobFinished : StreamingState.NoFile, job.IsSDFile); } else if (JobTimer.IsRunning && !job.Complete) { streamingHandler.Call(StreamingState.JobFinished, true); } break; case nameof(GrblViewModel.FileName): { if (string.IsNullOrEmpty(((GrblViewModel)sender).FileName)) { job.NextRow = null; } else { job.IsSDFile = false; job.CurrLine = job.PendingLine = job.ACKPending = model.BlockExecuting = 0; job.PgmEndLine = GCode.File.Blocks - 1; if (GCode.File.ToolChanges > 0 && GrblSettings.GetInteger(GrblSetting.ToolChangeMode) > 0 && !model.IsTloReferenceSet) { MessageBox.Show(string.Format("Job has {0} tool change(s), tool length reference should be established before start.", GCode.File.ToolChanges), "GCode Sender", MessageBoxButton.OK, MessageBoxImage.Warning); } streamingHandler.Call(GCode.File.IsLoaded ? StreamingState.Idle : StreamingState.NoFile, false); } break; } case nameof(GrblViewModel.GrblReset): { JobTimer.Stop(); streamingHandler.Call(StreamingState.Stop, true); } break; } } }
private void OnDataContextPropertyChanged(object sender, PropertyChangedEventArgs e) { if (sender is GrblViewModel) { switch (e.PropertyName) { case nameof(GrblViewModel.GrblState): GrblStateChanged((sender as GrblViewModel).GrblState); break; case nameof(GrblViewModel.MDI): SendCommand((sender as GrblViewModel).MDI); break; case nameof(GrblViewModel.IsMPGActive): grblState.MPG = (sender as GrblViewModel).IsMPGActive == true; (sender as GrblViewModel).Poller.SetState(grblState.MPG ? 0 : AppConfig.Settings.Base.PollInterval); streamingHandler.Call(grblState.MPG ? StreamingState.Disabled : StreamingState.Idle, false); break; case nameof(GrblViewModel.Signals): if (isActive) { var signals = (sender as GrblViewModel).Signals.Value; if (JobPending && signals.HasFlag(Signals.CycleStart) && !signals.HasFlag(Signals.Hold) && !cycleStartSignal) { CycleStart(); } holdSignal = signals.HasFlag(Signals.Hold); cycleStartSignal = signals.HasFlag(Signals.CycleStart); } break; case nameof(GrblViewModel.ProgramEnd): if (!GCode.File.IsLoaded) { streamingHandler.Call(model.IsSDCardJob ? StreamingState.JobFinished : StreamingState.NoFile, model.IsSDCardJob); } else if (JobTimer.IsRunning && !job.Complete) { streamingHandler.Call(StreamingState.JobFinished, true); } if (!model.IsParserStateLive) { SendCommand(GrblConstants.CMD_GETPARSERSTATE); } break; case nameof(GrblViewModel.FileName): { job.IsSDFile = false; if (string.IsNullOrEmpty((sender as GrblViewModel).FileName)) { job.NextRow = null; } else { job.ToolChangeLine = -1; job.CurrLine = job.PendingLine = job.ACKPending = model.BlockExecuting = 0; job.PgmEndLine = GCode.File.Blocks - 1; if ((sender as GrblViewModel).IsPhysicalFileLoaded) { if (GCode.File.ToolChanges > 0) { if (!GrblSettings.HasSetting(grblHALSetting.ToolChangeMode)) { MessageBox.Show(string.Format((string)FindResource("JobToolChanges"), GCode.File.ToolChanges), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (GrblSettings.GetInteger(grblHALSetting.ToolChangeMode) > 0 && !model.IsTloReferenceSet) { MessageBox.Show(string.Format((string)FindResource("JobToolReference"), GCode.File.ToolChanges), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning); } } if (GCode.File.HasGoPredefinedPosition && (sender as GrblViewModel).IsGrblHAL && (sender as GrblViewModel).HomedState != HomedState.Homed) { MessageBox.Show((string)FindResource("JobG28G30"), "ioSender", MessageBoxButton.OK, MessageBoxImage.Warning); } streamingHandler.Call(GCode.File.IsLoaded ? StreamingState.Idle : StreamingState.NoFile, false); } } break; } case nameof(GrblViewModel.GrblReset): { JobTimer.Stop(); streamingHandler.Call(StreamingState.Stop, true); } break; } } }