1
0
Fork 0
Browse Source

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.
stable
Craig Oates 3 years ago
parent
commit
690a9dd5dd
  1. 37
      src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml
  2. 2
      src/EyesAndEars.UWP/EyesAndEars.UWP/Package.appxmanifest
  3. 60
      src/EyesAndEars.UWP/EyesAndEars.UWP/Services/DataServices.cs

37
src/EyesAndEars.UWP/EyesAndEars.UWP/MainPage.xaml

@ -55,7 +55,8 @@
<Grid x:Name="Factory1Grid" Grid.Row="0" Grid.Column="0"
Background="{x:Bind _vm.Device1.StatusColour, Mode=OneWay,
FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="300">
FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="300"
CornerRadius="10">
<StackPanel Margin="12" VerticalAlignment="Stretch">
<TextBlock x:Name="Factory1Time"
Text="{x:Bind _vm.Device1.LatestReading.time,
@ -72,7 +73,8 @@
<Grid x:Name="Factory2Grid" Grid.Row="0" Grid.Column="1"
Background="{x:Bind _vm.Device2.StatusColour, Mode=OneWay,
FallbackValue=Orange}" Margin="12,0,12,12" Width="300" Height="300">
FallbackValue=Orange}" Margin="12,0,12,12" Width="300" Height="300"
CornerRadius="10">
<StackPanel Margin="12" VerticalAlignment="Stretch">
<TextBlock x:Name="Factory2Time" Foreground="White" FontSize="24"
Text="{x:Bind _vm.Device2.LatestReading.time,
@ -88,28 +90,33 @@
<Grid Grid.Row="0" Grid.Column="2" Grid.RowSpan="2">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Rectangle Fill="LightSeaGreen" Width="92" Height="52"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Rectangle Fill="LightSeaGreen" Width="92" Height="52"
RadiusX="5" RadiusY="5"/>
<TextBlock Text="Device is on" FontSize="42"
VerticalAlignment="Center" Margin="12,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="DarkSeaGreen" Width="92" Height="52"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Rectangle Fill="DarkSeaGreen" Width="92" Height="52"
RadiusX="5" RadiusY="5"/>
<TextBlock Text="Welding detected" FontSize="42"
VerticalAlignment="Center" Margin="12,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="LightSkyBlue" Width="92" Height="52"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Rectangle Fill="LightSkyBlue" Width="92" Height="52"
RadiusX="5" RadiusY="5"/>
<TextBlock Text="Low light in factory" FontSize="42"
VerticalAlignment="Center" Margin="12,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="DarkOrange" Width="92" Height="52"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Rectangle Fill="DarkOrange" Width="92" Height="52"
RadiusX="5" RadiusY="5"/>
<TextBlock Text="Unable to retrieve data" FontSize="42"
VerticalAlignment="Center" Margin="12,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Rectangle Fill="DarkRed" Width="92" Height="52"/>
<StackPanel Orientation="Horizontal" Margin="0,0,0,5">
<Rectangle Fill="DarkRed" Width="92" Height="52"
RadiusX="5" RadiusY="5"/>
<TextBlock Text="Device is off" FontSize="42"
VerticalAlignment="Center" Margin="12,0"/>
</StackPanel>
@ -143,7 +150,8 @@
<Grid x:Name="Gallery1Grid" Grid.Row="1" Grid.Column="0"
Background="{x:Bind _vm.Device4.StatusColour, Mode=OneWay,
FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="150">
FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="150"
CornerRadius="10">
<StackPanel Margin="12" VerticalAlignment="Bottom">
<TextBlock x:Name="Gallery1Time" Foreground="White"
Text="{x:Bind _vm.Device4.LatestStatus.time,
@ -159,7 +167,8 @@
<Grid x:Name="Gallery2Grid" Grid.Row="1" Grid.Column="1"
Background="{x:Bind _vm.Device5.StatusColour, Mode=OneWay,
FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="150">
FallbackValue=Pink}" Margin="0,0,0,12" Width="300" Height="150"
CornerRadius="10">
<StackPanel Margin="12" VerticalAlignment="Bottom">
<TextBlock x:Name="Gallery2Time" Foreground="White" FontSize="24"
Text="{x:Bind _vm.Device5.LatestStatus.time,

2
src/EyesAndEars.UWP/EyesAndEars.UWP/Package.appxmanifest

@ -9,7 +9,7 @@
<Identity
Name="55acd946-60d4-4776-b6c6-03fef750e3da"
Publisher="CN=Craig Oates"
Version="2020.1.14.0" />
Version="2021.1.14.0" />
<mp:PhoneIdentity PhoneProductId="55acd946-60d4-4776-b6c6-03fef750e3da" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

60
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);
}