From a1d5427ba1c10f926e8a33491740137dbf266483 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 6 Feb 2021 19:04:14 +0000 Subject: [PATCH 01/13] fine-tune the colour changes for each device and its status. There was a case where the device status would change to the 'low light detected' (light sky blue) when on the border between a weld being detected and not. This commit addresses that. Also, both Light Meters have been installed at this point and it is apparent both of the welding booths have different light levels. Becuase of this, the dashboard now has code in place which seperates the update-checks to match the device/welding booth. In other words, factory1 does not go dark see green at factory2's light levels. --- .../EyesAndEars.UWP/MainPage.xaml | 37 +++++++----- .../EyesAndEars.UWP/Package.appxmanifest | 2 +- .../EyesAndEars.UWP/Services/DataServices.cs | 60 ++++++++++--------- 3 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml index 757992b..0d2f1d4 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml @@ -55,7 +55,8 @@ + FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="300" + CornerRadius="10"> + FallbackValue=Orange}" Margin="12,0,12,12" Width="300" Height="300" + CornerRadius="10"> - - + + - - + + - - + + - - + + - - + + @@ -143,7 +150,8 @@ + FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="150" + CornerRadius="10"> + FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="150" + CornerRadius="10"> + Version="2021.1.14.0" /> diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs index b93de54..fa2916a 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs @@ -19,7 +19,7 @@ namespace EyesAndEars.UWP.Services { var statusJSON = await WebServices.GetJSON(statusAPI); var r = MapToLightReading(readingJSON); var s = MapToDeviceStatus(statusJSON); - var c = UpdateStatusColour(s.status, r.reading); + var c = UpdateStatusColour(deviceId, s.status, r.reading); return new Device(deviceId, r, s, c); } catch (Exception e) { @@ -28,38 +28,44 @@ namespace EyesAndEars.UWP.Services { } } - static SolidColorBrush UpdateStatusColour(string status, int reading) { + private static SolidColorBrush UpdateStatusColour(int device, string status, int reading) { try { if (status.Equals("on", StringComparison.OrdinalIgnoreCase)) { - /* Note: Reading values breakdown. - * ======================================= - * 1. When testing the light meters, the base line for normal - * light is 48 or below. Anything above this is when one of - * the guys in the factory was welding. Becuase of this, - * I have set 0 to 48 as the 'default' status on the - * dashboard. - * - * 2. During testing we noticed the light meters would - * return 'negative light' values. There is a reason for - * this but that is out of the scope of this project. This - * project just needs to process the data. The negative - * light values are when the lights in the factory are off. - * The light meter is still running but there is no light - * to measure. So, everything is fine but it looks broken. - * The 'LightSkyBlue' colour is used to help relay this - * bit of information. - */ - if (reading > 0 && reading < 48) // On but no weld detected. - return new SolidColorBrush(Colors.LightSeaGreen); - if (reading > 48) // On and weld detected. - return new SolidColorBrush(Colors.DarkSeaGreen); - else { - // On but factory lights are off. + + /* Note: 'Negative Light' Levels. + * ======================================================== + * The light meters will record 'negative light' values + * when the factory lights are off. This does not mean + * the light meters are not functioning properly. With that + * said, this dashboard make it look like they are. Because + * of this, the blocks in the dashboard will change to + * 'LightSkyBlue' to help indicate the change is something + * the system knows about and everything is fine -- nothing + * is broken. + */ + + if (device == 1) { + if (reading > 0 && reading <= 38) // No weld detected. + return new SolidColorBrush(Colors.LightSeaGreen); + if (reading > 38) // Weld detected. + return new SolidColorBrush(Colors.DarkSeaGreen); + } + else if (device == 2) { + if (reading > 0 && reading <= 48) // No weld detected. + return new SolidColorBrush(Colors.LightSeaGreen); + if (reading > 48) // Weld detected. + return new SolidColorBrush(Colors.DarkSeaGreen); + } + else if (reading < 0) { + // The device is on but factory lights are off. return new SolidColorBrush(Colors.LightSkyBlue); } } - else return new SolidColorBrush(Colors.DarkRed); } + // The device is off. + return new SolidColorBrush(Colors.DarkRed); + } catch (Exception e) { + // Extra protection to if-check at top of this try block. Debug.WriteLine(e.Message); return new SolidColorBrush(Colors.DarkOrange); } From 6ad2bcbf135b97effbde4e33650d48c269b12daf Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 6 Feb 2021 19:50:14 +0000 Subject: [PATCH 02/13] create a log section on dashboard and toggle button. This is in aid of providing the user with more feedback about the program (eyes and ears) than the light readings and web requests. The toggle button allows the user to turn-off the logs if they don't want or need them. This is not a full implementation of the logging system (this is just a start). --- .../EyesAndEars.UWP/MainPage.xaml | 23 +++++++++++++++++++ .../EyesAndEars.UWP/MainPage.xaml.cs | 8 +++++++ .../EyesAndEars.UWP/Package.appxmanifest | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml index 0d2f1d4..4473624 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml @@ -12,6 +12,7 @@ + @@ -203,6 +204,17 @@ + + + Executing Eyes and Ears..s. + + + + + @@ -210,6 +222,16 @@ + + + + + + Version="2021.2.6.0" /> From 90b7fedbc5815116d1c3573f4b38371f022450fa Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 6 Feb 2021 21:36:56 +0000 Subject: [PATCH 03/13] implement logging system on dashboard. The code added here is more about populating the area created for logging each web request. The XAML code was done in the previous commit. As I stated there, these logs are more about the providing the user of this program visual feedback about the state of the program. There are times when the various devices (light meters/relays) don't update and it's hard to tell if that's Eyes and Ears, the internet connection or the devices on the other end. --- .../EyesAndEars.UWP/MainPage.xaml | 8 ++-- .../EyesAndEars.UWP/MainPage.xaml.cs | 8 ++-- .../EyesAndEars.UWP/Services/DataServices.cs | 38 ++++++++++++++++++- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml index 4473624..92ecf9d 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml @@ -203,13 +203,13 @@ - + - - Executing Eyes and Ears..s. + VerticalScrollMode="Enabled" Margin="0,20"> + diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs index 94b528d..15e46b1 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml.cs @@ -50,11 +50,11 @@ namespace EyesAndEars.UWP { var url = _vm.BaseURL; if (!string.IsNullOrEmpty(url)) { // Devices 3 and 6 are not in use. - _vm.Device1 = await DataServices.UpdateDevice(url, 1); - _vm.Device2 = await DataServices.UpdateDevice(url, 2); + _vm.Device1 = await DataServices.UpdateDevice(url, 1, Logs); + _vm.Device2 = await DataServices.UpdateDevice(url, 2, Logs); // _vm.Device3 = await DataServices.UpdateDevice(url, 3); - _vm.Device4 = await DataServices.UpdateDevice(url, 4); - _vm.Device5 = await DataServices.UpdateDevice(url, 5); + _vm.Device4 = await DataServices.UpdateDevice(url, 4, Logs); + _vm.Device5 = await DataServices.UpdateDevice(url, 5, Logs); // _vm.Device6 = await DataServices.UpdateDevice(url, 6); _vm.CurrentTime = DateTime.UtcNow.ToShortTimeString(); } diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs index fa2916a..606b51e 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs @@ -6,11 +6,15 @@ using System.Threading.Tasks; using Windows.Storage; using Windows.UI; using Windows.UI.Xaml.Media; +using Windows.UI.Xaml.Controls; +using Windows.UI.Xaml.Documents; +using Windows.UI.Text; namespace EyesAndEars.UWP.Services { public static class DataServices { - public static async Task UpdateDevice(string url, int deviceId) { + public static async Task UpdateDevice(string url, int deviceId, + RichTextBlock logs) { try { var id = MapFactoryDeviceToGalleyDevice(deviceId); // Has note. var readingAPI = $"{url}/api/readings/latest/{id}"; @@ -20,7 +24,9 @@ namespace EyesAndEars.UWP.Services { var r = MapToLightReading(readingJSON); var s = MapToDeviceStatus(statusJSON); var c = UpdateStatusColour(deviceId, s.status, r.reading); - return new Device(deviceId, r, s, c); + var dev = new Device(deviceId, r, s, c); + LogUpdate(logs, dev); + return dev; } catch (Exception e) { Debug.WriteLine(e.Message); @@ -28,6 +34,34 @@ namespace EyesAndEars.UWP.Services { } } + private static void LogUpdate(RichTextBlock logs, Device dev) { + // Devices 3 and 6 are not in use. + string device; + if (dev.Id == 1) device = "factory1"; + else if (dev.Id == 2) device = "factory2"; + else if (dev.Id == 4) device = "gallery1"; + else device = "gallery2"; + Paragraph paragraph = new Paragraph(); + var run1 = new Run { + FontWeight = FontWeights.Bold, + Text = $"{DateTime.Now} | " + }; + var run2 = new Run { + Foreground = dev.StatusColour, + FontWeight = FontWeights.Bold, + Text = device + }; + var run3 = new Run { + Foreground = dev.StatusColour, + Text = $" | {dev.LatestReading.id} | {dev.LatestReading.reading} | " + + $"{dev.LatestStatus.status} | {dev.LatestReading.time}" + }; + paragraph.Inlines.Add(run1); + paragraph.Inlines.Add(run2); + paragraph.Inlines.Add(run3); + logs.Blocks.Insert(0, paragraph); + } + private static SolidColorBrush UpdateStatusColour(int device, string status, int reading) { try { if (status.Equals("on", StringComparison.OrdinalIgnoreCase)) { From e7a6ec1500770ef84084b442948379167bbe23d9 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sat, 6 Feb 2021 21:54:18 +0000 Subject: [PATCH 04/13] create a P.O.C. for a text-to-speech feature. This is a very rough bit of code. This is for testing the possibilty/usability of having the program provide updates using the SpeechSynthesizer class. The initial intention is to have the program denote any change in power status ('gallery1' is now off', 'weld detected by factory1' Etc.) and, if it's any good, expand it from there. The code changes made here are incomplete but I'm packing up for the day and going home -- it's late. I'm logging the current changes for future reference. --- src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml | 9 ++++++--- .../EyesAndEars.UWP/MainPage.xaml.cs | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml index 92ecf9d..1a20946 100644 --- a/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml +++ b/src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml @@ -7,9 +7,9 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource SystemControlAcrylicWindowBrush}"> - + - + @@ -28,6 +28,7 @@ + @@ -231,8 +232,10 @@ Unchecked="LogToggle_Unchecked" Checked="LogToggle_Checked" IsChecked="True"/> +