smartpi 0.1.19__py3-none-any.whl → 0.1.21__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 CHANGED
@@ -1,4 +1,4 @@
1
1
  __all__ = ["base_driver"]
2
2
 
3
- __version__ = "0.1.19"
3
+ __version__ = "0.1.21"
4
4
 
smartpi/base_driver.py CHANGED
@@ -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,6 +595,9 @@ 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():
smartpi/flash.py CHANGED
@@ -7,7 +7,7 @@ FLASH_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "/home/Int
7
7
  FLASH_FILE_2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), "/home/Interface/flash/flash_2.bin")
8
8
 
9
9
  DATA_SIZE = 2 # 每个数据2字节
10
- TOTAL_SLOTS = 100 # 100个数据槽
10
+ TOTAL_SLOTS = 120 # 100个数据槽
11
11
 
12
12
  def _init_flash_file():
13
13
  """初始化存储文件"""
smartpi/servo.py CHANGED
@@ -28,6 +28,17 @@ def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
28
28
  else:
29
29
  return 0
30
30
 
31
+ #���ֶ������ת������(���ԽǶ�) port:����P�˿ڣ�dir:0:����Խ0��;1:��̾�����ת;2:˳ʱ����ת;3:��ʱ����ת
32
+ def set_dir(port:bytes,dir:bytes) -> Optional[bytes]:
33
+ servo_str=[0xA0, 0x24, 0x01, 0x71, 0x00, 0xBE]
34
+ servo_str[0]=0XA0+port
35
+ servo_str[4]=dir
36
+ response = base_driver.single_operate_sensor(servo_str)
37
+ if response == None:
38
+ return None
39
+ else:
40
+ return 0
41
+
31
42
  #BE-9528���ֶ�����ٶ�ת���Ƕ� port:����P�˿ڣ�angle:�Ƕ�(0~360)��speed:�ٶ�(0~100)��
32
43
  def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
33
44
  servo_str=[0xA0, 0x0D, 0x01, 0x81, 0x00, 0x00, 0x81, 0x00, 0xBE]
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
- #循迹卡单通道光值读取 port:连接P端口;正常返回:通道光值数据; 读取错误:None
7
- def get_analog(port:bytes, chn:bytes) -> Optional[bytes]:
8
- trace_str=[0xA0, 0x21, 0x01, 0x71, 0x00, 0xBE]
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]=20+chn
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端口;正常返回:通道光值数据; 读取错误:None
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smartpi
3
- Version: 0.1.19
3
+ Version: 0.1.21
4
4
  Summary: A library use for H2-RCU
5
5
  Author: ZMROBO
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,20 +1,20 @@
1
- smartpi/__init__.py,sha256=XC4FyX6UBONemsJEdIZzMvIkF4pscJ5XGVvK8jgVCdA,55
2
- smartpi/base_driver.py,sha256=DV-jh7j4X7ak9zFSqgwjHrj1X18SDqUjCqewLovxDVU,24096
1
+ smartpi/__init__.py,sha256=QR4ouIPj9-lhXKMzcZUxB--K9gklRhYKZenfjmxWUOw,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
- smartpi/flash.py,sha256=Luz0TjinQSkx31uVknqfSWkiAiVrqIE2Iba7lk3AOzM,4132
5
+ smartpi/flash.py,sha256=-pUqg6FSVoBiLFKqrG9B4dFqn8lICnQsSPJr_MtZLIU,4132
6
6
  smartpi/gui.py,sha256=E98_soyWbEf_dwYhXZgMSXrgY5QuYoDTuFCPK63flIQ,2102
7
7
  smartpi/humidity.py,sha256=xtALQ_IlcwR2RCYvopCSmeNajB45kQU_ckk6FZ0rqko,497
8
8
  smartpi/led.py,sha256=n3_k1jGcQptfGXhezDLaYzH6UptgluP4Ze6qP_Y4WmU,536
9
9
  smartpi/light_sensor.py,sha256=glDa4O0wW0kamb-tI3qf509qM7zA8UUjVXbA9si3TXM,1844
10
10
  smartpi/motor.py,sha256=uvuAwt2j5LjdLaMfNisXqaGh1ro3fZDvHU8IXd2fn9Q,4527
11
11
  smartpi/move.py,sha256=3qzrJCGA-qbsLXBpklY2DErtw0jlzMELzozjhEvRzKs,6028
12
- smartpi/servo.py,sha256=B6X3yCoEz82qqpUIE5MSO0Eg9YZJ5zDzJEcRpioZpUo,4625
12
+ smartpi/servo.py,sha256=p8BxfqXVQYP81Kl0J9P23AGoGTrnn8To98ipo6Z_Tkk,5035
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=dtZQAkUUIsq578hycwrfR9GJUsIUCbHCF4ZvJv9GLrs,984
15
+ smartpi/trace.py,sha256=ntk3UwVATOV_eViGQhFi3lyil9xFmzeZZ_MBvQTq3UQ,4567
16
16
  smartpi/ultrasonic.py,sha256=0meczFKXFLUt92kLxipeEc37vb5duvJjPs4kgtlpO8M,622
17
- smartpi-0.1.19.dist-info/METADATA,sha256=kViF6wYE4k68vEkBr0T8XPnoZGIN3gmP0d7sAulJItg,311
18
- smartpi-0.1.19.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
- smartpi-0.1.19.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
20
- smartpi-0.1.19.dist-info/RECORD,,
17
+ smartpi-0.1.21.dist-info/METADATA,sha256=bZEx5P-yz1jfxEPLJS9W-DhGHNrjyfXHHiKLlkLqpHE,311
18
+ smartpi-0.1.21.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
+ smartpi-0.1.21.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
20
+ smartpi-0.1.21.dist-info/RECORD,,