From fd2641e5aa4e915cc133310bd87d21278b84e50b Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 18 Mar 2018 12:54:12 +0200 Subject: Working on machine events ! --- .../Tango.MachineStudio.Developer.csproj | 3 + .../ViewModels/MainViewVM.cs | 93 ++++++++++++++++++--- .../Tango.MachineStudio.Developer/error.wav | Bin 0 -> 146748 bytes .../Views/MainView.xaml | 2 +- .../EventLogging/DefaultEventLogger.cs | 1 + .../Tango.MachineStudio.UI/Images/warning.png | Bin 0 -> 2121 bytes .../Tango.MachineStudio.UI.csproj | 3 + .../Views/MachineSerialView.xaml | 10 +-- .../Tango.MachineStudio.UI/Views/MainView.xaml | 42 +++++++++- 9 files changed, 131 insertions(+), 23 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/error.wav create mode 100644 Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/warning.png (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj index 920dfd922..c165552d1 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Tango.MachineStudio.Developer.csproj @@ -356,5 +356,8 @@ + + + \ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 4a16be957..f455faa9e 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -56,6 +56,7 @@ namespace Tango.MachineStudio.Developer.ViewModels private ObservablesContext _activeJobDbContext; private SpeechSynthesizer _speech; private SoundPlayer _soundPlayer; + private SoundPlayer _soundPlayerErr; #region Properties @@ -629,6 +630,7 @@ namespace Tango.MachineStudio.Developer.ViewModels _speech = new SpeechSynthesizer(); _soundPlayer = new SoundPlayer(EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Developer.bip.wav")); + _soundPlayerErr = new SoundPlayer(EmbeddedResourceHelper.GetEmbeddedResourceStream("Tango.MachineStudio.Developer.error.wav")); _speech.SelectVoice(_speech.GetInstalledVoices().LastOrDefault(x => x.VoiceInfo.Gender == VoiceGender.Female).VoiceInfo.Name); //Initialize Commands... @@ -644,7 +646,7 @@ namespace Tango.MachineStudio.Developer.ViewModels RemoveBrushStopCommand = new RelayCommand(RemoveSelectedBrushStops, () => SelectedBrushStop != null); SaveJobCommand = new RelayCommand(SaveActiveJob, () => SelectedMachine != null); DiscardJobCommand = new RelayCommand(BackToJobs, () => SelectedMachine != null); - StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning && MachineOperator != null); + StartJobCommand = new RelayCommand(StartJob, () => ActiveJob != null && !IsJobRunning && MachineOperator != null && !MachineOperator.MachineEventsStateProvider.Events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.PreventJobExecution))); StopJobCommand = new RelayCommand(StopJob, () => IsJobRunning); CloseJobCompletionStatusCommand = new RelayCommand(CloseJobCompletionStatusBar); LoadJobCommand = new RelayCommand(LoadSelectedJob, () => SelectedMachineJob != null); @@ -671,6 +673,25 @@ namespace Tango.MachineStudio.Developer.ViewModels private void ApplicationManager_ConnectedMachineChanged(object sender, IExternalBridgeClient machine) { MachineOperator = machine; + + if (MachineOperator != null) + { + MachineOperator.MachineEventsStateProvider.EventsChanged -= MachineEventsStateProvider_EventsChanged; + MachineOperator.MachineEventsStateProvider.EventsChanged += MachineEventsStateProvider_EventsChanged; + + MachineOperator.MachineEventsStateProvider.NewEvents -= MachineEventsStateProvider_NewEvents; + MachineOperator.MachineEventsStateProvider.NewEvents += MachineEventsStateProvider_NewEvents; + } + } + + private void MachineEventsStateProvider_NewEvents(object sender, IEnumerable events) + { + HandleNewHardwareEvents(events); + } + + private void MachineEventsStateProvider_EventsChanged(object sender, IEnumerable changedEvents) + { + InvokeUI(StartJobCommand.RaiseCanExecuteChanged); } /// @@ -714,6 +735,42 @@ namespace Tango.MachineStudio.Developer.ViewModels #endregion + #region Hardware Events + + private void HandleNewHardwareEvents(IEnumerable events) + { + if (IsJobRunning) + { + SpeakError(events.Last().EventType.Name); + + if (events.ToList().Exists(x => x.ActionTypes.Contains(BL.Enumerations.ActionTypes.AbortRunningJob))) + { + if (_jobHandler != null) + { + InvokeUI(StopJob); + } + } + } + } + + #endregion + + #region Sound + + private void SpeakInfo(String text) + { + _soundPlayer.Play(); + _speech.SpeakAsync(text); + } + + private void SpeakError(String text) + { + _soundPlayerErr.Play(); + _speech.SpeakAsync(text); + } + + #endregion + #region Properties Changes /// @@ -895,12 +952,14 @@ namespace Tango.MachineStudio.Developer.ViewModels /// private void SetJobFailed() { - LogManager.Log("Setting job failed state..."); - IsJobRunning = false; - IsJobFailed = true; + if (IsJobRunning) + { + LogManager.Log("Setting job failed state..."); + IsJobRunning = false; + IsJobFailed = true; - _soundPlayer.Play(); - _speech.SpeakAsync("Job Failed!"); + SpeakError("Job Failed!"); + } } /// @@ -911,8 +970,7 @@ namespace Tango.MachineStudio.Developer.ViewModels LogManager.Log("Setting job completed state..."); IsJobRunning = false; IsJobCompleted = true; - _soundPlayer.Play(); - _speech.SpeakAsync("Job Completed!"); + SpeakInfo("Job Completed!"); } /// @@ -955,11 +1013,20 @@ namespace Tango.MachineStudio.Developer.ViewModels _jobHandler.StatusReceived += (x, status) => { - RunningJobRemainingTime = _runningJobEstimatedDuration - TimeSpan.FromSeconds(RunningJobProgress / (SelectedProcessParametersTable.DyeingSpeed / 100d)); - RunningJobProgress = status.Progress; + if (IsJobRunning) + { + + RunningJobRemainingTime = _runningJobEstimatedDuration - TimeSpan.FromSeconds(RunningJobProgress / (SelectedProcessParametersTable.DyeingSpeed / 100d)); + RunningJobProgress = status.Progress; + } foreach (var segment in RunningJobSegments) { + if (!IsJobRunning) + { + break; + } + var previousSegmentsWithThis = RunningJobSegments.Where(s => RunningJobSegments.IndexOf(s) <= RunningJobSegments.IndexOf(segment)).ToList(); var segmentsDuration = TimeSpan.FromSeconds(previousSegmentsWithThis.Sum(s => s.Length) / (SelectedProcessParametersTable.DyeingSpeed / 100d)); var segmentDuration = TimeSpan.FromSeconds(segment.Length / (SelectedProcessParametersTable.DyeingSpeed / 100d)); @@ -973,15 +1040,14 @@ namespace Tango.MachineStudio.Developer.ViewModels if (!segment.Started) { segment.Started = true; - _soundPlayer.Play(); if (segment.ID != -1) { - _speech.SpeakAsync(String.Format("Segment {0} Started.", segment.SegmentIndex)); + SpeakInfo(String.Format("Segment {0} Started.", segment.SegmentIndex)); } else { - _speech.SpeakAsync(String.Format("Inter Segment Started.")); + SpeakInfo(String.Format("Inter Segment Started.")); } } } @@ -1052,6 +1118,7 @@ namespace Tango.MachineStudio.Developer.ViewModels { new BrushStop() { + ColorSpace = ColorSpaces.Single(x => x.Code == BL.Enumerations.ColorSpaces.RGB.ToInt32()), Color = Colors.White, } }, diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/error.wav b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/error.wav new file mode 100644 index 000000000..4dce7d623 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/error.wav differ diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml index 6257fa2af..f704661cf 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MainView.xaml @@ -88,7 +88,7 @@ MACHINE DESIGNER - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs index 3763a06b4..b4015b297 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/EventLogging/DefaultEventLogger.cs @@ -71,6 +71,7 @@ namespace Tango.MachineStudio.Common.EventLogging _db.Configuration.LazyLoadingEnabled = false; _db.ActionTypes.ToList(); + _db.EventTypesActions.ToList(); _db.EventTypesCategories.ToList(); _db.EventTypesGroups.ToList(); _db.EventTypes.ToList(); diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/warning.png b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/warning.png new file mode 100644 index 000000000..a845b1226 Binary files /dev/null and b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Images/warning.png differ diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj index 95c2a9925..0a92f2c91 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Tango.MachineStudio.UI.csproj @@ -424,6 +424,9 @@ + + + if $(ConfigurationName) == Debug $(TargetDir)linkgen.exe -s "$(TargetPath)" -d "$(TargetDir)Utilities\Machine Studio.lnk" diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineSerialView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineSerialView.xaml index 83a6eece6..b988d0a76 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineSerialView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MachineSerialView.xaml @@ -8,7 +8,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:vm="clr-namespace:Tango.MachineStudio.UI.ViewModels" xmlns:local="clr-namespace:Tango.MachineStudio.UI.Views" - mc:Ignorable="d" Width="600" Height="400" Background="White" d:DataContext="{d:DesignInstance Type=vm:MachineSerialViewVM, IsDesignTimeCreatable=False}"> + mc:Ignorable="d" Width="559" Height="266" Background="White" d:DataContext="{d:DesignInstance Type=vm:MachineSerialViewVM, IsDesignTimeCreatable=False}"> @@ -36,15 +36,15 @@ - + Connecting directly to a machine's embedded firmware requires the selection of an existing machine from the database in order for machine studio to function properly. Please select a 'virtual machine' by entering the machine serial number - - + + @@ -65,7 +65,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml index beade3d88..b7a4cc93f 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/Views/MainView.xaml @@ -21,6 +21,7 @@ + @@ -234,7 +235,37 @@ hardware messages - + + + + + +