6 Commits

Author SHA1 Message Date
StevenBuzzi
c1273bd924 Merge remote-tracking branch 'origin/feature/ISSUE-51' into feature/ISSUE-51
# Conflicts:
#	app/src/main/java/com/laseroptek/raman/ui/screens/main/MainViewModel.kt
2026-03-06 11:55:53 +09:00
StevenBuzzi
56c516dec7 Merge remote-tracking branch 'origin/feature/ISSUE-51' into feature/ISSUE-51
# Conflicts:
#	app/src/main/java/com/laseroptek/raman/ui/screens/main/MainViewModel.kt
2026-03-06 11:54:55 +09:00
StevenBuzzi
91b41e6a2f Merge remote-tracking branch 'origin/feature/ISSUE-51' into feature/ISSUE-51
# Conflicts:
#	app/src/main/java/com/laseroptek/raman/ui/screens/main/MainViewModel.kt
2026-03-06 11:46:46 +09:00
StevenBuzzi
1bc8beadda 1. DCD 설정 시 Packet 0x41 고정으로 전송하도록 수정
2. DCD 설정값 변경 후 ok 누르면 Packet 전송하여 설정되도록 수정
3. 부팅 시 DCD Packet 0x41 고정으로 전송하도록 수정
2026-03-06 11:44:47 +09:00
StevenBuzzi
8a5fa3309b 1. DCD Delay 설정 가능 범위 수정
2. DCD Pressure 설정 기본값 수정
2026-03-06 11:40:07 +09:00
StevenBuzzi
4d12d42ddc Home화면 내 DCD 숫자 표시 위치 및 크기 조정 2026-03-06 11:40:06 +09:00
8 changed files with 100 additions and 124 deletions

View File

@@ -9,7 +9,7 @@ package com.laseroptek.raman.const
val HzTable_10_10 = mapOf( val HzTable_10_10 = mapOf(
// Pulse Width = 0.5f // Pulse Width = 0.5f
Pair(0.5f, 0.5f) to KEY_GREEN, Pair(0.5f, 0.5f) to KEY_BLUE,
Pair(0.5f, 0.6f) to KEY_BLUE, Pair(0.5f, 0.6f) to KEY_BLUE,
Pair(0.5f, 0.7f) to KEY_BLUE, Pair(0.5f, 0.7f) to KEY_BLUE,
Pair(0.5f, 0.8f) to KEY_BLUE, Pair(0.5f, 0.8f) to KEY_BLUE,

View File

@@ -24,7 +24,7 @@ val HzTable_5_5 = mapOf(
Pair(0.5f,3.4f) to KEY_BLUE, Pair(0.5f,3.4f) to KEY_BLUE,
Pair(0.5f,3.6f) to KEY_BLUE, Pair(0.5f,3.6f) to KEY_BLUE,
Pair(0.5f,3.8f) to KEY_BLUE, Pair(0.5f,3.8f) to KEY_BLUE,
Pair(0.5f,4.0f) to KEY_BLUE, Pair(0.5f,4.0f) to KEY_YELLOW,
Pair(0.5f,4.2f) to KEY_YELLOW, Pair(0.5f,4.2f) to KEY_YELLOW,
Pair(0.5f,4.4f) to KEY_YELLOW, Pair(0.5f,4.4f) to KEY_YELLOW,
Pair(0.5f,4.6f) to KEY_YELLOW, Pair(0.5f,4.6f) to KEY_YELLOW,

View File

@@ -108,7 +108,7 @@ val HzTable_7_7 = mapOf(
Pair(1.5f, 8.0f) to KEY_GRAY, Pair(1.5f, 8.0f) to KEY_GRAY,
// Pulse Width = 3f // Pulse Width = 3f
Pair(3f, 1.1f) to KEY_GRAY, Pair(3f, 1.1f) to KEY_RED,
Pair(3f, 1.2f) to KEY_GRAY, Pair(3f, 1.2f) to KEY_GRAY,
Pair(3f, 1.3f) to KEY_GRAY, Pair(3f, 1.3f) to KEY_GRAY,
Pair(3f, 1.4f) to KEY_GRAY, Pair(3f, 1.4f) to KEY_GRAY,

View File

@@ -1,5 +1,5 @@
package com.laseroptek.raman.data.model.serial package com.laseroptek.raman.data.model.serial
data class HandPiece( data class HandPiece(
val type:Int = 0 // ascii (00 ~ 99) val type:Int = 1 // ascii (00 ~ 99)
) )

View File

@@ -58,7 +58,7 @@ fun LifeTimeView(
Spacer(modifier = Modifier.height(2.px.dp)) Spacer(modifier = Modifier.height(2.px.dp))
// Temp 0..7 // Temp 0..7
for (i in 0..lifeTimeTypes.size - 1) { for (i in 0..lifeTimeTypes.size -1) {
val value = when (i) { val value = when (i) {
0 -> lifeTime.lamp 0 -> lifeTime.lamp
1 -> lifeTime.hp5x5 1 -> lifeTime.hp5x5

View File

@@ -304,7 +304,7 @@ fun HomeScreen(
pulseType = pulseType, pulseType = pulseType,
handPieceType = handPiece.type, handPieceType = handPiece.type,
type = LaserStatusType.REPETITION, type = LaserStatusType.REPETITION,
angle = if (pulseType == 0 || repetitionList.isEmpty()) 0f else repetitionAngle, angle = if (pulseType == 0 || repetitionList.size < 2) 0f else repetitionAngle,
onChange = { angle -> onChange = { angle ->
if (handPiece.type == 0) { if (handPiece.type == 0) {
Toast.makeText( Toast.makeText(
@@ -315,7 +315,7 @@ fun HomeScreen(
return@LaserControlView return@LaserControlView
} }
if (pulseType == 0 || repetitionList.isEmpty()) { if (pulseType == 0 || repetitionList.size < 2) {
//Toast.makeText(context, "Single pulse type (0 Hz)", Toast.LENGTH_SHORT).show() //Toast.makeText(context, "Single pulse type (0 Hz)", Toast.LENGTH_SHORT).show()
} else { } else {
mainViewModel.onChangeRepetition(angle) mainViewModel.onChangeRepetition(angle)
@@ -332,7 +332,7 @@ fun HomeScreen(
return@LaserControlView return@LaserControlView
} }
if (pulseType == 0 || repetitionList.isEmpty()) { if (pulseType == 0 || repetitionList.size < 2) {
//Toast.makeText(context, "Single pulse type (0 Hz)", Toast.LENGTH_SHORT).show() //Toast.makeText(context, "Single pulse type (0 Hz)", Toast.LENGTH_SHORT).show()
} else { } else {
//mainViewModel.onClickRepetition(state) //mainViewModel.onClickRepetition(state)

View File

@@ -780,25 +780,21 @@ fun PresetLoadPopup(
.noRippleClickable(onClick = { .noRippleClickable(onClick = {
Timber.d("onClick - Preset Load") Timber.d("onClick - Preset Load")
val selectedPreset = presetViewModel.getPreset(selectedPresetIndex) val selectedPreset =
if (selectedPreset == null) { presetViewModel.getPreset(selectedPresetIndex)
Timber.w("onClick - Preset Load: selectedPreset is null. index=$selectedPresetIndex") val priority =
return@noRippleClickable selectedPreset?.priority ?: 0
}
val priority = selectedPreset.priority
Timber.d("onClick - Preset Load ($priority)") Timber.d("onClick - Preset Load ($priority)")
if (priority > 0) { // if (priority > 0) { // TODO : 검증 필요
mainViewModel.setSelectedPresetIndex( priority ) mainViewModel.setSelectedPresetIndex( priority )
mainViewModel.applyPreset(priority) mainViewModel.applyPreset(priority)
} else { presetViewModel.clearPreset()
// 우선순위가 NONE인 경우, 인덱스 설정 X onClick.invoke(false)
mainViewModel.setSelectedPresetIndex(0) // } else {
mainViewModel.applyPreset(selectedPreset) // Timber.d("SKIP - Preset Load ($priority)")
} // }
presetViewModel.clearPreset()
onClick.invoke(false)
}) })
.size(40.px.dp) .size(40.px.dp)
.background(Color.Transparent) .background(Color.Transparent)

View File

@@ -134,7 +134,6 @@ import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import timber.log.Timber import timber.log.Timber
import kotlin.math.abs
import javax.inject.Inject import javax.inject.Inject
import kotlin.experimental.or import kotlin.experimental.or
import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.milliseconds
@@ -1106,7 +1105,7 @@ class MainViewModel @Inject constructor(
CMD.LASER_STATUS -> { CMD.LASER_STATUS -> {
val l = packet.data.toLaserStatus() val l = packet.data.toLaserStatus()
setLaserStatus(l.copy()) setLaserStatus(l.copy())
// on receive laser on (or interval) increase count and save to pref. // on receuve laser on (or interval) increase count and save to pref.
// Laser On 패킷만 counting 하도록 변경 (2개 패킷 모두 수신 됨) // Laser On 패킷만 counting 하도록 변경 (2개 패킷 모두 수신 됨)
if (_laserStatus.value.laserStatus == LASER_STATUS.LASER_ON /* || l.laserStatus == LASER_STATUS.INTERVAL */) { if (_laserStatus.value.laserStatus == LASER_STATUS.LASER_ON /* || l.laserStatus == LASER_STATUS.INTERVAL */) {
playBeepSound() playBeepSound()
@@ -1185,19 +1184,58 @@ class MainViewModel @Inject constructor(
setEnergyControl(EnergyControl(0x03, 0x00)) setEnergyControl(EnergyControl(0x03, 0x00))
setEnergyMeasured(EnergyMeasured(0x04, 0x00, 0x00)) setEnergyMeasured(EnergyMeasured(0x04, 0x00, 0x00))
val connectedHandPieceLifeTime = when (h.type) { // hand piece 별 count 증가
1 -> lifeTime.value.hp5x5 when (h.type) {
2 -> lifeTime.value.hp7x7 1 -> { // hp 5x5
3 -> lifeTime.value.hp10x10 setLifeTime(
4 -> lifeTime.value.hp12x12 _lifeTime.value.copy(
5 -> lifeTime.value.hp3x15 hp5x5 = _lifeTime.value.hp5x5 + 1
)
)
saveLifeTimeToPreference()
Timber.d("_lifeTime (hp5x5): ${_lifeTime}")
}
2 -> {
setLifeTime(
_lifeTime.value.copy(
hp7x7 = _lifeTime.value.hp7x7 + 1
)
)
saveLifeTimeToPreference()
Timber.d("_lifeTime (hp7x7): ${_lifeTime}")
}
3 -> {
setLifeTime(
_lifeTime.value.copy(
hp10x10 = _lifeTime.value.hp10x10 + 1
)
)
saveLifeTimeToPreference()
Timber.d("_lifeTime (hp10x10): ${_lifeTime}")
}
4 -> {
setLifeTime(
_lifeTime.value.copy(
hp12x12 = _lifeTime.value.hp12x12 + 1
)
)
saveLifeTimeToPreference()
Timber.d("_lifeTime (hp12x12): ${_lifeTime}")
}
5 -> {
setLifeTime(
_lifeTime.value.copy(
hp3x15 = _lifeTime.value.hp3x15 + 1
)
)
saveLifeTimeToPreference()
Timber.d("_lifeTime (hp3x15): ${_lifeTime}")
}
else -> { else -> {
Timber.d("Unknown Hand-piece type: ${h.type}") Timber.d("unknwon hand piece type: ${h.type}")
return@launch return@launch
} }
} }
Timber.d("HAND_PIECE lifetime: type=${h.type}, value=${connectedHandPieceLifeTime}, hpCount=${hpCount.value}")
// hand piece가 변경 시점 에서, pref 테이블 값을 -> energyTable 로 로딩 // hand piece가 변경 시점 에서, pref 테이블 값을 -> energyTable 로 로딩
loadFluenceTable(handPiece.value.type) loadFluenceTable(handPiece.value.type)
@@ -2043,58 +2081,28 @@ class MainViewModel @Inject constructor(
Timber.d("preset: ${preset}") Timber.d("preset: ${preset}")
val newPreset = if (preset == null) { val newPreset = if (preset == null) {
val defaultPulseWidth = PulseDurations.first()
Preset( Preset(
handPieceType = handPiece.value.type, handPieceType = handPiece.value.type,
priority = priority, priority = priority,
fluence = energyTable.value.getKey2ListForKey1(defaultPulseWidth).firstOrNull() ?: 0f, fluence = energyTable.value.getKey2ListForKey1(0.5f).first(),
repetition = repetitionList.value.first(), repetition = repetitionList.value.first(),
pulseWidth = defaultPulseWidth, pulseWidth = PulseDurations.first(),
) )
} else { } else {
preset preset
} }
applyPreset(newPreset)
}
fun applyPreset(preset: Preset) { val fluenceList = energyTable.value.getKey2ListForKey1(newPreset.pulseWidth)
val newPreset = preset.copy()
val pulseStep = PulseDurations.indexOf(newPreset.pulseWidth).takeIf {it != -1} ?: 0 val pulseStep = PulseDurations.indexOf(newPreset.pulseWidth).takeIf {it != -1} ?: 0
val resolvedPulseWidth = PulseDurations[pulseStep] val fluenceStep = fluenceList.indexOf(newPreset.fluence).takeIf {it != -1} ?: 0
val repetitionStep = repetitionList.value.indexOf(newPreset.repetition).takeIf {it != -1} ?: 0
// 프리셋의 pulseWidth 기준으로 실제 사용 가능한 fluence 목록을 먼저 동기화한다.
val newFluenceList = energyTable.value.getKey2ListForKey1(resolvedPulseWidth)
if (newFluenceList != fluenceList.value) {
setFluenceList(newFluenceList)
}
// 프리셋 fluence가 정확히 없을 수 있으므로, 가장 가까운 값으로 보정한다.
val resolvedFluence = newFluenceList.minByOrNull { abs(it - newPreset.fluence) }
?: newFluenceList.firstOrNull()
?: 0f
val fluenceStep = newFluenceList.indexOf(resolvedFluence).takeIf { it != -1 } ?: 0
// 보정된 (pulseWidth, fluence) 조합으로 repetition 테이블을 다시 계산한다.
val hzType = hzTable.value.getValue(resolvedPulseWidth, resolvedFluence)
val newRepetitionList = RepetitionsByColorKey[hzType] ?: RepetitionsByColorKey[KEY_YELLOW]!!
if (newRepetitionList != repetitionList.value) {
setRepetitionList(newRepetitionList)
}
val repetitionStep = newRepetitionList.indexOf(newPreset.repetition).takeIf { it != -1 } ?: 0
Timber.d("pulseStep: ${pulseStep} fluenceStep: ${fluenceStep} repetitionStep: ${repetitionStep}") Timber.d("pulseStep: ${pulseStep} fluenceStep: ${fluenceStep} repetitionStep: ${repetitionStep}")
val pulseAngle = pulseStep.stepToDegree(totalSteps = PulseDurations.size) val pulseAngle = pulseStep.stepToDegree(totalSteps = PulseDurations.size)
val fluenceAngle = if (newFluenceList.isNotEmpty()) { val fluenceAngle = fluenceStep.stepToDegree(totalSteps = fluenceList.size)
fluenceStep.stepToDegree(totalSteps = newFluenceList.size) val repetitionAngle = repetitionStep.stepToDegree(totalSteps = repetitionList.value.size)
} else {
0f
}
val repetitionAngle = repetitionIndexToAngle(
index = repetitionStep,
totalSteps = newRepetitionList.size,
)
Timber.d("pulseStep: ${pulseStep} fluenceStep: ${fluenceStep} repetitionStep: ${repetitionStep}") Timber.d("pulseStep: ${pulseStep} fluenceStep: ${fluenceStep} repetitionStep: ${repetitionStep}")
@@ -2124,35 +2132,30 @@ class MainViewModel @Inject constructor(
setFluenceList(newFluenceList) setFluenceList(newFluenceList)
} }
// 2-1. Resolve and apply fluence by value (not by old angle/index).
val resolvedFluence = newFluenceList.minByOrNull { abs(it - newFluence) } ?: 0f
val resolvedFluenceIndex = newFluenceList.indexOf(resolvedFluence).takeIf { it >= 0 } ?: 0
if (newFluenceList.isNotEmpty()) {
setFluenceAngle(resolvedFluenceIndex.stepToDegree(totalSteps = newFluenceList.size))
}
// 3. Safely Update Repetition List (Prevents NullPointerException) // 3. Safely Update Repetition List (Prevents NullPointerException)
val newHzType = hzTable.value.getValue(newPulseDuration, resolvedFluence) val newHzType = hzTable.value.getValue(newPulseDuration, newFluence)
val newRepetitionList = RepetitionsByColorKey[newHzType] ?: RepetitionsByColorKey[KEY_YELLOW]!! val newRepetitionList = RepetitionsByColorKey[newHzType] ?: RepetitionsByColorKey[KEY_YELLOW]!!
if (newRepetitionList != repetitionList.value) { if (newRepetitionList != repetitionList.value) {
setRepetitionList(newRepetitionList) setRepetitionList(newRepetitionList)
} }
// 4. Resolve and apply repetition by value (not by old angle/index). // Smartly preserve Repetition Angle
val targetRepetition = currentRepetitionValue ?: 0f // 4. Check if the old repetition value exists in the new list.
val resolvedRepetition = newRepetitionList.minByOrNull { abs(it - targetRepetition) } ?: 0f val oldRepetitionIndex = if (currentRepetitionValue != null) {
val resolvedRepetitionIndex = newRepetitionList.indexOf(resolvedRepetition).takeIf { it >= 0 } ?: 0 newRepetitionList.indexOf(currentRepetitionValue)
if (newRepetitionList.isNotEmpty()) {
val resolvedRepetitionAngle = repetitionIndexToAngle(
index = resolvedRepetitionIndex,
totalSteps = newRepetitionList.size,
)
setRepetitionAngle(resolvedRepetitionAngle)
Timber.d("Resolved repetition by value: old=$currentRepetitionValue, new=$resolvedRepetition, angle=$resolvedRepetitionAngle")
} else { } else {
-1
}
if (oldRepetitionIndex != -1) {
// If the old value exists, set the slider to that position.
val preservedAngle = oldRepetitionIndex.stepToDegree(totalSteps = newRepetitionList.size)
setRepetitionAngle(preservedAngle)
Timber.d("Repetition value $currentRepetitionValue preserved at new angle $preservedAngle.")
} else {
// If it doesn't exist, THEN reset the slider to the beginning.
setRepetitionAngle(0f) setRepetitionAngle(0f)
Timber.d("Repetition list is empty. Resetting repetition angle to 0f.") Timber.d("Repetition value $currentRepetitionValue not supported in new list. Resetting angle.")
} }
// 5. Conditionally reset the fluence angle slider if needed // 5. Conditionally reset the fluence angle slider if needed
@@ -2165,7 +2168,7 @@ class MainViewModel @Inject constructor(
// 6. Any change invalidates the current preset selection. // 6. Any change invalidates the current preset selection.
setSelectedPresetIndex(0) setSelectedPresetIndex(0)
Timber.d("Updated Laser Parameters: pulse=$newPulseDuration, fluence=$resolvedFluence -> newRepListSize=${newRepetitionList.size}") Timber.d("Updated Laser Parameters: pulse=$newPulseDuration, fluence=$newFluence -> newRepListSize=${newRepetitionList.size}")
} }
/** /**
@@ -2185,16 +2188,13 @@ class MainViewModel @Inject constructor(
setPulseAngle(newPulseStep.stepToDegree(totalSteps = PulseDurations.size)) setPulseAngle(newPulseStep.stepToDegree(totalSteps = PulseDurations.size))
val newPulseDuration = PulseDurations[newPulseStep] val newPulseDuration = PulseDurations[newPulseStep]
// Keep the current fluence value when pulse duration changes via slider. // When pulse duration changes via slider, we use the first available fluence for the new list.
val currentFluenceStep = fluenceAngle.value.degreeToStep(totalSteps = fluenceList.value.size) val firstFluence = energyTable.value.getKey2ListForKey1(newPulseDuration).firstOrNull() ?: 0f
val currentFluence = fluenceList.value.getOrNull(currentFluenceStep)
?: energyTable.value.getKey2ListForKey1(newPulseDuration).firstOrNull()
?: 0f
// Call the centralized helper using the preserved fluence value. // Call the centralized helper, resetting the fluence slider.
updateLaserParameters( updateLaserParameters(
newPulseDuration = newPulseDuration, newPulseDuration = newPulseDuration,
newFluence = currentFluence, newFluence = firstFluence,
) )
} }
@@ -2206,17 +2206,12 @@ class MainViewModel @Inject constructor(
setPulseAngle(newStep.stepToDegree(totalSteps = PulseDurations.size)) setPulseAngle(newStep.stepToDegree(totalSteps = PulseDurations.size))
val newPulseDuration = PulseDurations[newStep] val newPulseDuration = PulseDurations[newStep]
// Keep the current fluence value when pulse duration changes via slider. val firstFluence = energyTable.value.getKey2ListForKey1(newPulseDuration).firstOrNull() ?: 0f
val currentFluenceStep = fluenceAngle.value.degreeToStep(totalSteps = fluenceList.value.size)
val currentFluence = fluenceList.value.getOrNull(currentFluenceStep)
?: energyTable.value.getKey2ListForKey1(newPulseDuration).firstOrNull()
?: 0f
// Call the centralized helper, resetting the fluence slider. // Call the centralized helper, resetting the fluence slider.
updateLaserParameters( updateLaserParameters(
newPulseDuration = newPulseDuration, newPulseDuration = newPulseDuration,
newFluence = currentFluence, newFluence = firstFluence,
) )
} }
} }
@@ -2259,12 +2254,8 @@ class MainViewModel @Inject constructor(
fun onChangeRepetition(angle: Float) { fun onChangeRepetition(angle: Float) {
// This logic is simple and has no complex dependencies, so it can remain as is. // This logic is simple and has no complex dependencies, so it can remain as is.
val normalizedAngle = repetitionIndexToAngle( if (angle != repetitionAngle.value) {
index = angle.degreeToStep(totalSteps = repetitionList.value.size), setRepetitionAngle(angle)
totalSteps = repetitionList.value.size,
)
if (normalizedAngle != repetitionAngle.value) {
setRepetitionAngle(normalizedAngle)
} }
setSelectedPresetIndex(0) setSelectedPresetIndex(0)
} }
@@ -2275,23 +2266,12 @@ class MainViewModel @Inject constructor(
val newStep = if (state == UpDownState.Up) currentStep + 1 else currentStep - 1 val newStep = if (state == UpDownState.Up) currentStep + 1 else currentStep - 1
if (newStep in repetitionList.value.indices) { if (newStep in repetitionList.value.indices) {
val newRepetitionAngle = repetitionIndexToAngle( val newRepetitionAngle = newStep.stepToDegree(totalSteps = repetitionList.value.size)
index = newStep,
totalSteps = repetitionList.value.size,
)
setRepetitionAngle(newRepetitionAngle) setRepetitionAngle(newRepetitionAngle)
setSelectedPresetIndex(0) setSelectedPresetIndex(0)
} }
} }
private fun repetitionIndexToAngle(index: Int, totalSteps: Int): Float {
return when {
totalSteps <= 0 -> 0f
totalSteps == 1 -> 270f
else -> index.stepToDegree(totalSteps = totalSteps)
}
}
/** /**
* Perform all heavy I/O in a single background block. * Perform all heavy I/O in a single background block.
* This prevents the "Skipped frames" caused by 30+ sequential bridge calls * This prevents the "Skipped frames" caused by 30+ sequential bridge calls