smartpi 0.1.31__py3-none-any.whl → 0.1.32__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,6 +1,8 @@
1
1
  from ._gui import gui
2
+ from .base_driver import P1, P2, P3, P4, P5, P6, M1, M2, M3, M4, M5, M6
2
3
 
3
- __all__ = ["base_driver","gui","ultrasonic","touch_sensor","temperature","humidity","light_sensor","color_sensor","motor","servo","led","flash"]
4
+ __all__ = ["base_driver","gui","ultrasonic","touch_sensor","temperature","humidity","light_sensor","color_sensor","motor","servo","led","flash",
5
+ "P1", "P2", "P3", "P4", "P5", "P6", "M1", "M2", "M3", "M4", "M5", "M6"]
4
6
 
5
- __version__ = "0.1.31"
7
+ __version__ = "0.1.32"
6
8
 
smartpi/base_driver.py CHANGED
@@ -2,7 +2,7 @@
2
2
  import serial,time,struct,threading,fcntl,os
3
3
  from typing import List, Optional
4
4
  from collections import deque
5
- from . import servo,motor,cw2015
5
+ from . import servo,motor,cw2015,led,light_sensor
6
6
 
7
7
  # 创建全局线程锁
8
8
  serial_lock = threading.RLock()
@@ -49,6 +49,20 @@ MODE_CHANGE_L = 0X03
49
49
  SEND_CYCLE_H = 0X01
50
50
  SEND_CYCLE_L = 0X04
51
51
 
52
+ P1 = 1
53
+ P2 = 2
54
+ P3 = 3
55
+ P4 = 4
56
+ P5 = 5
57
+ P6 = 6
58
+
59
+ M1 = 1
60
+ M2 = 2
61
+ M3 = 3
62
+ M4 = 4
63
+ M5 = 5
64
+ M6 = 6
65
+
52
66
  frames_queue = deque()
53
67
  buffer = bytearray()
54
68
  HEADER = bytes.fromhex('86 AB') # 帧头
@@ -119,7 +133,7 @@ def write_data(command_h: int, command_l: int, send_data: bytes= None) -> Option
119
133
  # for x in send_bytes:
120
134
  # print(f"{x:02X}", end=' ')
121
135
  # print("\n")
122
-
136
+ buffer.clear()
123
137
  ser.write(send_bytes)
124
138
 
125
139
 
@@ -501,12 +515,7 @@ def smartpi_init():
501
515
  fcntl.flock(ser.fileno(), fcntl.LOCK_EX) # 进程锁,阻塞其他进程
502
516
  uart3_init()
503
517
  fcntl.flock(ser.fileno(), fcntl.LOCK_UN) # 释放进程锁
504
- P_port_init(1)
505
- P_port_init(2)
506
- P_port_init(3)
507
- P_port_init(4)
508
- P_port_init(5)
509
- P_port_init(6)
518
+
510
519
  servo.set_init(1)
511
520
  servo.set_init(2)
512
521
  servo.set_init(3)
@@ -530,7 +539,26 @@ def smartpi_init():
530
539
  motor.reset_motor_encoder(3)
531
540
  motor.reset_motor_encoder(4)
532
541
  motor.reset_motor_encoder(5)
533
- motor.reset_motor_encoder(6)
542
+ motor.reset_motor_encoder(6)
543
+ light_sensor.turn_off(1)
544
+ light_sensor.turn_off(2)
545
+ light_sensor.turn_off(3)
546
+ light_sensor.turn_off(4)
547
+ light_sensor.turn_off(5)
548
+ light_sensor.turn_off(6)
549
+ led.set_color(1,0)
550
+ led.set_color(2,0)
551
+ led.set_color(3,0)
552
+ led.set_color(4,0)
553
+ led.set_color(5,0)
554
+ led.set_color(6,0)
555
+ P_port_init(1)
556
+ P_port_init(2)
557
+ P_port_init(3)
558
+ P_port_init(4)
559
+ P_port_init(5)
560
+ P_port_init(6)
561
+
534
562
  time.sleep(0.1)
535
563
  serial_lock.release()
536
564
  time.sleep(0.1)
smartpi/led.py CHANGED
@@ -9,9 +9,10 @@ def set_color(port:bytes,command:bytes) -> Optional[bytes]:
9
9
  color_lamp_str=[0xA0, 0x05, 0x00, 0xBE]
10
10
  color_lamp_str[0]=0XA0+port
11
11
  color_lamp_str[2]=command
12
- response = base_driver.single_operate_sensor(color_lamp_str,0)
13
- if response == None:
14
- return None
15
- else:
16
- return 0
12
+ # response = base_driver.single_operate_sensor(color_lamp_str,0)
13
+ base_driver.write_data(0X01, 0X02, color_lamp_str)
14
+ # if response == None:
15
+ # return None
16
+ # else:
17
+ return 0
17
18
 
smartpi/light_sensor.py CHANGED
@@ -3,6 +3,18 @@ import time
3
3
  from typing import List, Optional
4
4
  from smartpi import base_driver
5
5
 
6
+ #����ֵ��ȡ port:����P�˿ڣ� �������أ���ֵ����; ��ȡ����-1
7
+ def turn_off(port:bytes) -> Optional[bytes]:
8
+ light_str=[0xA0, 0x02, 0x00, 0xBE]
9
+ light_str[0]=0XA0+port
10
+ light_str[2]=0x03
11
+ # response = base_driver.single_operate_sensor(light_str,0)
12
+ # base_driver.write_data(0X01, 0X02, light_str)
13
+ # if response == None:
14
+ # return None
15
+ # else:
16
+ return 0
17
+
6
18
  #����ֵ��ȡ port:����P�˿ڣ� �������أ���ֵ����; ��ȡ����-1
7
19
  def get_value(port:bytes) -> Optional[bytes]:
8
20
  light_str=[0xA0, 0x02, 0x00, 0xBE]
smartpi/motor.py CHANGED
@@ -21,22 +21,24 @@ def get_motor_encoder(port:bytes) -> Optional[bytes]:
21
21
  def reset_motor_encoder(port:bytes) -> Optional[bytes]:
22
22
  motor_str=[0xA0, 0x01, 0x03, 0xBE]
23
23
  motor_str[0]=0XA0+port
24
- response = base_driver.single_operate_sensor(motor_str,0)
25
- if response == None:
26
- return None
27
- else:
28
- return 0
24
+ # response = base_driver.single_operate_sensor(motor_str,0)
25
+ base_driver.write_data(0X01, 0X02, motor_str)
26
+ # if response == None:
27
+ # return None
28
+ # else:
29
+ return 0
29
30
 
30
31
  #���﷽����� port:����M�˿ڣ�dir:0��1
31
32
  def set_motor_direction(port:bytes,direc:bytes) -> Optional[bytes]:
32
33
  motor_str=[0xA0, 0x01, 0x06, 0x71, 0x00, 0xBE]
33
34
  motor_str[0]=0XA0+port
34
35
  motor_str[4]=direc
35
- response = base_driver.single_operate_sensor(motor_str,0)
36
- if response == None:
37
- return None
38
- else:
39
- return 0
36
+ # response = base_driver.single_operate_sensor(motor_str,0)
37
+ base_driver.write_data(0X01, 0X02, motor_str)
38
+ # if response == None:
39
+ # return None
40
+ # else:
41
+ return 0
40
42
 
41
43
  #�����ٶ�ת�� port:����M�˿ڣ�speed:-100~100
42
44
  def set_motor(port:bytes,speed:int) -> Optional[bytes]:
@@ -53,21 +55,23 @@ def set_motor(port:bytes,speed:int) -> Optional[bytes]:
53
55
 
54
56
  motor_str[4]=m_par
55
57
 
56
- response = base_driver.single_operate_sensor(motor_str,0)
57
- if response == None:
58
- return None
59
- else:
60
- return 0
58
+ # response = base_driver.single_operate_sensor(motor_str,0)
59
+ base_driver.write_data(0X01, 0X02, motor_str)
60
+ # if response == None:
61
+ # return None
62
+ # else:
63
+ return 0
61
64
 
62
65
  #����ֹͣ port:����M�˿ڣ�
63
66
  def set_motor_stop(port:bytes) -> Optional[bytes]:
64
67
  motor_str=[0xA0, 0x01, 0x0B, 0xBE]
65
68
  motor_str[0]=0XA0+port
66
- response = base_driver.single_operate_sensor(motor_str,0)
67
- if response == None:
68
- return None
69
- else:
70
- return 0
69
+ # response = base_driver.single_operate_sensor(motor_str,0)
70
+ base_driver.write_data(0X01, 0X02, motor_str)
71
+ # if response == None:
72
+ # return None
73
+ # else:
74
+ return 0
71
75
 
72
76
  #����Ƕȿ��� port:����M�˿ڣ�speed:-100~100��degree:0~65535
73
77
  def set_motor_angle(port:bytes,speed:int,degree:int) -> Optional[bytes]:
@@ -86,11 +90,12 @@ def set_motor_angle(port:bytes,speed:int,degree:int) -> Optional[bytes]:
86
90
  motor_str[4]=m_par
87
91
  motor_str[6]=degree//256
88
92
  motor_str[7]=degree%256
89
- response = base_driver.single_operate_sensor(motor_str,0)
90
- if response == None:
91
- return None
92
- else:
93
- return 0
93
+ # response = base_driver.single_operate_sensor(motor_str,0)
94
+ base_driver.write_data(0X01, 0X02, motor_str)
95
+ # if response == None:
96
+ # return None
97
+ # else:
98
+ return 0
94
99
 
95
100
  #���ﶨʱת�� port:����M�˿ڣ�speed:-100~100��second:1~256
96
101
  def set_motor_second(port:bytes,speed:int,second:float) -> Optional[bytes]:
@@ -116,11 +121,12 @@ def set_motor_second(port:bytes,speed:int,second:float) -> Optional[bytes]:
116
121
  motor_str[8]=byte_array[2]
117
122
  motor_str[9]=byte_array[3]
118
123
 
119
- response = base_driver.single_operate_sensor(motor_str,second)
120
- if response == None:
121
- return None
122
- else:
123
- return 0
124
+ # response = base_driver.single_operate_sensor(motor_str,0)
125
+ base_driver.write_data(0X01, 0X02, motor_str)
126
+ # if response == None:
127
+ # return None
128
+ # else:
129
+ return 0
124
130
 
125
131
  #���ﶨ��ת�� port:����M�˿ڣ�speed:-100~100
126
132
  def set_motor_constspeed(port:bytes,speed:int) -> Optional[bytes]:
@@ -138,11 +144,12 @@ def set_motor_constspeed(port:bytes,speed:int) -> Optional[bytes]:
138
144
 
139
145
  motor_str[4]=m_par
140
146
 
141
- response = base_driver.single_operate_sensor(motor_str,0)
142
- if response == None:
143
- return None
144
- else:
145
- return 0
147
+ # response = base_driver.single_operate_sensor(motor_str,0)
148
+ base_driver.write_data(0X01, 0X02, motor_str)
149
+ # if response == None:
150
+ # return None
151
+ # else:
152
+ return 0
146
153
 
147
154
  #�����ٶȶ�ȡ port:����M�˿ڣ�
148
155
  def get_motor_speed(port:bytes) -> Optional[bytes]:
smartpi/servo.py CHANGED
@@ -3,17 +3,17 @@ import time
3
3
  from typing import List, Optional
4
4
  from smartpi import base_driver
5
5
 
6
-
7
6
  #С������� port:����P�˿ڣ�angle:�Ƕ�0~270��
8
7
  def steer_angle(port:bytes,angle:bytes) -> Optional[bytes]:
9
8
  servo_str=[0xA0, 0x0E, 0x01, 0x71, 0x00, 0xBE]
10
9
  servo_str[0]=0XA0+port
11
10
  servo_str[4]=angle
12
- response = base_driver.single_operate_sensor(servo_str,0)
13
- if response == None:
14
- return None
15
- else:
16
- return 0
11
+ # response = base_driver.single_operate_sensor(servo_str,0)
12
+ base_driver.write_data(0X01, 0X02, servo_str)
13
+ # if response == None:
14
+ # return None
15
+ # else:
16
+ return 0
17
17
 
18
18
  #С�����ʱ���� port:����P�˿ڣ�angle:�Ƕ�0~270��second:1~256
19
19
  def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
@@ -22,22 +22,24 @@ def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
22
22
  servo_str[4]=angle//256
23
23
  servo_str[5]=angle%256
24
24
  servo_str[7]=second
25
- response = base_driver.single_operate_sensor(servo_str,0)
26
- if response == None:
27
- return None
28
- else:
29
- return 0
25
+ # response = base_driver.single_operate_sensor(servo_str,0)
26
+ base_driver.write_data(0X01, 0X02, servo_str)
27
+ # if response == None:
28
+ # return None
29
+ # else:
30
+ return 0
30
31
 
31
32
  #���ֶ������ת������(���ԽǶ�) port:����P�˿ڣ�dir:0:����Խ0��;1:��̾�����ת;2:˳ʱ����ת;3:��ʱ����ת
32
33
  def set_dir(port:bytes,dir:bytes) -> Optional[bytes]:
33
34
  servo_str=[0xA0, 0x24, 0x01, 0x71, 0x00, 0xBE]
34
35
  servo_str[0]=0XA0+port
35
36
  servo_str[4]=dir
36
- response = base_driver.single_operate_sensor(servo_str,0)
37
- if response == None:
38
- return None
39
- else:
40
- return 0
37
+ # response = base_driver.single_operate_sensor(servo_str,0)
38
+ base_driver.write_data(0X01, 0X02, servo_str)
39
+ # if response == None:
40
+ # return None
41
+ # else:
42
+ return 0
41
43
 
42
44
  #BE-9528���ֶ�����ٶ�ת���Ƕ� port:����P�˿ڣ�angle:�Ƕ�(0~360)��speed:�ٶ�(0~100)��
43
45
  def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
@@ -46,11 +48,12 @@ def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
46
48
  servo_str[4]=angle//256
47
49
  servo_str[5]=angle%256
48
50
  servo_str[7]=speed
49
- response = base_driver.single_operate_sensor(servo_str,0)
50
- if response == None:
51
- return None
52
- else:
53
- return 0
51
+ #response = base_driver.single_operate_sensor(servo_str,0)
52
+ base_driver.write_data(0X01, 0X02, servo_str)
53
+ # if response == None:
54
+ # return None
55
+ # else:
56
+ return 0
54
57
 
55
58
  #���ֶ��ת�����Ƕ���ʱʱ�� port:����P�˿ڣ�angle:�Ƕ�(0~360)��ms:��ʱʱ��(0~65535)��
56
59
  def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
@@ -60,21 +63,23 @@ def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
60
63
  servo_str[5]=angle%256
61
64
  servo_str[7]=ms//256
62
65
  servo_str[8]=ms%256
63
- response = base_driver.single_operate_sensor(servo_str,0)
64
- if response == None:
65
- return None
66
- else:
67
- return 0
66
+ # response = base_driver.single_operate_sensor(servo_str,0)
67
+ base_driver.write_data(0X01, 0X02, servo_str)
68
+ # if response == None:
69
+ # return None
70
+ # else:
71
+ return 0
68
72
 
69
73
  #���ֶ����λ port:����P�˿ڣ�
70
74
  def set_init(port:bytes) -> Optional[bytes]:
71
75
  servo_str=[0xA0, 0x12, 0x01, 0xBE]
72
76
  servo_str[0]=0XA0+port
73
- response = base_driver.single_operate_sensor(servo_str,0)
74
- if response == None:
75
- return None
76
- else:
77
- return 0
77
+ # response = base_driver.single_operate_sensor(servo_str,0)
78
+ base_driver.write_data(0X01, 0X02, servo_str)
79
+ # if response == None:
80
+ # return None
81
+ # else:
82
+ return 0
78
83
 
79
84
  #��ȡ���ֶ���Ƕ� port:����P�˿ڣ�
80
85
  def get_angle(port:bytes) -> Optional[bytes]:
@@ -102,11 +107,12 @@ def set_speed(port:bytes,speed:int) -> Optional[bytes]:
102
107
  m_par=256+speed
103
108
 
104
109
  servo_str[4]=m_par
105
- response = base_driver.single_operate_sensor(servo_str,0)
106
- if response == None:
107
- return None
108
- else:
109
- return 0
110
+ # response = base_driver.single_operate_sensor(servo_str,0)
111
+ base_driver.write_data(0X01, 0X02, servo_str)
112
+ # if response == None:
113
+ # return None
114
+ # else:
115
+ return 0
110
116
 
111
117
  #���ֶ������ת�� port:����P�˿ڣ�code:����(0~65535)��speed:�ٶ�(-100~100)��
112
118
  def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
@@ -126,21 +132,23 @@ def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
126
132
  m_par=256+speed
127
133
  servo_str[7]=m_par
128
134
 
129
- response = base_driver.single_operate_sensor(servo_str,0)
130
- if response == None:
131
- return None
132
- else:
133
- return 0
135
+ # response = base_driver.single_operate_sensor(servo_str,0)
136
+ base_driver.write_data(0X01, 0X02, servo_str)
137
+ # if response == None:
138
+ # return None
139
+ # else:
140
+ return 0
134
141
 
135
142
  #���ֶ������ֵ���� port:����P�˿ڣ�
136
143
  def reset_encode(port:bytes) -> Optional[bytes]:
137
144
  servo_str=[0xA0, 0x16, 0x01, 0xBE]
138
145
  servo_str[0]=0XA0+port
139
- response = base_driver.single_operate_sensor(servo_str,0)
140
- if response == None:
141
- return None
142
- else:
143
- return 0
146
+ # response = base_driver.single_operate_sensor(servo_str,0)
147
+ base_driver.write_data(0X01, 0X02, servo_str)
148
+ # if response == None:
149
+ # return None
150
+ # else:
151
+ return 0
144
152
 
145
153
  #��ȡ���ֶ������ֵ port:����P�˿ڣ�
146
154
  def get_encoder(port:bytes) -> Optional[bytes]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: smartpi
3
- Version: 0.1.31
3
+ Version: 0.1.32
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=Mx0R3q6LJmVf3XdhWEIDW7hj_vsJq0V5t3jS2XeErj8,199
1
+ smartpi/__init__.py,sha256=lUBmDOfuGaZ59JU3nE42ao8-9nV_D5vheF1X7Dq400k,356
2
2
  smartpi/_gui.py,sha256=ij-6HZAEIwdy_hvU7f0NkyQjx_-eephijlKbGUhf8Uo,2177
3
- smartpi/base_driver.py,sha256=P029DleVPCTYTWi0ckwTwdfBNzzRrb13mGFdxIWCSYQ,20131
3
+ smartpi/base_driver.py,sha256=WtRBSkjcOHikU402lU1cBSVlRHhyWGZMll_zffg2F2U,20609
4
4
  smartpi/color_sensor.py,sha256=YXJjknYjp7teTZsHYZRAWgi73CH0MhBp1go9y0Inxyo,498
5
5
  smartpi/cw2015.py,sha256=1lAF-pi_ye_ya1AZQS1sjbgsDf7MThO5IAskKsNGBzA,5695
6
6
  smartpi/flash.py,sha256=-pUqg6FSVoBiLFKqrG9B4dFqn8lICnQsSPJr_MtZLIU,4132
7
7
  smartpi/humidity.py,sha256=nZwiBtMWKNipVM83ymajZACPHxkC2vUJjDMmCOPN9lw,499
8
- smartpi/led.py,sha256=flvN7EJfP6VDTSiC93w1uR8pRxcZD9w2vLXA1GbJTo8,538
9
- smartpi/light_sensor.py,sha256=MayyVikWcXQfjeZrtYRnwYgHBDzu2g-mfJLpdd29EG8,1852
10
- smartpi/motor.py,sha256=CS-a1AxKeLFQNxsBpfThWE7lI3ZC27OZthXPfgk8vro,4792
8
+ smartpi/led.py,sha256=HXebd7mRO6HUjO2Xc2LBgJlAew0-IAAKpvcmVRhdGcA,594
9
+ smartpi/light_sensor.py,sha256=oG6hHr1Tb9Xcv-Y-OjhkED5DS1u82F-kduHKAiM3B5Q,2256
10
+ smartpi/motor.py,sha256=HTH0JqZ0d8D2HRdQ6UT9wwqBkyqErq6QaMuS_ZsDq9A,5144
11
11
  smartpi/move.py,sha256=mYw5li1qQe97845cqclMksuaKOL9n_0E0n9652EIMcI,6046
12
- smartpi/servo.py,sha256=SN4Md57MNDBBlu2vCrzby04IDQiLNqdwgvS4dCh0q8E,5057
12
+ smartpi/servo.py,sha256=XbI2pc-nejhh1QewE2liaiyoP01BWf2M2x7gwFcUTfI,5514
13
13
  smartpi/temperature.py,sha256=VT79CYA41q1d_4AM-Y0eIMeIw7AtCkSXjWVws6Yx5yE,462
14
14
  smartpi/touch_sensor.py,sha256=P57RRQlqY0KexpMi-ydqwF5albOKCBOGb0Rb6zeVTqk,440
15
15
  smartpi/trace.py,sha256=tut7BMbq87ShaR5eNuv7PZtAEz9DS5_BDf0_muIZ-tQ,4577
16
16
  smartpi/ultrasonic.py,sha256=kmVpUfvE1oHoqgv92ZU6Fi-sO6DSwm10ssKsImNeOkY,624
17
- smartpi-0.1.31.dist-info/METADATA,sha256=cWc5QT8cfatmdvFj6TYtDRYZf41lR7NlktAgu9Z-DM0,399
18
- smartpi-0.1.31.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
- smartpi-0.1.31.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
20
- smartpi-0.1.31.dist-info/RECORD,,
17
+ smartpi-0.1.32.dist-info/METADATA,sha256=YBHCXdnPlErDsEQmhqsrXSD6g2Jen0OT9ZKV8san8gw,399
18
+ smartpi-0.1.32.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
19
+ smartpi-0.1.32.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
20
+ smartpi-0.1.32.dist-info/RECORD,,