35 Commits

Author SHA1 Message Date
f420d19a6f Merge pull request 'H/P 연결할 때마다 Lifetime 기준값이 1씩 증가하는 버그 수정' (#64) from feature/ISSUE-14,15 into develop
Reviewed-on: #64
2026-03-18 08:00:29 +00:00
StevenBuzzi
6f2d24717d H/P 연결할 때마다 Lifetime 기준값이 1씩 증가하는 버그 수정 2026-03-18 11:58:07 +09:00
babd667c5f Merge pull request 'Fix repetition angle handling for single-value list' (#61) from feature/ISSUE-27 into develop
Reviewed-on: #61
2026-03-08 07:07:00 +00:00
areumwoo
c3a3338c8f Fix repetition angle handling for single-value list 2026-03-08 15:24:12 +09:00
8a49c3c832 Merge pull request 'feature/ISSUE-57' (#59) from feature/ISSUE-57 into develop
Reviewed-on: #59
2026-03-08 06:08:11 +00:00
areumwoo
ca8d89e9bb Load preset values even without priority 2026-03-08 14:45:27 +09:00
areumwoo
7ec7d8674f Preserve fluence by value when pulse duration changes 2026-03-08 14:26:35 +09:00
e7a5ce0de2 Merge pull request '제공된 에너지 테이블과 매칭' (#58) from feature/ISSUE-13 into develop
Reviewed-on: #58
2026-03-08 05:14:13 +00:00
steven
c8a9323178 제공된 에너지 테이블과 매칭 2026-03-08 14:13:38 +09:00
aa618627df Merge pull request 'DCD 설정 관련 수정' (#55) from feature/ISSUE-51 into develop
Reviewed-on: #55
2026-03-06 04:43:56 +00:00
StevenBuzzi
55a1398136 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 13:41:20 +09:00
StevenBuzzi
174cb4fb45 1. DCD 설정 시 Packet 0x41 고정으로 전송하도록 수정
2. DCD 설정값 변경 후 ok 누르면 Packet 전송하여 설정되도록 수정
3. 부팅 시 DCD Packet 0x41 고정으로 전송하도록 수정
2026-03-06 13:38:55 +09:00
StevenBuzzi
71ab4cc8d8 1. DCD Delay 설정 가능 범위 수정
2. DCD Pressure 설정 기본값 수정
2026-03-06 13:38:55 +09:00
StevenBuzzi
d2e375b305 Home화면 내 DCD 숫자 표시 위치 및 크기 조정 2026-03-06 13:38:55 +09:00
StevenBuzzi
92b679b996 잘못 적용된 초기화 값 수정 2026-03-06 13:38:07 +09:00
a5ef8f6da3 Merge pull request 'Packet 동작 이슈 수정' (#54) from feature/ISSUE-8 into develop
Reviewed-on: #54
2026-03-06 01:46:34 +00:00
StevenBuzzi
5ba515d123 1. DCD 설정 시 Packet 0x41 고정으로 전송하도록 수정
2. DCD 설정값 변경 후 ok 누르면 Packet 전송하여 설정되도록 수정
3. 부팅 시 DCD Packet 0x41 고정으로 전송하도록 수정
2026-03-06 10:35:44 +09:00
StevenBuzzi
8c85390d1e 1. DCD Delay 설정 가능 범위 수정
2. DCD Pressure 설정 기본값 수정
2026-03-05 18:32:29 +09:00
StevenBuzzi
72607b03a9 Home화면 내 DCD 숫자 표시 위치 및 크기 조정 2026-03-05 16:19:48 +09:00
StevenBuzzi
285e521f61 불필요한 내용 삭제 2026-03-05 15:35:33 +09:00
StevenBuzzi
ad27766342 부팅 시 KTP Temp write packet 전송하도록 수정 2026-03-05 15:35:31 +09:00
StevenBuzzi
0eeb830a9b q-interval packet 값이 비정상인 버그 수정 2026-03-05 14:29:08 +09:00
StevenBuzzi
628f7544be 부팅 시 serial packet이 전송되지 않는 버그 수정 2026-03-04 17:11:09 +09:00
steven
90c0a93a5e 부팅 시 가이드빔 패킷 맞도록 수정 2026-03-03 22:31:33 +09:00
69c22322c8 Merge pull request '삭제 버튼 위치 조정 / 프리셋 버튼 관련 수정' (#41) from feature/ISSUE-34 into develop
Reviewed-on: #41
2026-03-03 11:08:58 +00:00
areumwoo
28f0430e1d feat: 빠진 이미지 추가 2026-03-03 19:09:54 +09:00
fac756eacb Merge pull request 'Guide beam packet 오전송 수정' (#47) from feature/ISSUE-5 into develop
Reviewed-on: #47
2026-03-03 08:55:48 +00:00
StevenBuzzi
d0b8a78847 Guide beam packet 오전송 수정
1. Engineer; Min/Max에 표기된 값을 전송하도록 수정
2. Config; Guide beam Step에 맞게 전송하도록 수정
2026-03-03 17:40:25 +09:00
a817a5f14f Merge pull request 'LifeTimeView Count/Hour 분리' (#39) from feature/ISSUE-38 into develop
Reviewed-on: #39
2026-03-03 06:23:35 +00:00
StevenBuzzi
2099f4d178 1. Modified the range of applied item
2. Adjust padding @ Life Time, Temp
2026-03-03 14:44:09 +09:00
f7fca4219a Merge pull request 'Gradient 슬라이더 계산 로직 수정' (#40) from feature/ISSUE-20 into develop
Reviewed-on: #40
2026-03-03 05:01:57 +00:00
areumwoo
6cba0674cf 프리셋 저장 버튼/로드 버튼 크기 조정 2026-03-02 16:57:10 +09:00
areumwoo
b87d911cea 삭제 버튼 위치 및 여백 조정 2026-03-02 16:41:38 +09:00
areumwoo
1fc9640e38 Gradient 슬라이더 계산 로직 수정 2026-03-02 16:27:04 +09:00
areumwoo
00f2ec73d5 LifeTimeView Count/Hour 분리 2026-03-02 15:22:47 +09:00
23 changed files with 367 additions and 187 deletions

View File

@@ -214,3 +214,10 @@
- `loadFluenceTable()`, `loadHzTable()`, `calculateInterpolatedC()` 영향 확인
- 성능/안정성 이슈 시
- `txPacketLoop()` 주기, `RX_TIMEOUT_THRESHOLD`, DB 로그 적재량 점검
## 10) Troubleshooting
- 시리얼 초기 TX 누락(Startup race, FD 설명, 수정 내역):
- [`docs/serial_tx_startup_race.md`](docs/serial_tx_startup_race.md)
- 변경 요약 문서(`git diff` 기준):
- [`docs/change_summary_2026-03-04.md`](docs/change_summary_2026-03-04.md)

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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>(

View File

@@ -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)/
)

View File

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

View File

@@ -260,9 +260,11 @@ class MainActivity : ComponentActivity() {
// This prevents serial interrupts from stealing CPU during the first frame.
delay(200)
vm.txPacketOnce()
// IMPORTANT:
// rxPacketLoop() starts serial open() asynchronously.
// Start RX first so txPacketOnce() is less likely to run before FD is ready.
vm.rxPacketLoop()
vm.txPacketOnce()
vm.txPacketLoop()
Timber.d("System fully operational.")

View File

@@ -439,15 +439,15 @@ fun ConfigScreen(
mainViewModel.saveGuideBeamToPreference()
}
/*
val value = when(guideBeam.toInt()) {
0 -> 0
1 -> guideBeamMin
10 -> guideBeamMax
else -> (guideBeamMin + (guideBeam.toInt() - 1) * ((guideBeamMax - guideBeamMin) / 9))
// Guide Beam step mapping (0~10):
// 0 -> fixed 0
// 1~10 -> min~max range in 10 steps (10 -> max)
val step = guideBeam.toInt().coerceIn(0, 10)
val value = if (step == 0) {
0
} else {
guideBeamMin + ((step-1) * (guideBeamMax - guideBeamMin) / 9)
}
*/
val value = (guideBeamMin + (guideBeam.toInt() - 1) * ((guideBeamMax - guideBeamMin) / 9))
Timber.d("guideBeam: $value, guideBeamMax: $guideBeamMax, guideBeamMin: $guideBeamMin")
mainViewModel.txPacket(READ_WRITE.WRITE, CMD.GUIDE_BEAM, GuideBeam(value = value))
@@ -854,4 +854,4 @@ fun PreviewConfigScreen(
mainViewModel = mainViewModel,
configViewModel = configViewModel
)
}
}

View File

@@ -31,7 +31,7 @@ fun HourItemView(
modifier: Modifier = Modifier,
hour: Int = 0,
onClick: () -> Unit = {},
title:String = ""
title: String = ""
) {
Row(modifier = modifier,
horizontalArrangement = Arrangement.SpaceBetween,
@@ -129,4 +129,4 @@ fun PreviewHourItemView() {
title = "Hour Item View"
)
}
}
}

View File

@@ -32,11 +32,11 @@ fun LifeTimeView(
) {
Column(modifier = Modifier
//.noRippleClickable(onClick = onClick)
.size(388.px.dp, 276.px.dp)
.size(388.px.dp, 258.px.dp)
.clip(RoundedCornerShape(12.px.dp))
.border(width = 1.px.dp, color = Color(209, 209, 209), shape = RoundedCornerShape(10.px.dp))
.background(Color.White)
.padding(16.px.dp),
.padding(3.px.dp, 16.px.dp),
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally
) {
@@ -55,11 +55,11 @@ fun LifeTimeView(
),
)
Spacer(modifier = Modifier.height(10.px.dp))
Spacer(modifier = Modifier.height(2.px.dp))
// Temp 0..7
for (i in 0..lifeTimeTypes.size -1) {
val hour = when (i) {
for (i in 0..lifeTimeTypes.size - 1) {
val value = when (i) {
0 -> lifeTime.lamp
1 -> lifeTime.hp5x5
2 -> lifeTime.hp7x7
@@ -70,22 +70,35 @@ fun LifeTimeView(
7 -> lifeTime.water
else -> 0
}
HourItemView(
modifier = Modifier
.fillMaxSize()
.weight(1f)
.padding(
start = 20.px.dp,
end = 20.px.dp,
//bottom = 10.px.dp
),
title = lifeTimeTypes[i],
hour = hour,
onClick = {
Timber.d("onClick > Temp $i (${lifeTimeTypes[i]})")
onClick.invoke(i)
}
)
val modifier = Modifier
.fillMaxSize()
.weight(1f)
.padding(
start = 20.px.dp,
end = 20.px.dp,
//bottom = 10.px.dp
)
val title = lifeTimeTypes[i]
val onItemClick = {
Timber.d("onClick > Temp $i ($title)")
onClick.invoke(i)
}
if (i <= 5) {
CountItemView(
modifier = modifier,
title = title,
count = value,
onClick = onItemClick
)
} else {
HourItemView(
modifier = modifier,
title = title,
hour = value,
onClick = onItemClick
)
}
if (i < lifeTimeTypes.size -1) {
HorizontalDivider(
@@ -108,4 +121,4 @@ fun LifeTimeView(
@Composable
fun PreviewLifeTimeView() {
LifeTimeView()
}
}

View File

@@ -42,7 +42,7 @@ fun TemperatureView(
.clip(RoundedCornerShape(12.px.dp))
.border(width = 1.px.dp, color = Color(209, 209, 209), shape = RoundedCornerShape(10.px.dp))
.background(Color.White)
.padding(16.px.dp),
.padding(3.px.dp, 16.px.dp),
verticalArrangement = Arrangement.SpaceEvenly,
horizontalAlignment = Alignment.CenterHorizontally
) {

View File

@@ -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)

View File

@@ -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()
@@ -334,7 +342,7 @@ fun DcdSettingPopup(
modifier = Modifier
.fillMaxHeight()
.size(40.px.dp, 210.px.dp),
chargeRate = gasChargeRate.toInt()
chargeRate = gasChargeRate
)
// Icon
@@ -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 )

View File

@@ -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}")

View File

@@ -28,14 +28,26 @@ import com.laseroptek.raman.ui.screens.main.MainViewModel
import com.laseroptek.raman.utils.DefaultDispatcherProvider
import com.laseroptek.raman.utils.ext.px
import timber.log.Timber
import kotlin.math.abs
import kotlin.math.ceil
@Composable
fun GradientSlider(
modifier: Modifier = Modifier,
chargeRate: Int = 0, // Value from (0 .. 100)
chargeRate: Float = 0f,
) {
val chargeIndex = ((chargeRate.coerceIn(0, 100) + 4) / 5).toInt() // 0..19
val normalizedRate = chargeRate.coerceIn(0f, 100f)
val bucket = normalizedRate / 5f
val remainder = normalizedRate % 5f
val isExactMultiple = abs(remainder) < 0.0001f
val chargeIndex = when {
normalizedRate == 0f -> -1
isExactMultiple -> (bucket - 1f).toInt().coerceAtLeast(-1)
else -> (ceil(bucket.toDouble()).toInt() - 1)
}.coerceIn(-1, 19)
Timber.d("chargeRate: $chargeRate, chargeIndex: $chargeIndex")
Box(
@@ -103,6 +115,6 @@ fun GradientSliderPreview(
//mainViewModel = mainViewModel
modifier = Modifier
.size(40.px.dp, 210.px.dp),
chargeRate = 20
chargeRate = 20f
)
}

View File

@@ -108,15 +108,15 @@ fun PresetIconButton(
Image(
painter = painterResource(id =
if (type == PresetButtonType.SAVE) {
R.drawable.ic_preset_save
R.drawable.ic_preset_save2
} else {
R.drawable.ic_preset_load
}
),
contentDescription = "",
modifier = Modifier
.size(20.px.dp),
contentScale = ContentScale.Crop
.size(30.px.dp),
contentScale = ContentScale.Fit
)
}
}

View File

@@ -552,12 +552,12 @@ fun PresetLoadPopup(
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
Spacer(Modifier.weight(1f))
if (isEditMode) {
////////////////////////////////////////////////////
// Edit Mode
Spacer(modifier = Modifier.width(10.px.dp))
// Preset Delete (Delete confirm popup)
Box(
modifier = Modifier
@@ -578,7 +578,7 @@ fun PresetLoadPopup(
)
}
Spacer(Modifier.width(10.px.dp))
Spacer(Modifier.weight(1f))
// Preset Cancel (Reload selected item from mainViewModel)
Box(
@@ -743,7 +743,11 @@ fun PresetLoadPopup(
contentScale = ContentScale.Crop
)
}
Spacer(modifier = Modifier.width(10.px.dp))
} else {
Spacer(Modifier.weight(1f))
////////////////////////////////////////////////////
// Select Mode - hide Keyboard
focusManager.clearFocus(force = true) // Hide the keyboard
@@ -776,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)
presetViewModel.clearPreset()
onClick.invoke(false)
// } else {
// Timber.d("SKIP - Preset Load ($priority)")
// }
} else {
// 우선순위가 NONE인 경우, 인덱스 설정 X
mainViewModel.setSelectedPresetIndex(0)
mainViewModel.applyPreset(selectedPreset)
}
presetViewModel.clearPreset()
onClick.invoke(false)
})
.size(40.px.dp)
.background(Color.Transparent)
@@ -804,6 +812,8 @@ fun PresetLoadPopup(
contentScale = ContentScale.Crop
)
}
Spacer(modifier = Modifier.width(10.px.dp))
}
}

View File

@@ -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
@@ -583,22 +584,22 @@ class MainViewModel @Inject constructor(
saveGuideBeamMinToPreference()
saveGuideBeamMaxToPreference()
// After updating the state, send the packet
val newMin = guideBeamMin.value // get the potentially updated value
val newMax = guideBeamMax.value // get the potentially updated value
val guideBeam = guideBeam.value.toInt()
// Engineer 화면에서는 Min/Max 버튼에 따라 표시된 Min 또는 Max 값을 그대로 송신
val newMin = guideBeamMin.value
val newMax = guideBeamMax.value
val value = when (state) {
MinMaxUpDownState.MinDown,
MinMaxUpDownState.MinUp,
MinMaxUpDownState.MinLongDown,
MinMaxUpDownState.MinLongUp -> newMin
/*
val value = when(guideBeamValue) {
0 -> 0
1 -> newMin
10 -> newMax
else -> (newMin + (guideBeamValue - 1) * ((newMax - newMin) / 9))
MinMaxUpDownState.MaxDown,
MinMaxUpDownState.MaxUp,
MinMaxUpDownState.MaxLongDown,
MinMaxUpDownState.MaxLongUp -> newMax
}
*/
val value = (newMin + (guideBeam - 1) * ((newMax - newMin) / 9))
Timber.d("guideBeam: $value, guideBeam: $guideBeam, guideBeamMax: $newMax, guideBeamMin: $newMin")
Timber.d("Engineer guideBeam tx value: $value, guideBeamMax: $newMax, guideBeamMin: $newMin")
txPacket(READ_WRITE.WRITE, CMD.GUIDE_BEAM, GuideBeam(value = value))
}
@@ -814,24 +815,62 @@ class MainViewModel @Inject constructor(
}
fun txPacketOnce() {
// viewModel init 으로 이동. 필요.
// 경고 정보 조회 (주기적 heart beat)
// repeatOnLifecycle은 Activity가 포그라운드에 있을 때로 한정지어, 특정 Lifecycle이 Trigger 되었을 때 동작하도록 만드는 block 임.
viewModelScope.launch(dispatcherProvider.io) {
// txPacketOnce is called during app startup.
// Because serial open() is started in rxPacketLoop() asynchronously,
// FD can still be -1 here (startup race). Wait briefly before first TX burst.
if (!waitUntilSerialReady()) {
Timber.e("txPacketOnce skipped: serial port is not ready (fd=%d)", serialPortRepository.getFD())
return@launch
}
// tx Version Read
txPacket(READ_WRITE.READ, CMD.VERSION, byteArrayOf(0x41.toByte()))
// viewModel init 으로 이동. 필요.
// 경고 정보 조회 (주기적 heart beat)
// repeatOnLifecycle은 Activity가 포그라운드에 있을 때로 한정지어, 특정 Lifecycle이 Trigger 되었을 때 동작하도록 만드는 block 임.
// tx Q-Switch Write
txPacket(READ_WRITE.WRITE, CMD.Q_SWITCH, qSwitch.value)
// tx Version Read
txPacket(READ_WRITE.READ, CMD.VERSION, byteArrayOf(0x41.toByte()))
// tx Guide Beam Write
txPacket(READ_WRITE.WRITE, CMD.GUIDE_BEAM, GuideBeam(value = guideBeam.value.toInt()))
// tx Q-Switch Write
txPacket(READ_WRITE.WRITE, CMD.Q_SWITCH, qSwitch.value)
// tx DCD_GAS Write (DEFAULT VALUE)
txPacket(READ_WRITE.WRITE, CMD.DCD_GAS, dcdGas.value.copy(status = 0x50))
// tx Oven Write (align with Engineer KTP write source)
txPacket(READ_WRITE.WRITE, CMD.OVEN, Oven(ktp = temperature_write.value.ktp))
// tx SPRAY_DCD Write (DEFAULT VALUE)
txPacket(READ_WRITE.WRITE, CMD.SPRAY_DCD, sprayDcd.value)
// tx Guide Beam Write
txPacket(READ_WRITE.WRITE, CMD.GUIDE_BEAM, GuideBeam(value = getGuideBeamTxValue()))
// tx DCD_GAS Write (DEFAULT VALUE)
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.copy(status = 0x41))
}
}
private suspend fun waitUntilSerialReady(
timeoutMillis: Long = 2000L,
pollIntervalMillis: Long = 20L
): Boolean {
// Poll FD until open() completes, with a bounded timeout to avoid blocking forever.
val start = System.currentTimeMillis()
while (System.currentTimeMillis() - start < timeoutMillis) {
if (serialPortRepository.getFD() != -1) return true
delay(pollIntervalMillis)
}
return serialPortRepository.getFD() != -1
}
// Guide Beam step mapping (0~10)
// 0 -> fixed 0
// 1~10 -> min~max range in 10 steps (10 -> max)
private fun getGuideBeamTxValue(): Int {
val step = guideBeam.value.toInt().coerceIn(0, 10)
return if (step == 0) {
0
} else {
guideBeamMin.value + ((step - 1) * (guideBeamMax.value - guideBeamMin.value) / 9)
}
}
// Example: Emitting an event after a delay
@@ -1067,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()
@@ -1146,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)
@@ -2043,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}")
@@ -2094,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
@@ -2130,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}")
}
/**
@@ -2150,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,
)
}
@@ -2168,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,
)
}
}
@@ -2216,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)
}
@@ -2228,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
@@ -2286,4 +2344,4 @@ class MainViewModel @Inject constructor(
// ONLY do light, non-IO variable initialization here.
// DO NOT call load... functions here.
}
}
}

View File

@@ -487,7 +487,7 @@ fun QSwitch.toByteArray(): ByteArray {
val delayTimeIntegerPart = this.delayTime.toInt()
val delayTimeFractionPart = ((this.delayTime - delayTimeIntegerPart) * 10).toInt()
val intervalTimeIntegerPart = this.intervalTime.toInt()
val intervalTimeFractionPart = ((this.intervalTime - delayTimeIntegerPart) * 10).toInt()
val intervalTimeFractionPart = ((this.intervalTime - intervalTimeIntegerPart) * 10).toInt()
val delayTimeArray = byteArrayOf(
((delayTimeIntegerPart.getNthDigit(2) + 0x30) and 0xFF).toByte(),

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,23 @@
# 변경 요약 (2026-03-04)
이 문서는 현재 `git diff` 기준으로 반영된 변경을 정리합니다.
## 1) 시리얼 초기 전송 누락(Startup race) 대응
### 변경 파일
- `app/src/main/java/com/laseroptek/raman/ui/MainActivity.kt`
- `app/src/main/java/com/laseroptek/raman/ui/screens/main/MainViewModel.kt`
### 변경 내용
- `MainActivity.initialize()`의 시리얼 시작 순서를 조정
- 이전: `txPacketOnce()` -> `rxPacketLoop()` -> `txPacketLoop()`
- 이후: `rxPacketLoop()` -> `txPacketOnce()` -> `txPacketLoop()`
- `MainViewModel.txPacketOnce()`를 코루틴(IO)에서 실행하도록 변경
- `waitUntilSerialReady()` 추가
- 최대 2초 동안 20ms 간격으로 `FD != -1` 확인
- 준비 실패 시 에러 로그 후 초기 TX 중단
- 관련 설명 주석 추가
### 의도/효과
- 앱 시작 직후 `open()` 완료 전 TX가 먼저 발생하는 레이스를 완화/방어
- 포트 미준비 상태(`FD == -1`)에서 write가 호출되어 초기 패킷이 누락되는 문제를 줄임

View File

@@ -0,0 +1,41 @@
# Serial TX Startup Race 정리
## 1) FD(File Descriptor)란?
- `FD`는 리눅스/안드로이드에서 열린 리소스(파일/소켓/시리얼 포트)를 가리키는 정수 핸들입니다.
- 이 프로젝트에서 시리얼 포트 상태는 다음처럼 판단합니다.
- `FD == -1`: 포트 미오픈(유효하지 않음)
- `FD >= 0`: 포트 오픈 완료(유효)
- 따라서 `FD == -1` 상태에서 `write()`를 호출하면 실제 시리얼 전송이 되지 않습니다.
## 2) 문제 원인
- `txPacketOnce()`가 앱 시작 직후 실행됩니다.
- 시리얼 포트 `open()``rxPacketLoop()` 내부에서 코루틴으로 비동기 시작됩니다.
- 기존 순서에서 `txPacketOnce()`가 먼저 호출되면, 포트 오픈 완료 전(`FD == -1`)에 TX가 시도되어 초기 패킷 전송이 누락될 수 있습니다.
## 3) 적용한 수정
### A. 초기 호출 순서 조정
- 파일: `app/src/main/java/com/laseroptek/raman/ui/MainActivity.kt`
- 변경:
- 이전: `txPacketOnce()` -> `rxPacketLoop()` -> `txPacketLoop()`
- 이후: `rxPacketLoop()` -> `txPacketOnce()` -> `txPacketLoop()`
- 목적: RX 루프가 먼저 포트 오픈을 시작하도록 해서 초기 TX 레이스 확률을 줄임
### B. `txPacketOnce()`에 포트 준비 대기 추가
- 파일: `app/src/main/java/com/laseroptek/raman/ui/screens/main/MainViewModel.kt`
- 변경:
- `txPacketOnce()`를 IO 코루틴에서 실행
- `waitUntilSerialReady()`(최대 2초, 20ms 폴링)로 `FD != -1` 확인 후 TX 진행
- 시간 내 준비 실패 시 로그를 남기고 전송 중단
- 목적: 순서만으로 보장되지 않는 코루틴 스케줄링 레이스를 방어
## 4) 왜 TX에서 직접 open()하지 않았는가?
- 현재 구조에서 `open()`의 데이터 콜백은 `rxPacketLoop()``callbackFlow`와 연결됩니다.
- TX 경로에서 별도 `open()`을 하면 중복 오픈/콜백 소유권/FD 교체 타이밍 이슈가 생길 수 있습니다.
- 안정적인 패턴은:
- 포트 오픈 책임: RX(단일 지점)
- 포트 사용(TX): ready 확인 후 write
## 5) 확인 포인트
- 앱 시작 직후 로그에서 `FD`가 유효해진 뒤 `txPacketOnce()`의 TX 로그가 출력되는지 확인
- 장비 측 시리얼 모니터에서 초기 패킷(Version/Q-Switch/GuideBeam/DCD/SprayDCD) 수신 여부 확인