hzgrow_r502/lib.rs
1//! **hzgrow-r502** is an embedded-hal driver for the HZ Grow R502 (and likely similar) fingerprint
2//! module.
3//!
4//! This is a work in progress and does not strive to meet all use cases of the device. However,
5//! it should cover the basics, and may possibly become a basis for other drivers for HZ Grow and
6//! similar modules, provided that the suppliers of those use a rougly similar API.
7//!
8//! ## Basics
9//!
10//! See the commands implemented by the driver in [`Command`](enum.Command.html).
11//!
12//! Response types are all linked from [`Reply`](enum.Reply.html).
13//!
14//! ## Example
15//!
16//! To authenticate with the R502:
17//! ```
18//! # use embedded_hal::serial::{Read, Write};
19//! use hzgrow_r502::{R502, Command, Reply};
20//! # struct TestTx;
21//! # struct TestRx(usize);
22//! #
23//! # impl Write<u8> for TestTx {
24//! # type Error = ();
25//! # fn write(&mut self, _word: u8) -> nb::Result<(), Self::Error> {
26//! # return Ok(());
27//! # }
28//! # fn flush(&mut self) -> nb::Result<(), Self::Error> {
29//! # return Ok(());
30//! # }
31//! # }
32//! #
33//! # const res_data: &[u8] = &[ 0xef, 0x01, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x03, 0x00, 0x00, 0x0a ];
34//! #
35//! # impl Read<u8> for TestRx {
36//! # type Error = ();
37//! # fn read(&mut self) -> nb::Result<u8, Self::Error> {
38//! # let word = res_data[self.0];
39//! # self.0 += 1;
40//! # return Ok(word);
41//! # }
42//! # }
43//! # let mut rx = TestRx(0);
44//! # let mut tx = TestTx;
45//!
46//! // Obtain tx, rx from some serial port implementation
47//! let mut r502 = R502::new(tx, rx, 0xffffffff);
48//! match r502.send_command(Command::VfyPwd { password: 0x00000000 }) {
49//! Ok(Reply::VfyPwd(result)) => println!("Status: {:#?}", result.confirmation_code),
50//! Err(error) => panic!("Error: {:#?}", error),
51//! _ => {},
52//! }
53//! ```
54//!
55//! For more examples, see [the `examples` directory](https://github.com/FLamparski/hzgrow-r502/tree/master/examples).
56#![warn(missing_debug_implementations, rust_2018_idioms)]
57#![no_std]
58
59mod commands;
60mod driver;
61mod responses;
62mod utils;
63
64pub use crate::commands::Command;
65pub use crate::driver::R502;
66pub use crate::responses::{
67 GenImgResult, GenImgStatus, Img2TzResult, Img2TzStatus, LoadCharResult, LoadCharStatus,
68 MatchResult, MatchStatus, PasswordVerificationState, ReadSysParaResult, RegModelResult,
69 RegModelStatus, Reply, SearchResult, SearchStatus, SystemParameters, TemplateNumResult,
70 TemplateNumStatus, VfyPwdResult, StoreResult, StoreStatus, DeletCharResult, DeletCharStatus,
71};
72pub use crate::utils::Error;