smartpi 1.1.5__py3-none-any.whl → 1.1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smartpi/__init__.py +1 -1
- smartpi/onnx_text_workflow.pyc +0 -0
- smartpi/posenet_utils.pyc +0 -0
- smartpi/rknn_text_workflow.pyc +0 -0
- {smartpi-1.1.5.dist-info → smartpi-1.1.6.dist-info}/METADATA +2 -3
- {smartpi-1.1.5.dist-info → smartpi-1.1.6.dist-info}/RECORD +8 -68
- smartpi/__init__.pyc +0 -0
- smartpi/_gui.py +0 -66
- smartpi/ai_asr.py +0 -1037
- smartpi/ai_llm.py +0 -934
- smartpi/ai_tts.py +0 -938
- smartpi/ai_vad.py +0 -83
- smartpi/audio.py +0 -125
- smartpi/base_driver.py +0 -618
- smartpi/camera.py +0 -84
- smartpi/color_sensor.py +0 -18
- smartpi/cw2015.py +0 -179
- smartpi/flash.py +0 -130
- smartpi/humidity.py +0 -20
- smartpi/led.py +0 -19
- smartpi/light_sensor.py +0 -72
- smartpi/local_model.py +0 -432
- smartpi/mcp_client.py +0 -100
- smartpi/mcp_fastmcp.py +0 -322
- smartpi/mcp_intent_recognizer.py +0 -408
- smartpi/models/__init__.pyc +0 -0
- smartpi/models/snakers4_silero-vad/__init__.pyc +0 -0
- smartpi/models/snakers4_silero-vad/hubconf.pyc +0 -0
- smartpi/motor.py +0 -177
- smartpi/move.py +0 -218
- smartpi/onnx_hand_workflow.py +0 -201
- smartpi/onnx_image_workflow.py +0 -176
- smartpi/onnx_pose_workflow.py +0 -482
- smartpi/onnx_text_workflow.py +0 -173
- smartpi/onnx_voice_workflow.py +0 -437
- smartpi/posemodel/__init__.pyc +0 -0
- smartpi/posenet_utils.py +0 -222
- smartpi/rknn_hand_workflow.py +0 -245
- smartpi/rknn_image_workflow.py +0 -405
- smartpi/rknn_pose_workflow.py +0 -592
- smartpi/rknn_text_workflow.py +0 -240
- smartpi/rknn_voice_workflow.py +0 -394
- smartpi/servo.py +0 -178
- smartpi/temperature.py +0 -18
- smartpi/tencentcloud-speech-sdk-python/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/flash_recognizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/speech_recognizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/credential.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/log.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/common/utils.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/soe/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/soe/speaking_assessment.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/flowing_speech_synthesizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer_ws.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/vc/__init__.pyc +0 -0
- smartpi/tencentcloud-speech-sdk-python/vc/speech_convertor_ws.pyc +0 -0
- smartpi/text_gte_model/__init__.pyc +0 -0
- smartpi/text_gte_model/config/__init__.pyc +0 -0
- smartpi/text_gte_model/gte/__init__.pyc +0 -0
- smartpi/touch_sensor.py +0 -16
- smartpi/trace.py +0 -120
- smartpi/ultrasonic.py +0 -20
- {smartpi-1.1.5.dist-info → smartpi-1.1.6.dist-info}/WHEEL +0 -0
- {smartpi-1.1.5.dist-info → smartpi-1.1.6.dist-info}/top_level.txt +0 -0
smartpi/servo.py
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
import time
|
|
3
|
-
from typing import List, Optional
|
|
4
|
-
from smartpi import base_driver
|
|
5
|
-
|
|
6
|
-
#小舵机控制 port:连接P端口;angle:角度0~270;
|
|
7
|
-
def steer_angle(port:bytes,angle:bytes) -> Optional[bytes]:
|
|
8
|
-
servo_str=[0xA0, 0x0E, 0x01, 0x71, 0x00, 0xBE]
|
|
9
|
-
servo_str[0]=0XA0+port
|
|
10
|
-
servo_str[4]=angle
|
|
11
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
12
|
-
time.sleep(0.005)
|
|
13
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
14
|
-
# if response == None:
|
|
15
|
-
# return None
|
|
16
|
-
# else:
|
|
17
|
-
return 0
|
|
18
|
-
|
|
19
|
-
#小舵机延时控制 port:连接P端口;angle:角度0~270;second:1~256
|
|
20
|
-
def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
|
|
21
|
-
servo_str=[0xA0, 0x10, 0x01, 0x81, 0x00, 0x00, 0x81, 0x00, 0xBE]
|
|
22
|
-
servo_str[0]=0XA0+port
|
|
23
|
-
servo_str[4]=angle//256
|
|
24
|
-
servo_str[5]=angle%256
|
|
25
|
-
servo_str[7]=second
|
|
26
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
27
|
-
time.sleep(0.005)
|
|
28
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
29
|
-
# if response == None:
|
|
30
|
-
# return None
|
|
31
|
-
# else:
|
|
32
|
-
return 0
|
|
33
|
-
|
|
34
|
-
#数字舵机设置转动方向(绝对角度) port:连接P端口;dir:0:不跨越0°;1:最短距离旋转;2:顺时针旋转;3:逆时针旋转
|
|
35
|
-
def set_dir(port:bytes,dir:bytes) -> Optional[bytes]:
|
|
36
|
-
servo_str=[0xA0, 0x24, 0x01, 0x71, 0x00, 0xBE]
|
|
37
|
-
servo_str[0]=0XA0+port
|
|
38
|
-
servo_str[4]=dir
|
|
39
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
40
|
-
time.sleep(0.005)
|
|
41
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
42
|
-
# if response == None:
|
|
43
|
-
# return None
|
|
44
|
-
# else:
|
|
45
|
-
return 0
|
|
46
|
-
|
|
47
|
-
#BE-9528数字舵机以速度转至角度 port:连接P端口;angle:角度(0~360);speed:速度(0~100);
|
|
48
|
-
def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
|
|
49
|
-
servo_str=[0xA0, 0x0D, 0x01, 0x81, 0x00, 0x00, 0x81, 0x00, 0xBE]
|
|
50
|
-
servo_str[0]=0XA0+port
|
|
51
|
-
servo_str[4]=angle//256
|
|
52
|
-
servo_str[5]=angle%256
|
|
53
|
-
servo_str[7]=speed
|
|
54
|
-
#response = base_driver.single_operate_sensor(servo_str,0)
|
|
55
|
-
time.sleep(0.005)
|
|
56
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
57
|
-
# if response == None:
|
|
58
|
-
# return None
|
|
59
|
-
# else:
|
|
60
|
-
return 0
|
|
61
|
-
|
|
62
|
-
#数字舵机转动到角度延时时间 port:连接P端口;angle:角度(0~360);ms:延时时间(0~65535);
|
|
63
|
-
def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
|
|
64
|
-
servo_str=[0xA0, 0x11, 0x01, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0xBE]
|
|
65
|
-
servo_str[0]=0XA0+port
|
|
66
|
-
servo_str[4]=angle//256
|
|
67
|
-
servo_str[5]=angle%256
|
|
68
|
-
servo_str[7]=ms//256
|
|
69
|
-
servo_str[8]=ms%256
|
|
70
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
71
|
-
time.sleep(0.005)
|
|
72
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
73
|
-
# if response == None:
|
|
74
|
-
# return None
|
|
75
|
-
# else:
|
|
76
|
-
return 0
|
|
77
|
-
|
|
78
|
-
#数字舵机复位 port:连接P端口;
|
|
79
|
-
def set_init(port:bytes) -> Optional[bytes]:
|
|
80
|
-
servo_str=[0xA0, 0x12, 0x01, 0xBE]
|
|
81
|
-
servo_str[0]=0XA0+port
|
|
82
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
83
|
-
time.sleep(0.005)
|
|
84
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
85
|
-
# if response == None:
|
|
86
|
-
# return None
|
|
87
|
-
# else:
|
|
88
|
-
return 0
|
|
89
|
-
|
|
90
|
-
#获取数字舵机角度 port:连接P端口;
|
|
91
|
-
def get_angle(port:bytes) -> Optional[bytes]:
|
|
92
|
-
servo_str=[0xA0, 0x13, 0x01, 0xBE]
|
|
93
|
-
servo_str[0]=0XA0+port
|
|
94
|
-
time.sleep(0.005)
|
|
95
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
96
|
-
if response == None:
|
|
97
|
-
return None
|
|
98
|
-
else:
|
|
99
|
-
angle_data=response[4:-1]
|
|
100
|
-
angle_num=int.from_bytes(angle_data, byteorder='big', signed=True)
|
|
101
|
-
return angle_num
|
|
102
|
-
|
|
103
|
-
#数字舵机速度转动 port:连接P端口;
|
|
104
|
-
def set_speed(port:bytes,speed:int) -> Optional[bytes]:
|
|
105
|
-
servo_str=[0xA0, 0x14, 0x01, 0x71, 0x00, 0xBE]
|
|
106
|
-
servo_str[0]=0XA0+port
|
|
107
|
-
if speed>100:
|
|
108
|
-
m_par=100
|
|
109
|
-
elif speed>=0 and speed<=100:
|
|
110
|
-
m_par=speed
|
|
111
|
-
elif speed<-100:
|
|
112
|
-
m_par=156
|
|
113
|
-
elif speed<=0 and speed>=-100:
|
|
114
|
-
m_par=256+speed
|
|
115
|
-
|
|
116
|
-
servo_str[4]=m_par
|
|
117
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
118
|
-
time.sleep(0.005)
|
|
119
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
120
|
-
# if response == None:
|
|
121
|
-
# return None
|
|
122
|
-
# else:
|
|
123
|
-
return 0
|
|
124
|
-
|
|
125
|
-
#数字舵机编码转动 port:连接P端口;code:编码(0~65535);speed:速度(-100~100);
|
|
126
|
-
def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
|
|
127
|
-
servo_str=[0xA0, 0x15, 0x01, 0x81, 0x00, 0x00, 0x71, 0x00, 0xBE]
|
|
128
|
-
servo_str[0]=0XA0+port
|
|
129
|
-
|
|
130
|
-
servo_str[4]=code//256
|
|
131
|
-
servo_str[5]=code%256
|
|
132
|
-
|
|
133
|
-
if speed>100:
|
|
134
|
-
m_par=100
|
|
135
|
-
elif speed>=0 and speed<=100:
|
|
136
|
-
m_par=speed
|
|
137
|
-
elif speed<-100:
|
|
138
|
-
m_par=156
|
|
139
|
-
elif speed<=0 and speed>=-100:
|
|
140
|
-
m_par=256+speed
|
|
141
|
-
servo_str[7]=m_par
|
|
142
|
-
|
|
143
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
144
|
-
time.sleep(0.005)
|
|
145
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
146
|
-
# if response == None:
|
|
147
|
-
# return None
|
|
148
|
-
# else:
|
|
149
|
-
return 0
|
|
150
|
-
|
|
151
|
-
#数字舵机编码值清零 port:连接P端口;
|
|
152
|
-
def reset_encode(port:bytes) -> Optional[bytes]:
|
|
153
|
-
servo_str=[0xA0, 0x16, 0x01, 0xBE]
|
|
154
|
-
servo_str[0]=0XA0+port
|
|
155
|
-
# response = base_driver.single_operate_sensor(servo_str,0)
|
|
156
|
-
time.sleep(0.005)
|
|
157
|
-
base_driver.write_data(0X01, 0X02, servo_str)
|
|
158
|
-
# if response == None:
|
|
159
|
-
# return None
|
|
160
|
-
# else:
|
|
161
|
-
return 0
|
|
162
|
-
|
|
163
|
-
#获取数字舵机编码值 port:连接P端口;
|
|
164
|
-
def get_encoder(port:bytes) -> Optional[bytes]:
|
|
165
|
-
servo_str=[0xA0, 0x17, 0x01, 0xBE]
|
|
166
|
-
servo_str[0]=0XA0+port
|
|
167
|
-
time.sleep(0.005)
|
|
168
|
-
response = base_driver.single_operate_sensor(servo_str,0)
|
|
169
|
-
if response == None:
|
|
170
|
-
return None
|
|
171
|
-
else:
|
|
172
|
-
code_data=response[4:-1]
|
|
173
|
-
code_num=int.from_bytes(code_data, byteorder='big', signed=True)
|
|
174
|
-
return code_num
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
smartpi/temperature.py
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
import time
|
|
3
|
-
from typing import List, Optional
|
|
4
|
-
from smartpi import base_driver
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
#温度读取 port:连接P端口;正常返回:温度数据; 读取错误:-1
|
|
8
|
-
def get_value(port:bytes) -> Optional[bytes]:
|
|
9
|
-
temp_str=[0XA0, 0X0C, 0X01, 0X71, 0X00, 0XBE]
|
|
10
|
-
temp_str[0]=0XA0+port
|
|
11
|
-
temp_str[4]=0
|
|
12
|
-
time.sleep(0.005)
|
|
13
|
-
response = base_driver.single_operate_sensor(temp_str,0)
|
|
14
|
-
if response == None:
|
|
15
|
-
return None
|
|
16
|
-
else:
|
|
17
|
-
return response[4]
|
|
18
|
-
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
smartpi/touch_sensor.py
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
import time
|
|
3
|
-
from typing import List, Optional
|
|
4
|
-
from smartpi import base_driver
|
|
5
|
-
|
|
6
|
-
#触碰传感器 port:连接P端口 正常返回:1、0; 读取错误:-1
|
|
7
|
-
def get_value(port:bytes) -> Optional[bytes]:
|
|
8
|
-
read_sw_str=[0xA0, 0x03, 0x01, 0xBE]
|
|
9
|
-
read_sw_str[0]=0XA0+port
|
|
10
|
-
time.sleep(0.005)
|
|
11
|
-
response = base_driver.single_operate_sensor(read_sw_str,0)
|
|
12
|
-
if response == None:
|
|
13
|
-
return None
|
|
14
|
-
else:
|
|
15
|
-
return response[4]
|
|
16
|
-
|
smartpi/trace.py
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
import time,fcntl,serial,threading
|
|
3
|
-
from typing import List, Optional
|
|
4
|
-
from smartpi import base_driver
|
|
5
|
-
|
|
6
|
-
# 串口配置参数
|
|
7
|
-
SERIAL_PORT = "/dev/ttyS3" # 串口设备路径
|
|
8
|
-
BAUD_RATE = 921600 # 波特率
|
|
9
|
-
TIMEOUT = 0.1 # 读取超时时间(秒)
|
|
10
|
-
|
|
11
|
-
ser = serial.Serial(
|
|
12
|
-
port=SERIAL_PORT,
|
|
13
|
-
baudrate=BAUD_RATE,
|
|
14
|
-
bytesize=serial.EIGHTBITS, # 8位数据位
|
|
15
|
-
parity=serial.PARITY_NONE, # 无校验位
|
|
16
|
-
stopbits=serial.STOPBITS_ONE, # 1位停止位
|
|
17
|
-
timeout=TIMEOUT,
|
|
18
|
-
xonxoff=False, # 关闭软件流控
|
|
19
|
-
rtscts=False, # 关闭硬件流控
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
# 创建全局线程锁
|
|
23
|
-
serial_lock = threading.RLock()
|
|
24
|
-
|
|
25
|
-
#循迹卡单通道阈值比较后的布尔值读取 port:连接P端口;chn:检测通道1~7;正常返回:通道布尔值; 读取错误:None
|
|
26
|
-
def get_chn_data(port:bytes, chn:bytes) -> Optional[bytes]:
|
|
27
|
-
trace_str=[0xA0, 0x18, 0x01, 0x71, 0x00, 0xBE]
|
|
28
|
-
trace_str[0]=0XA0+port
|
|
29
|
-
trace_str[4]=chn
|
|
30
|
-
time.sleep(0.005)
|
|
31
|
-
response = base_driver.single_operate_sensor(trace_str,0)
|
|
32
|
-
if response == None:
|
|
33
|
-
return None
|
|
34
|
-
else:
|
|
35
|
-
return response[4]
|
|
36
|
-
|
|
37
|
-
#循迹卡设置各通道颜色 port:连接P端口;color1~color7:7个通道彩灯的颜色1~7(红、绿、蓝、黄、紫、青、白)
|
|
38
|
-
def set_chn_color(port:bytes, color1:bytes, color2:bytes, color3:bytes, color4:bytes, color5:bytes, color6:bytes, color7:bytes) -> Optional[bytes]:
|
|
39
|
-
trace_str=[0xA0, 0x19, 0x01, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
40
|
-
trace_str[0]=0XA0+port
|
|
41
|
-
trace_str[4]=color1
|
|
42
|
-
trace_str[6]=color2
|
|
43
|
-
trace_str[8]=color3
|
|
44
|
-
trace_str[10]=color4
|
|
45
|
-
trace_str[12]=color5
|
|
46
|
-
trace_str[14]=color6
|
|
47
|
-
trace_str[16]=color7
|
|
48
|
-
time.sleep(0.005)
|
|
49
|
-
base_driver.write_data(0X01, 0X02, trace_str)
|
|
50
|
-
# response = base_driver.single_operate_sensor(trace_str,0)
|
|
51
|
-
# if response == None:
|
|
52
|
-
# return None
|
|
53
|
-
# else:
|
|
54
|
-
return 0
|
|
55
|
-
|
|
56
|
-
#循迹卡设置全部颜色 port:连接P端口;color:全部彩灯的颜色1~7(红、绿、蓝、黄、紫、青、白)
|
|
57
|
-
def set_color(port:bytes, color:bytes) -> Optional[bytes]:
|
|
58
|
-
trace_str=[0xA0, 0x20, 0x01, 0x71, 0x00, 0xBE]
|
|
59
|
-
trace_str[0]=0XA0+port
|
|
60
|
-
trace_str[4]=color
|
|
61
|
-
time.sleep(0.005)
|
|
62
|
-
base_driver.write_data(0X01, 0X02, trace_str)
|
|
63
|
-
# response = base_driver.single_operate_sensor(trace_str,0)
|
|
64
|
-
# if response == None:
|
|
65
|
-
# return None
|
|
66
|
-
# else:
|
|
67
|
-
return 0
|
|
68
|
-
|
|
69
|
-
#循迹卡单通道光值读取 port:连接P端口;chn:检测通道;正常返回:通道光值数据; 读取错误:None
|
|
70
|
-
def get_analog(port:bytes, chn:bytes) -> Optional[bytes]:
|
|
71
|
-
trace_str=[0xA0, 0x21, 0x01, 0x71, 0x00, 0xBE]
|
|
72
|
-
trace_str[0]=0XA0+port
|
|
73
|
-
trace_str[4]=20+chn
|
|
74
|
-
time.sleep(0.005)
|
|
75
|
-
response = base_driver.single_operate_sensor(trace_str,0)
|
|
76
|
-
if response == None:
|
|
77
|
-
return None
|
|
78
|
-
else:
|
|
79
|
-
return response[4]
|
|
80
|
-
|
|
81
|
-
#循迹卡判断是否组合图形 port:连接P端口;state:判断图形组合 1:TT 2:TL 3:TR 4:TM 5:L2 6:L1 7:L 8:M 9:R 10:R1 11:R2
|
|
82
|
-
#正常返回:True/False; 读取错误:None
|
|
83
|
-
def get_line_state(port:bytes, state:bytes) -> Optional[bytes]:
|
|
84
|
-
trace_str=[0xA0, 0x22, 0x01, 0x71, 0x00, 0xBE]
|
|
85
|
-
trace_str[0]=0XA0+port
|
|
86
|
-
trace_str[4]=state
|
|
87
|
-
time.sleep(0.005)
|
|
88
|
-
response = base_driver.single_operate_sensor(trace_str,0)
|
|
89
|
-
if response == None:
|
|
90
|
-
return None
|
|
91
|
-
else:
|
|
92
|
-
return response[4]
|
|
93
|
-
|
|
94
|
-
#循迹卡自动设置灰度阈值 port:连接P端口;second:秒数
|
|
95
|
-
def set_threshold(port:bytes, second:int) -> Optional[bytes]:
|
|
96
|
-
trace_str=[0xA0, 0x23, 0x01, 0x81, 0x00, 0x00, 0xBE]
|
|
97
|
-
trace_str[0]=0XA0+port
|
|
98
|
-
trace_str[4]=second//256
|
|
99
|
-
trace_str[5]=second%256
|
|
100
|
-
time.sleep(0.005)
|
|
101
|
-
serial_lock.acquire() #获取线程锁
|
|
102
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
103
|
-
base_driver.write_data(0X01, 0X02, trace_str, False)
|
|
104
|
-
start_time = time.time()
|
|
105
|
-
|
|
106
|
-
while True:
|
|
107
|
-
response =base_driver.process_received_data()
|
|
108
|
-
if response:
|
|
109
|
-
serial_lock.release() #释放线程锁
|
|
110
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
111
|
-
display_data = response[6:-3]
|
|
112
|
-
return display_data
|
|
113
|
-
else:
|
|
114
|
-
if time.time() - start_time > second+2:
|
|
115
|
-
print("读取超时")
|
|
116
|
-
base_driver.buf_clear()
|
|
117
|
-
serial_lock.release() #释放线程锁
|
|
118
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
119
|
-
return None
|
|
120
|
-
|
smartpi/ultrasonic.py
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# coding=utf-8
|
|
2
|
-
import time
|
|
3
|
-
from typing import List, Optional
|
|
4
|
-
from smartpi import base_driver
|
|
5
|
-
|
|
6
|
-
#超声波测距传感器 port:连接P端口 正常返回:测距数据; 读取错误:-1
|
|
7
|
-
def get_value(port:bytes) -> Optional[bytes]:
|
|
8
|
-
ultrasonic_str=[0xA0, 0x06, 0x00, 0xBE]
|
|
9
|
-
ultrasonic_str[0]=0XA0+port
|
|
10
|
-
ultrasonic_str[2]=1
|
|
11
|
-
time.sleep(0.005)
|
|
12
|
-
response = base_driver.single_operate_sensor(ultrasonic_str,0)
|
|
13
|
-
|
|
14
|
-
if response == None:
|
|
15
|
-
return None
|
|
16
|
-
else:
|
|
17
|
-
distance_data=response[4:-1]
|
|
18
|
-
distance_num=int.from_bytes(distance_data, byteorder='big', signed=True)
|
|
19
|
-
return distance_num
|
|
20
|
-
|
|
File without changes
|
|
File without changes
|