-
Notifications
You must be signed in to change notification settings - Fork 0
/
DWM1001.py
76 lines (59 loc) · 1.63 KB
/
DWM1001.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from serial import Serial
from datetime import datetime
import os, time, warnings
import pandas as pd
import kbhit, math
warnings.filterwarnings("ignore")
port = "/dev/ttyACM0"
def getDistance():
distList=[]
timeList=[]
lx = kbhit.lxTerm()
lx.start()
ser = Serial(port, 115200)
distIndex = 7
dateIndex = 0
timeCnt = 0
print("DWM1001 Start\n")
while True:
res = ser.readline()
dist= res.decode()[:len(res)-1].split(",")[distIndex]
if len(dist) == 0:
print("Data Stop")
timeCnt+=1
time.sleep(0.5)
continue
else:
if(timeCnt > 0):
print("Data Return")
timecnt = 0
date = datetime.now()
distList.append(dist[:len(dist)-1])
timeList.append(date)
print("[",date,"] ",dist)
if stopLogging(lx):
break
if timeCnt == 10:
print("Stop Loggin Enabled")
if stopLogging(lx):
break
lx.reset()
toDistCSV(timeList, distList)
def stopLogging(lx):
if lx.kbhit():
c = lx.getch()
c_ord = ord(c)
if c_ord == 32: # Spacebar
print("\nDWM1001 Stop")
return True
def toDistCSV(timeList, distList):
dwmDf = pd.DataFrame({'time': timeList, 'distance': distList})
now = datetime.now()
fileName = str(now.strftime('%Y-%m-%d %H:%M:%S'))+".csv"
os.chdir("dwm1001_csv/")
dwmDf.to_csv(fileName, index=False)
#os.chdir("../../")
def changeDir():
os.chdir("/home/pi/Documents/Python-RPI-RTLS")
changeDir()
getDistance()