subeen

hz계산 라즈베리파이 코드 수정

......@@ -48,7 +48,7 @@ def read_raw_data(addr):
value = value - 65536
return value
def start_record(data):
def start_record(data, timeData):
MPU_Init()
t = threading.currentThread()
print (" Reading Data of Gyroscope and Accelerometer")
......@@ -63,6 +63,8 @@ def start_record(data):
value=abs(acc_x+acc_y+acc_z)/10
data.append(value)
print(value)
if(time.time()>start_time+10):
if(time.time()>start_time+60):
break
end_time = time.time()
timeData.append(round(end_time-start_time,2))
\ No newline at end of file
......
......@@ -28,7 +28,7 @@
<h1>Haptic Data Recording</h1>
<p style="margin-top: 2%;">Subeen Kang & Jinhyeong Park</p>
<form method ="post" action="/record">
<button style="margin-top: 10%;" type="button" id="start" > START </button>
<button style="margin-top: 10%;" type="submit" id="start" > START </button>
</form>
</div>
<script type="module" src="{{url_for('static', filename = 'app.js')}}"></script>
......
......@@ -7,7 +7,7 @@
<title>Haptic Recording</title>
<link rel="stylesheet" href="{{url_for('static', filename = 'style.css')}}">
<style>
#stop {
#stop, #home {
width:100px;
background-color: #f8585b;
border: none;
......@@ -29,8 +29,11 @@
<h1>Converting...</h1>
<h1 style="margin-top: 2%; color:#f8585b;"id="clock">00:00</h1>
<form method ="post" action="/stop">
<button style="margin-top: 10%;" id="stop" type="button"> STOP </button>
</form>
<button style="margin-top: 10%;" id="stop" type="submit"> STOP </button>
</form>
<button style="margin-top: 10%; visibility: hidden;" id="home" type="button" onclick="location.href='/'"> HOME </button>
</div>
<script type="module" src="{{url_for('static', filename = 'app.js')}}"></script>
</body>
......@@ -57,6 +60,8 @@
function stopit(){
clearInterval(inter);
document.getElementById("home").style.visibility="visible";
document.getElementById("stop").style.visibility="hidden";
}
document.getElementById('stop').addEventListener('click', stopit);
......
......@@ -11,24 +11,29 @@ import time
app = Flask(__name__)
global data
global th
global timeData
timeData = []
data=[]
th = threading.Thread(target=acc_test_2.start_record,args=(data,))
th = threading.Thread(target=acc_test_2.start_record,args=(data,timeData,))
th.setDaemon(True)
@app.route('/')
def upload_main():
print(timeData)
return render_template('index.html')
@app.route('/record', methods=['GET','POST'])
def submit():
global th
global data
global timeData
print(threading.enumerate())
if not th.is_alive():
print('dead')
data=[]
th = threading.Thread(target=acc_test_2.start_record,args=(data,))
timeData=[]
th = threading.Thread(target=acc_test_2.start_record,args=(data,timeData,))
th.start()
......@@ -39,13 +44,14 @@ def stop():
th.do_run = False
th.join()
print("data length is " + str(len(data)))
print("timeData is " + str(timeData[0]))
r = upload(data)
return (r.content, r.status_code, r.headers.items())
def upload(datas):
params={'datas':datas}
url='http://192.168.0.25:80/upload'
params={'datas':datas, 'timeData':timeData[0]}
url='http://192.168.0.36:80/upload'
return requests.post(url,data =json.dumps(params))
......