Threading rockt
This commit is contained in:
parent
42e167bdef
commit
5ebf0ad6a6
@ -15,7 +15,7 @@ namespace Matomat
|
|||||||
|
|
||||||
public Automat() {
|
public Automat() {
|
||||||
lcd = Factory.getLCDDisplay();
|
lcd = Factory.getLCDDisplay();
|
||||||
inp = new Input();
|
inp = Factory.getInput();
|
||||||
}
|
}
|
||||||
internal void doJob(InputData input)
|
internal void doJob(InputData input)
|
||||||
{
|
{
|
||||||
@ -54,7 +54,7 @@ namespace Matomat
|
|||||||
|
|
||||||
private void showUserInfo(User user)
|
private void showUserInfo(User user)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
lcd.print("User x",5);
|
||||||
}
|
}
|
||||||
|
|
||||||
private User findUser(int userId)
|
private User findUser(int userId)
|
||||||
|
@ -8,6 +8,7 @@ namespace Matomat
|
|||||||
class Factory
|
class Factory
|
||||||
{
|
{
|
||||||
static LCDDisplay lcd_i = null;
|
static LCDDisplay lcd_i = null;
|
||||||
|
static Input inp_i = null;
|
||||||
internal static LCDDisplay getLCDDisplay()
|
internal static LCDDisplay getLCDDisplay()
|
||||||
{
|
{
|
||||||
if (lcd_i == null)
|
if (lcd_i == null)
|
||||||
@ -20,5 +21,18 @@ namespace Matomat
|
|||||||
LCDDisplay lcd = LCDDisplay.getInstance("lpd1");
|
LCDDisplay lcd = LCDDisplay.getInstance("lpd1");
|
||||||
return lcd;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,17 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
namespace Matomat
|
namespace Matomat
|
||||||
{
|
{
|
||||||
class InputData
|
class InputData
|
||||||
{
|
{
|
||||||
|
public InputData()
|
||||||
|
{
|
||||||
|
this.id = 0;
|
||||||
|
this.type = types.None;
|
||||||
|
}
|
||||||
public enum types
|
public enum types
|
||||||
{
|
{
|
||||||
Card,
|
Card,
|
||||||
@ -18,14 +24,75 @@ namespace Matomat
|
|||||||
}
|
}
|
||||||
class Input
|
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<instance> 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)
|
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)
|
internal InputData getProdInput(int timeout)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static Input getInstance()
|
||||||
|
{
|
||||||
|
if (instances == null)
|
||||||
|
instances = new List<instance>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,9 @@
|
|||||||
<Compile Include="BarcodeReader.cs" />
|
<Compile Include="BarcodeReader.cs" />
|
||||||
<Compile Include="Factory.cs" />
|
<Compile Include="Factory.cs" />
|
||||||
<Compile Include="Helper.cs" />
|
<Compile Include="Helper.cs" />
|
||||||
|
<Compile Include="Input.cs" />
|
||||||
<Compile Include="LCDDisplay.cs" />
|
<Compile Include="LCDDisplay.cs" />
|
||||||
|
<Compile Include="Prod.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="RFIDReader.cs" />
|
<Compile Include="RFIDReader.cs" />
|
||||||
|
@ -17,7 +17,7 @@ namespace Matomat
|
|||||||
|
|
||||||
while (!workerThread.IsAlive) ;
|
while (!workerThread.IsAlive) ;
|
||||||
|
|
||||||
while (workerThread.ThreadState == ThreadState.Running)
|
while (workerThread.IsAlive)
|
||||||
{
|
{
|
||||||
Thread.Sleep(1);
|
Thread.Sleep(1);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace Matomat
|
|||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
if (true)
|
if (true)
|
||||||
this.found = false;
|
this.found = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal bool vaild()
|
internal bool vaild()
|
||||||
|
@ -19,17 +19,18 @@ namespace Matomat
|
|||||||
barcode = new BarcodeReader();
|
barcode = new BarcodeReader();
|
||||||
automat = new Automat();
|
automat = new Automat();
|
||||||
lcd = Factory.getLCDDisplay();
|
lcd = Factory.getLCDDisplay();
|
||||||
inp = new Input();
|
inp = Factory.getInput();
|
||||||
}
|
}
|
||||||
public void DoWork()
|
public void DoWork()
|
||||||
{
|
{
|
||||||
while (!_shouldStop)
|
while (!_shouldStop)
|
||||||
{
|
{
|
||||||
|
lcd.print("Matomat, wikommen: Beste Säufer: x x x");
|
||||||
InputData input = inp.getAnyInput(0);
|
InputData input = inp.getAnyInput(0);
|
||||||
|
|
||||||
/*int userId = rfid.getCardID();
|
/*int userId = rfid.getCardID();
|
||||||
|
|
||||||
* lcd.print("Bitte Sudierendenausweis über den RFID Leser halten.");
|
* ;
|
||||||
long codeId = barcode.getCodeID();*/
|
long codeId = barcode.getCodeID();*/
|
||||||
automat.doJob(input);
|
automat.doJob(input);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user