Browse Source

Create Dynamic Light

Zixuan 1 month ago
parent
commit
c4f7405096

+ 28 - 2
FurnaceNewWorld/FurnaceNewWorld/Controls/BuzzerLight.xaml.cs

@@ -52,6 +52,8 @@ public partial class BuzzerLight : UserControl
         if (e.NewValue is not BuzzerLightEnum lightEnum)
         if (e.NewValue is not BuzzerLightEnum lightEnum)
             return;
             return;
 
 
+        _warningTimer?.Dispose();
+
         light.Red.Width = DisableWidth;
         light.Red.Width = DisableWidth;
         light.Yellow.Width = DisableWidth;
         light.Yellow.Width = DisableWidth;
         light.Green.Width = DisableWidth;
         light.Green.Width = DisableWidth;
@@ -79,8 +81,8 @@ public partial class BuzzerLight : UserControl
         if (border is null)
         if (border is null)
             return;
             return;
 
 
-        border.Width=EnableWidth;
-        border.Height=EnableHeight;
+        border.Width = EnableWidth;
+        border.Height = EnableHeight;
         border.IsEnabled = true;
         border.IsEnabled = true;
 
 
         border.Background = lightEnum switch
         border.Background = lightEnum switch
@@ -92,6 +94,30 @@ public partial class BuzzerLight : UserControl
             _ => null
             _ => null
         };
         };
 
 
+        if (lightEnum == BuzzerLightEnum.Red)
+        {
+            _warningTimer = new(WarningTimerCallBack, light, 2000, 2000);
+        }
+
+    }
+
+    private static Timer? _warningTimer;
+    private static void WarningTimerCallBack(object? state)
+    {
+        if (state is not BuzzerLight light)
+            return;
+
+
+        App.Current.Dispatcher?.Invoke(() =>
+        {
+            light.Red.Background = (SolidColorBrush)App.Current.FindResource("LightEmergencyColor");
+        });
+        Thread.Sleep(500);
+        App.Current.Dispatcher?.Invoke(() =>
+        {
+            light.Red.Background = (SolidColorBrush)App.Current.FindResource("EmergencyColor");
+        });
+
     }
     }
 }
 }
 
 

+ 1 - 1
FurnaceNewWorld/FurnaceNewWorld/Controls/HeaderBar.xaml

@@ -112,7 +112,7 @@
 
 
         </Border>
         </Border>
 
 
-        <local:BuzzerLight Grid.Column="6" LightType="Green"/>
+        <local:BuzzerLight Grid.Column="6" LightType="Red"/>
 
 
     </Grid>
     </Grid>
 </UserControl>
 </UserControl>