Compare commits

...

8 Commits

Author SHA1 Message Date
c42abc1537 Update 'WaveshareUARTFingerprintSensor.Sample/README.md' 2021-01-12 18:35:59 +01:00
48f7f59594 Update 'README.md' 2021-01-12 18:26:57 +01:00
c416358def Update README.md 2021-01-12 18:21:53 +01:00
b9cc6e0aac Add README.md 2021-01-12 18:17:41 +01:00
2a413fb9fb Prepare for nuget 2021-01-12 16:27:48 +01:00
e602fb26c7 Add Settings 2021-01-10 01:54:25 +01:00
747db9d7dd [Sample] Add missing titles 2021-01-10 01:21:29 +01:00
56a0eecdc9 [Sample] Add Sleep command 2021-01-10 00:51:55 +01:00
11 changed files with 335 additions and 21 deletions

View File

@@ -0,0 +1,69 @@
# Waveshare UART fingerprint sensor (C)
A C# library for the [**Waveshare UART fingerprint sensor (C)**][Sensor], running on
.Net Framework 4.7 (**Mono**) on a **Raspberry Pi**
This library is tested using a Raspberry Pi Zero (hence the use of Mono)
but should work on any Raspberry.
It should also be easily portable to any device that supports Mono
or an equivalent (*.Net Core*).
## Usage
- First install it from [**nuget**](https://www.nuget.org/packages/WaveshareUARTFingerprintSensor/)
Then you only need to start the sensor
```csharp
// PrimarySerialPort refers to /dev/ttyAMA0
// SecondarySerialPort refers to /dev/ttyS0
// You need to choose it according to your Raspberry
// Check the table below
var sensor = new FingerprintSensor(FingerprintSensor.PrimarySerialPort);
sensor.Start();
// Do any command
// Example: get the user count
if (sensor.TryGetUserCount(out ushort count))
{
Console.WriteLine($"User count: {count}");
}
```
Here is a table of which serial port to use on which Raspberry Pi,
it may be different for you
| Model | Port |
| --------- | ---------------------- |
| Pi Zero | Primary (/dev/ttyAMA0) |
| Pi Zero W | Secondary (/dev/ttyS0) |
| Pi 1 | Primary (/dev/ttyAMA0) |
| Pi 2 | Primary (/dev/ttyAMA0) |
| Pi 3 | Secondary (/dev/ttyS0) |
| Pi Zero 4 | Secondary (/dev/ttyS0) |
> The Secondary UART is **disabled by default**, you an activate it in `raspi-config`
> [**Source**](https://www.raspberrypi.org/documentation/configuration/uart.md)
## Sample App
You can find a [**sample app**](WaveshareUARTFingerprintSensor.Sample) which shows basic usages of
this library and may help you to understand how to use it
## Contributing
If you have a feature idea or want to report a bug, don't hesitate to create a new
[**Issue**](https://github.com/Eveldee/WaveshareUARTFingerprintSensor/issues) or do a
[**Pull Request**](https://github.com/Eveldee/WaveshareUARTFingerprintSensor/pulls)
## Copyright and license
*[**WaveshareUARTFingerprintSensor**](README.md)* library is licensed under the [MIT License](LICENSE).
*[**Unosquare.Raspberry.IO**](https://github.com/migueldeicaza/gui.cs/)* library is under the [MIT License](https://github.com/unosquare/raspberryio/blob/master/LICENSE).
<!-- Links -->
[Sensor]: https://www.waveshare.com/wiki/UART_Fingerprint_Sensor_(C)

BIN
Sample.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@@ -26,7 +26,7 @@ namespace WaveshareUARTFingerprintSensor.Sample
ColorScheme = Colors.TopLevel;
// Creates the top-level window to show
var win = new Window("TUIManager")
var win = new Window(_title)
{
X = 0,
Y = 0,

View File

@@ -14,14 +14,8 @@ namespace WaveshareUARTFingerprintSensor.Sample
{
class Program
{
public static FingerprintSensor FingerprintSensor { get; private set; }
static void Main(string[] args)
{
FingerprintSensor = new FingerprintSensor(FingerprintSensor.SecondarySerialPort);
FingerprintSensor.Start();
Application.Run<TUIManager>();
}
}

View File

@@ -0,0 +1,22 @@
# Sample App
A sample app for the [Waveshare UART fingerprint sensor (C) library](../README.md)
![Sample](../Sample.png)
## Build
You can compile it using any **C# IDE** that supports **.Net Framework** or by running
`dotnet build` in a **terminal** using [**.Net CLI**](https://docs.microsoft.com/en-us/dotnet/core/tools/)
## Usage
- Install [**Mono**](https://www.mono-project.com/) on your Raspberry Pi
- [**Download**](https://github.com/Eveldee/WaveshareUARTFingerprintSensor/releases) or [**Build**](#build) the application
- Run it with `mono WaveshareUARTFingerprintSensor.Sample.exe`
## Copyright and license
[**WaveshareUARTFingerprintSensor**](../README.md) library is licensed under the [MIT License](../LICENSE).
[**gui.cs**](https://github.com/migueldeicaza/gui.cs/) library is under the [MIT License](https://github.com/migueldeicaza/gui.cs/blob/master/LICENSE).

View 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);
}
}
}

View 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();
}
}
}

View File

@@ -12,8 +12,10 @@ namespace WaveshareUARTFingerprintSensor.Sample
public class TUIManager : Toplevel
{
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 _userCountLabel;
@@ -21,8 +23,6 @@ namespace WaveshareUARTFingerprintSensor.Sample
public TUIManager()
{
_fingerprintSensor = Program.FingerprintSensor;
Init();
}
@@ -48,7 +48,7 @@ namespace WaveshareUARTFingerprintSensor.Sample
// Creates a menubar, the item "New" has a help menu.
var menu = new MenuBar(new MenuBarItem[] {
new MenuBarItem ("_Options", new MenuItem [] {
new MenuItem ("Reset Config", "", () => { ResetConfig(); }),
new MenuItem ("_Change Config", "", () => { ChangeConfig(); }),
new MenuItem ("_Quit", "", () => { Application.RequestStop(); })
})
});
@@ -56,12 +56,18 @@ namespace WaveshareUARTFingerprintSensor.Sample
Add(menu);
// Window Content
_comparisonLevelLabel = new Label("Comparison Level: 0")
_serialPortLabel = new Label("Serial Port:")
{
X = 2,
Y = 1,
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")
{
X = Pos.Left(_comparisonLevelLabel),
@@ -140,6 +146,7 @@ namespace WaveshareUARTFingerprintSensor.Sample
quitButton.Clicked += Quit_Clicked;
win.Add(
_serialPortLabel,
_comparisonLevelLabel,
_userCountLabel,
userCountButton,
@@ -154,10 +161,30 @@ namespace WaveshareUARTFingerprintSensor.Sample
quitButton
);
// Init Sensor
if (!File.Exists(SettingsFilePath))
{
Application.Run(new SettingsDisplay());
}
InitSensor();
// Update gui
UpdateSerialPort();
UpdateUserCount();
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()
@@ -264,7 +291,9 @@ namespace WaveshareUARTFingerprintSensor.Sample
private void SleepButton_Clicked()
{
//TODO
var window = new SleepDisplay(_fingerprintSensor);
Application.Run(window);
}
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()

View File

@@ -104,6 +104,8 @@
<Compile Include="FingerprintDialog.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SettingsDisplay.cs" />
<Compile Include="SleepDisplay.cs" />
<Compile Include="TUIManager.cs" />
</ItemGroup>
<ItemGroup>

View File

@@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("WaveshareUARTFingerprintSensor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Waveshare UART Fingerprint Sensor (C)")]
[assembly: AssemblyDescription("C# library for the Waveshare UART fingerprint sensor (C)")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Ilyx")]
[assembly: AssemblyProduct("WaveshareUARTFingerprintSensor")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>Waveshare UART Fingerprint Sensor</title>
<authors>Eveldee</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
<projectUrl>https://github.com/Eveldee/WaveshareUARTFingerprintSensor</projectUrl>
<!-- <iconUrl>http://icon_url_here_or_delete_this_line/</iconUrl> -->
<description>C# library for the Waveshare UART fingerprint sensor (C)</description>
<releaseNotes>Initial version.</releaseNotes>
<copyright>$copyright$</copyright>
<tags>Fingerprint Sensor Waveshare UART</tags>
</metadata>
</package>