Compare commits
3 Commits
7c2a102bee
...
e602fb26c7
| Author | SHA1 | Date | |
|---|---|---|---|
| e602fb26c7 | |||
| 747db9d7dd | |||
| 56a0eecdc9 |
@@ -26,7 +26,7 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
ColorScheme = Colors.TopLevel;
|
ColorScheme = Colors.TopLevel;
|
||||||
|
|
||||||
// Creates the top-level window to show
|
// Creates the top-level window to show
|
||||||
var win = new Window("TUIManager")
|
var win = new Window(_title)
|
||||||
{
|
{
|
||||||
X = 0,
|
X = 0,
|
||||||
Y = 0,
|
Y = 0,
|
||||||
|
|||||||
@@ -14,14 +14,8 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
public static FingerprintSensor FingerprintSensor { get; private set; }
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
FingerprintSensor = new FingerprintSensor(FingerprintSensor.SecondarySerialPort);
|
|
||||||
|
|
||||||
FingerprintSensor.Start();
|
|
||||||
|
|
||||||
Application.Run<TUIManager>();
|
Application.Run<TUIManager>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
71
WaveshareUARTFingerprintSensor.Sample/SettingsDisplay.cs
Normal file
71
WaveshareUARTFingerprintSensor.Sample/SettingsDisplay.cs
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Terminal.Gui;
|
||||||
|
|
||||||
|
namespace WaveshareUARTFingerprintSensor.Sample
|
||||||
|
{
|
||||||
|
public class SettingsDisplay : Toplevel
|
||||||
|
{
|
||||||
|
private string _port;
|
||||||
|
private RadioGroup _radioPort;
|
||||||
|
|
||||||
|
public SettingsDisplay()
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init()
|
||||||
|
{
|
||||||
|
ColorScheme = Colors.Error;
|
||||||
|
|
||||||
|
// Creates the top-level window to show
|
||||||
|
var win = new Window("Settings")
|
||||||
|
{
|
||||||
|
X = 0,
|
||||||
|
Y = 0,
|
||||||
|
|
||||||
|
// By using Dim.Fill(), it will automatically resize without manual intervention
|
||||||
|
Width = Dim.Fill(),
|
||||||
|
Height = Dim.Fill()
|
||||||
|
};
|
||||||
|
|
||||||
|
win.ColorScheme = Colors.ColorSchemes["Dialog"];
|
||||||
|
|
||||||
|
Add(win);
|
||||||
|
|
||||||
|
// Window Content
|
||||||
|
var portLabel = new Label("Serial Port:")
|
||||||
|
{
|
||||||
|
X = 4,
|
||||||
|
Y = 3
|
||||||
|
};
|
||||||
|
_radioPort = new RadioGroup(new NStack.ustring[] { FingerprintSensor.PrimarySerialPort, FingerprintSensor.SecondarySerialPort })
|
||||||
|
{
|
||||||
|
X = Pos.Right(portLabel) + 2,
|
||||||
|
Y = Pos.Top(portLabel),
|
||||||
|
Width = Dim.Fill()
|
||||||
|
};
|
||||||
|
|
||||||
|
var saveButton = new Button("_Save")
|
||||||
|
{
|
||||||
|
X = Pos.Right(this) - 14,
|
||||||
|
Y = Pos.Bottom(this) - 4
|
||||||
|
};
|
||||||
|
saveButton.Clicked += () => { Save(); Application.RequestStop(); };
|
||||||
|
|
||||||
|
win.Add(portLabel, _radioPort, saveButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Save()
|
||||||
|
{
|
||||||
|
_port = _radioPort.RadioLabels[_radioPort.SelectedItem].ToString();
|
||||||
|
|
||||||
|
File.WriteAllText(TUIManager.SettingsFilePath, _port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
106
WaveshareUARTFingerprintSensor.Sample/SleepDisplay.cs
Normal file
106
WaveshareUARTFingerprintSensor.Sample/SleepDisplay.cs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Terminal.Gui;
|
||||||
|
|
||||||
|
namespace WaveshareUARTFingerprintSensor.Sample
|
||||||
|
{
|
||||||
|
public class SleepDisplay : Toplevel
|
||||||
|
{
|
||||||
|
private FingerprintSensor _fingerprintSensor;
|
||||||
|
private int _count;
|
||||||
|
private int _lastID;
|
||||||
|
private Label _sleepModeLabel;
|
||||||
|
private Label _readCountLabel;
|
||||||
|
private Label _lastReadLabel;
|
||||||
|
|
||||||
|
public SleepDisplay(FingerprintSensor fingerprintSensor)
|
||||||
|
{
|
||||||
|
_fingerprintSensor = fingerprintSensor;
|
||||||
|
_count = 0;
|
||||||
|
_lastID = -1;
|
||||||
|
|
||||||
|
Init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Init()
|
||||||
|
{
|
||||||
|
ColorScheme = Colors.Error;
|
||||||
|
|
||||||
|
// Creates the top-level window to show
|
||||||
|
var win = new Window("Sleep")
|
||||||
|
{
|
||||||
|
X = 0,
|
||||||
|
Y = 0,
|
||||||
|
|
||||||
|
// By using Dim.Fill(), it will automatically resize without manual intervention
|
||||||
|
Width = Dim.Fill(),
|
||||||
|
Height = Dim.Fill()
|
||||||
|
};
|
||||||
|
|
||||||
|
win.ColorScheme = Colors.ColorSchemes["Dialog"];
|
||||||
|
|
||||||
|
Add(win);
|
||||||
|
|
||||||
|
// Window Content
|
||||||
|
_sleepModeLabel = new Label("Sleep mode is on, waiting for fingerprints...")
|
||||||
|
{
|
||||||
|
X = 2,
|
||||||
|
Y = 1,
|
||||||
|
Width = Dim.Fill()
|
||||||
|
};
|
||||||
|
_readCountLabel = new Label("Read: 0")
|
||||||
|
{
|
||||||
|
X = Pos.Left(_sleepModeLabel),
|
||||||
|
Y = Pos.Bottom(_sleepModeLabel) + 1,
|
||||||
|
Width = Dim.Fill()
|
||||||
|
};
|
||||||
|
_lastReadLabel = new Label("Last User: - 1")
|
||||||
|
{
|
||||||
|
X = Pos.Left(_readCountLabel),
|
||||||
|
Y = Pos.Bottom(_readCountLabel),
|
||||||
|
Width = Dim.Fill()
|
||||||
|
};
|
||||||
|
|
||||||
|
var stopButton = new Button("_Stop")
|
||||||
|
{
|
||||||
|
X = Pos.Right(this) - 11,
|
||||||
|
Y = Pos.Bottom(this) - 2
|
||||||
|
};
|
||||||
|
stopButton.Clicked += () => { _fingerprintSensor.Waked -= FingerprintSensor_Waked; Application.RequestStop(); };
|
||||||
|
|
||||||
|
win.Add(_sleepModeLabel, _readCountLabel, _lastReadLabel);
|
||||||
|
|
||||||
|
Add(stopButton);
|
||||||
|
|
||||||
|
_fingerprintSensor.Waked += FingerprintSensor_Waked;
|
||||||
|
|
||||||
|
_fingerprintSensor.Sleep();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateInfo()
|
||||||
|
{
|
||||||
|
_readCountLabel.Text = $"Read: {_count}";
|
||||||
|
_lastReadLabel.Text = $"Last User: {_lastID}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FingerprintSensor_Waked(FingerprintSensor sender)
|
||||||
|
{
|
||||||
|
_fingerprintSensor.Wake();
|
||||||
|
|
||||||
|
if (_fingerprintSensor.TryComparison1N(out var userInfo))
|
||||||
|
{
|
||||||
|
_count += 1;
|
||||||
|
_lastID = userInfo.userID;
|
||||||
|
|
||||||
|
Application.MainLoop.Invoke(UpdateInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
_fingerprintSensor.Sleep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,8 +12,10 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
public class TUIManager : Toplevel
|
public class TUIManager : Toplevel
|
||||||
{
|
{
|
||||||
public const string OutputFilePath = "out.txt";
|
public const string OutputFilePath = "out.txt";
|
||||||
|
public const string SettingsFilePath = "settings.txt";
|
||||||
|
|
||||||
private readonly FingerprintSensor _fingerprintSensor;
|
private FingerprintSensor _fingerprintSensor;
|
||||||
|
private Label _serialPortLabel;
|
||||||
private Label _comparisonLevelLabel;
|
private Label _comparisonLevelLabel;
|
||||||
private Label _userCountLabel;
|
private Label _userCountLabel;
|
||||||
|
|
||||||
@@ -21,8 +23,6 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
|
|
||||||
public TUIManager()
|
public TUIManager()
|
||||||
{
|
{
|
||||||
_fingerprintSensor = Program.FingerprintSensor;
|
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
// Creates a menubar, the item "New" has a help menu.
|
// Creates a menubar, the item "New" has a help menu.
|
||||||
var menu = new MenuBar(new MenuBarItem[] {
|
var menu = new MenuBar(new MenuBarItem[] {
|
||||||
new MenuBarItem ("_Options", new MenuItem [] {
|
new MenuBarItem ("_Options", new MenuItem [] {
|
||||||
new MenuItem ("Reset Config", "", () => { ResetConfig(); }),
|
new MenuItem ("_Change Config", "", () => { ChangeConfig(); }),
|
||||||
new MenuItem ("_Quit", "", () => { Application.RequestStop(); })
|
new MenuItem ("_Quit", "", () => { Application.RequestStop(); })
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -56,12 +56,18 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
Add(menu);
|
Add(menu);
|
||||||
|
|
||||||
// Window Content
|
// Window Content
|
||||||
_comparisonLevelLabel = new Label("Comparison Level: 0")
|
_serialPortLabel = new Label("Serial Port:")
|
||||||
{
|
{
|
||||||
X = 2,
|
X = 2,
|
||||||
Y = 1,
|
Y = 1,
|
||||||
Width = Dim.Fill()
|
Width = Dim.Fill()
|
||||||
};
|
};
|
||||||
|
_comparisonLevelLabel = new Label("Comparison Level: 0")
|
||||||
|
{
|
||||||
|
X = Pos.Left(_serialPortLabel),
|
||||||
|
Y = Pos.Bottom(_serialPortLabel),
|
||||||
|
Width = Dim.Fill()
|
||||||
|
};
|
||||||
_userCountLabel = new Label("Users: 0")
|
_userCountLabel = new Label("Users: 0")
|
||||||
{
|
{
|
||||||
X = Pos.Left(_comparisonLevelLabel),
|
X = Pos.Left(_comparisonLevelLabel),
|
||||||
@@ -140,6 +146,7 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
quitButton.Clicked += Quit_Clicked;
|
quitButton.Clicked += Quit_Clicked;
|
||||||
|
|
||||||
win.Add(
|
win.Add(
|
||||||
|
_serialPortLabel,
|
||||||
_comparisonLevelLabel,
|
_comparisonLevelLabel,
|
||||||
_userCountLabel,
|
_userCountLabel,
|
||||||
userCountButton,
|
userCountButton,
|
||||||
@@ -154,10 +161,30 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
quitButton
|
quitButton
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Init Sensor
|
||||||
|
if (!File.Exists(SettingsFilePath))
|
||||||
|
{
|
||||||
|
Application.Run(new SettingsDisplay());
|
||||||
|
}
|
||||||
|
|
||||||
|
InitSensor();
|
||||||
|
|
||||||
|
// Update gui
|
||||||
|
UpdateSerialPort();
|
||||||
UpdateUserCount();
|
UpdateUserCount();
|
||||||
UpdateComparisonLevel();
|
UpdateComparisonLevel();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO Config at first start
|
private void UpdateSerialPort()
|
||||||
|
{
|
||||||
|
_serialPortLabel.Text = $"Serial Port: {_fingerprintSensor.PortName}";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitSensor()
|
||||||
|
{
|
||||||
|
_fingerprintSensor = new FingerprintSensor(File.ReadAllText(SettingsFilePath));
|
||||||
|
|
||||||
|
_fingerprintSensor.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateUserCount()
|
private void UpdateUserCount()
|
||||||
@@ -264,7 +291,9 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
|
|
||||||
private void SleepButton_Clicked()
|
private void SleepButton_Clicked()
|
||||||
{
|
{
|
||||||
//TODO
|
var window = new SleepDisplay(_fingerprintSensor);
|
||||||
|
|
||||||
|
Application.Run(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ClearFingerprintsButton_Clicked()
|
private void ClearFingerprintsButton_Clicked()
|
||||||
@@ -368,11 +397,15 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResetConfig()
|
private void ChangeConfig()
|
||||||
{
|
{
|
||||||
MessageBox.Query("Reset Config", "Config reset", "OK");
|
File.Delete(SettingsFilePath);
|
||||||
|
|
||||||
//TODO
|
Application.Run(new SettingsDisplay());
|
||||||
|
|
||||||
|
InitSensor();
|
||||||
|
|
||||||
|
UpdateSerialPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Quit_Clicked()
|
private void Quit_Clicked()
|
||||||
|
|||||||
@@ -104,6 +104,8 @@
|
|||||||
<Compile Include="FingerprintDialog.cs" />
|
<Compile Include="FingerprintDialog.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="SettingsDisplay.cs" />
|
||||||
|
<Compile Include="SleepDisplay.cs" />
|
||||||
<Compile Include="TUIManager.cs" />
|
<Compile Include="TUIManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user