import subprocess
执行 adb shell 命令并返回输出结果
def run_adb_shell_command(command):
result = subprocess.run([‘adb’, ‘shell’, command], capture_output=True, text=True)
return result.stdout.strip()
获取三个数字值并命名为 x, y, z
def get_acc_sensor_data():
# 执行命令序列
commands = [
‘cd /sys/class/sensors/acc_sensor/’,
‘echo 1 > enable’,
‘echo 10 > set_delay’,
‘echo 1 > sdc_config_disable’,
‘cat get_data’
]
for command in commands:
run_adb_shell_command(command)
# 获取数据并分别赋值给 x, y, z
data_output = run_adb_shell_command('cat get_data')
x, y, z = data_output.split()
return x, y, z
调用函数获取数据并赋值给变量
x, y, z = get_acc_sensor_data()