diff --git a/app/src/main/java/com/example/medilightv2android/ui/views/monitoring/PiezoMonitoringView.kt b/app/src/main/java/com/example/medilightv2android/ui/views/monitoring/PiezoMonitoringView.kt index 8783e7e..38edc70 100644 --- a/app/src/main/java/com/example/medilightv2android/ui/views/monitoring/PiezoMonitoringView.kt +++ b/app/src/main/java/com/example/medilightv2android/ui/views/monitoring/PiezoMonitoringView.kt @@ -120,25 +120,39 @@ fun PiezoMonitoringView(appState: AppState) { } } - // 6ch BV estimation (center 4ch + lateral lr_ratio) - val bvResult = estimateBladderVolume6ch(allWalls) - if (bvResult != null) { - lastVolumeMl = bvResult.volumeMl - maxVolumeMl = maxOf(maxVolumeMl, bvResult.volumeMl) - Log.d("PiezoMonitor", "BV: ${"%.1f".format(bvResult.volumeMl)}ml (6ch, lr=${ - "%.2f".format(bvResult.lrRatio)}, ${bvResult.validChannels.size}ch)") - } else { - Log.d("PiezoMonitor", "BV: estimation failed (< 2 valid channels)") - } + // Count valid center channels (CH0~CH3) + val centerWallCount = (0..3).count { allWalls[it] != null } + val totalWallCount = allWalls.count { it != null } - // Log per-channel detail for (ch in analysisResult.channels) { if (ch.isValid && ch.result != null) { Log.d("PiezoMonitor", " CH${ch.channel}: ant=${ch.result.ant} post=${ch.result.post} urine=${ch.result.urineLen} score=${"%.1f".format(ch.result.score)}") } } + + if (centerWallCount >= 3) { + // 6ch BV estimation (center 4ch + lateral lr_ratio) + val bvResult = estimateBladderVolume6ch(allWalls) + if (bvResult != null) { + lastVolumeMl = bvResult.volumeMl + maxVolumeMl = maxOf(maxVolumeMl, bvResult.volumeMl) + Log.d("PiezoMonitor", "BV: ${"%.1f".format(bvResult.volumeMl)}ml (6ch, lr=${"%.2f".format(bvResult.lrRatio)}, center=${centerWallCount}/4)") + bleManager.debugLogger.measurementResult(bvResult.volumeMl, bvResult.lrRatio, totalWallCount, + (0..5).map { allWalls[it]?.let { w -> w.second - w.first } ?: 0 }) + } + } else if (centerWallCount > 0) { + Log.w("PiezoMonitor", "Insufficient center channels: $centerWallCount/4 (need 3+)") + bleManager.debugLogger.warn("BV_SKIP center=$centerWallCount/4 total=$totalWallCount/6") + android.widget.Toast.makeText(context, + "측정 부족 (${centerWallCount}/4채널) — 센서 위치를 조절해주세요", + android.widget.Toast.LENGTH_SHORT).show() + } } else { Log.d("PiezoMonitor", "No valid channels — volume unchanged") + bleManager.debugLogger.warn("BV_FAIL no valid channels") + android.widget.Toast.makeText(context, + "방광이 감지되지 않았습니다. 센서 접촉을 확인해주세요.", + android.widget.Toast.LENGTH_SHORT).show() } // Update level based on measured volume