smartpi 0.1.2__py3-none-any.whl → 0.1.4__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 +13 -3
- smartpi/color_sensor.py +12 -1
- smartpi/humidity.py +2 -2
- smartpi/light_sensor.py +30 -15
- smartpi/motor.py +114 -22
- smartpi/servo.py +134 -11
- smartpi/temperature.py +5 -6
- smartpi/touch_sensor.py +1 -1
- smartpi/ultrasonic.py +3 -12
- {smartpi-0.1.2.dist-info → smartpi-0.1.4.dist-info}/METADATA +2 -2
- smartpi-0.1.4.dist-info/RECORD +15 -0
- smartpi/GUI.py +0 -0
- smartpi/move.py +0 -0
- smartpi/photosensitive.py +0 -0
- smartpi/trace.py +0 -0
- smartpi-0.1.2.dist-info/RECORD +0 -19
- {smartpi-0.1.2.dist-info → smartpi-0.1.4.dist-info}/WHEEL +0 -0
- {smartpi-0.1.2.dist-info → smartpi-0.1.4.dist-info}/top_level.txt +0 -0
smartpi/__init__.py
CHANGED
smartpi/base_driver.py
CHANGED
|
@@ -290,7 +290,7 @@ def write_device_name(send_data: str) -> Optional[bytes]:
|
|
|
290
290
|
buffer.clear()
|
|
291
291
|
return -1
|
|
292
292
|
|
|
293
|
-
"""读取连接方式"""
|
|
293
|
+
"""读取连接方式"""
|
|
294
294
|
def read_connected() -> Optional[bytes]:
|
|
295
295
|
write_data(READ_CONNECT_H, READ_CONNECT_L)
|
|
296
296
|
start_time = time.time()
|
|
@@ -440,7 +440,7 @@ def read_peripheral() -> Optional[bytes]:
|
|
|
440
440
|
if time.time() - start_time > 3:
|
|
441
441
|
print("读取超时")
|
|
442
442
|
buffer.clear()
|
|
443
|
-
return -1
|
|
443
|
+
return -1
|
|
444
444
|
|
|
445
445
|
"""单次操作外设"""
|
|
446
446
|
def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
@@ -458,7 +458,17 @@ def single_operate_sensor(op_struct: bytes) -> Optional[bytes]:
|
|
|
458
458
|
if time.time() - start_time > 3:
|
|
459
459
|
print("读取超时")
|
|
460
460
|
buffer.clear()
|
|
461
|
-
return -1
|
|
461
|
+
return -1
|
|
462
|
+
|
|
463
|
+
#P端口初始化释放
|
|
464
|
+
def P_port_init(port:bytes) -> Optional[bytes]:
|
|
465
|
+
servo_str=[0xA0, 0x0F, 0x00, 0xBE]
|
|
466
|
+
servo_str[0]=0XA0+port
|
|
467
|
+
response = single_operate_sensor(servo_str)
|
|
468
|
+
if response:
|
|
469
|
+
return 0
|
|
470
|
+
else:
|
|
471
|
+
return -1
|
|
462
472
|
|
|
463
473
|
"""从机模式转换"""
|
|
464
474
|
def mode_change(send_data: str) -> Optional[bytes]:
|
smartpi/color_sensor.py
CHANGED
|
@@ -3,4 +3,15 @@ import time
|
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
#����ֵ��1-��ɫ��2-��ɫ��3-��ɫ��4-��ɫ��5-��ɫ��6-��ɫ
|
|
7
|
+
def get_value(port:bytes) -> Optional[bytes]:
|
|
8
|
+
color_str=[0xA0, 0x04, 0x00, 0xBE]
|
|
9
|
+
color_str[0]=0XA0+port
|
|
10
|
+
color_str[2]=1
|
|
11
|
+
response = base_driver.single_operate_sensor(color_str)
|
|
12
|
+
if response:
|
|
13
|
+
return response[4]
|
|
14
|
+
else:
|
|
15
|
+
return -1
|
|
16
|
+
|
|
17
|
+
|
smartpi/humidity.py
CHANGED
|
@@ -8,10 +8,10 @@ from smartpi import base_driver
|
|
|
8
8
|
def get_value(port:bytes) -> Optional[bytes]:
|
|
9
9
|
humiture_str=[0xA0, 0x0C, 0x01, 0x71, 0x00, 0xBE]
|
|
10
10
|
humiture_str[0]=0XA0+port
|
|
11
|
-
humiture_str[
|
|
11
|
+
humiture_str[4]=1
|
|
12
12
|
response = base_driver.single_operate_sensor(humiture_str)
|
|
13
13
|
if response:
|
|
14
|
-
return
|
|
14
|
+
return response[4]
|
|
15
15
|
else:
|
|
16
16
|
return -1
|
|
17
17
|
|
smartpi/light_sensor.py
CHANGED
|
@@ -3,25 +3,40 @@ import time
|
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
#����ȡ port:����P�˿ڣ�command:1:��ȡ��2:���ƣ�3:�صƣ�
|
|
9
|
-
#def get_value(port:bytes,command:bytes) -> Optional[bytes]:
|
|
10
|
-
# light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
11
|
-
# light_str[0]=0XA0+port
|
|
12
|
-
# light_str[2]=command
|
|
13
|
-
# response = base_driver.single_operate_sensor(light_str)
|
|
14
|
-
# if response:
|
|
15
|
-
# return 0
|
|
16
|
-
# else:
|
|
17
|
-
# return -1
|
|
18
6
|
|
|
19
7
|
def get_value(port:bytes) -> Optional[bytes]:
|
|
20
8
|
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
21
9
|
light_str[0]=0XA0+port
|
|
22
|
-
light_str[2]=1
|
|
10
|
+
light_str[2]=1
|
|
11
|
+
response = base_driver.single_operate_sensor(light_str)
|
|
12
|
+
if response:
|
|
13
|
+
light_data=response[4:-1]
|
|
14
|
+
light_num=int.from_bytes(light_data, byteorder='big', signed=True)
|
|
15
|
+
return light_num
|
|
16
|
+
else:
|
|
17
|
+
return -1
|
|
18
|
+
|
|
19
|
+
def light_on(port:bytes) -> Optional[bytes]:
|
|
20
|
+
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
21
|
+
light_str[0]=0XA0+port
|
|
22
|
+
light_str[2]=2
|
|
23
|
+
response = base_driver.single_operate_sensor(light_str)
|
|
24
|
+
if response:
|
|
25
|
+
light_data=response[4:-1]
|
|
26
|
+
light_num=int.from_bytes(light_data, byteorder='big', signed=True)
|
|
27
|
+
return light_num
|
|
28
|
+
else:
|
|
29
|
+
return -1
|
|
30
|
+
|
|
31
|
+
def light_off(port:bytes) -> Optional[bytes]:
|
|
32
|
+
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
33
|
+
light_str[0]=0XA0+port
|
|
34
|
+
light_str[2]=3
|
|
23
35
|
response = base_driver.single_operate_sensor(light_str)
|
|
24
36
|
if response:
|
|
25
|
-
|
|
37
|
+
light_data=response[4:-1]
|
|
38
|
+
light_num=int.from_bytes(light_data, byteorder='big', signed=True)
|
|
39
|
+
return light_num
|
|
26
40
|
else:
|
|
27
|
-
return -1
|
|
41
|
+
return -1
|
|
42
|
+
|
smartpi/motor.py
CHANGED
|
@@ -4,57 +4,149 @@ from typing import List, Optional
|
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
##############################################################
|
|
8
|
-
# motor.write_motor_dir(1,0)
|
|
9
|
-
# motor.write_motor_speed(1,100)
|
|
10
|
-
# time.sleep(0.5)
|
|
11
|
-
# motor.write_motor_dir(1,1)
|
|
12
|
-
# motor.write_motor_speed(1,50)
|
|
13
|
-
# time.sleep(0.5)
|
|
14
|
-
##############################################################
|
|
15
|
-
|
|
16
7
|
#��������ȡ port:����M�˿ڣ�
|
|
17
|
-
def
|
|
8
|
+
def get_motor_encoder(port:bytes) -> Optional[bytes]:
|
|
18
9
|
motor_str=[0xA0, 0x01, 0x01, 0xBE]
|
|
19
10
|
motor_str[0]=0XA0+port
|
|
20
11
|
response = base_driver.single_operate_sensor(motor_str)
|
|
12
|
+
if response:
|
|
13
|
+
code_data=response[4:-1]
|
|
14
|
+
code_num=int.from_bytes(code_data, byteorder='big', signed=True)
|
|
15
|
+
return code_num
|
|
16
|
+
else:
|
|
17
|
+
return -1
|
|
18
|
+
|
|
19
|
+
#����������� port:����M�˿ڣ�
|
|
20
|
+
def reset_motor_encoder(port:bytes) -> Optional[bytes]:
|
|
21
|
+
motor_str=[0xA0, 0x01, 0x03, 0xBE]
|
|
22
|
+
motor_str[0]=0XA0+port
|
|
23
|
+
response = base_driver.single_operate_sensor(motor_str)
|
|
21
24
|
if response:
|
|
22
25
|
return 0
|
|
23
26
|
else:
|
|
24
27
|
return -1
|
|
25
28
|
|
|
26
|
-
|
|
27
|
-
def
|
|
29
|
+
#���﷽����� port:����M�˿ڣ�dir:0��1
|
|
30
|
+
def set_motor_direction(port:bytes,direc:bytes) -> Optional[bytes]:
|
|
31
|
+
motor_str=[0xA0, 0x01, 0x06, 0x71, 0x00, 0xBE]
|
|
32
|
+
motor_str[0]=0XA0+port
|
|
33
|
+
motor_str[4]=direc
|
|
34
|
+
response = base_driver.single_operate_sensor(motor_str)
|
|
35
|
+
if response:
|
|
36
|
+
return 0
|
|
37
|
+
else:
|
|
38
|
+
return -1
|
|
39
|
+
|
|
40
|
+
#�����ٶ�ת�� port:����M�˿ڣ�speed:-100~100
|
|
41
|
+
def set_motor(port:bytes,speed:int) -> Optional[bytes]:
|
|
28
42
|
motor_str=[0xA0, 0x01, 0x02, 0x71, 0x00, 0xBE]
|
|
29
43
|
motor_str[0]=0XA0+port
|
|
30
|
-
|
|
44
|
+
if speed>100:
|
|
45
|
+
m_par=100
|
|
46
|
+
elif speed>=0 and speed<=100:
|
|
47
|
+
m_par=speed
|
|
48
|
+
elif speed<-100:
|
|
49
|
+
m_par=156
|
|
50
|
+
elif speed<=0 and speed>=-100:
|
|
51
|
+
m_par=256+speed
|
|
52
|
+
|
|
53
|
+
motor_str[4]=m_par
|
|
54
|
+
|
|
31
55
|
response = base_driver.single_operate_sensor(motor_str)
|
|
32
56
|
if response:
|
|
33
57
|
return 0
|
|
34
58
|
else:
|
|
35
59
|
return -1
|
|
36
60
|
|
|
37
|
-
|
|
38
|
-
def
|
|
61
|
+
#����ֹͣ port:����M�˿ڣ�
|
|
62
|
+
def set_motor_stop(port:bytes) -> Optional[bytes]:
|
|
63
|
+
motor_str=[0xA0, 0x01, 0x0B, 0xBE]
|
|
64
|
+
motor_str[0]=0XA0+port
|
|
65
|
+
response = base_driver.single_operate_sensor(motor_str)
|
|
66
|
+
if response:
|
|
67
|
+
return 0
|
|
68
|
+
else:
|
|
69
|
+
return -1
|
|
70
|
+
|
|
71
|
+
#���������� port:����M�˿ڣ�speed:-100~100��code:0~65535
|
|
72
|
+
def set_motor_angle(port:bytes,speed:int,degree:int) -> Optional[bytes]:
|
|
39
73
|
motor_str=[0xA0, 0x01, 0x04, 0x81, 0x00, 0x81, 0x00, 0x00, 0xBE]
|
|
40
74
|
motor_str[0]=0XA0+port
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
75
|
+
|
|
76
|
+
if speed>100:
|
|
77
|
+
m_par=100
|
|
78
|
+
elif speed>=0 and speed<=100:
|
|
79
|
+
m_par=speed
|
|
80
|
+
elif speed<-100:
|
|
81
|
+
m_par=156
|
|
82
|
+
elif speed<=0 and speed>=-100:
|
|
83
|
+
m_par=256+speed
|
|
84
|
+
|
|
85
|
+
motor_str[4]=m_par
|
|
86
|
+
motor_str[6]=degree//256
|
|
87
|
+
motor_str[7]=degree%256
|
|
44
88
|
response = base_driver.single_operate_sensor(motor_str)
|
|
45
89
|
if response:
|
|
46
90
|
return 0
|
|
47
91
|
else:
|
|
48
92
|
return -1
|
|
49
93
|
|
|
50
|
-
|
|
51
|
-
def
|
|
52
|
-
motor_str=[0xA0, 0x01,
|
|
94
|
+
#���ﶨʱת�� port:����M�˿ڣ�speed:-100~100��second:1~256
|
|
95
|
+
def set_motor_second(port:bytes,speed:int,second:bytes) -> Optional[bytes]:
|
|
96
|
+
motor_str=[0xA0, 0x01, 0x08, 0x81, 0x00, 0x71, 0x00, 0xBE]
|
|
53
97
|
motor_str[0]=0XA0+port
|
|
54
|
-
|
|
98
|
+
|
|
99
|
+
if speed>100:
|
|
100
|
+
m_par=100
|
|
101
|
+
elif speed>=0 and speed<=100:
|
|
102
|
+
m_par=speed
|
|
103
|
+
elif speed<-100:
|
|
104
|
+
m_par=156
|
|
105
|
+
elif speed<=0 and speed>=-100:
|
|
106
|
+
m_par=256+speed
|
|
107
|
+
|
|
108
|
+
motor_str[4]=m_par
|
|
109
|
+
motor_str[6]=second
|
|
110
|
+
response = base_driver.single_operate_sensor(motor_str)
|
|
111
|
+
if response:
|
|
112
|
+
return 0
|
|
113
|
+
else:
|
|
114
|
+
return -1
|
|
115
|
+
|
|
116
|
+
#���ﶨ��ת�� port:����M�˿ڣ�speed:-100~100
|
|
117
|
+
def set_motor_constspeed(port:bytes,speed:int) -> Optional[bytes]:
|
|
118
|
+
motor_str=[0xA0, 0x01, 0x09, 0x71, 0x00, 0xBE]
|
|
119
|
+
motor_str[0]=0XA0+port
|
|
120
|
+
|
|
121
|
+
if speed>100:
|
|
122
|
+
m_par=100
|
|
123
|
+
elif speed>=0 and speed<=100:
|
|
124
|
+
m_par=speed
|
|
125
|
+
elif speed<-100:
|
|
126
|
+
m_par=156
|
|
127
|
+
elif speed<=0 and speed>=-100:
|
|
128
|
+
m_par=256+speed
|
|
129
|
+
|
|
130
|
+
motor_str[4]=m_par
|
|
131
|
+
|
|
55
132
|
response = base_driver.single_operate_sensor(motor_str)
|
|
56
133
|
if response:
|
|
57
134
|
return 0
|
|
58
135
|
else:
|
|
59
136
|
return -1
|
|
137
|
+
|
|
138
|
+
#��������ȡ port:����M�˿ڣ�
|
|
139
|
+
def get_motor_speed(port:bytes) -> Optional[bytes]:
|
|
140
|
+
motor_str=[0xA0, 0x01, 0x10, 0xBE]
|
|
141
|
+
motor_str[0]=0XA0+port
|
|
142
|
+
response = base_driver.single_operate_sensor(motor_str)
|
|
143
|
+
if response:
|
|
144
|
+
code_data=response[4:-1]
|
|
145
|
+
code_num=int.from_bytes(code_data, byteorder='big', signed=True)
|
|
146
|
+
return code_num
|
|
147
|
+
else:
|
|
148
|
+
return -1
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
60
152
|
|
smartpi/servo.py
CHANGED
|
@@ -4,22 +4,145 @@ from typing import List, Optional
|
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# time.sleep(0.5)
|
|
10
|
-
# servo.servo_operate(1,1,180)
|
|
11
|
-
# time.sleep(0.5)
|
|
12
|
-
###############################################
|
|
13
|
-
|
|
14
|
-
#������� port:����P�˿ڣ�command:1:���� angle:�Ƕ�
|
|
15
|
-
def servo_operate(port:bytes,command:bytes,angle:bytes) -> Optional[bytes]:
|
|
7
|
+
#С������� port:����P�˿ڣ�angle:�Ƕ�0~270��
|
|
8
|
+
def steer_angle(port:bytes,angle:bytes) -> Optional[bytes]:
|
|
16
9
|
servo_str=[0xA0, 0x0E, 0x01, 0x71, 0x00, 0xBE]
|
|
17
10
|
servo_str[0]=0XA0+port
|
|
18
|
-
servo_str[2]=command
|
|
19
11
|
servo_str[4]=angle
|
|
20
12
|
response = base_driver.single_operate_sensor(servo_str)
|
|
21
13
|
if response:
|
|
22
14
|
return 0
|
|
23
15
|
else:
|
|
24
16
|
return -1
|
|
25
|
-
|
|
17
|
+
|
|
18
|
+
#С������� port:����P�˿ڣ�angle:�Ƕ�0~270��second:1~256
|
|
19
|
+
def steer_angle_delay(port:bytes,angle:bytes,second:bytes) -> Optional[bytes]:
|
|
20
|
+
servo_str=[0xA0, 0x10, 0x01, 0x81, 0x00, 0x00, 0x81, 0x00, 0xBE]
|
|
21
|
+
servo_str[0]=0XA0+port
|
|
22
|
+
servo_str[4]=angle//256
|
|
23
|
+
servo_str[5]=angle%256
|
|
24
|
+
servo_str[7]=second
|
|
25
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
26
|
+
if response:
|
|
27
|
+
return 0
|
|
28
|
+
else:
|
|
29
|
+
return -1
|
|
30
|
+
|
|
31
|
+
#BE-9528������� port:����P�˿ڣ�angle:�Ƕ�(0~360)��speed:�ٶ�(0~100)��
|
|
32
|
+
def set_angle_speed(port:bytes,angle:bytes,speed:bytes) -> Optional[bytes]:
|
|
33
|
+
servo_str=[0xA0, 0x0D, 0x01, 0x81, 0x00, 0x00, 0x81, 0x00, 0xBE]
|
|
34
|
+
servo_str[0]=0XA0+port
|
|
35
|
+
servo_str[4]=angle//256
|
|
36
|
+
servo_str[5]=angle%256
|
|
37
|
+
servo_str[7]=speed
|
|
38
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
39
|
+
if response:
|
|
40
|
+
return 0
|
|
41
|
+
else:
|
|
42
|
+
return -1
|
|
43
|
+
|
|
44
|
+
#���ֶ��ת�����Ƕ���ʱʱ�� port:����P�˿ڣ�angle:�Ƕ�(0~360)��ms:��ʱʱ��(0~65535)��
|
|
45
|
+
def set_angle_ms(port:bytes,angle:bytes,ms:int) -> Optional[bytes]:
|
|
46
|
+
servo_str=[0xA0, 0x11, 0x01, 0x81, 0x00, 0x00, 0x81, 0x00, 0x00, 0xBE]
|
|
47
|
+
servo_str[0]=0XA0+port
|
|
48
|
+
servo_str[4]=angle//256
|
|
49
|
+
servo_str[5]=angle%256
|
|
50
|
+
servo_str[7]=ms//256
|
|
51
|
+
servo_str[8]=ms%256
|
|
52
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
53
|
+
if response:
|
|
54
|
+
return 0
|
|
55
|
+
else:
|
|
56
|
+
return -1
|
|
57
|
+
|
|
58
|
+
#���ֶ����λ port:����P�˿ڣ�
|
|
59
|
+
def set_init(port:bytes) -> Optional[bytes]:
|
|
60
|
+
servo_str=[0xA0, 0x12, 0x01, 0xBE]
|
|
61
|
+
servo_str[0]=0XA0+port
|
|
62
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
63
|
+
if response:
|
|
64
|
+
return 0
|
|
65
|
+
else:
|
|
66
|
+
return -1
|
|
67
|
+
|
|
68
|
+
#��ȡ���ֶ���Ƕ� port:����P�˿ڣ�
|
|
69
|
+
def get_angle(port:bytes) -> Optional[bytes]:
|
|
70
|
+
servo_str=[0xA0, 0x13, 0x01, 0xBE]
|
|
71
|
+
servo_str[0]=0XA0+port
|
|
72
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
73
|
+
if response:
|
|
74
|
+
angle_data=response[4:-1]
|
|
75
|
+
angle_num=int.from_bytes(angle_data, byteorder='big', signed=True)
|
|
76
|
+
return angle_num
|
|
77
|
+
else:
|
|
78
|
+
return -1
|
|
79
|
+
|
|
80
|
+
#���ֶ���ٶ�ת�� port:����P�˿ڣ�
|
|
81
|
+
def set_speed(port:bytes,speed:int) -> Optional[bytes]:
|
|
82
|
+
servo_str=[0xA0, 0x14, 0x01, 0x71, 0x00, 0xBE]
|
|
83
|
+
servo_str[0]=0XA0+port
|
|
84
|
+
if speed>100:
|
|
85
|
+
m_par=100
|
|
86
|
+
elif speed>=0 and speed<=100:
|
|
87
|
+
m_par=speed
|
|
88
|
+
elif speed<-100:
|
|
89
|
+
m_par=156
|
|
90
|
+
elif speed<=0 and speed>=-100:
|
|
91
|
+
m_par=256+speed
|
|
92
|
+
|
|
93
|
+
servo_str[4]=m_par
|
|
94
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
95
|
+
if response:
|
|
96
|
+
return 0
|
|
97
|
+
else:
|
|
98
|
+
return -1
|
|
99
|
+
|
|
100
|
+
#���ֶ������ת�� port:����P�˿ڣ�code:����(0~65535)��speed:�ٶ�(-100~100)��
|
|
101
|
+
def set_code_speed(port:bytes,code:int,speed:int) -> Optional[bytes]:
|
|
102
|
+
servo_str=[0xA0, 0x15, 0x01, 0x81, 0x00, 0x00, 0x71, 0x00, 0xBE]
|
|
103
|
+
servo_str[0]=0XA0+port
|
|
104
|
+
|
|
105
|
+
servo_str[4]=code//256
|
|
106
|
+
servo_str[5]=code%256
|
|
107
|
+
|
|
108
|
+
if speed>100:
|
|
109
|
+
m_par=100
|
|
110
|
+
elif speed>=0 and speed<=100:
|
|
111
|
+
m_par=speed
|
|
112
|
+
elif speed<-100:
|
|
113
|
+
m_par=156
|
|
114
|
+
elif speed<=0 and speed>=-100:
|
|
115
|
+
m_par=256+speed
|
|
116
|
+
servo_str[7]=m_par
|
|
117
|
+
|
|
118
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
119
|
+
if response:
|
|
120
|
+
return 0
|
|
121
|
+
else:
|
|
122
|
+
return -1
|
|
123
|
+
|
|
124
|
+
#���ֶ������ֵ���� port:����P�˿ڣ�
|
|
125
|
+
def reset_encode(port:bytes) -> Optional[bytes]:
|
|
126
|
+
servo_str=[0xA0, 0x16, 0x01, 0xBE]
|
|
127
|
+
servo_str[0]=0XA0+port
|
|
128
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
129
|
+
if response:
|
|
130
|
+
return 0
|
|
131
|
+
else:
|
|
132
|
+
return -1
|
|
133
|
+
|
|
134
|
+
#��ȡ���ֶ������ֵ port:����P�˿ڣ�
|
|
135
|
+
def get_encoder(port:bytes) -> Optional[bytes]:
|
|
136
|
+
servo_str=[0xA0, 0x17, 0x01, 0xBE]
|
|
137
|
+
servo_str[0]=0XA0+port
|
|
138
|
+
response = base_driver.single_operate_sensor(servo_str)
|
|
139
|
+
if response:
|
|
140
|
+
code_data=response[4:-1]
|
|
141
|
+
code_num=int.from_bytes(code_data, byteorder='big', signed=True)
|
|
142
|
+
return code_num
|
|
143
|
+
else:
|
|
144
|
+
return -1
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
smartpi/temperature.py
CHANGED
|
@@ -4,15 +4,14 @@ from typing import List, Optional
|
|
|
4
4
|
from smartpi import base_driver
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
#�¶ȶ�ȡ port:����P�˿ڣ�
|
|
9
8
|
def get_value(port:bytes) -> Optional[bytes]:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
response = base_driver.single_operate_sensor(
|
|
9
|
+
temp_str=[0xA0, 0x0C, 0x01, 0x71, 0x00, 0xBE]
|
|
10
|
+
temp_str[0]=0XA0+port
|
|
11
|
+
temp_str[4]=0
|
|
12
|
+
response = base_driver.single_operate_sensor(temp_str)
|
|
14
13
|
if response:
|
|
15
|
-
return
|
|
14
|
+
return response[4]
|
|
16
15
|
else:
|
|
17
16
|
return -1
|
|
18
17
|
|
smartpi/touch_sensor.py
CHANGED
smartpi/ultrasonic.py
CHANGED
|
@@ -2,17 +2,6 @@
|
|
|
2
2
|
import time
|
|
3
3
|
from typing import List, Optional
|
|
4
4
|
from smartpi import base_driver
|
|
5
|
-
|
|
6
|
-
#��������ȡ port:����P�˿ڣ�command:1:��ȡ��
|
|
7
|
-
#def get_value(port:bytes,command:bytes) -> Optional[bytes]:
|
|
8
|
-
# ultrasonic_str=[0xA0, 0x06, 0x00, 0xBE]
|
|
9
|
-
# ultrasonic_str[0]=0XA0+port
|
|
10
|
-
# ultrasonic_str[2]=command
|
|
11
|
-
# response = base_driver.single_operate_sensor(ultrasonic_str)
|
|
12
|
-
# if response:
|
|
13
|
-
# return 0
|
|
14
|
-
# else:
|
|
15
|
-
# return -1
|
|
16
5
|
|
|
17
6
|
|
|
18
7
|
def get_value(port:bytes) -> Optional[bytes]:
|
|
@@ -21,7 +10,9 @@ def get_value(port:bytes) -> Optional[bytes]:
|
|
|
21
10
|
ultrasonic_str[2]=1
|
|
22
11
|
response = base_driver.single_operate_sensor(ultrasonic_str)
|
|
23
12
|
if response:
|
|
24
|
-
|
|
13
|
+
distance_data=response[4:-1]
|
|
14
|
+
distance_num=int.from_bytes(distance_data, byteorder='big', signed=True)
|
|
15
|
+
return distance_num
|
|
25
16
|
else:
|
|
26
17
|
return -1
|
|
27
18
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: smartpi
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.4
|
|
4
4
|
Summary: A library use for H2-RCU
|
|
5
|
-
Author
|
|
5
|
+
Author: ZMROBO
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
7
7
|
Classifier: License :: OSI Approved :: MIT License
|
|
8
8
|
Classifier: Operating System :: OS Independent
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
smartpi/__init__.py,sha256=Pavr-N-hqEpqeTD1ck9SZw9vGtn_Ju7cbQF81qkkDxg,54
|
|
2
|
+
smartpi/base_driver.py,sha256=xnAfn8PjaJUhlFLxKRXDbtKY5nmp_yiDGtx4lyHEp9U,17441
|
|
3
|
+
smartpi/color_sensor.py,sha256=HJAUGO8CPaoodgLwgzx_LVdvf0MoG63fg91-Y5Qp3fk,446
|
|
4
|
+
smartpi/humidity.py,sha256=Y8vLrK8FD5hdR_KshQxka2ygfJcCbuWs48gGr7zBqu4,456
|
|
5
|
+
smartpi/led.py,sha256=f8K7ebHFy9kIlCLWKEyQbmPQv4z2TMTNGs1vaKOtMAs,495
|
|
6
|
+
smartpi/light_sensor.py,sha256=QdY5jB_yg0mh3r7eUBsULqAEmQgaQgaUQHnKR0z3FAs,1279
|
|
7
|
+
smartpi/motor.py,sha256=igk9OFJjsS4nq16Sfl8s1ok8qolALreTFWXUeuDmHi4,4424
|
|
8
|
+
smartpi/servo.py,sha256=NFaoiDPdgs6wUklNWhL175CHIF0dJSRNDyOYRfum1xM,4492
|
|
9
|
+
smartpi/temperature.py,sha256=FUSoR7FeLZ4a_xj7ej60jXqXbX1frUTz3wDXzSTkob8,418
|
|
10
|
+
smartpi/touch_sensor.py,sha256=Y491KYiQBljX3IAvldld3Z8nXkBOAqqx7cTXda3Y-tA,396
|
|
11
|
+
smartpi/ultrasonic.py,sha256=lGPJRxDZN_uIIxqFMUa715miuN7ZXoKJ9npD03dyuXU,539
|
|
12
|
+
smartpi-0.1.4.dist-info/METADATA,sha256=fevHCCy6ZRYLCt1tl8cHMi-eIC8WHRIMc768xVPaIzo,310
|
|
13
|
+
smartpi-0.1.4.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
14
|
+
smartpi-0.1.4.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
15
|
+
smartpi-0.1.4.dist-info/RECORD,,
|
smartpi/GUI.py
DELETED
|
File without changes
|
smartpi/move.py
DELETED
|
File without changes
|
smartpi/photosensitive.py
DELETED
|
File without changes
|
smartpi/trace.py
DELETED
|
File without changes
|
smartpi-0.1.2.dist-info/RECORD
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
smartpi/GUI.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
smartpi/__init__.py,sha256=xdzDVGW4Uw7PG44QR4hHh12hTBDzyxg6RujH2fQAjnM,54
|
|
3
|
-
smartpi/base_driver.py,sha256=EIJp-H02io5S09u7oQTxV8plIfCcf9yvFUxhwVPF0zc,17197
|
|
4
|
-
smartpi/color_sensor.py,sha256=COa4bh_yrcBMJbb-iFCf4k5fNwfEdpYvPdTbIwFis4M,101
|
|
5
|
-
smartpi/humidity.py,sha256=CJVjulD4Gk_c9iwy4zmaGLv-Ta6M00koDmR2qfahkZ4,446
|
|
6
|
-
smartpi/led.py,sha256=f8K7ebHFy9kIlCLWKEyQbmPQv4z2TMTNGs1vaKOtMAs,495
|
|
7
|
-
smartpi/light_sensor.py,sha256=PHonOg7d3POjZnB6uETHeOQk8dWszxNoMfn6u9Tl1ow,726
|
|
8
|
-
smartpi/motor.py,sha256=NPzDZ1kVpBu30JOntjcIqr8XslFu6nRehj31MROLCOY,1942
|
|
9
|
-
smartpi/move.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
smartpi/photosensitive.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
smartpi/servo.py,sha256=uoitiCWzh4dnfztpXXo5ABkGF-a3qdvXMxjlIBZZQaU,783
|
|
12
|
-
smartpi/temperature.py,sha256=p89_AYIeEQsF7UKKnTexOCIRNXipYKKZWrULqjKeMLM,426
|
|
13
|
-
smartpi/touch_sensor.py,sha256=MyzghSoTkwAGp2_uNemYKRu9zeR3A2PeW3f0S8su3SI,386
|
|
14
|
-
smartpi/trace.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
smartpi/ultrasonic.py,sha256=xdSZe6uyihbfaBLiGmFahKYXTsOgVailMyq5ZYHrlFU,768
|
|
16
|
-
smartpi-0.1.2.dist-info/METADATA,sha256=mTtF5nXDibfCDSOUZuDgkzFOGrWneydBRDMIk0-4XnI,340
|
|
17
|
-
smartpi-0.1.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
18
|
-
smartpi-0.1.2.dist-info/top_level.txt,sha256=PoLhUCmWAiQUg5UeN2fS-Y1iQyBbF2rdUlizXtpHGRQ,8
|
|
19
|
-
smartpi-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|