Add ip/port setting
This commit is contained in:
@@ -60,7 +60,7 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
{
|
{
|
||||||
_port = _radioPort.RadioLabels[_radioPort.SelectedItem].ToString();
|
_port = _radioPort.RadioLabels[_radioPort.SelectedItem].ToString();
|
||||||
|
|
||||||
File.WriteAllText(TUIManager.SettingsFilePath, _port);
|
File.WriteAllText(WaveshareUARTProvider.SerialPortFilePath, _port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
using Akari.Provider.WaveshareUART.Users;
|
using Akari.Provider.WaveshareUART.Users;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Terminal.Gui;
|
using Terminal.Gui;
|
||||||
using WaveshareUARTFingerprintSensor;
|
using WaveshareUARTFingerprintSensor;
|
||||||
@@ -8,8 +10,6 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
{
|
{
|
||||||
public class TUIManager : Toplevel
|
public class TUIManager : Toplevel
|
||||||
{
|
{
|
||||||
public const string SettingsFilePath = "settings.txt";
|
|
||||||
|
|
||||||
public WaveshareUARTProvider Provider => WaveshareUARTProvider.Instance;
|
public WaveshareUARTProvider Provider => WaveshareUARTProvider.Instance;
|
||||||
public FingerprintSensor FingerprintSensor => Provider.FingerprintSensor;
|
public FingerprintSensor FingerprintSensor => Provider.FingerprintSensor;
|
||||||
public UsersManager UsersManager => Provider.UsersManager;
|
public UsersManager UsersManager => Provider.UsersManager;
|
||||||
@@ -17,6 +17,7 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
private Label _serialPortLabel;
|
private Label _serialPortLabel;
|
||||||
private Label _comparisonLevelLabel;
|
private Label _comparisonLevelLabel;
|
||||||
private Label _userCountLabel;
|
private Label _userCountLabel;
|
||||||
|
private Label _serverIPLabel;
|
||||||
private bool _needToClear;
|
private bool _needToClear;
|
||||||
|
|
||||||
public TUIManager()
|
public TUIManager()
|
||||||
@@ -72,11 +73,17 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
Y = Pos.Bottom(_comparisonLevelLabel),
|
Y = Pos.Bottom(_comparisonLevelLabel),
|
||||||
Width = Dim.Fill()
|
Width = Dim.Fill()
|
||||||
};
|
};
|
||||||
|
_serverIPLabel = new Label("Server IP: N/A")
|
||||||
|
{
|
||||||
|
X = Pos.Left(_comparisonLevelLabel),
|
||||||
|
Y = Pos.Bottom(_userCountLabel),
|
||||||
|
Width = Dim.Fill()
|
||||||
|
};
|
||||||
|
|
||||||
var manageUsersButton = new Button("_Manage Users")
|
var manageUsersButton = new Button("_Manage Users")
|
||||||
{
|
{
|
||||||
X = Pos.Center(),
|
X = Pos.Center(),
|
||||||
Y = Pos.Center() - 1
|
Y = Pos.Center() - 2
|
||||||
};
|
};
|
||||||
manageUsersButton.Clicked += ManageUsersButton_Clicked;
|
manageUsersButton.Clicked += ManageUsersButton_Clicked;
|
||||||
|
|
||||||
@@ -87,6 +94,20 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
};
|
};
|
||||||
setComparisonLevelButton.Clicked += SetComparisonLevelButton_Clicked;
|
setComparisonLevelButton.Clicked += SetComparisonLevelButton_Clicked;
|
||||||
|
|
||||||
|
var setServerIP = new Button("Set Server _IP")
|
||||||
|
{
|
||||||
|
X = Pos.Center(),
|
||||||
|
Y = Pos.Bottom(setComparisonLevelButton) + 1
|
||||||
|
};
|
||||||
|
setServerIP.Clicked += SetServerIP_Clicked;
|
||||||
|
|
||||||
|
var setServerPort = new Button("Set Server _Port")
|
||||||
|
{
|
||||||
|
X = Pos.Center(),
|
||||||
|
Y = Pos.Bottom(setServerIP)
|
||||||
|
};
|
||||||
|
setServerPort.Clicked += SetServerPort_Clicked;
|
||||||
|
|
||||||
var quitButton = new Button("_Quit")
|
var quitButton = new Button("_Quit")
|
||||||
{
|
{
|
||||||
X = Pos.Center(),
|
X = Pos.Center(),
|
||||||
@@ -98,13 +119,16 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
_serialPortLabel,
|
_serialPortLabel,
|
||||||
_comparisonLevelLabel,
|
_comparisonLevelLabel,
|
||||||
_userCountLabel,
|
_userCountLabel,
|
||||||
|
_serverIPLabel,
|
||||||
manageUsersButton,
|
manageUsersButton,
|
||||||
setComparisonLevelButton,
|
setComparisonLevelButton,
|
||||||
|
setServerIP,
|
||||||
|
setServerPort,
|
||||||
quitButton
|
quitButton
|
||||||
);
|
);
|
||||||
|
|
||||||
// Init Sensor
|
// Init Sensor
|
||||||
if (!File.Exists(SettingsFilePath))
|
if (!File.Exists(WaveshareUARTProvider.SerialPortFilePath))
|
||||||
{
|
{
|
||||||
_needToClear = true;
|
_needToClear = true;
|
||||||
|
|
||||||
@@ -127,6 +151,7 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
UpdateSerialPort();
|
UpdateSerialPort();
|
||||||
UpdateUserCount();
|
UpdateUserCount();
|
||||||
UpdateComparisonLevel();
|
UpdateComparisonLevel();
|
||||||
|
UpdateServerIP();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSerialPort()
|
private void UpdateSerialPort()
|
||||||
@@ -147,6 +172,14 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateServerIP()
|
||||||
|
{
|
||||||
|
if (File.Exists(WaveshareUARTProvider.ServerIPFilePath) && File.Exists(WaveshareUARTProvider.ServerPortFilePath))
|
||||||
|
{
|
||||||
|
_serverIPLabel.Text = $"Server IP: {File.ReadAllText(WaveshareUARTProvider.ServerIPFilePath)}:{File.ReadAllText(WaveshareUARTProvider.ServerPortFilePath)}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SetComparisonLevelButton_Clicked()
|
private void SetComparisonLevelButton_Clicked()
|
||||||
{
|
{
|
||||||
if (new EntryDialog("Comparison Level", i => int.TryParse(i.ToString(), out var n) && n > 0 && n < 10, "Need to be a valid number in 0-9 range").TryShow(out var input))
|
if (new EntryDialog("Comparison Level", i => int.TryParse(i.ToString(), out var n) && n > 0 && n < 10, "Need to be a valid number in 0-9 range").TryShow(out var input))
|
||||||
@@ -160,56 +193,24 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
UpdateComparisonLevel();
|
UpdateComparisonLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddUserButton_Clicked()
|
private void SetServerIP_Clicked()
|
||||||
{
|
{
|
||||||
if (new EntryDialog("User id", i => ushort.TryParse(i.ToString(), out var n), "Need to be a valid user id").TryShow(out var input))
|
if (new EntryDialog("Server IP", i => Uri.CheckHostName(i.ToString()) != UriHostNameType.Unknown, "Need to be a valid ip address").TryShow(out var input))
|
||||||
{
|
{
|
||||||
var dialog = new FingerprintDialog("Add Fingerprint", "Can't add fingerprint, try to place your finger flat on the sensor");
|
File.WriteAllText(WaveshareUARTProvider.ServerIPFilePath, input.ToString());
|
||||||
|
|
||||||
Task.Run(() =>
|
|
||||||
{
|
|
||||||
switch (FingerprintSensor.AddFingerprint(ushort.Parse(input.ToString()), UserPermission.Level1))
|
|
||||||
{
|
|
||||||
case ResponseType.Success:
|
|
||||||
dialog.Cancel();
|
|
||||||
|
|
||||||
Application.MainLoop.Invoke(() => MessageBox.Query("Add Fingerprint", "Successfully added fingerprint", "Ok"));
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ResponseType.Full:
|
|
||||||
dialog.ErrorMessage = "Sensor full, can't add more users";
|
|
||||||
|
|
||||||
dialog.CancelAndShowError();
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ResponseType.NoUser:
|
|
||||||
dialog.ErrorMessage = "Can't add fingerprint, invalid id";
|
|
||||||
|
|
||||||
dialog.CancelAndShowError();
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ResponseType.FingerOccupied:
|
|
||||||
dialog.ErrorMessage = "Can't add fingerprint, finger already registered";
|
|
||||||
|
|
||||||
dialog.CancelAndShowError();
|
|
||||||
|
|
||||||
break;
|
|
||||||
case ResponseType.UserOccupied:
|
|
||||||
dialog.ErrorMessage = "Can't add fingerprint, id already used";
|
|
||||||
|
|
||||||
dialog.CancelAndShowError();
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
dialog.CancelAndShowError();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
dialog.Show();
|
UpdateServerIP();
|
||||||
|
|
||||||
UpdateUserCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetServerPort_Clicked()
|
||||||
|
{
|
||||||
|
if (new EntryDialog("Server Port", i => short.TryParse(i.ToString(), out _), "Need to be a valid port").TryShow(out var input))
|
||||||
|
{
|
||||||
|
File.WriteAllText(WaveshareUARTProvider.ServerPortFilePath, input.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateServerIP();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ManageUsersButton_Clicked()
|
private void ManageUsersButton_Clicked()
|
||||||
@@ -221,7 +222,7 @@ namespace Akari.Provider.WaveshareUART.Views
|
|||||||
|
|
||||||
private void ChangeConfig()
|
private void ChangeConfig()
|
||||||
{
|
{
|
||||||
File.Delete(SettingsFilePath);
|
File.Delete(WaveshareUARTProvider.SerialPortFilePath);
|
||||||
|
|
||||||
Application.Run(new SettingsDisplay());
|
Application.Run(new SettingsDisplay());
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Akari.Provider.WaveshareUART.Users;
|
using Akari.Provider.WaveshareUART.Users;
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using WaveshareUARTFingerprintSensor;
|
using WaveshareUARTFingerprintSensor;
|
||||||
|
|
||||||
@@ -6,7 +7,9 @@ namespace Akari.Provider.WaveshareUART
|
|||||||
{
|
{
|
||||||
public class WaveshareUARTProvider
|
public class WaveshareUARTProvider
|
||||||
{
|
{
|
||||||
public const string SettingsFilePath = "settings.txt";
|
public const string SerialPortFilePath = "serial.txt";
|
||||||
|
public const string ServerIPFilePath = "ip.txt";
|
||||||
|
public const string ServerPortFilePath = "port.txt";
|
||||||
|
|
||||||
public static WaveshareUARTProvider Instance { get; }
|
public static WaveshareUARTProvider Instance { get; }
|
||||||
|
|
||||||
@@ -25,7 +28,21 @@ namespace Akari.Provider.WaveshareUART
|
|||||||
|
|
||||||
public void InitSensor()
|
public void InitSensor()
|
||||||
{
|
{
|
||||||
FingerprintSensor = new FingerprintSensor(File.ReadAllText(SettingsFilePath));
|
try
|
||||||
|
{
|
||||||
|
FingerprintSensor = new FingerprintSensor(File.ReadAllText(SerialPortFilePath));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine(e);
|
||||||
|
|
||||||
|
Console.WriteLine();
|
||||||
|
Console.WriteLine($"Couldn't read settings file '{SerialPortFilePath}'");
|
||||||
|
Console.WriteLine($"Launch the program with '-c' to config the provider");
|
||||||
|
|
||||||
|
Environment.Exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
FingerprintSensor.Start();
|
FingerprintSensor.Start();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user