Created
October 7, 2012 02:40
-
-
Save shifei010/3846914 to your computer and use it in GitHub Desktop.
Measure Biopotential / ECG using Python on the Android Smartphone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://www.smartphonedaq.com/android-python-ecg.page | |
droid = android.Android() | |
droid.webViewShow('file:///sdcard/sl4a/scripts/graph.html') | |
loop=True | |
while loop: | |
e = droid.eventWaitFor('check').result | |
if (e['data']=='timer'): | |
... | |
# display results | |
data={} | |
data['hr']=shr | |
data['wf']=format4Flot(reading) | |
droid.eventPost("respond",json.dumps(data)) | |
else: | |
droid.makeToast(e['data']) | |
loop = not(e['data']=="quit") | |
graph.html | |
<script language="javascript" type="text/javascript" src="jquery.min.js"></script> | |
<script language="javascript" type="text/javascript" src="jquery.flot.min.js"></script> | |
<h1>ECG Graph</h1> | |
<div>Heart Rate (BPM): <div id="ehr" style="display: inline;"/></div> | |
<div id="egraph" style="width:300px;height:300px;"></div> | |
<div> | |
<button id="start" onClick='timerstart();'>Start</button> | |
<button id="stop" onClick='timerstop();'>Stop</button> | |
<button id="quit" onClick='quit();'>Quit</button> | |
</div> | |
<script type="text/javascript"> | |
var timerOn = 0; | |
var timerInterval = 2500; | |
var droid = new Android(); | |
var display = function(result) { | |
var json_data = eval("(" + result.data + ")"); | |
$.plot($("#egraph"), [json_data.wf]); | |
document.getElementById("ehr").innerHTML = json_data.hr; | |
} | |
droid.registerCallback("respond", display); | |
function timerstart(){ | |
droid.eventPost("check", "timer"); | |
timerOn = setInterval(function() { droid.eventPost("check", "timer"); }, timerInterval); | |
} | |
function timerstop(){ clearInterval(timerOn); droid.eventPost("check", "stop"); } | |
function quit(){ clearInterval(timerOn); droid.eventPost("check", "quit"); droid.dismiss();} | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment