smartpi 0.1.18__py3-none-any.whl → 0.1.20__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/base_driver.py +27 -20
- smartpi/trace.py +90 -6
- {smartpi-0.1.18.dist-info → smartpi-0.1.20.dist-info}/METADATA +1 -1
- {smartpi-0.1.18.dist-info → smartpi-0.1.20.dist-info}/RECORD +7 -7
- {smartpi-0.1.18.dist-info → smartpi-0.1.20.dist-info}/WHEEL +0 -0
- {smartpi-0.1.18.dist-info → smartpi-0.1.20.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
smartpi/base_driver.py
CHANGED
|
@@ -201,8 +201,8 @@ def process_received_data():
|
|
|
201
201
|
##############################################################################读取设备信息
|
|
202
202
|
"""读取设备型号"""
|
|
203
203
|
def read_device_model() -> Optional[bytes]:
|
|
204
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
205
204
|
serial_lock.acquire() #获取线程锁
|
|
205
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
206
206
|
write_data(READ_MODEL_H, READ_MODEL_L)
|
|
207
207
|
start_time = time.time()
|
|
208
208
|
while True:
|
|
@@ -223,8 +223,8 @@ def read_device_model() -> Optional[bytes]:
|
|
|
223
223
|
|
|
224
224
|
"""读取版本号"""
|
|
225
225
|
def read_version() -> Optional[bytes]:
|
|
226
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
227
226
|
serial_lock.acquire() #获取线程锁
|
|
227
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
228
228
|
write_data(READ_VERSION_H, READ_VERSION_L)
|
|
229
229
|
start_time = time.time()
|
|
230
230
|
while True:
|
|
@@ -245,8 +245,8 @@ def read_version() -> Optional[bytes]:
|
|
|
245
245
|
|
|
246
246
|
"""读取工厂信息"""
|
|
247
247
|
def read_factory_data() -> Optional[bytes]:
|
|
248
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
249
248
|
serial_lock.acquire() #获取线程锁
|
|
249
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
250
250
|
write_data(READ_FACTORY_H, READ_FACTORY_L)
|
|
251
251
|
start_time = time.time()
|
|
252
252
|
while True:
|
|
@@ -267,8 +267,8 @@ def read_factory_data() -> Optional[bytes]:
|
|
|
267
267
|
|
|
268
268
|
"""读取硬件ID"""
|
|
269
269
|
def read_hardware_ID() -> Optional[bytes]:
|
|
270
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
271
270
|
serial_lock.acquire() #获取线程锁
|
|
271
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
272
272
|
write_data(READ_HW_ID_H, READ_HW_ID_L)
|
|
273
273
|
start_time = time.time()
|
|
274
274
|
while True:
|
|
@@ -289,8 +289,8 @@ def read_hardware_ID() -> Optional[bytes]:
|
|
|
289
289
|
|
|
290
290
|
"""读取设备名称"""
|
|
291
291
|
def read_device_name() -> Optional[bytes]:
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
serial_lock.acquire() #获取线程锁
|
|
293
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
294
294
|
write_data(READ_NAME_H, READ_NAME_L)
|
|
295
295
|
start_time = time.time()
|
|
296
296
|
while True:
|
|
@@ -311,8 +311,8 @@ def read_device_name() -> Optional[bytes]:
|
|
|
311
311
|
|
|
312
312
|
"""设置设备名称"""
|
|
313
313
|
def write_device_name(send_data: str) -> Optional[bytes]:
|
|
314
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
315
314
|
serial_lock.acquire() #获取线程锁
|
|
315
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
316
316
|
data_bytes = send_data.encode('utf-8')
|
|
317
317
|
write_data(WRITE_NAME_H, WRITE_NAME_L, data_bytes)
|
|
318
318
|
start_time = time.time()
|
|
@@ -334,8 +334,8 @@ def write_device_name(send_data: str) -> Optional[bytes]:
|
|
|
334
334
|
|
|
335
335
|
"""读取连接方式"""
|
|
336
336
|
def read_connected() -> Optional[bytes]:
|
|
337
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
338
337
|
serial_lock.acquire() #获取线程锁
|
|
338
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
339
339
|
write_data(READ_CONNECT_H, READ_CONNECT_L)
|
|
340
340
|
start_time = time.time()
|
|
341
341
|
while True:
|
|
@@ -464,8 +464,8 @@ def read_battery() -> Optional[bytes]:
|
|
|
464
464
|
|
|
465
465
|
"""读取外设连接情况"""
|
|
466
466
|
def read_peripheral() -> Optional[bytes]:
|
|
467
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
468
467
|
serial_lock.acquire() #获取线程锁
|
|
468
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
469
469
|
write_data(READ_PERIPH_H, READ_PERIPH_L)
|
|
470
470
|
start_time = time.time()
|
|
471
471
|
while True:
|
|
@@ -487,9 +487,9 @@ def read_peripheral() -> Optional[bytes]:
|
|
|
487
487
|
return None
|
|
488
488
|
|
|
489
489
|
"""单次操作外设"""
|
|
490
|
-
def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
491
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
490
|
+
def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
492
491
|
serial_lock.acquire() #获取线程锁
|
|
492
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
493
493
|
write_data(SINGLE_OP_H, SINGLE_OP_L, op_struct)
|
|
494
494
|
start_time = time.time()
|
|
495
495
|
while True:
|
|
@@ -522,8 +522,8 @@ def P_port_init(port:bytes) -> Optional[bytes]:
|
|
|
522
522
|
|
|
523
523
|
"""从机模式转换"""
|
|
524
524
|
def mode_change(send_data: str) -> Optional[bytes]:
|
|
525
|
-
|
|
526
|
-
|
|
525
|
+
serial_lock.acquire() #获取线程锁
|
|
526
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
527
527
|
write_data(MODE_CHANGE_H, MODE_CHANGE_L, send_data)
|
|
528
528
|
start_time = time.time()
|
|
529
529
|
while True:
|
|
@@ -546,8 +546,8 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
546
546
|
|
|
547
547
|
"""智能模式发送周期"""
|
|
548
548
|
def mode_change(send_data: str) -> Optional[bytes]:
|
|
549
|
-
|
|
550
|
-
|
|
549
|
+
serial_lock.acquire() #获取线程锁
|
|
550
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
551
551
|
write_data(SEND_CYCLE_H, SEND_CYCLE_L, send_data)
|
|
552
552
|
start_time = time.time()
|
|
553
553
|
while True:
|
|
@@ -569,16 +569,16 @@ def mode_change(send_data: str) -> Optional[bytes]:
|
|
|
569
569
|
return None
|
|
570
570
|
|
|
571
571
|
def shut_down():
|
|
572
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
573
572
|
serial_lock.acquire() #获取线程锁
|
|
573
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
574
574
|
write_data(0XFF, 0XFE)
|
|
575
575
|
serial_lock.release() #释放线程锁
|
|
576
576
|
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
577
577
|
time.sleep(0.5)
|
|
578
578
|
|
|
579
579
|
def shut_down_state() -> bool:
|
|
580
|
-
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
581
580
|
serial_lock.acquire() #获取线程锁
|
|
581
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
582
582
|
response =process_received_data()
|
|
583
583
|
if response:
|
|
584
584
|
receive_data = response[4:-3]
|
|
@@ -587,6 +587,7 @@ def shut_down_state() -> bool:
|
|
|
587
587
|
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
588
588
|
return True
|
|
589
589
|
else:
|
|
590
|
+
buffer.clear()
|
|
590
591
|
serial_lock.release() #释放线程锁
|
|
591
592
|
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
592
593
|
return False
|
|
@@ -594,15 +595,21 @@ def shut_down_state() -> bool:
|
|
|
594
595
|
serial_lock.release() #释放线程锁
|
|
595
596
|
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
596
597
|
return False
|
|
598
|
+
|
|
599
|
+
def buf_clear():
|
|
600
|
+
buffer.clear()
|
|
597
601
|
|
|
598
602
|
"""H2-RCU初始化"""
|
|
599
603
|
def smartpi_init():
|
|
600
604
|
|
|
601
605
|
if is_lock_locked(serial_lock):
|
|
602
|
-
serial_lock.release()
|
|
606
|
+
serial_lock.release() #释放线程锁
|
|
603
607
|
|
|
604
|
-
|
|
608
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
609
|
+
serial_lock.acquire() #获取线程锁
|
|
610
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
605
611
|
uart3_init()
|
|
612
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
606
613
|
P_port_init(1)
|
|
607
614
|
P_port_init(2)
|
|
608
615
|
P_port_init(3)
|
|
@@ -635,6 +642,6 @@ def smartpi_init():
|
|
|
635
642
|
motor.reset_motor_encoder(6)
|
|
636
643
|
time.sleep(0.1)
|
|
637
644
|
gui.init()
|
|
638
|
-
serial_lock.release()
|
|
645
|
+
serial_lock.release()
|
|
639
646
|
time.sleep(0.1)
|
|
640
647
|
|
smartpi/trace.py
CHANGED
|
@@ -1,20 +1,56 @@
|
|
|
1
1
|
# coding=utf-8
|
|
2
|
-
import time
|
|
2
|
+
import time,fcntl,serial,threading
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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]
|
|
9
28
|
trace_str[0]=0XA0+port
|
|
10
|
-
trace_str[4]=
|
|
29
|
+
trace_str[4]=chn
|
|
30
|
+
response = base_driver.single_operate_sensor(trace_str)
|
|
31
|
+
if response == None:
|
|
32
|
+
return None
|
|
33
|
+
else:
|
|
34
|
+
return response[4]
|
|
35
|
+
|
|
36
|
+
#循迹卡设置各通道颜色 port:连接P端口;color1~color7:7个通道彩灯的颜色1~7(红、绿、蓝、黄、紫、青、白)
|
|
37
|
+
def set_chn_color(port:bytes, color1:bytes, color2:bytes, color3:bytes, color4:bytes, color5:bytes, color6:bytes, color7:bytes) -> Optional[bytes]:
|
|
38
|
+
trace_str=[0xA0, 0x19, 0x01, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0x71, 0x00, 0xBE]
|
|
39
|
+
trace_str[0]=0XA0+port
|
|
40
|
+
trace_str[4]=color1
|
|
41
|
+
trace_str[6]=color2
|
|
42
|
+
trace_str[8]=color3
|
|
43
|
+
trace_str[10]=color4
|
|
44
|
+
trace_str[12]=color5
|
|
45
|
+
trace_str[14]=color6
|
|
46
|
+
trace_str[16]=color7
|
|
11
47
|
response = base_driver.single_operate_sensor(trace_str)
|
|
12
48
|
if response == None:
|
|
13
49
|
return None
|
|
14
50
|
else:
|
|
15
51
|
return response[4]
|
|
16
52
|
|
|
17
|
-
#循迹卡设置全部颜色 port:连接P
|
|
53
|
+
#循迹卡设置全部颜色 port:连接P端口;color:全部彩灯的颜色1~7(红、绿、蓝、黄、紫、青、白)
|
|
18
54
|
def set_color(port:bytes, color:bytes) -> Optional[bytes]:
|
|
19
55
|
trace_str=[0xA0, 0x20, 0x01, 0x71, 0x00, 0xBE]
|
|
20
56
|
trace_str[0]=0XA0+port
|
|
@@ -25,5 +61,53 @@ def set_color(port:bytes, color:bytes) -> Optional[bytes]:
|
|
|
25
61
|
else:
|
|
26
62
|
return response[4]
|
|
27
63
|
|
|
64
|
+
#循迹卡单通道光值读取 port:连接P端口;chn:检测通道;正常返回:通道光值数据; 读取错误:None
|
|
65
|
+
def get_analog(port:bytes, chn:bytes) -> Optional[bytes]:
|
|
66
|
+
trace_str=[0xA0, 0x21, 0x01, 0x71, 0x00, 0xBE]
|
|
67
|
+
trace_str[0]=0XA0+port
|
|
68
|
+
trace_str[4]=20+chn
|
|
69
|
+
response = base_driver.single_operate_sensor(trace_str)
|
|
70
|
+
if response == None:
|
|
71
|
+
return None
|
|
72
|
+
else:
|
|
73
|
+
return response[4]
|
|
74
|
+
|
|
75
|
+
#循迹卡判断是否组合图形 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
|
|
76
|
+
#正常返回:True/False; 读取错误:None
|
|
77
|
+
def get_line_state(port:bytes, state:bytes) -> Optional[bytes]:
|
|
78
|
+
trace_str=[0xA0, 0x22, 0x01, 0x71, 0x00, 0xBE]
|
|
79
|
+
trace_str[0]=0XA0+port
|
|
80
|
+
trace_str[4]=state
|
|
81
|
+
response = base_driver.single_operate_sensor(trace_str)
|
|
82
|
+
if response == None:
|
|
83
|
+
return None
|
|
84
|
+
else:
|
|
85
|
+
return response[4]
|
|
28
86
|
|
|
87
|
+
#循迹卡自动设置灰度阈值 port:连接P端口;second:秒数
|
|
88
|
+
def set_threshold(port:bytes, second:int) -> Optional[bytes]:
|
|
89
|
+
trace_str=[0xA0, 0x23, 0x01, 0x81, 0x00, 0x00, 0xBE]
|
|
90
|
+
trace_str[0]=0XA0+port
|
|
91
|
+
trace_str[4]=second//256
|
|
92
|
+
trace_str[5]=second%256
|
|
93
|
+
|
|
94
|
+
serial_lock.acquire() #获取线程锁
|
|
95
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
|
|
96
|
+
base_driver.write_data(0X01, 0X02, trace_str)
|
|
97
|
+
start_time = time.time()
|
|
98
|
+
|
|
99
|
+
while True:
|
|
100
|
+
response =base_driver.process_received_data()
|
|
101
|
+
if response:
|
|
102
|
+
serial_lock.release() #释放线程锁
|
|
103
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
104
|
+
display_data = response[6:-3]
|
|
105
|
+
return display_data
|
|
106
|
+
else:
|
|
107
|
+
if time.time() - start_time > second+2:
|
|
108
|
+
print("读取超时")
|
|
109
|
+
base_driver.buf_clear()
|
|
110
|
+
serial_lock.release() #释放线程锁
|
|
111
|
+
fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
|
|
112
|
+
return None
|
|
29
113
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
smartpi/__init__.py,sha256=
|
|
2
|
-
smartpi/base_driver.py,sha256=
|
|
1
|
+
smartpi/__init__.py,sha256=eXDn9vmrk3l7U0NFTdKpBbQyKKA1oPV1uTs_UkaNtOE,55
|
|
2
|
+
smartpi/base_driver.py,sha256=n_KIkdfk2BLzaPZpOj-hH30QuyiGwHSMQuosxj2YnOU,24172
|
|
3
3
|
smartpi/color_sensor.py,sha256=sTqD3jApjmc6qHMrDyEy2UjaRt8vhJZNR88vzgUiLKs,496
|
|
4
4
|
smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
|
|
5
5
|
smartpi/flash.py,sha256=Luz0TjinQSkx31uVknqfSWkiAiVrqIE2Iba7lk3AOzM,4132
|
|
@@ -12,9 +12,9 @@ smartpi/move.py,sha256=3qzrJCGA-qbsLXBpklY2DErtw0jlzMELzozjhEvRzKs,6028
|
|
|
12
12
|
smartpi/servo.py,sha256=B6X3yCoEz82qqpUIE5MSO0Eg9YZJ5zDzJEcRpioZpUo,4625
|
|
13
13
|
smartpi/temperature.py,sha256=px2YeqgG63nPkyhJA1wDg3dwYx_oOCYuhMjtsVm_YO0,460
|
|
14
14
|
smartpi/touch_sensor.py,sha256=F6IIQGewNRhC9U1RbHpVzuGYqb8H41lpeQ1Ejwsc_T8,438
|
|
15
|
-
smartpi/trace.py,sha256=
|
|
15
|
+
smartpi/trace.py,sha256=ntk3UwVATOV_eViGQhFi3lyil9xFmzeZZ_MBvQTq3UQ,4567
|
|
16
16
|
smartpi/ultrasonic.py,sha256=0meczFKXFLUt92kLxipeEc37vb5duvJjPs4kgtlpO8M,622
|
|
17
|
-
smartpi-0.1.
|
|
18
|
-
smartpi-0.1.
|
|
19
|
-
smartpi-0.1.
|
|
20
|
-
smartpi-0.1.
|
|
17
|
+
smartpi-0.1.20.dist-info/METADATA,sha256=3WlrHNedbYaRx4tWEm8ZTa9hqPwTPwxO3HuefgnoP3M,311
|
|
18
|
+
smartpi-0.1.20.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
19
|
+
smartpi-0.1.20.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
20
|
+
smartpi-0.1.20.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|