1 Commits

Author SHA1 Message Date
areumwoo
f5d7187c0f Enforce standby when lamp lifetime exceeded 2026-03-02 14:54:34 +09:00
2 changed files with 34 additions and 27 deletions

View File

@@ -35,6 +35,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
import com.laseroptek.raman.const.LaserParameter import com.laseroptek.raman.const.LaserParameter
import com.laseroptek.raman.const.LASER_STATUS
import com.laseroptek.raman.const.LaserStatusType import com.laseroptek.raman.const.LaserStatusType
import com.laseroptek.raman.const.MAX_LASER_COUNT import com.laseroptek.raman.const.MAX_LASER_COUNT
import com.laseroptek.raman.const.PresetButtonType import com.laseroptek.raman.const.PresetButtonType
@@ -92,10 +93,18 @@ fun HomeScreen(
val presetList by mainViewModel.presetList.collectAsState() val presetList by mainViewModel.presetList.collectAsState()
LaunchedEffect(Unit) { LaunchedEffect(lampCount, lifeTime.lamp, laserStatus.laserStatus) {
Timber.d("LaunchedEffect - HomeScreen") Timber.d("LaunchedEffect - HomeScreen")
focusManager.clearFocus(force = true) // Hide the keyboard focusManager.clearFocus(force = true) // Hide the keyboard
// Ensure the system returns to StandBy when lamp thresholds are exceeded
val lampLifetimeLimit = lifeTime.lamp
val reachedLifetimeLimit = lampLifetimeLimit > 0 && lampCount >= lampLifetimeLimit
if (reachedLifetimeLimit && laserStatus.laserStatus != LASER_STATUS.STAND_BY) {
Timber.d("HomeScreen load - forcing StandBy state due to lamp count limit")
mainViewModel.txLaserStatusEntry(LASER_STATUS.STAND_BY)
}
Timber.d("Attempted to hide keyboard on EngineerScreen launch") Timber.d("Attempted to hide keyboard on EngineerScreen launch")
} }
@@ -482,6 +491,18 @@ fun HomeScreen(
return@StandByButton return@StandByButton
} }
val lampLifetimeLimit = lifeTime.lamp
if (lampLifetimeLimit > 0 && lampCount >= lampLifetimeLimit) {
Toast.makeText(
context,
"Lamp lifetime limit reached",
Toast.LENGTH_SHORT
).show()
return@StandByButton
}
val hpCount = mainViewModel.getHPCount() val hpCount = mainViewModel.getHPCount()
if (hpCount < 1) { if (hpCount < 1) {
Toast.makeText( Toast.makeText(

View File

@@ -646,7 +646,7 @@ fun PresetLoadPopup(
Timber.d("onClick - Confirm Save") Timber.d("onClick - Confirm Save")
// Check empty names and conflict priority exist in the preset viewmodel's presetList // Check empty names and conflict priority exist in the preset viewmodel's presetList
var listToValidate = presetViewModel.presetList.value val listToValidate = presetViewModel.presetList.value
// Check for any presets with an empty name // Check for any presets with an empty name
val hasEmptyName = val hasEmptyName =
@@ -678,32 +678,18 @@ fun PresetLoadPopup(
} }
// Check for duplicate priorities (ignoring priority 0) // Check for duplicate priorities (ignoring priority 0)
val duplicatePriorityGroups = listToValidate val priorityConflicts = listToValidate
.filter { it.priority > 0 } .filter { it.priority > 0 } // Only consider prioritized items
.groupBy { it.priority } .groupBy { it.priority } // Group them by priority
.filter { it.value.size > 1 } .any { it.value.size > 1 } // Check if any group is larger than 1
if (duplicatePriorityGroups.isNotEmpty()) { if (priorityConflicts) {
val resolvedList = listToValidate.map { it.copy() }.toMutableList() Toast.makeText(
val selectedPreset = resolvedList.getOrNull(selectedPresetIndex) context,
"There are duplicate priorities. Please ensure each priority is unique.",
duplicatePriorityGroups.forEach { (priorityValue, presets) -> Toast.LENGTH_LONG
val keeperId = presets ).show()
.firstOrNull { preset -> return@noRippleClickable // Stop the process
selectedPreset != null && preset.id == selectedPreset.id
}
?.id
?: presets.first().id
resolvedList.forEachIndexed { index, preset ->
if (preset.priority == priorityValue && preset.id != keeperId) {
resolvedList[index] = preset.copy(priority = 0)
}
}
}
presetViewModel.setPresetList(resolvedList)
listToValidate = resolvedList
} }
Timber.d("Validation successful. Saving list to MainViewModel.") Timber.d("Validation successful. Saving list to MainViewModel.")