Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
araobp committed Sep 2, 2020
1 parent c8bbc44 commit 0b999b5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class AnalyzerActivity : AppCompatActivity() {

private fun updateFeatureFileCnt() {
val classLabel = classLabel()
textViewCnt.text = "${featureCollector.fileCntPerLabel(classLabel)}/${featureCollector.fileCnt()}"
textViewCnt.post {
textViewCnt.text =
"${featureCollector.fileCntPerLabel(classLabel)}/${featureCollector.fileCnt()}"
}
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -243,12 +246,6 @@ class AnalyzerActivity : AppCompatActivity() {
finish()
}

radioButtonSave.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
startSaving()
}
}

enableDumpWindow(toggleButtonDump.isChecked)
}

Expand All @@ -265,13 +262,12 @@ class AnalyzerActivity : AppCompatActivity() {
mOscilloscope?.update(data)
}
if (mSave) {
runOnUiThread {
if (featureCollector.add(data)) {
mSave = false
radioButtonSave.isChecked = false
radioButtonSave.isEnabled = true
updateFeatureFileCnt()
if (featureCollector.add(data)) {
mSave = false
textViewSave.post {
textViewSave.isEnabled = false
}
updateFeatureFileCnt()
}
}
}
Expand All @@ -296,8 +292,13 @@ class AnalyzerActivity : AppCompatActivity() {
}

private fun startSaving() {
radioButtonSave.isEnabled = false
featureCollector.getReady(classLabel(), FEATURE_COLLECTOR_ENTRIES, mProps.accelRange, mProps.gyroRange)
textViewSave.isEnabled = true
featureCollector.getReady(
classLabel(),
FEATURE_COLLECTOR_ENTRIES,
mProps.accelRange,
mProps.gyroRange
)
mSave = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import java.io.FileWriter

class FeatureCollector(val context: Context) {

companion object {
const val header = "sno,ax,ay,az,gx,gy,gz\r\n"
}

private var mMpu9250DataArray = ArrayList<Mpu9250Data>()

private var mClassLabel = "Unknown"
Expand Down Expand Up @@ -35,13 +39,13 @@ class FeatureCollector(val context: Context) {

private fun save(): Int {
var cnt = fileCntPerLabel(mClassLabel)
val fileName = "${mClassLabel}-${mAccelRange}-${mGyroRange}-$cnt.csv"
val fileName = "${mClassLabel}:${mAccelRange}:${mGyroRange}:$cnt.csv"
val file = File(context.filesDir, fileName)
val fileWriter = FileWriter(file)
fileWriter.append(header)
mMpu9250DataArray.forEach {
fileWriter.append(it.toCsv())
}
fileWriter.flush()
fileWriter.close()
return ++cnt
}
Expand Down
5 changes: 3 additions & 2 deletions android/mpu9250/app/src/main/res/layout/activity_analyzer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@
android:layout_height="wrap_content"
android:text="Edit" />

<RadioButton
android:id="@+id/radioButtonSave"
<TextView
android:id="@+id/textViewSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:text="Save" />

<TextView
Expand Down

0 comments on commit 0b999b5

Please sign in to comment.