forked from vjsyong/LD2410
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
68 lines (48 loc) · 2.1 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from LD2410 import *
# from .LD2450 import *
import logging
import time
def main():
radar = LD2450("/dev/ttyUSB0", PARAM_BAUD_256000, verbosity=logging.DEBUG) # Set desired level of verbosity [DEBUG, INFO, WARNING]
# Get Radar Firmware version
fw_ver = radar.read_firmware_version()
print(fw_ver)
# Set max detection gate for moving to 2, static to 3, and empty timeout to 1s
# radar.edit_detection_params(2, 3, 1)
# Set the gate 3 moving energy sentivity to 50 and static sensitivity to 40
# Note: Static sensitivity cannot be set for gate 1 and 2, it must be set to zero e.g (1, 50, 0)
# radar.edit_gate_sensitivity(3, 50, 40)
# Retrieve the set detection parameters
# Returns 3 arrays
# 1. Gate parameters. we set it earlier to (2, 3, 1)
# 2. Motion energy sensitivities for gates 0-8
# 3. Static energy sensitivities for gates 0-8
# detection_params = radar.read_detection_params()
# print(detection_params)
# Get data in standard mode
# Start the radar polling
radar.start() # The radar polls asynchronously at 10Hz
# Get 3 data frames 1s apart. If you use a delay less than 0.1, you will get repeat data
for _ in range(3):
print(radar.get_data()) # The right 2 arrays will be blank since we are polling in standard mode
time.sleep(1)
# Get data in engineering mode
# radar.enable_engineering_mode()
# Get 3 data frames 1s apart. If you use a delay less than 0.1, you will get repeat data
for _ in range(3):
print(radar.get_data()) # The right 2 arrays will be blank since we are polling in standard mode
time.sleep(1)
# radar.disable_engineering_mode()
radar.stop() # Stop polling the radar
# Restart the radar
radar.restart_module()
# Enable bluetooth (On by default, you don't have to call it)
radar.bt_enable()
# Get bluetooth MAC address
print(radar.bt_query_mac())
# Set module baud rate
# radar.set_baud_rate(PARAM_BAUD_460800)
# Factory reset the module
# radar.factory_reset()
if __name__ == "__main__":
main()