-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
nebulosa-indi-client/src/main/kotlin/nebulosa/indi/client/device/dustcap/INDIDustCap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package nebulosa.indi.client.device.dustcap | ||
|
||
import nebulosa.indi.client.INDIClient | ||
import nebulosa.indi.client.device.INDIDevice | ||
import nebulosa.indi.device.dustcap.DustCap | ||
import nebulosa.indi.device.dustcap.DustCapCanParkChanged | ||
import nebulosa.indi.device.dustcap.DustCapParkChanged | ||
import nebulosa.indi.device.firstOnSwitchOrNull | ||
import nebulosa.indi.protocol.DefSwitchVector | ||
import nebulosa.indi.protocol.DefVector.Companion.isNotReadOnly | ||
import nebulosa.indi.protocol.INDIProtocol | ||
import nebulosa.indi.protocol.SwitchVector | ||
import nebulosa.indi.protocol.Vector.Companion.isBusy | ||
|
||
internal open class INDIDustCap( | ||
override val sender: INDIClient, | ||
override val name: String, | ||
) : INDIDevice(), DustCap { | ||
|
||
@Volatile final override var canPark = false | ||
@Volatile final override var parking = false | ||
@Volatile final override var parked = false | ||
|
||
override fun handleMessage(message: INDIProtocol) { | ||
when (message) { | ||
is SwitchVector<*> -> { | ||
when (message.name) { | ||
"CAP_PARK" -> { | ||
if (message is DefSwitchVector) { | ||
canPark = message.isNotReadOnly | ||
|
||
sender.fireOnEventReceived(DustCapCanParkChanged(this)) | ||
} | ||
|
||
parking = message.isBusy | ||
parked = message.firstOnSwitchOrNull()?.name == "PARK" | ||
|
||
sender.fireOnEventReceived(DustCapParkChanged(this)) | ||
} | ||
} | ||
} | ||
else -> Unit | ||
} | ||
|
||
super.handleMessage(message) | ||
} | ||
|
||
override fun park() { | ||
if (canPark) { | ||
sendNewSwitch("CAP_PARK", "PARK" to true) | ||
} | ||
} | ||
|
||
override fun unpark() { | ||
if (canPark) { | ||
sendNewSwitch("CAP_PARK", "UNPARK" to true) | ||
} | ||
} | ||
|
||
override fun close() = Unit | ||
|
||
override fun toString() = "DustCap(name=$name, connected=$connected, parking=$parking, parked=$parked)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
nebulosa-indi-device/src/main/kotlin/nebulosa/indi/device/dustcap/DustCap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package nebulosa.indi.device.dustcap | ||
|
||
import nebulosa.indi.device.Device | ||
import nebulosa.indi.device.DeviceType | ||
import nebulosa.indi.device.Parkable | ||
|
||
interface DustCap : Device, Parkable | ||
interface DustCap : Device, Parkable { | ||
|
||
override val type | ||
get() = DeviceType.DUST_CAP | ||
} |