smartpi 1.1.3__py3-none-any.whl → 1.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__.pyc +0 -0
- smartpi/_gui.pyc +0 -0
- smartpi/ai_asr.pyc +0 -0
- smartpi/ai_llm.pyc +0 -0
- smartpi/ai_tts.pyc +0 -0
- smartpi/ai_vad.pyc +0 -0
- smartpi/audio.pyc +0 -0
- smartpi/base_driver.pyc +0 -0
- smartpi/camera.pyc +0 -0
- smartpi/color_sensor.pyc +0 -0
- smartpi/cw2015.pyc +0 -0
- smartpi/flash.pyc +0 -0
- smartpi/humidity.pyc +0 -0
- smartpi/led.pyc +0 -0
- smartpi/light_sensor.pyc +0 -0
- smartpi/local_model.pyc +0 -0
- smartpi/mcp_client.pyc +0 -0
- smartpi/mcp_fastmcp.pyc +0 -0
- smartpi/mcp_intent_recognizer.pyc +0 -0
- 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.pyc +0 -0
- smartpi/move.pyc +0 -0
- smartpi/onnx_hand_workflow.pyc +0 -0
- smartpi/onnx_image_workflow.pyc +0 -0
- smartpi/onnx_pose_workflow.pyc +0 -0
- smartpi/onnx_text_workflow.pyc +0 -0
- smartpi/onnx_voice_workflow.pyc +0 -0
- smartpi/posemodel/__init__.pyc +0 -0
- smartpi/posenet_utils.pyc +0 -0
- smartpi/rknn_hand_workflow.pyc +0 -0
- smartpi/rknn_image_workflow.pyc +0 -0
- smartpi/rknn_pose_workflow.pyc +0 -0
- smartpi/rknn_text_workflow.pyc +0 -0
- smartpi/rknn_voice_workflow.pyc +0 -0
- smartpi/servo.pyc +0 -0
- smartpi/temperature.pyc +0 -0
- 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.pyc +0 -0
- smartpi/trace.pyc +0 -0
- smartpi/ultrasonic.pyc +0 -0
- {smartpi-1.1.3.dist-info → smartpi-1.1.4.dist-info}/METADATA +1 -1
- smartpi-1.1.4.dist-info/RECORD +77 -0
- smartpi/__init__.py +0 -8
- 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__.py +0 -0
- smartpi/models/snakers4_silero-vad/__init__.py +0 -0
- smartpi/models/snakers4_silero-vad/hubconf.py +0 -56
- 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__.py +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__.py +0 -1
- smartpi/tencentcloud-speech-sdk-python/asr/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/asr/flash_recognizer.py +0 -178
- smartpi/tencentcloud-speech-sdk-python/asr/speech_recognizer.py +0 -311
- smartpi/tencentcloud-speech-sdk-python/common/__init__.py +0 -1
- smartpi/tencentcloud-speech-sdk-python/common/credential.py +0 -6
- smartpi/tencentcloud-speech-sdk-python/common/log.py +0 -16
- smartpi/tencentcloud-speech-sdk-python/common/utils.py +0 -7
- smartpi/tencentcloud-speech-sdk-python/soe/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/soe/speaking_assessment.py +0 -276
- smartpi/tencentcloud-speech-sdk-python/tts/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/tts/flowing_speech_synthesizer.py +0 -294
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer.py +0 -144
- smartpi/tencentcloud-speech-sdk-python/tts/speech_synthesizer_ws.py +0 -234
- smartpi/tencentcloud-speech-sdk-python/vc/__init__.py +0 -0
- smartpi/tencentcloud-speech-sdk-python/vc/speech_convertor_ws.py +0 -237
- smartpi/text_gte_model/__init__.py +0 -0
- smartpi/text_gte_model/config/__init__.py +0 -0
- smartpi/text_gte_model/gte/__init__.py +0 -0
- smartpi/touch_sensor.py +0 -16
- smartpi/trace.py +0 -120
- smartpi/ultrasonic.py +0 -20
- smartpi-1.1.3.dist-info/RECORD +0 -77
- {smartpi-1.1.3.dist-info → smartpi-1.1.4.dist-info}/WHEEL +0 -0
- {smartpi-1.1.3.dist-info → smartpi-1.1.4.dist-info}/top_level.txt +0 -0
smartpi/color_sensor.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
|
-
#��ɫ��ȡ ��������ֵ��1-��ɫ��2-��ɫ��3-��ɫ��4-��ɫ��5-��ɫ��6-��ɫ�� ��ȡ����-1
|
|
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
|
-
time.sleep(0.005)
|
|
12
|
-
response = base_driver.single_operate_sensor(color_str,0)
|
|
13
|
-
if response == None:
|
|
14
|
-
return None
|
|
15
|
-
else:
|
|
16
|
-
return response[4]
|
|
17
|
-
|
|
18
|
-
|
smartpi/cw2015.py
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
import os
|
|
3
|
-
import sys
|
|
4
|
-
import fcntl
|
|
5
|
-
import time
|
|
6
|
-
|
|
7
|
-
# I2C设备文件路径
|
|
8
|
-
I2C_DEV_PATH = "/dev/i2c-2" # 根据实际情况修改总线号
|
|
9
|
-
|
|
10
|
-
# I2C从设备地址
|
|
11
|
-
CW2015_ADDR = 0x62 # 7位地址
|
|
12
|
-
|
|
13
|
-
# I2C通信常量
|
|
14
|
-
I2C_SLAVE = 0x0703
|
|
15
|
-
I2C_SMBUS = 0x0720 # SMBus传输
|
|
16
|
-
|
|
17
|
-
# SMBus命令结构
|
|
18
|
-
class i2c_smbus_ioctl_data:
|
|
19
|
-
def __init__(self, read_write, command, size, data):
|
|
20
|
-
self.read_write = read_write # 0 = write, 1 = read
|
|
21
|
-
self.command = command # 寄存器地址
|
|
22
|
-
self.size = size # 数据大小
|
|
23
|
-
self.data = data # 数据指针
|
|
24
|
-
|
|
25
|
-
# 寄存器地址定义
|
|
26
|
-
VERSION = 0x00
|
|
27
|
-
VCELL_H = 0x02
|
|
28
|
-
VCELL_L = 0x03
|
|
29
|
-
SOC_B = 0x04
|
|
30
|
-
SOC = 0x05
|
|
31
|
-
RRT_H = 0x06
|
|
32
|
-
RRT_L = 0x07
|
|
33
|
-
CONFIG = 0x08
|
|
34
|
-
MOOD = 0x0A
|
|
35
|
-
|
|
36
|
-
class I2CDevice:
|
|
37
|
-
"""通过设备文件直接访问I2C设备"""
|
|
38
|
-
def __init__(self, device_path, device_addr):
|
|
39
|
-
"""
|
|
40
|
-
初始化I2C设备
|
|
41
|
-
:param device_path: I2C设备文件路径 (例如 "/dev/i2c-2")
|
|
42
|
-
:param device_addr: I2C从设备地址 (7位地址)
|
|
43
|
-
"""
|
|
44
|
-
self.device_path = device_path
|
|
45
|
-
self.device_addr = device_addr
|
|
46
|
-
self.fd = None
|
|
47
|
-
|
|
48
|
-
try:
|
|
49
|
-
# 打开设备文件
|
|
50
|
-
self.fd = os.open(device_path, os.O_RDWR)
|
|
51
|
-
# 设置从设备地址
|
|
52
|
-
fcntl.ioctl(self.fd, I2C_SLAVE, device_addr)
|
|
53
|
-
#print(f"成功打开 {device_path} 并设置地址 0x{device_addr:02X}")
|
|
54
|
-
except Exception as e:
|
|
55
|
-
print(f"打开I2C设备失败: {e}")
|
|
56
|
-
if self.fd:
|
|
57
|
-
os.close(self.fd)
|
|
58
|
-
sys.exit(1)
|
|
59
|
-
|
|
60
|
-
def __del__(self):
|
|
61
|
-
"""关闭设备文件"""
|
|
62
|
-
if self.fd:
|
|
63
|
-
os.close(self.fd)
|
|
64
|
-
|
|
65
|
-
def write_byte(self, reg_addr, value):
|
|
66
|
-
"""
|
|
67
|
-
向寄存器写入一个字节
|
|
68
|
-
:param reg_addr: 寄存器地址
|
|
69
|
-
:param value: 要写入的值
|
|
70
|
-
:return: 成功返回True,失败返回False
|
|
71
|
-
"""
|
|
72
|
-
try:
|
|
73
|
-
# 构造写入数据:寄存器地址 + 值
|
|
74
|
-
data = bytes([reg_addr, value])
|
|
75
|
-
os.write(self.fd, data)
|
|
76
|
-
return True
|
|
77
|
-
except Exception as e:
|
|
78
|
-
print(f"写入寄存器0x{reg_addr:02X}失败: {e}")
|
|
79
|
-
return False
|
|
80
|
-
|
|
81
|
-
def read_byte(self, reg_addr):
|
|
82
|
-
"""
|
|
83
|
-
从寄存器读取一个字节
|
|
84
|
-
:param reg_addr: 寄存器地址
|
|
85
|
-
:return: 读取到的字节值,失败返回0
|
|
86
|
-
"""
|
|
87
|
-
try:
|
|
88
|
-
# 先写入寄存器地址
|
|
89
|
-
os.write(self.fd, bytes([reg_addr]))
|
|
90
|
-
# 然后读取一个字节
|
|
91
|
-
value = os.read(self.fd, 1)
|
|
92
|
-
return value[0] if value else 0
|
|
93
|
-
except Exception as e:
|
|
94
|
-
print(f"读取寄存器0x{reg_addr:02X}失败: {e}")
|
|
95
|
-
return 0
|
|
96
|
-
|
|
97
|
-
def read_word(self, reg_addr):
|
|
98
|
-
"""
|
|
99
|
-
从寄存器读取两个字节(先高字节后低字节)
|
|
100
|
-
:param reg_addr: 寄存器地址(高字节寄存器)
|
|
101
|
-
:return: (高字节 << 8) | 低字节
|
|
102
|
-
"""
|
|
103
|
-
try:
|
|
104
|
-
# 先写入寄存器地址
|
|
105
|
-
os.write(self.fd, bytes([reg_addr]))
|
|
106
|
-
# 读取两个字节
|
|
107
|
-
data = os.read(self.fd, 2)
|
|
108
|
-
if len(data) == 2:
|
|
109
|
-
return (data[0] << 8) | data[1]
|
|
110
|
-
else:
|
|
111
|
-
return 0
|
|
112
|
-
except Exception as e:
|
|
113
|
-
print(f"读取寄存器0x{reg_addr:02X}失败: {e}")
|
|
114
|
-
return 0
|
|
115
|
-
|
|
116
|
-
class CW2015:
|
|
117
|
-
"""CW2015电池监测芯片驱动"""
|
|
118
|
-
def __init__(self, i2c_dev_path=I2C_DEV_PATH, i2c_addr=CW2015_ADDR):
|
|
119
|
-
"""
|
|
120
|
-
初始化CW2015
|
|
121
|
-
:param i2c_dev_path: I2C设备路径
|
|
122
|
-
:param i2c_addr: I2C地址
|
|
123
|
-
"""
|
|
124
|
-
self.device = I2CDevice(i2c_dev_path, i2c_addr)
|
|
125
|
-
|
|
126
|
-
def init(self):
|
|
127
|
-
"""初始化芯片配置"""
|
|
128
|
-
# 写入配置
|
|
129
|
-
if not self.device.write_byte(CONFIG, 0x50):
|
|
130
|
-
print("配置寄存器写入失败")
|
|
131
|
-
return False
|
|
132
|
-
if not self.device.write_byte(MOOD, 0x00):
|
|
133
|
-
print("模式寄存器写入失败")
|
|
134
|
-
return False
|
|
135
|
-
|
|
136
|
-
time.sleep(0.05) # 50ms延时
|
|
137
|
-
#print("CW2015初始化完成")
|
|
138
|
-
return True
|
|
139
|
-
|
|
140
|
-
def get_id(self):
|
|
141
|
-
"""获取芯片ID"""
|
|
142
|
-
return self.device.read_byte(VERSION)
|
|
143
|
-
|
|
144
|
-
def get_voltage(self):
|
|
145
|
-
"""读取电池电压(mV)"""
|
|
146
|
-
# 读取电压高字节寄存器
|
|
147
|
-
vh = self.device.read_byte(VCELL_H)
|
|
148
|
-
# 读取电压低字节寄存器
|
|
149
|
-
vl = self.device.read_byte(VCELL_L)
|
|
150
|
-
|
|
151
|
-
# 组合14位ADC值
|
|
152
|
-
adc_value = ((vh & 0x3F) << 8) | vl
|
|
153
|
-
# 转换为电压值 (305μV/LSB)
|
|
154
|
-
voltage = adc_value * 305 / 1000
|
|
155
|
-
return int(voltage)
|
|
156
|
-
|
|
157
|
-
def get_soc(self, mode=0):
|
|
158
|
-
"""读取电池剩余电量"""
|
|
159
|
-
if mode == 0:
|
|
160
|
-
return self.device.read_byte(SOC_B) # 百分比整数
|
|
161
|
-
else:
|
|
162
|
-
return self.device.read_byte(SOC) # 高精度值
|
|
163
|
-
|
|
164
|
-
def get_remaining_time(self):
|
|
165
|
-
"""获取剩余工作时间(分钟)"""
|
|
166
|
-
# 读取时间高字节寄存器
|
|
167
|
-
rh = self.device.read_byte(RRT_H)
|
|
168
|
-
# 读取时间低字节寄存器
|
|
169
|
-
rl = self.device.read_byte(RRT_L)
|
|
170
|
-
|
|
171
|
-
# 提取剩余时间(13位)
|
|
172
|
-
remaining_time = ((rh & 0x1F) << 8) | rl
|
|
173
|
-
return remaining_time
|
|
174
|
-
|
|
175
|
-
def get_alert_status(self):
|
|
176
|
-
"""获取告警状态"""
|
|
177
|
-
rh = self.device.read_byte(RRT_H)
|
|
178
|
-
return (rh >> 7) & 0x01
|
|
179
|
-
|
smartpi/flash.py
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import struct
|
|
3
|
-
import fcntl
|
|
4
|
-
|
|
5
|
-
# 配置文件路径 (当前目录下的flash.bin)
|
|
6
|
-
FLASH_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "/home/Interface/flash/flash.bin")
|
|
7
|
-
FLASH_FILE_2 = os.path.join(os.path.dirname(os.path.abspath(__file__)), "/home/Interface/flash/flash_2.bin")
|
|
8
|
-
|
|
9
|
-
DATA_SIZE = 2 # 每个数据2字节
|
|
10
|
-
TOTAL_SLOTS = 120 # 100个数据槽
|
|
11
|
-
|
|
12
|
-
def _init_flash_file():
|
|
13
|
-
"""初始化存储文件"""
|
|
14
|
-
if not os.path.exists(FLASH_FILE):
|
|
15
|
-
with open(FLASH_FILE, "wb") as f:
|
|
16
|
-
f.write(b'\x00' * DATA_SIZE * TOTAL_SLOTS)
|
|
17
|
-
|
|
18
|
-
def write(address, data):
|
|
19
|
-
"""
|
|
20
|
-
写入数据到指定地址
|
|
21
|
-
:param address: 地址编号 (1-100)
|
|
22
|
-
:param data: 要写入的整数数据 (2字节范围)
|
|
23
|
-
"""
|
|
24
|
-
if not 1 <= address <= TOTAL_SLOTS:
|
|
25
|
-
raise ValueError(f"地址必须在1-{TOTAL_SLOTS}范围内")
|
|
26
|
-
|
|
27
|
-
# 2字节数据范围: 0-65535 (0xFFFF)
|
|
28
|
-
if not 0 <= data <= 0xFFFF:
|
|
29
|
-
raise ValueError("数据必须在0-65535范围内")
|
|
30
|
-
|
|
31
|
-
_init_flash_file()
|
|
32
|
-
|
|
33
|
-
# 计算文件偏移量 (每个地址2字节)
|
|
34
|
-
offset = (address - 1) * DATA_SIZE
|
|
35
|
-
|
|
36
|
-
with open(FLASH_FILE, "r+b") as f:
|
|
37
|
-
# 使用文件锁确保写入安全
|
|
38
|
-
fcntl.flock(f, fcntl.LOCK_EX)
|
|
39
|
-
f.seek(offset)
|
|
40
|
-
# 将整数打包为2字节小端格式
|
|
41
|
-
f.write(struct.pack('<H', data))
|
|
42
|
-
f.flush()
|
|
43
|
-
fcntl.flock(f, fcntl.LOCK_UN)
|
|
44
|
-
|
|
45
|
-
def read(address):
|
|
46
|
-
"""
|
|
47
|
-
从指定地址读取数据
|
|
48
|
-
:param address: 地址编号 (1-100)
|
|
49
|
-
:return: 读取到的整数数据
|
|
50
|
-
"""
|
|
51
|
-
if not 1 <= address <= TOTAL_SLOTS:
|
|
52
|
-
raise ValueError(f"地址必须在1-{TOTAL_SLOTS}范围内")
|
|
53
|
-
|
|
54
|
-
_init_flash_file()
|
|
55
|
-
|
|
56
|
-
offset = (address - 1) * DATA_SIZE
|
|
57
|
-
|
|
58
|
-
with open(FLASH_FILE, "rb") as f:
|
|
59
|
-
fcntl.flock(f, fcntl.LOCK_SH) # 共享锁
|
|
60
|
-
f.seek(offset)
|
|
61
|
-
# 读取2字节并解包为整数
|
|
62
|
-
data_bytes = f.read(DATA_SIZE)
|
|
63
|
-
fcntl.flock(f, fcntl.LOCK_UN)
|
|
64
|
-
|
|
65
|
-
if len(data_bytes) != DATA_SIZE:
|
|
66
|
-
return 0 # 返回默认值0
|
|
67
|
-
|
|
68
|
-
return struct.unpack('<H', data_bytes)[0]
|
|
69
|
-
|
|
70
|
-
# 可选扩展功能
|
|
71
|
-
def erase_all():
|
|
72
|
-
"""擦除所有数据(重置为0)"""
|
|
73
|
-
with open(FLASH_FILE, "wb") as f:
|
|
74
|
-
f.write(b'\x00' * DATA_SIZE * TOTAL_SLOTS)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def _init_flash_file_2():
|
|
78
|
-
"""初始化存储文件"""
|
|
79
|
-
if not os.path.exists(FLASH_FILE_2):
|
|
80
|
-
with open(FLASH_FILE_2, "wb") as f:
|
|
81
|
-
f.write(b'\x00' * DATA_SIZE * TOTAL_SLOTS)
|
|
82
|
-
|
|
83
|
-
def write_2(address, data):
|
|
84
|
-
if not 1 <= address <= TOTAL_SLOTS:
|
|
85
|
-
raise ValueError(f"地址必须在1-{TOTAL_SLOTS}范围内")
|
|
86
|
-
|
|
87
|
-
# 2字节数据范围: 0-65535 (0xFFFF)
|
|
88
|
-
if not 0 <= data <= 0xFFFF:
|
|
89
|
-
raise ValueError("数据必须在0-65535范围内")
|
|
90
|
-
|
|
91
|
-
_init_flash_file_2()
|
|
92
|
-
|
|
93
|
-
# 计算文件偏移量 (每个地址2字节)
|
|
94
|
-
offset = (address - 1) * DATA_SIZE
|
|
95
|
-
|
|
96
|
-
with open(FLASH_FILE_2, "r+b") as f:
|
|
97
|
-
# 使用文件锁确保写入安全
|
|
98
|
-
fcntl.flock(f, fcntl.LOCK_EX)
|
|
99
|
-
f.seek(offset)
|
|
100
|
-
# 将整数打包为2字节小端格式
|
|
101
|
-
f.write(struct.pack('<H', data))
|
|
102
|
-
f.flush()
|
|
103
|
-
fcntl.flock(f, fcntl.LOCK_UN)
|
|
104
|
-
|
|
105
|
-
def read_2(address):
|
|
106
|
-
if not 1 <= address <= TOTAL_SLOTS:
|
|
107
|
-
raise ValueError(f"地址必须在1-{TOTAL_SLOTS}范围内")
|
|
108
|
-
|
|
109
|
-
_init_flash_file_2()
|
|
110
|
-
|
|
111
|
-
offset = (address - 1) * DATA_SIZE
|
|
112
|
-
|
|
113
|
-
with open(FLASH_FILE_2, "rb") as f:
|
|
114
|
-
fcntl.flock(f, fcntl.LOCK_SH) # 共享锁
|
|
115
|
-
f.seek(offset)
|
|
116
|
-
# 读取2字节并解包为整数
|
|
117
|
-
data_bytes = f.read(DATA_SIZE)
|
|
118
|
-
fcntl.flock(f, fcntl.LOCK_UN)
|
|
119
|
-
|
|
120
|
-
if len(data_bytes) != DATA_SIZE:
|
|
121
|
-
return 0 # 返回默认值0
|
|
122
|
-
|
|
123
|
-
return struct.unpack('<H', data_bytes)[0]
|
|
124
|
-
|
|
125
|
-
# 可选扩展功能
|
|
126
|
-
def erase_all_2():
|
|
127
|
-
"""擦除所有数据(重置为0)"""
|
|
128
|
-
with open(FLASH_FILE_2, "wb") as f:
|
|
129
|
-
f.write(b'\x00' * DATA_SIZE * TOTAL_SLOTS)
|
|
130
|
-
|
smartpi/humidity.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
|
-
|
|
7
|
-
#湿度读取 port:连接P端口;正常返回:湿度数据; 读取错误:-1
|
|
8
|
-
def get_value(port:bytes) -> Optional[bytes]:
|
|
9
|
-
humi_str=[0XA0, 0X0C, 0X01, 0X71, 0X00, 0XBE]
|
|
10
|
-
humi_str[0]=0XA0+port
|
|
11
|
-
humi_str[4]=0X01
|
|
12
|
-
time.sleep(0.005)
|
|
13
|
-
response = base_driver.single_operate_sensor(humi_str,0)
|
|
14
|
-
if response == None:
|
|
15
|
-
return None
|
|
16
|
-
else:
|
|
17
|
-
return response[4]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
smartpi/led.py
DELETED
|
@@ -1,19 +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�˿ڣ�command:0:�صƣ�1:�죻2:�̣�3:����4:�ƣ�5:�ϣ�6:�ࣻ7:�ף� �������أ�0; ��ȡ����-1
|
|
8
|
-
def set_color(port:bytes,command:bytes) -> Optional[bytes]:
|
|
9
|
-
color_lamp_str=[0xA0, 0x05, 0x00, 0xBE]
|
|
10
|
-
color_lamp_str[0]=0XA0+port
|
|
11
|
-
color_lamp_str[2]=command
|
|
12
|
-
# response = base_driver.single_operate_sensor(color_lamp_str,0)
|
|
13
|
-
time.sleep(0.005)
|
|
14
|
-
base_driver.write_data(0X01, 0X02, color_lamp_str)
|
|
15
|
-
# if response == None:
|
|
16
|
-
# return None
|
|
17
|
-
# else:
|
|
18
|
-
return 0
|
|
19
|
-
|
smartpi/light_sensor.py
DELETED
|
@@ -1,72 +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 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
|
-
|
|
18
|
-
#����ֵ��ȡ port:����P�˿ڣ� �������أ���ֵ����; ��ȡ����-1
|
|
19
|
-
def get_value(port:bytes) -> Optional[bytes]:
|
|
20
|
-
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
21
|
-
light_str[0]=0XA0+port
|
|
22
|
-
light_str[2]=0x01
|
|
23
|
-
time.sleep(0.005)
|
|
24
|
-
response = base_driver.single_operate_sensor(light_str,0)
|
|
25
|
-
if response == None:
|
|
26
|
-
return None
|
|
27
|
-
else:
|
|
28
|
-
light_data=response[4:-1]
|
|
29
|
-
light_num=int.from_bytes(light_data, byteorder='big', signed=True)
|
|
30
|
-
return light_num
|
|
31
|
-
|
|
32
|
-
#�����ֵ���� port:����P�˿ڣ� threshold�����õ���ֵ0~4000
|
|
33
|
-
def set_threshold(port:bytes,threshold:int) -> Optional[bytes]:
|
|
34
|
-
light_str=[0xA0, 0x02, 0x00, 0x81, 0x00, 0x00, 0xBE]
|
|
35
|
-
light_str[0]=0XA0+port
|
|
36
|
-
light_str[2]=0x04
|
|
37
|
-
light_str[4]=threshold//256
|
|
38
|
-
light_str[5]=threshold%256
|
|
39
|
-
time.sleep(0.005)
|
|
40
|
-
base_driver.write_data(0X01, 0X02, light_str)
|
|
41
|
-
# response = base_driver.single_operate_sensor(light_str,0)
|
|
42
|
-
# if response == None:
|
|
43
|
-
# return None
|
|
44
|
-
# else:
|
|
45
|
-
return 0
|
|
46
|
-
|
|
47
|
-
#�����ֵ��ȡ port:����P�˿ڣ�
|
|
48
|
-
def get_threshold(port:bytes) -> Optional[bytes]:
|
|
49
|
-
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
50
|
-
light_str[0]=0XA0+port
|
|
51
|
-
light_str[2]=0x05
|
|
52
|
-
time.sleep(0.005)
|
|
53
|
-
response = base_driver.single_operate_sensor(light_str,0)
|
|
54
|
-
if response == None:
|
|
55
|
-
return None
|
|
56
|
-
else:
|
|
57
|
-
light_data=response[4:-1]
|
|
58
|
-
light_num=int.from_bytes(light_data, byteorder='big', signed=True)
|
|
59
|
-
return light_num
|
|
60
|
-
|
|
61
|
-
#����ȡ��ǰֵ���趨��ֵ�ȽϺ��boolֵ port:����P�˿ڣ�
|
|
62
|
-
def get_bool_data(port:bytes) -> Optional[bytes]:
|
|
63
|
-
light_str=[0xA0, 0x02, 0x00, 0xBE]
|
|
64
|
-
light_str[0]=0XA0+port
|
|
65
|
-
light_str[2]=0x06
|
|
66
|
-
time.sleep(0.005)
|
|
67
|
-
response = base_driver.single_operate_sensor(light_str,0)
|
|
68
|
-
if response == None:
|
|
69
|
-
return None
|
|
70
|
-
else:
|
|
71
|
-
return response[4]
|
|
72
|
-
|