Skip to content

Commit

Permalink
[api]: Fix cannot access the file because it is being used by another…
Browse files Browse the repository at this point in the history
… process
  • Loading branch information
tiagohm committed Feb 1, 2024
1 parent 472c831 commit fad12d9
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardStep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,25 @@ data class FlatWizardStep(
val savedPath = cameraExposureStep.savedPath

if (!stopped && savedPath != null) {
Fits(savedPath).also(Fits::read).use { fits ->
image = image?.load(fits, false) ?: Image.open(fits, false)

val statistics = STATISTICS.compute(image!!)

LOG.info("flat frame captured. duration={}, statistics={}", exposureTime, statistics)

if (statistics.mean in meanRange) {
val path = request.captureRequest.makeSavePath(true)
savedPath.inputStream().transferAndClose(path.outputStream())
savedPath.deleteIfExists()
LOG.info("Found an optimal exposure time. exposure={}, path={}", exposureTime, path)
flatWizardExecutionListeners.forEach { it.onFlatCaptured(this, path, exposureTime) }
} else if (statistics.mean < meanRange.start) {
exposureMin = cameraExposureStep.exposureTime
return StepResult.CONTINUABLE
} else {
exposureMax = cameraExposureStep.exposureTime
return StepResult.CONTINUABLE
}
image = Fits(savedPath).also(Fits::read).use { fits ->
image?.load(fits, false) ?: Image.open(fits, false)
}

val statistics = STATISTICS.compute(image!!)
LOG.info("flat frame captured. duration={}, statistics={}", exposureTime, statistics)

if (statistics.mean in meanRange) {
val path = request.captureRequest.makeSavePath(true)
savedPath.inputStream().transferAndClose(path.outputStream())
savedPath.deleteIfExists()
LOG.info("Found an optimal exposure time. exposure={}, path={}", exposureTime, path)
flatWizardExecutionListeners.forEach { it.onFlatCaptured(this, path, exposureTime) }
} else if (statistics.mean < meanRange.start) {
exposureMin = cameraExposureStep.exposureTime
return StepResult.CONTINUABLE
} else {
exposureMax = cameraExposureStep.exposureTime
return StepResult.CONTINUABLE
}
}

Expand Down

0 comments on commit fad12d9

Please sign in to comment.