diff --git a/Matomat/Automat.cs b/Matomat/Automat.cs index a343dc4..61acad8 100644 --- a/Matomat/Automat.cs +++ b/Matomat/Automat.cs @@ -15,7 +15,7 @@ namespace Matomat public Automat() { lcd = Factory.getLCDDisplay(); - inp = new Input(); + inp = Factory.getInput(); } internal void doJob(InputData input) { @@ -54,7 +54,7 @@ namespace Matomat private void showUserInfo(User user) { - throw new NotImplementedException(); + lcd.print("User x",5); } private User findUser(int userId) diff --git a/Matomat/Factory.cs b/Matomat/Factory.cs index fff9b37..44e75bf 100644 --- a/Matomat/Factory.cs +++ b/Matomat/Factory.cs @@ -8,6 +8,7 @@ namespace Matomat class Factory { static LCDDisplay lcd_i = null; + static Input inp_i = null; internal static LCDDisplay getLCDDisplay() { if (lcd_i == null) @@ -20,5 +21,18 @@ namespace Matomat LCDDisplay lcd = LCDDisplay.getInstance("lpd1"); return lcd; } + + internal static Input getInput() + { + if (inp_i == null) + inp_i = Factory._createInput(); + return inp_i; + } + + private static Input _createInput() + { + Input inp = Input.getInstance(); + return inp; + } } } diff --git a/Matomat/Input.cs b/Matomat/Input.cs index 672cad2..5223c38 100644 --- a/Matomat/Input.cs +++ b/Matomat/Input.cs @@ -2,11 +2,17 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; namespace Matomat { class InputData { + public InputData() + { + this.id = 0; + this.type = types.None; + } public enum types { Card, @@ -18,14 +24,75 @@ namespace Matomat } class Input { + private class instance + { + public Input input; + public double signature; + + public instance(Input input, double signature) + { + this.input = input; + this.signature = signature; + } + } + static List instances; + private InputData data; + private void doWorkCard() + { + while (true) + { + Thread.Sleep(1); + data.type = InputData.types.Card; + data.id = 3; + } + + } + private void doWorkCode() + { + while (true) + { + Thread.Sleep(1); + } + } internal InputData getAnyInput(int timeout) { - throw new NotImplementedException(); + if (timeout == 0) + timeout = Int32.MaxValue; + data = new InputData(); + Thread wtCard = new Thread(this.doWorkCard); + Thread wtCode = new Thread(this.doWorkCode); + wtCard.Start(); + wtCode.Start(); + while (!wtCard.IsAlive) ; + while (!wtCode.IsAlive) ; + DateTime time = DateTime.Now.AddSeconds(timeout); + while (time.Ticks < DateTime.Now.Ticks || data.type == InputData.types.None) + { + Thread.Sleep(1); + } + wtCard.Abort(); + wtCode.Abort(); + return data; } internal InputData getProdInput(int timeout) { throw new NotImplementedException(); } + + internal static Input getInstance() + { + if (instances == null) + instances = new List(); + double signature = 1.0; + foreach (instance i in instances) + { + if (i.signature == signature) + return i.input; + } + instance instance = new instance(new Input(), signature); + instances.Add(instance); + return instance.input; + } } } diff --git a/Matomat/Matomat.csproj b/Matomat/Matomat.csproj index 3b7b34e..2ea42bd 100644 --- a/Matomat/Matomat.csproj +++ b/Matomat/Matomat.csproj @@ -47,7 +47,9 @@ + + diff --git a/Matomat/Program.cs b/Matomat/Program.cs index 3efa6ff..ceb3961 100644 --- a/Matomat/Program.cs +++ b/Matomat/Program.cs @@ -17,7 +17,7 @@ namespace Matomat while (!workerThread.IsAlive) ; - while (workerThread.ThreadState == ThreadState.Running) + while (workerThread.IsAlive) { Thread.Sleep(1); } diff --git a/Matomat/User.cs b/Matomat/User.cs index 29b6755..9a32600 100644 --- a/Matomat/User.cs +++ b/Matomat/User.cs @@ -20,7 +20,7 @@ namespace Matomat private void load() { if (true) - this.found = false; + this.found = true; } internal bool vaild() diff --git a/Matomat/Worker.cs b/Matomat/Worker.cs index e391fdd..11f711f 100644 --- a/Matomat/Worker.cs +++ b/Matomat/Worker.cs @@ -19,17 +19,18 @@ namespace Matomat barcode = new BarcodeReader(); automat = new Automat(); lcd = Factory.getLCDDisplay(); - inp = new Input(); + inp = Factory.getInput(); } public void DoWork() { while (!_shouldStop) { + lcd.print("Matomat, wikommen: Beste Säufer: x x x"); InputData input = inp.getAnyInput(0); /*int userId = rfid.getCardID(); - * lcd.print("Bitte Sudierendenausweis über den RFID Leser halten."); + * ; long codeId = barcode.getCodeID();*/ automat.doJob(input); }