Compare commits
2
Commits
dev
..
9da5863136
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9da5863136 | ||
|
|
d950e3511f |
@@ -1,32 +1,12 @@
|
|||||||
using PamhagenSysCtrl.Helpers.Pipeline;
|
using PamhagenSysCtrl.Helpers.Pipeline;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace PamhagenSysCtrl.Helpers {
|
namespace PamhagenSysCtrl.Helpers {
|
||||||
public class PamhagenPlant : IDisposable {
|
public class PamhagenPlant : IDisposable {
|
||||||
|
|
||||||
public enum Xbe24Key {
|
|
||||||
START_REBLER = 6, STOP_REBLER = 7,
|
|
||||||
START_TROUGH_AUGER = 12, STOP_TROUGH_AUGER = 13,
|
|
||||||
SELECT_MW1 = 14, SELECT_MW2 = 8,
|
|
||||||
STIRRER_MW1 = 15, STIRRER_MW2 = 9,
|
|
||||||
START_MP1 = 16, STOP_MP1 = 17,
|
|
||||||
START_MP2 = 10, STOP_MP2 = 11,
|
|
||||||
FAST_SELECT_MW1_1 = 18,
|
|
||||||
FAST_SELECT_MW1_2 = 19,
|
|
||||||
FAST_SELECT_MW1_3 = 20,
|
|
||||||
FAST_SELECT_MW1_4 = 21,
|
|
||||||
FAST_SELECT_MW1_5 = 22,
|
|
||||||
FAST_SELECT_MW1_6 = 23,
|
|
||||||
FAST_SELECT_MW2_1 = 0,
|
|
||||||
FAST_SELECT_MW2_2 = 1,
|
|
||||||
FAST_SELECT_MW2_3 = 2,
|
|
||||||
FAST_SELECT_MW2_4 = 3,
|
|
||||||
FAST_SELECT_MW2_5 = 4,
|
|
||||||
FAST_SELECT_MW2_6 = 5,
|
|
||||||
}
|
|
||||||
|
|
||||||
protected PamhagenPlc? Plc;
|
protected PamhagenPlc? Plc;
|
||||||
protected Xbe24Keyboard? Keyboard;
|
protected Xbe24Keyboard? Keyboard;
|
||||||
public PamhagenGraph Graph;
|
public PamhagenGraph Graph;
|
||||||
@@ -170,28 +150,28 @@ namespace PamhagenSysCtrl.Helpers {
|
|||||||
protected void UpdateKeyboardBacklights(object? sender, PlantEventArgs evt) {
|
protected void UpdateKeyboardBacklights(object? sender, PlantEventArgs evt) {
|
||||||
if (sender is not PamhagenPlant plant || plant.Keyboard is not Xbe24Keyboard k) return;
|
if (sender is not PamhagenPlant plant || plant.Keyboard is not Xbe24Keyboard k) return;
|
||||||
|
|
||||||
k.SetBacklight((int)Xbe24Key.START_REBLER, plant.IsReblerActive ? Color.FromRgb(0, 255, 0) : plant.IsAuger1Active ? Color.FromRgb(255, 255, 0) : plant.IsAuger2Active || plant.IsAuger3Active ? Color.FromRgb(32, 32, 4) : Color.FromRgb(4, 32, 4));
|
k.SetBacklight(0, plant.IsReblerActive ? Color.FromRgb(0, 255, 0) : plant.IsAuger1Active ? Color.FromRgb(255, 255, 0) : plant.IsAuger2Active || plant.IsAuger3Active ? Color.FromRgb(32, 32, 4) : Color.FromRgb(4, 32, 4));
|
||||||
k.SetBacklight((int)Xbe24Key.STOP_REBLER, !plant.IsReblerActive ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
k.SetBacklight(1, !plant.IsReblerActive ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
||||||
|
|
||||||
k.SetBacklight((int)Xbe24Key.START_TROUGH_AUGER, !plant.TroughAugerHasClearance ? k.IsKeyPressed((int)Xbe24Key.START_TROUGH_AUGER) ? Color.FromRgb(255, 32, 0) : Color.FromRgb(32, 4, 4) : plant.IsTroughAugerActive ? Color.FromRgb(0, 255, 0) : Color.FromRgb(4, 32, 4));
|
k.SetBacklight(6, !plant.TroughAugerHasClearance ? k.IsKeyPressed(6) ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4) : plant.IsTroughAugerActive ? Color.FromRgb(0, 255, 0) : Color.FromRgb(4, 32, 4));
|
||||||
k.SetBacklight((int)Xbe24Key.STOP_TROUGH_AUGER, !plant.IsTroughAugerActive ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
k.SetBacklight(7, !plant.IsTroughAugerActive ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
||||||
|
|
||||||
k.SetBacklight((int)Xbe24Key.SELECT_MW2, plant.WantMW2Selected || plant.IsMW2Selected ? Color.FromRgb(0, 0, 255) : Color.FromRgb(4, 4, 16), plant.WantMW2Selected && !plant.IsMW2Selected);
|
k.SetBacklight(2, plant.WantMW2Selected || plant.IsMW2Selected ? Color.FromRgb(0, 0, 255) : Color.FromRgb(4, 4, 16), plant.WantMW2Selected && !plant.IsMW2Selected);
|
||||||
k.SetBacklight((int)Xbe24Key.SELECT_MW1, plant.WantMW1Selected || plant.IsMW1Selected ? Color.FromRgb(0, 0, 255) : Color.FromRgb(4, 4, 16), plant.WantMW1Selected && !plant.IsMW1Selected);
|
k.SetBacklight(8, plant.WantMW1Selected || plant.IsMW1Selected ? Color.FromRgb(0, 0, 255) : Color.FromRgb(4, 4, 16), plant.WantMW1Selected && !plant.IsMW1Selected);
|
||||||
|
|
||||||
var buttons = new Dictionary<Xbe24Key, (ISource Source, Pump Pump, ISink Sink)> {
|
var buttons = new Dictionary<int, (ISource Source, Pump Pump, ISink Sink)> {
|
||||||
[Xbe24Key.FAST_SELECT_MW1_1] = (Graph.MW1, Graph.MP1, Graph.Press1),
|
[12] = (Graph.MW1, Graph.MP1, Graph.Press1),
|
||||||
[Xbe24Key.FAST_SELECT_MW2_1] = (Graph.MW2, Graph.MP2, Graph.Press1),
|
[18] = (Graph.MW2, Graph.MP2, Graph.Press1),
|
||||||
[Xbe24Key.FAST_SELECT_MW1_2] = (Graph.MW1, Graph.MP1, Graph.Press2),
|
[13] = (Graph.MW1, Graph.MP1, Graph.Press2),
|
||||||
[Xbe24Key.FAST_SELECT_MW2_2] = (Graph.MW2, Graph.MP2, Graph.Press2),
|
[19] = (Graph.MW2, Graph.MP2, Graph.Press2),
|
||||||
[Xbe24Key.FAST_SELECT_MW1_3] = (Graph.MW1, Graph.MP1, Graph.Tank1),
|
[14] = (Graph.MW1, Graph.MP1, Graph.Tank1),
|
||||||
[Xbe24Key.FAST_SELECT_MW2_3] = (Graph.MW2, Graph.MP2, Graph.Tank1),
|
[20] = (Graph.MW2, Graph.MP2, Graph.Tank1),
|
||||||
[Xbe24Key.FAST_SELECT_MW1_4] = (Graph.MW1, Graph.MP1, Graph.Tank2),
|
[15] = (Graph.MW1, Graph.MP1, Graph.Tank2),
|
||||||
[Xbe24Key.FAST_SELECT_MW2_4] = (Graph.MW2, Graph.MP2, Graph.Tank2),
|
[21] = (Graph.MW2, Graph.MP2, Graph.Tank2),
|
||||||
[Xbe24Key.FAST_SELECT_MW1_5] = (Graph.MW1, Graph.MP1, Graph.Tank3),
|
[16] = (Graph.MW1, Graph.MP1, Graph.Tank3),
|
||||||
[Xbe24Key.FAST_SELECT_MW2_5] = (Graph.MW2, Graph.MP2, Graph.Tank3),
|
[22] = (Graph.MW2, Graph.MP2, Graph.Tank3),
|
||||||
[Xbe24Key.FAST_SELECT_MW1_6] = (Graph.MW1, Graph.MP1, Graph.Tank4),
|
[17] = (Graph.MW1, Graph.MP1, Graph.Tank4),
|
||||||
[Xbe24Key.FAST_SELECT_MW2_6] = (Graph.MW2, Graph.MP2, Graph.Tank4),
|
[23] = (Graph.MW2, Graph.MP2, Graph.Tank4),
|
||||||
};
|
};
|
||||||
|
|
||||||
bool preparingMP1 = false, preparingMP2 = false;
|
bool preparingMP1 = false, preparingMP2 = false;
|
||||||
@@ -204,27 +184,27 @@ namespace PamhagenSysCtrl.Helpers {
|
|||||||
if (!isReady && d.Pump == Graph.MP1) preparingMP1 = true;
|
if (!isReady && d.Pump == Graph.MP1) preparingMP1 = true;
|
||||||
if (!isReady && d.Pump == Graph.MP2) preparingMP2 = true;
|
if (!isReady && d.Pump == Graph.MP2) preparingMP2 = true;
|
||||||
var isDefault = !path.Hops.SkipLast(1).Any(h => h.Node is not Valve && h.Node is not PipeJoin && h.Node is not Pump);
|
var isDefault = !path.Hops.SkipLast(1).Any(h => h.Node is not Valve && h.Node is not PipeJoin && h.Node is not Pump);
|
||||||
k.SetBacklight((int)idx, isRunning ? isDefault ? Color.FromRgb(0, 255, 255) : Color.FromRgb(255, 64, 255) : isDefault ? Color.FromRgb(0, 0, 255) : Color.FromRgb(128, 0, 128), !isReady);
|
k.SetBacklight(idx, isRunning ? isDefault ? Color.FromRgb(0, 255, 255) : Color.FromRgb(255, 64, 255) : isDefault ? Color.FromRgb(0, 0, 255) : Color.FromRgb(128, 0, 128), !isReady);
|
||||||
} else {
|
} else {
|
||||||
var isFree = Graph.GetFreePath([d.Source, d.Sink], overrideStart: true) != null;
|
var isFree = Graph.GetFreePath([d.Source, d.Sink], overrideStart: true) != null;
|
||||||
if (isRunning && k.IsKeyPressed((int)idx) && d.Pump == Graph.MP1) highlightOffMP1 = true;
|
if (isRunning && k.IsKeyPressed(idx) && d.Pump == Graph.MP1) highlightOffMP1 = true;
|
||||||
if (isRunning && k.IsKeyPressed((int)idx) && d.Pump == Graph.MP2) highlightOffMP2 = true;
|
if (isRunning && k.IsKeyPressed(idx) && d.Pump == Graph.MP2) highlightOffMP2 = true;
|
||||||
k.SetBacklight((int)idx, isRunning ? k.IsKeyPressed((int)idx) ? Color.FromRgb(255, 16, 0) : Color.FromRgb(4, 4, 4) : isFree ? Color.FromRgb(8, 8, 32) : k.IsKeyPressed((int)idx) ? Color.FromRgb(255, 32, 0) : Color.FromRgb(4, 4, 4));
|
k.SetBacklight(idx, isRunning ? k.IsKeyPressed(idx) ? Color.FromRgb(255, 0, 0) : Color.FromRgb(4, 4, 4) : isFree ? Color.FromRgb(8, 8, 32) : k.IsKeyPressed(idx) ? Color.FromRgb(255, 0, 0) : Color.FromRgb(4, 4, 4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plant.MP2HasPathClearance && plant.MP2HasDryRunClearance && preparingMP2) {
|
if (!plant.MP2HasPathClearance && plant.MP2HasDryRunClearance && preparingMP2) {
|
||||||
k.SetBacklight((int)Xbe24Key.START_MP2, Color.FromRgb(4, 32, 4), true);
|
k.SetBacklight(4, Color.FromRgb(4, 32, 4), true);
|
||||||
} else {
|
} else {
|
||||||
k.SetBacklight((int)Xbe24Key.START_MP2, !plant.MP2HasClearance ? k.IsKeyPressed((int)Xbe24Key.START_MP2) ? Color.FromRgb(255, 32, 0) : Color.FromRgb(32, 4, 4) : plant.IsMP2Active ? Color.FromRgb(0, 255, 0) : Color.FromRgb(4, 32, 4));
|
k.SetBacklight(4, !plant.MP2HasClearance ? k.IsKeyPressed(4) ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4) : plant.IsMP2Active ? Color.FromRgb(0, 255, 0) : Color.FromRgb(4, 32, 4));
|
||||||
}
|
}
|
||||||
if (!plant.MP1HasPathClearance && plant.MP1HasDryRunClearance && preparingMP1) {
|
if (!plant.MP1HasPathClearance && plant.MP1HasDryRunClearance && preparingMP1) {
|
||||||
k.SetBacklight((int)Xbe24Key.START_MP1, Color.FromRgb(4, 32, 4), true);
|
k.SetBacklight(10, Color.FromRgb(4, 32, 4), true);
|
||||||
} else {
|
} else {
|
||||||
k.SetBacklight((int)Xbe24Key.START_MP1, !plant.MP1HasClearance ? k.IsKeyPressed((int)Xbe24Key.START_MP1) ? Color.FromRgb(255, 32, 0) : Color.FromRgb(32, 4, 4) : plant.IsMP1Active ? Color.FromRgb(0, 255, 0) : Color.FromRgb(4, 32, 4));
|
k.SetBacklight(10, !plant.MP1HasClearance ? k.IsKeyPressed(10) ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4) : plant.IsMP1Active ? Color.FromRgb(0, 255, 0) : Color.FromRgb(4, 32, 4));
|
||||||
}
|
}
|
||||||
k.SetBacklight((int)Xbe24Key.STOP_MP2, highlightOffMP2 ? Color.FromRgb(255, 32, 0) : !plant.IsMP2Active ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
k.SetBacklight(5, highlightOffMP2 ? Color.FromRgb(255, 64, 0) : !plant.IsMP2Active ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
||||||
k.SetBacklight((int)Xbe24Key.STOP_MP1, highlightOffMP1 ? Color.FromRgb(255, 32, 0) : !plant.IsMP1Active ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
k.SetBacklight(11, highlightOffMP1 ? Color.FromRgb(255, 64, 0) : !plant.IsMP1Active ? Color.FromRgb(255, 0, 0) : Color.FromRgb(32, 4, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StartThread() {
|
public async Task StartThread() {
|
||||||
@@ -319,12 +299,11 @@ namespace PamhagenSysCtrl.Helpers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Keyboard_KeyDown(object? sender, int keyIndex) {
|
private void Keyboard_KeyDown(object? sender, int keyIndex) {
|
||||||
var key = (Xbe24Key)keyIndex;
|
|
||||||
App.MainDispatcher?.BeginInvoke(() => {
|
App.MainDispatcher?.BeginInvoke(() => {
|
||||||
try {
|
try {
|
||||||
if (key == Xbe24Key.START_REBLER) {
|
if (keyIndex == 0) {
|
||||||
StartRebler();
|
StartRebler();
|
||||||
} else if (key == Xbe24Key.STOP_REBLER) {
|
} else if (keyIndex == 1) {
|
||||||
if (IsReblerActive) {
|
if (IsReblerActive) {
|
||||||
StopRebler();
|
StopRebler();
|
||||||
} else {
|
} else {
|
||||||
@@ -334,45 +313,45 @@ namespace PamhagenSysCtrl.Helpers {
|
|||||||
StopAuger3();
|
StopAuger3();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (key == Xbe24Key.START_TROUGH_AUGER) {
|
} else if (keyIndex == 6) {
|
||||||
StartTroughAuger();
|
StartTroughAuger();
|
||||||
} else if (key == Xbe24Key.STOP_TROUGH_AUGER) {
|
} else if (keyIndex == 7) {
|
||||||
StopTroughAuger();
|
StopTroughAuger();
|
||||||
} else if (key == Xbe24Key.SELECT_MW2) {
|
} else if (keyIndex == 2) {
|
||||||
SelectMW2();
|
SelectMW2();
|
||||||
} else if (key == Xbe24Key.SELECT_MW1) {
|
} else if (keyIndex == 8) {
|
||||||
SelectMW1();
|
SelectMW1();
|
||||||
} else if (key == Xbe24Key.START_MP2) {
|
} else if (keyIndex == 4) {
|
||||||
StartMP2Forward();
|
StartMP2Forward();
|
||||||
} else if (key == Xbe24Key.STOP_MP2) {
|
} else if (keyIndex == 5) {
|
||||||
StopMP2();
|
StopMP2();
|
||||||
} else if (key == Xbe24Key.START_MP1) {
|
} else if (keyIndex == 10) {
|
||||||
StartMP1Forward();
|
StartMP1Forward();
|
||||||
} else if (key == Xbe24Key.STOP_MP1) {
|
} else if (keyIndex == 11) {
|
||||||
StopMP1();
|
StopMP1();
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW1_1) {
|
} else if (keyIndex == 12) {
|
||||||
FastSelect(Graph.MW1, Graph.Press1);
|
FastSelect(Graph.MW1, Graph.Press1);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW1_2) {
|
} else if (keyIndex == 13) {
|
||||||
FastSelect(Graph.MW1, Graph.Press2);
|
FastSelect(Graph.MW1, Graph.Press2);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW1_3) {
|
} else if (keyIndex == 14) {
|
||||||
FastSelect(Graph.MW1, Graph.Tank1);
|
FastSelect(Graph.MW1, Graph.Tank1);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW1_4) {
|
} else if (keyIndex == 15) {
|
||||||
FastSelect(Graph.MW1, Graph.Tank2);
|
FastSelect(Graph.MW1, Graph.Tank2);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW1_5) {
|
} else if (keyIndex == 16) {
|
||||||
FastSelect(Graph.MW1, Graph.Tank3);
|
FastSelect(Graph.MW1, Graph.Tank3);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW1_6) {
|
} else if (keyIndex == 17) {
|
||||||
FastSelect(Graph.MW1, Graph.Tank4);
|
FastSelect(Graph.MW1, Graph.Tank4);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW2_1) {
|
} else if (keyIndex == 18) {
|
||||||
FastSelect(Graph.MW2, Graph.Press1);
|
FastSelect(Graph.MW2, Graph.Press1);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW2_2) {
|
} else if (keyIndex == 19) {
|
||||||
FastSelect(Graph.MW2, Graph.Press2);
|
FastSelect(Graph.MW2, Graph.Press2);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW2_3) {
|
} else if (keyIndex == 20) {
|
||||||
FastSelect(Graph.MW2, Graph.Tank1);
|
FastSelect(Graph.MW2, Graph.Tank1);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW2_4) {
|
} else if (keyIndex == 21) {
|
||||||
FastSelect(Graph.MW2, Graph.Tank2);
|
FastSelect(Graph.MW2, Graph.Tank2);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW2_5) {
|
} else if (keyIndex == 22) {
|
||||||
FastSelect(Graph.MW2, Graph.Tank3);
|
FastSelect(Graph.MW2, Graph.Tank3);
|
||||||
} else if (key == Xbe24Key.FAST_SELECT_MW2_6) {
|
} else if (keyIndex == 23) {
|
||||||
FastSelect(Graph.MW2, Graph.Tank4);
|
FastSelect(Graph.MW2, Graph.Tank4);
|
||||||
}
|
}
|
||||||
} catch (NoClearanceException) {
|
} catch (NoClearanceException) {
|
||||||
|
|||||||
Reference in new issue
Block a user