import csv
import os
import time
if __name__ == '__main__':
f = open("result.csv", 'w',encoding='utf-8-sig',newline='' "")
csv_writer = csv.writer(f)
csv_writer.writerow(["get_voltage_now","get_input_current_now","get_voltage_now","get_current_now","get_capacity","get_temp","get_resistance_id","get_charge_type","get_real_type","get_charge_full","get_esr_actual"])
row_count = 1
while 1:
list_onerow = []
# 先判断是否开机
os.system("adb wait-for-usb-device")
r = os.popen("adb shell source /data/test.sh")
list_onerow = [r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),r.readline().replace("\n",""),]
# 追加到CSV
if list_onerow[0] != '':
csv_writer.writerow(list_onerow)
print(row_count)
row_count+=1
# time.sleep(1)
test.sh
cat /sys/class/power_supply/usb/voltage_now
cat /sys/class/power_supply/usb/input_current_now
cat /sys/class/power_supply/battery/voltage_now
cat /sys/class/power_supply/battery/current_now
cat /sys/class/power_supply/battery/capacity
cat /sys/class/power_supply/battery/temp
cat /sys/class/power_supply/bms/resistance_id
cat /sys/class/power_supply/battery/charge_type
cat /sys/class/power_supply/usb/real_type
cat /sys/class/power_supply/bms/charge_full
cat /sys/class/power_supply/bms/esr_actual