From 4cc4089f36b0a9b9d754e33acb49da930f846699 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 13 May 2019 13:58:45 +0300 Subject: Some fixed to TCC mobile design. Implemented DFU reset on Machine Operator. --- .../Android_Studio/ColorCapture/app/build.gradle | 4 +- .../colorcapture/views/main/MainActivityVM.java | 10 ++++- .../app/src/main/res/layout/side_menu.xml | 4 +- Software/DB/PPC/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/PPC/Tango_log.ldf | Bin 53673984 -> 53673984 bytes Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes .../Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 2 + .../ViewModels/SystemViewVM.cs | 24 +++++++++++ .../Tango.PPC.Technician/Views/SystemView.xaml | 3 +- .../Printing/DefaultPrintingManager.cs | 46 +++++++++++++++++---- .../Visual_Studio/PPC/Tango.PPC.UI/app.manifest | 2 +- .../Tango.BL/ObservablesContextExtension.cs | 18 ++++++++ .../ExtensionMethods/FrameworkElementExtensions.cs | 4 +- .../Operation/IMachineOperator.cs | 6 +++ .../Tango.Integration/Operation/MachineOperator.cs | 36 ++++++++++++++++ .../Tango.Integration/Tango.Integration.csproj | 6 ++- 17 files changed, 147 insertions(+), 18 deletions(-) (limited to 'Software') diff --git a/Software/Android_Studio/ColorCapture/app/build.gradle b/Software/Android_Studio/ColorCapture/app/build.gradle index b733330cc..ef4857b1d 100644 --- a/Software/Android_Studio/ColorCapture/app/build.gradle +++ b/Software/Android_Studio/ColorCapture/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "com.twine.colorcapture" minSdkVersion 22 targetSdkVersion 27 - versionCode 3 - versionName "1.3" + versionCode 4 + versionName "1.4" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/main/MainActivityVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/main/MainActivityVM.java index 72a088fa2..673146417 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/main/MainActivityVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/main/MainActivityVM.java @@ -1,5 +1,7 @@ package com.twine.colorcapture.views.main; +import android.os.Handler; + import com.squareup.otto.Bus; import com.twine.colorcapture.dialogs.welcome.WelcomeDialog; import com.twine.colorcapture.mvvm.RelayCommand; @@ -85,9 +87,13 @@ public class MainActivityVM extends ViewModelBase private void handleHowToUseCommand() { view.closeMenu(); - notificationProvider.showDialog(new WelcomeDialog(), (vm) -> + + new Handler().postDelayed(() -> { - }); + notificationProvider.showDialog(new WelcomeDialog(), (vm) -> + { + }); + },300); } private void handleAboutCommand() diff --git a/Software/Android_Studio/ColorCapture/app/src/main/res/layout/side_menu.xml b/Software/Android_Studio/ColorCapture/app/src/main/res/layout/side_menu.xml index e5e15f4b7..3369f0a35 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/res/layout/side_menu.xml +++ b/Software/Android_Studio/ColorCapture/app/src/main/res/layout/side_menu.xml @@ -175,8 +175,8 @@ android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:layout_marginBottom="60dp" - bind:text=" Get a twine TTCâ„¢ card" - bind:textSize="@dimen/medium_font_size" + bind:text="Get a twine TTCâ„¢ card" + bind:textSize="@dimen/small_font_size" bind:src="@drawable/icon_twine_card" android:clickable="true" /> diff --git a/Software/DB/PPC/Tango.mdf b/Software/DB/PPC/Tango.mdf index e85b35642..6751ca940 100644 Binary files a/Software/DB/PPC/Tango.mdf and b/Software/DB/PPC/Tango.mdf differ diff --git a/Software/DB/PPC/Tango_log.ldf b/Software/DB/PPC/Tango_log.ldf index 014618103..0f6384349 100644 Binary files a/Software/DB/PPC/Tango_log.ldf and b/Software/DB/PPC/Tango_log.ldf differ diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index beb586477..1782a99c7 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 9ebef8596..0044974e0 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs index 3b7c70bf8..e2c29cac5 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs @@ -522,6 +522,8 @@ namespace Tango.PPC.Jobs.ViewModels } } + Job.LastUpdated = DateTime.UtcNow; + Job.JobStatus = BL.Enumerations.JobStatuses.Draft; await _db.SaveChangesAsync(); RaiseMessage(new JobSavedMessage() { Job = Job }); diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs index 47d5835f5..b2f93c29d 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/ViewModels/SystemViewVM.cs @@ -17,6 +17,7 @@ namespace Tango.PPC.Technician.ViewModels { private IOperationSystemManager _os; private Timer _statsTimer; + private bool _resettingDevice; private float _cpu; public float CPU @@ -39,6 +40,8 @@ namespace Tango.PPC.Technician.ViewModels set { _temperature = value; RaisePropertyChangedAuto(); } } + public RelayCommand ResetDeviceCommand { get; set; } + public RelayCommand RestartCommand { get; set; } public RelayCommand ShutdownCommand { get; set; } @@ -58,6 +61,27 @@ namespace Tango.PPC.Technician.ViewModels ShutdownCommand = new RelayCommand(ShutdownSystem); FactoryResetCommand = new RelayCommand(FactoryReset); ExitToExplorerCommand = new RelayCommand(ExitToExplorer); + ResetDeviceCommand = new RelayCommand(ResetDevice, () => !_resettingDevice); + } + + private async void ResetDevice() + { + try + { + _resettingDevice = true; + ResetDeviceCommand.RaiseCanExecuteChanged(); + await MachineProvider.MachineOperator.ResetDFU(); + await NotificationProvider.ShowInfo("Embedded device has been reset successfully."); + } + catch (Exception ex) + { + await NotificationProvider.ShowError(ex.FlattenMessage()); + } + finally + { + _resettingDevice = false; + ResetDeviceCommand.RaiseCanExecuteChanged(); + } } private async void FactoryReset() diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/SystemView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/SystemView.xaml index 0b067b09b..d96da4f93 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/SystemView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Technician/Views/SystemView.xaml @@ -50,7 +50,8 @@ - Restart Device + Reset Machine + Restart Device Shutdown Device Factory Reset Exit To Shell diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs index 7d4aa154e..1f09023cb 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Printing/DefaultPrintingManager.cs @@ -45,7 +45,6 @@ namespace Tango.PPC.UI.Printing /// public async Task Print(Job job, ObservablesContext context) { - JobHandler handler = null; #if STUBPRINT @@ -66,9 +65,25 @@ namespace Tango.PPC.UI.Printing { try { + job.JobStatus = JobStatuses.Completed; + + if (!context.IsDisposed) + { + await context.SaveChangesAsync(); + } + else + { + using (var newContext = ObservablesContext.CreateDefault()) + { + var newJob = newContext.Jobs.SingleOrDefault(y => y.Guid == job.Guid); + if (newJob != null) + { + newJob.JobStatus = JobStatuses.Completed; + await newContext.SaveChangesAsync(); + } + } + } - job.JobStatus = BL.Enumerations.JobStatuses.Completed; - await context.SaveChangesAsync(); RaiseJobSaved(job); } catch (Exception ex) @@ -76,12 +91,12 @@ namespace Tango.PPC.UI.Printing LogManager.Log(ex, "Error occurred after job printing completed."); } }; - handler.Canceled += async (x, e) => + handler.Canceled += (x, e) => { try { //No change in status ! - await context.SaveChangesAsync(); + //await context.SaveChangesAsync(); RaiseJobSaved(job); } catch (Exception ex) @@ -94,8 +109,25 @@ namespace Tango.PPC.UI.Printing try { - job.JobStatus = BL.Enumerations.JobStatuses.Disrupted; - await context.SaveChangesAsync(); + job.JobStatus = JobStatuses.Disrupted; + + if (!context.IsDisposed) + { + await context.SaveChangesAsync(); + } + else + { + using (var newContext = ObservablesContext.CreateDefault()) + { + var newJob = newContext.Jobs.SingleOrDefault(y => y.Guid == job.Guid); + if (newJob != null) + { + newJob.JobStatus = JobStatuses.Disrupted; + await newContext.SaveChangesAsync(); + } + } + } + RaiseJobSaved(job); } catch (Exception ex) diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest index d72e75011..efc5f8179 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - + diff --git a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs index de882c910..be5f5439f 100644 --- a/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs +++ b/Software/Visual_Studio/Tango.BL/ObservablesContextExtension.cs @@ -25,6 +25,11 @@ namespace Tango.BL private static DataSource _override_datasource; private DataSource _dataSource; + /// + /// Gets a value indicating whether this instance is disposed. + /// + public bool IsDisposed { get; private set; } + /// /// Initializes a new instance of the class. /// @@ -248,5 +253,18 @@ namespace Tango.BL EntityFrameworkCache.Initialize(cache); } } + + /// + /// Disposes the context. The underlying is also disposed if it was created + /// is by this context or ownership was passed to this context when this context was created. + /// The connection to the database ( object) is also disposed if it was created + /// is by this context or ownership was passed to this context when this context was created. + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected override void Dispose(bool disposing) + { + base.Dispose(disposing); + IsDisposed = true; + } } } diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs index 6e9c11b03..7539deba2 100644 --- a/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs +++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/FrameworkElementExtensions.cs @@ -454,7 +454,7 @@ public static class FrameworkElementExtensions { bool isLoaded = false; - element.Loaded += (sender, e) => + element.AddHandler(FrameworkElement.LoadedEvent, new RoutedEventHandler((x, y) => { if (!isLoaded) { @@ -462,7 +462,7 @@ public static class FrameworkElementExtensions handler(element, new EventArgs()); } - }; + })); } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs index a5534a063..e110e6189 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs @@ -358,6 +358,12 @@ namespace Tango.Integration.Operation /// Task Reset(); + /// + /// Resets the device through the DFU channel. + /// + /// + Task ResetDFU(); + /// /// Upgrades the firmware. /// diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index 4047ae7a2..1f01c8873 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -34,6 +34,7 @@ using Tango.PMR.FirmwareUpgrade; using Tango.Integration.Logging; using Tango.Integration.JobRuns; using Tango.FirmwareUpdateLib.WPF; +using Tango.FirmwareUpdateLib; namespace Tango.Integration.Operation { @@ -2266,6 +2267,41 @@ namespace Tango.Integration.Operation return response; } + /// + /// Resets the device through the DFU channel. + /// + /// + public Task ResetDFU() + { + return Task.Factory.StartNew(() => + { + LogManager.Log("Performing device reset through DFU..."); + + FirmwareUpdateManager updateManager = new FirmwareUpdateManager(); + + LogManager.Log("Initializing DFU API..."); + updateManager.Initialize(); + + LogManager.Log("Enumerating DFU devices..."); + var device = updateManager.GetAvailableDevices(false).Where(x => !x.DeviceName.Contains("In-Circuit Debug Interface")).FirstOrDefault(); + if (device != null) + { + LogManager.Log($"DFU device found: '{device.DeviceName}'."); + LogManager.Log("Switching to DFU mode..."); + device.SwitchToDFUMode(); + Thread.Sleep(3000); + LogManager.Log("Resetting device..."); + device.Reset(); + Thread.Sleep(1000); + LogManager.Log("Reset completed."); + } + else + { + throw LogManager.Log(new Exception("DFU device not found.")); + } + }); + } + /// /// Creates a storage manager for managing the machine file system. /// diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj index 377cb04fb..b536b1281 100644 --- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj +++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj @@ -73,6 +73,10 @@ + + False + ..\Build\Core\Debug\Tango.FirmwareUpdateLib.dll + @@ -180,7 +184,7 @@ - + \ No newline at end of file -- cgit v1.3.1