Compare commits
17 Commits
92b679b996
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| f420d19a6f | |||
|
|
6f2d24717d | ||
| babd667c5f | |||
|
|
c3a3338c8f | ||
| 8a49c3c832 | |||
|
|
ca8d89e9bb | ||
|
|
7ec7d8674f | ||
| e7a5ce0de2 | |||
|
|
c8a9323178 | ||
| aa618627df | |||
|
|
55a1398136 | ||
|
|
174cb4fb45 | ||
|
|
71ab4cc8d8 | ||
|
|
d2e375b305 | ||
|
|
5ba515d123 | ||
|
|
8c85390d1e | ||
|
|
72607b03a9 |
@@ -9,7 +9,7 @@ package com.laseroptek.raman.const
|
||||
|
||||
val HzTable_10_10 = mapOf(
|
||||
// Pulse Width = 0.5f
|
||||
Pair(0.5f, 0.5f) to KEY_BLUE,
|
||||
Pair(0.5f, 0.5f) to KEY_GREEN,
|
||||
Pair(0.5f, 0.6f) to KEY_BLUE,
|
||||
Pair(0.5f, 0.7f) to KEY_BLUE,
|
||||
Pair(0.5f, 0.8f) to KEY_BLUE,
|
||||
|
||||
@@ -24,7 +24,7 @@ val HzTable_5_5 = mapOf(
|
||||
Pair(0.5f,3.4f) to KEY_BLUE,
|
||||
Pair(0.5f,3.6f) to KEY_BLUE,
|
||||
Pair(0.5f,3.8f) to KEY_BLUE,
|
||||
Pair(0.5f,4.0f) to KEY_YELLOW,
|
||||
Pair(0.5f,4.0f) to KEY_BLUE,
|
||||
Pair(0.5f,4.2f) to KEY_YELLOW,
|
||||
Pair(0.5f,4.4f) to KEY_YELLOW,
|
||||
Pair(0.5f,4.6f) to KEY_YELLOW,
|
||||
|
||||
@@ -108,7 +108,7 @@ val HzTable_7_7 = mapOf(
|
||||
Pair(1.5f, 8.0f) to KEY_GRAY,
|
||||
|
||||
// Pulse Width = 3f
|
||||
Pair(3f, 1.1f) to KEY_RED,
|
||||
Pair(3f, 1.1f) to KEY_GRAY,
|
||||
Pair(3f, 1.2f) to KEY_GRAY,
|
||||
Pair(3f, 1.3f) to KEY_GRAY,
|
||||
Pair(3f, 1.4f) to KEY_GRAY,
|
||||
|
||||
@@ -61,7 +61,7 @@ const val MAX_Q_SWITCH_VALUE = 250.0f
|
||||
const val MAX_REFER1_VALUE = 99999999 // 8 byte ascii (ENERGY DETECT MEASURED VALUE)
|
||||
const val DEFAULT_REFER1_VALUE = 0 // initial state
|
||||
|
||||
const val DEFAULT_DCD_GAS_PRESSURE = 06.5f
|
||||
const val DEFAULT_DCD_GAS_PRESSURE = 08.0f
|
||||
const val DEFAULT_SPAY_DCD_TIME = 10
|
||||
const val DEFAULT_SPAY_DCD_DELAY = 10
|
||||
|
||||
@@ -461,17 +461,17 @@ val dcdLifeSpanAdjustLists = listOf( 0.5f, 0.7f, 0.9f, 1.0f, 1.1f, 1.2f )
|
||||
val dcdLifeSpanAdjustStringLists = dcdLifeSpanAdjustLists.map{ it.toString() }
|
||||
|
||||
val dcdSprayValues = listOf(10, 20, 30, 40, 50, 60, 70, 80, 90, 100).map{ it.toString() }
|
||||
val dcdDelayValues = listOf(10, 20, 30, 40, 50, 60, 70, 80, 90, 100).map{ it.toString() }
|
||||
val dcdDelayValues = listOf(10, 20, 30, 40).map{ it.toString() }
|
||||
|
||||
// default spray dcd list for options
|
||||
val SprayDcdList = listOf<SprayDcd>(
|
||||
SprayDcd(status = 0x44, sprayTime = 10, sprayDelay = 10), // default
|
||||
SprayDcd(status = 0x44, sprayTime = 10, sprayDelay = 10),
|
||||
SprayDcd(status = 0x44, sprayTime = 20, sprayDelay = 20),
|
||||
SprayDcd(status = 0x44, sprayTime = 30, sprayDelay = 20),
|
||||
SprayDcd(status = 0x44, sprayTime = 40, sprayDelay = 40),
|
||||
SprayDcd(status = 0x44, sprayTime = 50, sprayDelay = 50),
|
||||
SprayDcd(status = 0x44, sprayTime = 60, sprayDelay = 60),
|
||||
SprayDcd(status = 0x41, sprayTime = 10, sprayDelay = 10), // default
|
||||
SprayDcd(status = 0x41, sprayTime = 10, sprayDelay = 10),
|
||||
SprayDcd(status = 0x41, sprayTime = 20, sprayDelay = 10),
|
||||
SprayDcd(status = 0x41, sprayTime = 30, sprayDelay = 20),
|
||||
SprayDcd(status = 0x41, sprayTime = 40, sprayDelay = 20),
|
||||
SprayDcd(status = 0x41, sprayTime = 50, sprayDelay = 30),
|
||||
SprayDcd(status = 0x41, sprayTime = 60, sprayDelay = 30),
|
||||
)
|
||||
|
||||
val PresetList = listOf<Preset>(
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.laseroptek.raman.data.model.serial
|
||||
import com.laseroptek.raman.const.DEFAULT_DCD_GAS_PRESSURE
|
||||
|
||||
data class DcdGas(
|
||||
val status: Int = 0x41, // 1Byte(A(0x41): on, D(0x44): off, P(0x50): pressure)
|
||||
val status: Int = 0x50, // 1Byte(A(0x41): on, D(0x44): off, P(0x50): pressure)
|
||||
val pressure: Float = DEFAULT_DCD_GAS_PRESSURE, // Ascii 4Byte (xx.x): Pressure
|
||||
val ok: Int = 0x00, // 1Byte(N(0x4E): Not OK, O(0x00F): OK)/
|
||||
)
|
||||
|
||||
@@ -58,7 +58,7 @@ fun LifeTimeView(
|
||||
Spacer(modifier = Modifier.height(2.px.dp))
|
||||
|
||||
// Temp 0..7
|
||||
for (i in 0..lifeTimeTypes.size -1) {
|
||||
for (i in 0..lifeTimeTypes.size - 1) {
|
||||
val value = when (i) {
|
||||
0 -> lifeTime.lamp
|
||||
1 -> lifeTime.hp5x5
|
||||
|
||||
@@ -304,7 +304,7 @@ fun HomeScreen(
|
||||
pulseType = pulseType,
|
||||
handPieceType = handPiece.type,
|
||||
type = LaserStatusType.REPETITION,
|
||||
angle = if (pulseType == 0 || repetitionList.size < 2) 0f else repetitionAngle,
|
||||
angle = if (pulseType == 0 || repetitionList.isEmpty()) 0f else repetitionAngle,
|
||||
onChange = { angle ->
|
||||
if (handPiece.type == 0) {
|
||||
Toast.makeText(
|
||||
@@ -315,7 +315,7 @@ fun HomeScreen(
|
||||
return@LaserControlView
|
||||
}
|
||||
|
||||
if (pulseType == 0 || repetitionList.size < 2) {
|
||||
if (pulseType == 0 || repetitionList.isEmpty()) {
|
||||
//Toast.makeText(context, "Single pulse type (0 Hz)", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
mainViewModel.onChangeRepetition(angle)
|
||||
@@ -332,7 +332,7 @@ fun HomeScreen(
|
||||
return@LaserControlView
|
||||
}
|
||||
|
||||
if (pulseType == 0 || repetitionList.size < 2) {
|
||||
if (pulseType == 0 || repetitionList.isEmpty()) {
|
||||
//Toast.makeText(context, "Single pulse type (0 Hz)", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
//mainViewModel.onClickRepetition(state)
|
||||
|
||||
@@ -256,7 +256,11 @@ fun DcdSettingPopup(
|
||||
mainViewModel.setSelectedSprayDcdIndex(i)
|
||||
val optionValue = mainViewModel.sprayDcdList[i]
|
||||
mainViewModel.setSprayDcd(optionValue)
|
||||
mainViewModel.txPacket(READ_WRITE.WRITE, CMD.SPRAY_DCD, optionValue)
|
||||
mainViewModel.txPacket(
|
||||
READ_WRITE.WRITE,
|
||||
CMD.SPRAY_DCD,
|
||||
optionValue.copy(status = 0x41)
|
||||
)
|
||||
|
||||
scope.launch {
|
||||
mainViewModel.saveSprayDcdIndexToPreference()
|
||||
@@ -303,7 +307,11 @@ fun DcdSettingPopup(
|
||||
mainViewModel.setSelectedSprayDcdIndex(i)
|
||||
val optionValue = mainViewModel.sprayDcdList[i]
|
||||
mainViewModel.setSprayDcd(optionValue)
|
||||
mainViewModel.txPacket(READ_WRITE.WRITE, CMD.SPRAY_DCD, optionValue)
|
||||
mainViewModel.txPacket(
|
||||
READ_WRITE.WRITE,
|
||||
CMD.SPRAY_DCD,
|
||||
optionValue.copy(status = 0x41)
|
||||
)
|
||||
|
||||
scope.launch {
|
||||
mainViewModel.saveSprayDcdToPreference()
|
||||
@@ -603,6 +611,12 @@ fun DcdSettingPopup(
|
||||
sprayDcd
|
||||
)
|
||||
|
||||
mainViewModel.txPacket(
|
||||
READ_WRITE.WRITE,
|
||||
CMD.SPRAY_DCD,
|
||||
sprayDcd.copy(status = 0x41)
|
||||
)
|
||||
|
||||
mainViewModel.setSelectedSprayDcdIndex( selectedSprayDcdIndex )
|
||||
//mainViewModel.setSprayDcdList( mainViewModel.sprayDcdList )
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ fun DcdView(
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.width(45.px.dp)
|
||||
.width(55.px.dp)
|
||||
.fillMaxHeight()
|
||||
, horizontalAlignment = Alignment.CenterHorizontally
|
||||
, verticalArrangement = Arrangement.Center
|
||||
@@ -120,7 +120,7 @@ fun DcdView(
|
||||
)
|
||||
}
|
||||
|
||||
Spacer( Modifier.width(10.px.dp))
|
||||
Spacer( Modifier.width(5.px.dp))
|
||||
|
||||
VerticalDivider(
|
||||
color = Color(161,161,170),
|
||||
@@ -128,7 +128,7 @@ fun DcdView(
|
||||
modifier = Modifier.size(1.px.dp, 30.px.dp)
|
||||
)
|
||||
|
||||
Spacer( Modifier.width(10.px.dp))
|
||||
Spacer( Modifier.width(5.px.dp))
|
||||
|
||||
// Delay
|
||||
Timber.d("selectedSprayDcdIndex.value: ${selectedSprayDcdIndex}")
|
||||
|
||||
@@ -780,21 +780,25 @@ fun PresetLoadPopup(
|
||||
.noRippleClickable(onClick = {
|
||||
Timber.d("onClick - Preset Load")
|
||||
|
||||
val selectedPreset =
|
||||
presetViewModel.getPreset(selectedPresetIndex)
|
||||
val priority =
|
||||
selectedPreset?.priority ?: 0
|
||||
val selectedPreset = presetViewModel.getPreset(selectedPresetIndex)
|
||||
if (selectedPreset == null) {
|
||||
Timber.w("onClick - Preset Load: selectedPreset is null. index=$selectedPresetIndex")
|
||||
return@noRippleClickable
|
||||
}
|
||||
val priority = selectedPreset.priority
|
||||
|
||||
Timber.d("onClick - Preset Load ($priority)")
|
||||
|
||||
// if (priority > 0) { // TODO : 검증 필요
|
||||
if (priority > 0) {
|
||||
mainViewModel.setSelectedPresetIndex( priority )
|
||||
mainViewModel.applyPreset(priority)
|
||||
} else {
|
||||
// 우선순위가 NONE인 경우, 인덱스 설정 X
|
||||
mainViewModel.setSelectedPresetIndex(0)
|
||||
mainViewModel.applyPreset(selectedPreset)
|
||||
}
|
||||
presetViewModel.clearPreset()
|
||||
onClick.invoke(false)
|
||||
// } else {
|
||||
// Timber.d("SKIP - Preset Load ($priority)")
|
||||
// }
|
||||
})
|
||||
.size(40.px.dp)
|
||||
.background(Color.Transparent)
|
||||
|
||||
@@ -134,6 +134,7 @@ import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import kotlin.math.abs
|
||||
import javax.inject.Inject
|
||||
import kotlin.experimental.or
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
@@ -843,7 +844,7 @@ class MainViewModel @Inject constructor(
|
||||
txPacket(READ_WRITE.WRITE, CMD.DCD_GAS, dcdGas.value.copy(status = 0x50))
|
||||
|
||||
// tx SPRAY_DCD Write (DEFAULT VALUE)
|
||||
txPacket(READ_WRITE.WRITE, CMD.SPRAY_DCD, sprayDcd.value)
|
||||
txPacket(READ_WRITE.WRITE, CMD.SPRAY_DCD, sprayDcd.value.copy(status = 0x41))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,7 +1106,7 @@ class MainViewModel @Inject constructor(
|
||||
CMD.LASER_STATUS -> {
|
||||
val l = packet.data.toLaserStatus()
|
||||
setLaserStatus(l.copy())
|
||||
// on receuve laser on (or interval) increase count and save to pref.
|
||||
// on receive laser on (or interval) increase count and save to pref.
|
||||
// Laser On 패킷만 counting 하도록 변경 (2개 패킷 모두 수신 됨)
|
||||
if (_laserStatus.value.laserStatus == LASER_STATUS.LASER_ON /* || l.laserStatus == LASER_STATUS.INTERVAL */) {
|
||||
playBeepSound()
|
||||
@@ -1184,58 +1185,19 @@ class MainViewModel @Inject constructor(
|
||||
setEnergyControl(EnergyControl(0x03, 0x00))
|
||||
setEnergyMeasured(EnergyMeasured(0x04, 0x00, 0x00))
|
||||
|
||||
// hand piece 별 count 증가
|
||||
when (h.type) {
|
||||
1 -> { // hp 5x5
|
||||
setLifeTime(
|
||||
_lifeTime.value.copy(
|
||||
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}")
|
||||
}
|
||||
val connectedHandPieceLifeTime = when (h.type) {
|
||||
1 -> lifeTime.value.hp5x5
|
||||
2 -> lifeTime.value.hp7x7
|
||||
3 -> lifeTime.value.hp10x10
|
||||
4 -> lifeTime.value.hp12x12
|
||||
5 -> lifeTime.value.hp3x15
|
||||
else -> {
|
||||
Timber.d("unknwon hand piece type: ${h.type}")
|
||||
Timber.d("Unknown Hand-piece type: ${h.type}")
|
||||
return@launch
|
||||
}
|
||||
}
|
||||
Timber.d("HAND_PIECE lifetime: type=${h.type}, value=${connectedHandPieceLifeTime}, hpCount=${hpCount.value}")
|
||||
|
||||
|
||||
// hand piece가 변경 시점 에서, pref 테이블 값을 -> energyTable 로 로딩
|
||||
loadFluenceTable(handPiece.value.type)
|
||||
@@ -2081,28 +2043,58 @@ class MainViewModel @Inject constructor(
|
||||
Timber.d("preset: ${preset}")
|
||||
|
||||
val newPreset = if (preset == null) {
|
||||
val defaultPulseWidth = PulseDurations.first()
|
||||
Preset(
|
||||
handPieceType = handPiece.value.type,
|
||||
priority = priority,
|
||||
fluence = energyTable.value.getKey2ListForKey1(0.5f).first(),
|
||||
fluence = energyTable.value.getKey2ListForKey1(defaultPulseWidth).firstOrNull() ?: 0f,
|
||||
repetition = repetitionList.value.first(),
|
||||
pulseWidth = PulseDurations.first(),
|
||||
pulseWidth = defaultPulseWidth,
|
||||
)
|
||||
} else {
|
||||
preset
|
||||
}
|
||||
applyPreset(newPreset)
|
||||
}
|
||||
|
||||
val fluenceList = energyTable.value.getKey2ListForKey1(newPreset.pulseWidth)
|
||||
fun applyPreset(preset: Preset) {
|
||||
val newPreset = preset.copy()
|
||||
|
||||
val pulseStep = PulseDurations.indexOf(newPreset.pulseWidth).takeIf {it != -1} ?: 0
|
||||
val fluenceStep = fluenceList.indexOf(newPreset.fluence).takeIf {it != -1} ?: 0
|
||||
val repetitionStep = repetitionList.value.indexOf(newPreset.repetition).takeIf {it != -1} ?: 0
|
||||
val resolvedPulseWidth = PulseDurations[pulseStep]
|
||||
|
||||
// 프리셋의 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}")
|
||||
|
||||
val pulseAngle = pulseStep.stepToDegree(totalSteps = PulseDurations.size)
|
||||
val fluenceAngle = fluenceStep.stepToDegree(totalSteps = fluenceList.size)
|
||||
val repetitionAngle = repetitionStep.stepToDegree(totalSteps = repetitionList.value.size)
|
||||
val fluenceAngle = if (newFluenceList.isNotEmpty()) {
|
||||
fluenceStep.stepToDegree(totalSteps = newFluenceList.size)
|
||||
} else {
|
||||
0f
|
||||
}
|
||||
val repetitionAngle = repetitionIndexToAngle(
|
||||
index = repetitionStep,
|
||||
totalSteps = newRepetitionList.size,
|
||||
)
|
||||
|
||||
Timber.d("pulseStep: ${pulseStep} fluenceStep: ${fluenceStep} repetitionStep: ${repetitionStep}")
|
||||
|
||||
@@ -2132,30 +2124,35 @@ class MainViewModel @Inject constructor(
|
||||
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)
|
||||
val newHzType = hzTable.value.getValue(newPulseDuration, newFluence)
|
||||
val newHzType = hzTable.value.getValue(newPulseDuration, resolvedFluence)
|
||||
val newRepetitionList = RepetitionsByColorKey[newHzType] ?: RepetitionsByColorKey[KEY_YELLOW]!!
|
||||
if (newRepetitionList != repetitionList.value) {
|
||||
setRepetitionList(newRepetitionList)
|
||||
}
|
||||
|
||||
// Smartly preserve Repetition Angle
|
||||
// 4. Check if the old repetition value exists in the new list.
|
||||
val oldRepetitionIndex = if (currentRepetitionValue != null) {
|
||||
newRepetitionList.indexOf(currentRepetitionValue)
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
// 4. Resolve and apply repetition by value (not by old angle/index).
|
||||
val targetRepetition = currentRepetitionValue ?: 0f
|
||||
val resolvedRepetition = newRepetitionList.minByOrNull { abs(it - targetRepetition) } ?: 0f
|
||||
val resolvedRepetitionIndex = newRepetitionList.indexOf(resolvedRepetition).takeIf { it >= 0 } ?: 0
|
||||
|
||||
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.")
|
||||
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 {
|
||||
// If it doesn't exist, THEN reset the slider to the beginning.
|
||||
setRepetitionAngle(0f)
|
||||
Timber.d("Repetition value $currentRepetitionValue not supported in new list. Resetting angle.")
|
||||
Timber.d("Repetition list is empty. Resetting repetition angle to 0f.")
|
||||
}
|
||||
|
||||
// 5. Conditionally reset the fluence angle slider if needed
|
||||
@@ -2168,7 +2165,7 @@ class MainViewModel @Inject constructor(
|
||||
// 6. Any change invalidates the current preset selection.
|
||||
setSelectedPresetIndex(0)
|
||||
|
||||
Timber.d("Updated Laser Parameters: pulse=$newPulseDuration, fluence=$newFluence -> newRepListSize=${newRepetitionList.size}")
|
||||
Timber.d("Updated Laser Parameters: pulse=$newPulseDuration, fluence=$resolvedFluence -> newRepListSize=${newRepetitionList.size}")
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2188,13 +2185,16 @@ class MainViewModel @Inject constructor(
|
||||
setPulseAngle(newPulseStep.stepToDegree(totalSteps = PulseDurations.size))
|
||||
|
||||
val newPulseDuration = PulseDurations[newPulseStep]
|
||||
// When pulse duration changes via slider, we use the first available fluence for the new list.
|
||||
val firstFluence = energyTable.value.getKey2ListForKey1(newPulseDuration).firstOrNull() ?: 0f
|
||||
// Keep the current fluence value when pulse duration changes via slider.
|
||||
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 using the preserved fluence value.
|
||||
updateLaserParameters(
|
||||
newPulseDuration = newPulseDuration,
|
||||
newFluence = firstFluence,
|
||||
newFluence = currentFluence,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -2206,12 +2206,17 @@ class MainViewModel @Inject constructor(
|
||||
setPulseAngle(newStep.stepToDegree(totalSteps = PulseDurations.size))
|
||||
|
||||
val newPulseDuration = PulseDurations[newStep]
|
||||
val firstFluence = energyTable.value.getKey2ListForKey1(newPulseDuration).firstOrNull() ?: 0f
|
||||
// Keep the current fluence value when pulse duration changes via slider.
|
||||
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.
|
||||
updateLaserParameters(
|
||||
newPulseDuration = newPulseDuration,
|
||||
newFluence = firstFluence,
|
||||
newFluence = currentFluence,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -2254,8 +2259,12 @@ class MainViewModel @Inject constructor(
|
||||
|
||||
fun onChangeRepetition(angle: Float) {
|
||||
// This logic is simple and has no complex dependencies, so it can remain as is.
|
||||
if (angle != repetitionAngle.value) {
|
||||
setRepetitionAngle(angle)
|
||||
val normalizedAngle = repetitionIndexToAngle(
|
||||
index = angle.degreeToStep(totalSteps = repetitionList.value.size),
|
||||
totalSteps = repetitionList.value.size,
|
||||
)
|
||||
if (normalizedAngle != repetitionAngle.value) {
|
||||
setRepetitionAngle(normalizedAngle)
|
||||
}
|
||||
setSelectedPresetIndex(0)
|
||||
}
|
||||
@@ -2266,12 +2275,23 @@ class MainViewModel @Inject constructor(
|
||||
val newStep = if (state == UpDownState.Up) currentStep + 1 else currentStep - 1
|
||||
|
||||
if (newStep in repetitionList.value.indices) {
|
||||
val newRepetitionAngle = newStep.stepToDegree(totalSteps = repetitionList.value.size)
|
||||
val newRepetitionAngle = repetitionIndexToAngle(
|
||||
index = newStep,
|
||||
totalSteps = repetitionList.value.size,
|
||||
)
|
||||
setRepetitionAngle(newRepetitionAngle)
|
||||
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.
|
||||
* This prevents the "Skipped frames" caused by 30+ sequential bridge calls
|
||||
|
||||
Reference in New Issue
Block a user