Compare commits
4 Commits
feature/IS
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| f420d19a6f | |||
|
|
6f2d24717d | ||
| babd667c5f | |||
|
|
c3a3338c8f |
@@ -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
|
||||||
|
|||||||
@@ -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.size < 2) 0f else repetitionAngle,
|
angle = if (pulseType == 0 || repetitionList.isEmpty()) 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.size < 2) {
|
if (pulseType == 0 || repetitionList.isEmpty()) {
|
||||||
//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.size < 2) {
|
if (pulseType == 0 || repetitionList.isEmpty()) {
|
||||||
//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)
|
||||||
|
|||||||
@@ -1106,7 +1106,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 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개 패킷 모두 수신 됨)
|
// 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,58 +1185,19 @@ class MainViewModel @Inject constructor(
|
|||||||
setEnergyControl(EnergyControl(0x03, 0x00))
|
setEnergyControl(EnergyControl(0x03, 0x00))
|
||||||
setEnergyMeasured(EnergyMeasured(0x04, 0x00, 0x00))
|
setEnergyMeasured(EnergyMeasured(0x04, 0x00, 0x00))
|
||||||
|
|
||||||
// hand piece 별 count 증가
|
val connectedHandPieceLifeTime = when (h.type) {
|
||||||
when (h.type) {
|
1 -> lifeTime.value.hp5x5
|
||||||
1 -> { // hp 5x5
|
2 -> lifeTime.value.hp7x7
|
||||||
setLifeTime(
|
3 -> lifeTime.value.hp10x10
|
||||||
_lifeTime.value.copy(
|
4 -> lifeTime.value.hp12x12
|
||||||
hp5x5 = _lifeTime.value.hp5x5 + 1
|
5 -> lifeTime.value.hp3x15
|
||||||
)
|
|
||||||
)
|
|
||||||
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("unknwon hand piece type: ${h.type}")
|
Timber.d("Unknown 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)
|
||||||
@@ -2130,11 +2091,10 @@ class MainViewModel @Inject constructor(
|
|||||||
} else {
|
} else {
|
||||||
0f
|
0f
|
||||||
}
|
}
|
||||||
val repetitionAngle = if (newRepetitionList.isNotEmpty()) {
|
val repetitionAngle = repetitionIndexToAngle(
|
||||||
repetitionStep.stepToDegree(totalSteps = newRepetitionList.size)
|
index = repetitionStep,
|
||||||
} else {
|
totalSteps = newRepetitionList.size,
|
||||||
0f
|
)
|
||||||
}
|
|
||||||
|
|
||||||
Timber.d("pulseStep: ${pulseStep} fluenceStep: ${fluenceStep} repetitionStep: ${repetitionStep}")
|
Timber.d("pulseStep: ${pulseStep} fluenceStep: ${fluenceStep} repetitionStep: ${repetitionStep}")
|
||||||
|
|
||||||
@@ -2178,23 +2138,21 @@ class MainViewModel @Inject constructor(
|
|||||||
setRepetitionList(newRepetitionList)
|
setRepetitionList(newRepetitionList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Smartly preserve Repetition Angle
|
// 4. Resolve and apply repetition by value (not by old angle/index).
|
||||||
// 4. Check if the old repetition value exists in the new list.
|
val targetRepetition = currentRepetitionValue ?: 0f
|
||||||
val oldRepetitionIndex = if (currentRepetitionValue != null) {
|
val resolvedRepetition = newRepetitionList.minByOrNull { abs(it - targetRepetition) } ?: 0f
|
||||||
newRepetitionList.indexOf(currentRepetitionValue)
|
val resolvedRepetitionIndex = newRepetitionList.indexOf(resolvedRepetition).takeIf { it >= 0 } ?: 0
|
||||||
} else {
|
|
||||||
-1
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldRepetitionIndex != -1) {
|
if (newRepetitionList.isNotEmpty()) {
|
||||||
// If the old value exists, set the slider to that position.
|
val resolvedRepetitionAngle = repetitionIndexToAngle(
|
||||||
val preservedAngle = oldRepetitionIndex.stepToDegree(totalSteps = newRepetitionList.size)
|
index = resolvedRepetitionIndex,
|
||||||
setRepetitionAngle(preservedAngle)
|
totalSteps = newRepetitionList.size,
|
||||||
Timber.d("Repetition value $currentRepetitionValue preserved at new angle $preservedAngle.")
|
)
|
||||||
|
setRepetitionAngle(resolvedRepetitionAngle)
|
||||||
|
Timber.d("Resolved repetition by value: old=$currentRepetitionValue, new=$resolvedRepetition, angle=$resolvedRepetitionAngle")
|
||||||
} else {
|
} else {
|
||||||
// If it doesn't exist, THEN reset the slider to the beginning.
|
|
||||||
setRepetitionAngle(0f)
|
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
|
// 5. Conditionally reset the fluence angle slider if needed
|
||||||
@@ -2301,8 +2259,12 @@ 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.
|
||||||
if (angle != repetitionAngle.value) {
|
val normalizedAngle = repetitionIndexToAngle(
|
||||||
setRepetitionAngle(angle)
|
index = angle.degreeToStep(totalSteps = repetitionList.value.size),
|
||||||
|
totalSteps = repetitionList.value.size,
|
||||||
|
)
|
||||||
|
if (normalizedAngle != repetitionAngle.value) {
|
||||||
|
setRepetitionAngle(normalizedAngle)
|
||||||
}
|
}
|
||||||
setSelectedPresetIndex(0)
|
setSelectedPresetIndex(0)
|
||||||
}
|
}
|
||||||
@@ -2313,12 +2275,23 @@ 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 = newStep.stepToDegree(totalSteps = repetitionList.value.size)
|
val newRepetitionAngle = repetitionIndexToAngle(
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user