V0.1
parent
29b747ac88
commit
4a4c472b63
@ -0,0 +1,134 @@
|
||||
import sqlite3
|
||||
import time
|
||||
def init():
|
||||
gear_cmd = 0
|
||||
auto_acc=0
|
||||
brk_open=0
|
||||
brk_change=0
|
||||
stop=0
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set gear_cmd='%s',auto_acc='%s',brk_open='%s',brk_change='%s' ,stop='%s'WHERE id = 1"%(
|
||||
gear_cmd,auto_acc,brk_open,brk_change,stop)
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
def gear_p():
|
||||
print('P')
|
||||
gear_cmd = 1
|
||||
auto_acc=0
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set gear_cmd='%s',auto_acc='%s' WHERE id = 1"%(gear_cmd,auto_acc)
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
|
||||
def gear_n():
|
||||
print('N')
|
||||
gear_cmd = 3 # n
|
||||
auto_acc=0
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set gear_cmd='%s',auto_acc='%s' WHERE id = 1"%(gear_cmd,auto_acc)
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
def gear_r():
|
||||
gear_cmd = 2 # r
|
||||
print('r')
|
||||
auto_acc = input("请输入油门深度:")
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set gear_cmd='%s',auto_acc='%s' WHERE id = 1"%(gear_cmd,auto_acc)
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
def gear_d():
|
||||
gear_cmd = 4 # r
|
||||
print('d')
|
||||
auto_acc = input("请输入油门深度:")
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set gear_cmd='%s',auto_acc='%s' WHERE id = 1"%(gear_cmd,auto_acc)
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
def shache():
|
||||
brk_open = 30
|
||||
brk_change=1
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set brk_open='%s',brk_change='%s' WHERE id = 1"%(brk_open,brk_change)
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
def shache2():
|
||||
brk_change=0
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set brk_change='%s' WHERE id = 1"%brk_change
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
def stop():
|
||||
stop=1
|
||||
db_file = "geardb.db"
|
||||
conn = sqlite3.connect(db_file)
|
||||
cur = conn.cursor()
|
||||
# sql='INSERT INTO geardb(id) VALUES(1);'
|
||||
sql = "update geardb set stop='%s' WHERE id = 1"%stop
|
||||
cur.execute(sql)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
conn.close()
|
||||
def main():
|
||||
while True:
|
||||
gear_change = int(input('请输入档位:\n'
|
||||
'1:P档\n'
|
||||
'2:R档\n'
|
||||
'3:N档\n'
|
||||
'4:D档\n'
|
||||
'5:刹车\n'
|
||||
'6:紧急停止\n'))
|
||||
if gear_change==1:
|
||||
gear_p()
|
||||
elif gear_change==3:
|
||||
gear_n()
|
||||
elif gear_change==2:
|
||||
gear_r()
|
||||
elif gear_change==4:
|
||||
gear_d()
|
||||
elif gear_change==5:
|
||||
shache()
|
||||
time.sleep(0.1)
|
||||
shache2()
|
||||
elif gear_change==6:
|
||||
stop()
|
||||
|
||||
else:
|
||||
print('请重新输入')
|
||||
if __name__=='__main__':
|
||||
init()
|
||||
main()
|
Loading…
Reference in New Issue