Add AddFingerprint command
This commit is contained in:
@@ -19,9 +19,9 @@ namespace WaveshareUARTFingerprintSensor.Sample
|
||||
|
||||
sensor.Start();
|
||||
|
||||
sensor.Waked += s => sensor.Wake();
|
||||
Console.WriteLine("Adding fingerprint");
|
||||
|
||||
sensor.Sleep();
|
||||
var response = sensor.AddFingerprint(40, UserPermission.Level3);
|
||||
|
||||
Console.WriteLine("End");
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace WaveshareUARTFingerprintSensor
|
||||
public const string PrimarySerialPort = "/dev/ttyAMA0";
|
||||
public const string SecondarySerialPort = "/dev/ttyS0";
|
||||
public const int DefaultTimeout = 10_000;
|
||||
public const int MaxUserID = 0xFFF;
|
||||
|
||||
public event WakedEventHandler Waked;
|
||||
public delegate void WakedEventHandler(FingerprintSensor sender);
|
||||
@@ -177,6 +178,36 @@ namespace WaveshareUARTFingerprintSensor
|
||||
_rstPin.Write(GpioPinValue.High);
|
||||
}
|
||||
|
||||
public ResponseType AddFingerprint(ushort userID, UserPermission userPermission)
|
||||
{
|
||||
if (userID > MaxUserID)
|
||||
{
|
||||
return ResponseType.Full;
|
||||
}
|
||||
|
||||
CommandType[] commands = { CommandType.AddFingerprint1, CommandType.AddFingerprint2, CommandType.AddFingerprint3 };
|
||||
(byte idHigh, byte idLow) = Utils.Split(userID);
|
||||
|
||||
foreach (var command in commands)
|
||||
{
|
||||
if (TrySendAndReceive(command, idHigh, idLow, (byte)userPermission, out var response))
|
||||
{
|
||||
if (response.responseType != ResponseType.Success)
|
||||
{
|
||||
return response.responseType;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return ResponseType.Timeout;
|
||||
}
|
||||
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
|
||||
return ResponseType.Success;
|
||||
}
|
||||
|
||||
private void OnWake()
|
||||
{
|
||||
if (_wakePin.Read())
|
||||
|
||||
9
WaveshareUARTFingerprintSensor/UserPermission.cs
Normal file
9
WaveshareUARTFingerprintSensor/UserPermission.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace WaveshareUARTFingerprintSensor
|
||||
{
|
||||
public enum UserPermission
|
||||
{
|
||||
Level1 = 1,
|
||||
Level2 = 2,
|
||||
Level3 = 3
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@
|
||||
<Compile Include="FingerprintSensor.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ResponseType.cs" />
|
||||
<Compile Include="UserPermission.cs" />
|
||||
<Compile Include="Utils.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user