Skip to content

Commit

Permalink
[api]: Fix ASCOM Camera and Focuser thermometer
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Apr 19, 2024
1 parent ba5e796 commit 7597dab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,13 +281,13 @@ data class ASCOMCamera(

override fun close() {
if (hasThermometer) {
sender.unregisterThermometer(this)
hasThermometer = false
sender.unregisterThermometer(this)
}

if (canPulseGuide) {
sender.unregisterGuideOutput(this)
canPulseGuide = false
sender.unregisterGuideOutput(this)
}

super.close()
Expand Down Expand Up @@ -591,8 +591,10 @@ data class ASCOMCamera(
sender.registerThermometer(this)
}

temperature = it.value
sender.fireOnEventReceived(CameraTemperatureChanged(this))
if (it.value != temperature) {
temperature = it.value
sender.fireOnEventReceived(CameraTemperatureChanged(this))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@ import nebulosa.alpaca.api.ConfiguredDevice
import nebulosa.alpaca.indi.client.AlpacaClient
import nebulosa.alpaca.indi.device.ASCOMDevice
import nebulosa.indi.device.Device
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.focuser.FocuserCanAbsoluteMoveChanged
import nebulosa.indi.device.focuser.FocuserMovingChanged
import nebulosa.indi.device.focuser.FocuserPositionChanged
import nebulosa.indi.device.focuser.*
import nebulosa.indi.device.thermometer.ThermometerAttached
import nebulosa.indi.device.thermometer.ThermometerDetached
import nebulosa.indi.device.thermometer.ThermometerTemperatureChanged
import nebulosa.indi.protocol.INDIProtocol

@Suppress("RedundantModalityModifier")
Expand Down Expand Up @@ -75,7 +70,6 @@ data class ASCOMFocuser(
override fun onConnected() {
processCapabilities()
processPosition()
processTemperature()
}

override fun onDisconnected() {
Expand All @@ -99,20 +93,20 @@ data class ASCOMFocuser(
}

override fun close() {
super.close()

if (hasThermometer) {
hasThermometer = false
sender.fireOnEventReceived(ThermometerDetached(this))
sender.unregisterThermometer(this)
}

super.close()
}

override fun refresh(elapsedTimeInSeconds: Long) {
super.refresh(elapsedTimeInSeconds)

processMoving()
processPosition()
processTemperature()
processTemperature(false)
}

private fun processCapabilities() {
Expand All @@ -127,6 +121,8 @@ data class ASCOMFocuser(
hasThermometer = true
sender.fireOnEventReceived(ThermometerAttached(this))
}

processTemperature(true)
}

private fun processMoving() {
Expand All @@ -149,13 +145,19 @@ data class ASCOMFocuser(
}
}

private fun processTemperature() {
if (hasThermometer) {
private fun processTemperature(init: Boolean) {
if (hasThermometer || init) {
service.temperature(device.number).doRequest {
if (it.value != temperature) {
temperature = it.value

sender.fireOnEventReceived(ThermometerTemperatureChanged(this))
if (it.errorNumber == 0) {
if (!hasThermometer) {
hasThermometer = true
sender.registerThermometer(this)
}

if (it.value != temperature) {
temperature = it.value
sender.fireOnEventReceived(FocuserTemperatureChanged(this))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ internal open class INDICamera(

override fun close() {
if (hasThermometer) {
sender.unregisterThermometer(this)
hasThermometer = false
sender.unregisterThermometer(this)
}

if (canPulseGuide) {
sender.unregisterGuideOutput(this)
canPulseGuide = false
sender.unregisterGuideOutput(this)
}

if (guideHead != null) {
Expand Down

0 comments on commit 7597dab

Please sign in to comment.