void btn_Click(object sender, RoutedEventArgs e) { switch ((StatusButton)((Control)sender).Tag) { case StatusButton.Reset: Grbl.Reset(); break; case StatusButton.Unlock: (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_UNLOCK); break; case StatusButton.Home: // ((Control)sender).Background = Brushes.LightSkyBlue; (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_HOMING); break; case StatusButton.Check: GrblStates state = (DataContext as GrblViewModel).GrblState.State; if(state == GrblStates.Check && (sender as CheckBox).IsChecked == false) Grbl.Reset(); else if (state == GrblStates.Idle && (sender as CheckBox).IsChecked == true) (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_CHECK); break; } }
void btn_Click(object sender, RoutedEventArgs e) { switch ((StatusButton)((Control)sender).Tag) { case StatusButton.Reset: var model = (DataContext as GrblViewModel); if (model.GrblState.State == GrblStates.Alarm && model.GrblState.Substate == 10 && model.Signals.Value.HasFlag(Signals.EStop)) { MessageBox.Show((string)FindResource("ClearEStop"), "ioSender", MessageBoxButton.OK, MessageBoxImage.Exclamation); } else { Grbl.Reset(); } break; case StatusButton.Unlock: (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_UNLOCK); break; case StatusButton.Home: // ((Control)sender).Background = Brushes.LightSkyBlue; (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_HOMING); break; case StatusButton.Check: GrblStates state = (DataContext as GrblViewModel).GrblState.State; if (state == GrblStates.Check && (sender as CheckBox).IsChecked == false) { Grbl.Reset(); } else if (state == GrblStates.Idle && (sender as CheckBox).IsChecked == true) { (DataContext as GrblViewModel).ExecuteCommand(GrblConstants.CMD_CHECK); } break; } }