Skip to content

Commit

Permalink
Saving data to file working perfectly, charts to work on
Browse files Browse the repository at this point in the history
  • Loading branch information
tainfante committed Sep 21, 2019
1 parent 208ec1a commit bc61db3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
14 changes: 11 additions & 3 deletions app/src/main/java/com/example/rehabapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MainActivity : AppCompatActivity(), ComFragment.ComFragmentInterface, Conn
private lateinit var chronometer: Chronometer
private var connectedDevice = ConnectDevice(this, this)
private val queueHandler = QueueHandler()
private val saveToFile = SaveToFile(this)
private val saveToFile = SaveToFile(this, this)


private var bluetoothAdapter: BluetoothAdapter? = null
Expand Down Expand Up @@ -124,8 +124,16 @@ class MainActivity : AppCompatActivity(), ComFragment.ComFragmentInterface, Conn
override fun onStartButtonClicked() {
connectedDevice.macAddress=macaddress
connectedDevice.execute()
saveToFile.createFile("eloelo.txt")
saveToFile.saveToFile()
val calendar = Calendar.getInstance()
val d = calendar.get(Calendar.DAY_OF_MONTH)
val mon = calendar.get(Calendar.MONTH)
val y = calendar.get(Calendar.YEAR)
val h = calendar.get(Calendar.HOUR_OF_DAY)
val m = calendar.get(Calendar.MINUTE)
val result = "$d:$mon:$y"+ "_"+"$h:$m"
saveToFile.createFile(result)
saveToFile.saveEmgToFile()
saveToFile.saveAccToFile()

}

Expand Down
68 changes: 63 additions & 5 deletions app/src/main/java/com/example/rehabapp/SaveToFile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,81 @@ package com.example.rehabapp

import android.content.Context
import java.io.File
import java.io.IOException

class SaveToFile(val context: Context) {
class SaveToFile(val context: Context, queueHandOuter: QueueHandOuter) {

private var file: File? = null
private var accfile: File? = null
private var emgfile: File? = null
private var directory: File? = null
private var queueHandOuter: QueueHandOuter? = null

init {
this.queueHandOuter = queueHandOuter
}

fun createFile(filename:String){

val path = context.getExternalFilesDir(null)
directory = File(path, "DATA")
val success = directory!!.mkdirs()
file = File(directory, filename)
accfile = File(directory, filename+"_acc.txt")
emgfile = File(directory, filename+"_emg.txt")

}
fun saveAccToFile(){

var accFrame: AccFrame
var accx: Float
var accy:Float
var accz: Float
var gyrx: Float
var gyry: Float
var gyrz: Float

val saveAccDataThread = Thread(Runnable {
while (true) {
try {

accFrame=queueHandOuter!!.giveMeTheAccQueue().take()
accx=accFrame.getAccX()
accy=accFrame.getAccY()
accz=accFrame.getAccZ()
gyrx=accFrame.getGyrX()
gyry=accFrame.getGyrY()
gyrz=accFrame.getGyrZ()
accfile?.appendText("$accx $accy $accz $gyrx $gyry $gyrz\n\r")

} catch (ex: IOException) {

}

}
})
saveAccDataThread.start()

}
fun saveToFile(){
fun saveEmgToFile(){

var rawEmg: Float
var filtredEmg: Float
var emgFrame: EmgFrame

val saveEmgDataThread = Thread(Runnable {
while (true) {
try {
emgFrame = queueHandOuter!!.giveMeTheEmgQueue().take()
rawEmg= emgFrame.getRawEmg()
filtredEmg=emgFrame.getFiltredEmg()
emgfile?.appendText("$rawEmg $filtredEmg\n\r")

} catch (ex: IOException) {

}

file?.appendText("eloelo")
}
})
saveEmgDataThread.start()

}
}

0 comments on commit bc61db3

Please sign in to comment.