Finger Unit
The following products are supported:
Micropython Example:
1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from unit import FingerUnit 9import time 10 11 12rect0 = None 13rect1 = None 14rect2 = None 15label0 = None 16label1 = None 17label2 = None 18label3 = None 19title0 = None 20finger_0 = None 21 22 23ret = None 24cur_time = None 25t_x = None 26last_touch_time = None 27t_y = None 28 29 30# Describe this function... 31def add_handler(): 32 global \ 33 ret, \ 34 cur_time, \ 35 t_x, \ 36 last_touch_time, \ 37 t_y, \ 38 rect0, \ 39 rect1, \ 40 rect2, \ 41 label0, \ 42 label1, \ 43 label2, \ 44 label3, \ 45 title0, \ 46 finger_0 47 label2.setColor(0xFFFFFF, 0x222222) 48 label2.setText(str("add...")) 49 if (finger_0.add_user(1, 1)) == 1: 50 label2.setColor(0xFFFFFF, 0x62B900) 51 label2.setText(str("added")) 52 else: 53 label2.setColor(0xFFFFFF, 0xF45554) 54 label2.setText(str("add failed")) 55 56 57# Describe this function... 58def match_handler(): 59 global \ 60 ret, \ 61 cur_time, \ 62 t_x, \ 63 last_touch_time, \ 64 t_y, \ 65 rect0, \ 66 rect1, \ 67 rect2, \ 68 label0, \ 69 label1, \ 70 label2, \ 71 label3, \ 72 title0, \ 73 finger_0 74 label2.setColor(0xFFFFFF, 0x222222) 75 label2.setText(str("macth...")) 76 ret = finger_0.compare_finger() 77 if ret == 1: 78 label2.setColor(0xFFFFFF, 0x62B900) 79 label2.setText(str("macth")) 80 else: 81 label2.setColor(0xFFFFFF, 0xF45554) 82 label2.setText(str("no macth")) 83 84 85def setup(): 86 global \ 87 rect0, \ 88 rect1, \ 89 rect2, \ 90 label0, \ 91 label1, \ 92 label2, \ 93 label3, \ 94 title0, \ 95 finger_0, \ 96 ret, \ 97 cur_time, \ 98 t_x, \ 99 last_touch_time, \ 100 t_y 101 102 M5.begin() 103 Widgets.fillScreen(0x222222) 104 rect0 = Widgets.Rectangle(8, 206, 95, 30, 0xFFFFFF, 0xFFFFFF) 105 rect1 = Widgets.Rectangle(112, 206, 95, 30, 0xFFFFFF, 0xFFFFFF) 106 rect2 = Widgets.Rectangle(216, 206, 95, 30, 0xFFFFFF, 0xFFFFFF) 107 label0 = Widgets.Label("Add", 37, 213, 1.0, 0x000000, 0xFFFFFF, Widgets.FONTS.DejaVu18) 108 label1 = Widgets.Label("Match", 132, 212, 1.0, 0x000000, 0xFCFCFC, Widgets.FONTS.DejaVu18) 109 label2 = Widgets.Label("label2", 132, 109, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 110 label3 = Widgets.Label("label3", 8, 27, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu18) 111 title0 = Widgets.Title("Finger Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18) 112 113 finger_0 = FingerUnit(port=(18, 17)) 114 finger_0.delete_all_user() 115 finger_0.set_add_mode(0) 116 label3.setText(str((str("User Num: ") + str((finger_0.get_user_count()))))) 117 last_touch_time = time.ticks_ms() 118 119 120def loop(): 121 global \ 122 rect0, \ 123 rect1, \ 124 rect2, \ 125 label0, \ 126 label1, \ 127 label2, \ 128 label3, \ 129 title0, \ 130 finger_0, \ 131 ret, \ 132 cur_time, \ 133 t_x, \ 134 last_touch_time, \ 135 t_y 136 M5.update() 137 if M5.Touch.getCount(): 138 cur_time = time.ticks_ms() 139 if cur_time - last_touch_time > 150: 140 t_x = M5.Touch.getX() 141 t_y = M5.Touch.getY() 142 if t_x >= 8 and t_x <= 8 + 95 and t_y >= 206 and t_y <= 206 + 30: 143 rect0.setColor(color=0x007BFF, fill_c=0x007BFF) 144 label0.setColor(0xFFFFFF, 0x007BFF) 145 add_handler() 146 else: 147 rect0.setColor(color=0xFFFFFF, fill_c=0xFFFFFF) 148 label0.setColor(0x000000, 0xFFFFFF) 149 if t_x >= 112 and t_x <= 112 + 95 and t_y >= 206 and t_y <= 206 + 30: 150 rect1.setColor(color=0x007BFF, fill_c=0x007BFF) 151 label1.setColor(0xFFFFFF, 0x007BFF) 152 match_handler() 153 else: 154 rect1.setColor(color=0xFFFFFF, fill_c=0xFFFFFF) 155 label1.setColor(0x000000, 0xFFFFFF) 156 last_touch_time = time.ticks_ms() 157 label3.setText(str((str("User Num: ") + str((finger_0.get_user_count()))))) 158 159 160if __name__ == "__main__": 161 try: 162 setup() 163 while True: 164 loop() 165 except (Exception, KeyboardInterrupt) as e: 166 try: 167 from utility import print_error_msg 168 169 print_error_msg(e) 170 except ImportError: 171 print("please update to latest firmware")
UIFLOW2 Example:
class FingerUnit
Constructors
Methods
- FingerUnit.sleep() bool
After calling this method successfully, FPC1020A will not be able to respond to any messages.
- 返回:
True if the command was successful, False otherwise.
UIFLOW2:
- FingerUnit.get_add_mode() int
In the no-repeat mode, only one user can be added with the same finger, and an error message will be returned if the second round of adding is forced.
- 返回:
mode (0: no-repeat mode, 1: repeat mode)
UIFLOW2:
- FingerUnit.set_add_mode(mode: int) int
In the no-repeat mode, only one user can be added with the same finger, and an error message will be returned if the second round of adding is forced.
- 参数:
mode – mode (0: no-repeat mode, 1: repeat mode)
- 返回:
mode (0: no-repeat mode, 1: repeat mode)
UIFLOW2:
- FingerUnit.add_user(id: int, permission: Literal[1, 2, 3]) int
add new user
After calling this method, you need to put your finger on the fingerprint module.
- 参数:
id – user id (0-149)
permission – user permission (1: normal, 2: admin, 3: super admin)
- 返回:
-1 if the command was unsuccessful, otherwise the user id.
UIFLOW2:
- FingerUnit.delete_user(id: int) int
Delete the user with the specified id.
- 参数:
id – user id (0-149)
- 返回:
-1 if the command was unsuccessful, otherwise the user id.
UIFLOW2:
- FingerUnit.delete_all_user() bool
Delete all users.
- 返回:
True if the command was successful, False otherwise.
UIFLOW2:
- FingerUnit.get_user_count() int
Get registered users count.
- 返回:
-1 if the command was unsuccessful, otherwise the number of registered users.
UIFLOW2:
- FingerUnit.get_user_capacity() int
Get the maximum number of users that can be registered.
- 返回:
-1 if the command was unsuccessful, otherwise the maximum number of users that can be registered.
UIFLOW2:
- FingerUnit.compare_id(id: int, timeout: int = 5000) bool
Check whether the currently collected fingerprint matches the specified user id.
- 参数:
id – user id (0-149)
- 返回:
-1 if the command was unsuccessful, otherwise the user id.
UIFLOW2:
- FingerUnit.compare_finger(timeout: int = 5000) int
Detect whether the currently collected fingerprint is a registered user.
- 返回:
-1 if the command was unsuccessful, otherwise the user id.
UIFLOW2:
- FingerUnit.get_user_list() list
Get the list of registered users.
- 返回:
list of registered users.
UIFLOW2:
- FingerUnit.get_user_info(id: int) Union[tuple, None]:
Get the information of the user with the specified id.
- 参数:
id – user id (0-149)
- 返回:
tuple of (id, permission) if the command was successful, None otherwise.
UIFLOW2:
- FingerUnit.get_user_permission(id: int) int
Get the permission of the user with the specified id.
- 参数:
id – user id (0-149)
- 返回:
-1 if the command was unsuccessful, otherwise the permission of the user.
UIFLOW2:
- FingerUnit.get_user_characteristics(id: int) bytes | None
Get the characteristics of the user with the specified id.
- 参数:
id – user id (0-149)
- 返回:
bytes of the characteristics if the command was successful, None otherwise.
UIFLOW2:
- FingerUnit.add_user_info(id, permissions, characteristic, timeout: int = 5000) bool
Register a new user with FPC1020A.
- 参数:
id – user id (0-149)
permissions – user permission (1: normal, 2: admin, 3: super admin)
characteristic – user characteristics
timeout – timeout in milliseconds
- 返回:
True if the command was successful, False otherwise.
UIFLOW2:
- FingerUnit.capture_characteristic(timeout: int = 5000) bytes
Capture the characteristics of the fingerprint.
- 参数:
timeout – timeout in milliseconds
- 返回:
bytes of the characteristics if the command was successful, None otherwise.
- FingerUnit.get_match_level() int
The comparison level ranges from 0 to 9, the larger the value, the stricter the comparison, and the default value is 5.
- 返回:
match level (0-9)
UIFLOW2: