Skip to content

Commit

Permalink
DustCap (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm authored Aug 28, 2024
2 parents f25f772 + 1666fe1 commit b9d51ed
Show file tree
Hide file tree
Showing 51 changed files with 682 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import nebulosa.api.calibration.CalibrationFrameRepository
import nebulosa.api.connection.ConnectionService
import nebulosa.indi.device.Device
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.dustcap.DustCap
import nebulosa.indi.device.filterwheel.FilterWheel
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.gps.GPS
Expand Down Expand Up @@ -43,6 +44,7 @@ class DeviceOrEntityParamMethodArgumentResolver(
GPS::class.java to { connectionService.gps(it) },
GuideOutput::class.java to { connectionService.guideOutput(it) },
LightBox::class.java to { connectionService.lightBox(it) },
DustCap::class.java to { connectionService.dustCap(it) },
Thermometer::class.java to { connectionService.thermometer(it) },
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package nebulosa.api.connection

import nebulosa.api.cameras.CameraEventHub
import nebulosa.api.dustcap.DustCapEventHub
import nebulosa.api.focusers.FocuserEventHub
import nebulosa.api.guiding.GuideOutputEventHub
import nebulosa.api.lightboxes.LightBoxEventHub
import nebulosa.api.mounts.MountEventHub
import nebulosa.api.rotators.RotatorEventHub
import nebulosa.api.wheels.WheelEventHub
import nebulosa.indi.device.DeviceConnectionEvent
import nebulosa.indi.device.DeviceEvent
import nebulosa.indi.device.DeviceEventHandler
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.dustcap.DustCap
import nebulosa.indi.device.filterwheel.FilterWheel
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.guider.GuideOutput
import nebulosa.indi.device.lightbox.LightBox
import nebulosa.indi.device.mount.Mount
import nebulosa.indi.device.rotator.Rotator
import org.springframework.stereotype.Component
Expand All @@ -25,6 +29,8 @@ class ConnectionEventHub(
private val wheelEventHub: WheelEventHub,
private val guideOutputEventHub: GuideOutputEventHub,
private val rotatorEventHub: RotatorEventHub,
private val lightBoxEventHub: LightBoxEventHub,
private val dustCapEventHub: DustCapEventHub,
) : DeviceEventHandler.EventReceived {

override fun onEventReceived(event: DeviceEvent<*>) {
Expand All @@ -37,6 +43,8 @@ class ConnectionEventHub(
if (device is FilterWheel) wheelEventHub.onConnectionChanged(device)
if (device is Rotator) rotatorEventHub.onConnectionChanged(device)
if (device is GuideOutput) guideOutputEventHub.onConnectionChanged(device)
if (device is LightBox) lightBoxEventHub.onConnectionChanged(device)
if (device is DustCap) dustCapEventHub.onConnectionChanged(device)
}
}
}
18 changes: 18 additions & 0 deletions api/src/main/kotlin/nebulosa/api/connection/ConnectionService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import nebulosa.indi.device.Device
import nebulosa.indi.device.DeviceEventHandler
import nebulosa.indi.device.INDIDeviceProvider
import nebulosa.indi.device.camera.Camera
import nebulosa.indi.device.dustcap.DustCap
import nebulosa.indi.device.filterwheel.FilterWheel
import nebulosa.indi.device.focuser.Focuser
import nebulosa.indi.device.gps.GPS
Expand Down Expand Up @@ -139,6 +140,10 @@ class ConnectionService(
return providers[id]?.lightBoxes() ?: emptyList()
}

fun dustCaps(id: String): Collection<DustCap> {
return providers[id]?.dustCaps() ?: emptyList()
}

fun thermometers(id: String): Collection<Thermometer> {
return providers[id]?.thermometers() ?: emptyList()
}
Expand Down Expand Up @@ -175,6 +180,10 @@ class ConnectionService(
return providers.values.flatMap { it.lightBoxes() }
}

fun dustCaps(): List<DustCap> {
return providers.values.flatMap { it.dustCaps() }
}

fun thermometers(): List<Thermometer> {
return providers.values.flatMap { it.thermometers() }
}
Expand Down Expand Up @@ -211,6 +220,10 @@ class ConnectionService(
return providers[id]?.lightBox(name)
}

fun dustCap(id: String, name: String): DustCap? {
return providers[id]?.dustCap(name)
}

fun thermometer(id: String, name: String): Thermometer? {
return providers[id]?.thermometer(name)
}
Expand Down Expand Up @@ -247,6 +260,10 @@ class ConnectionService(
return providers.firstNotNullOfOrNull { it.value.lightBox(name) }
}

fun dustCap(name: String): DustCap? {
return providers.firstNotNullOfOrNull { it.value.dustCap(name) }
}

fun thermometer(name: String): Thermometer? {
return providers.firstNotNullOfOrNull { it.value.thermometer(name) }
}
Expand All @@ -259,6 +276,7 @@ class ConnectionService(
?: rotator(name)
?: guideOutput(name)
?: lightBox(name)
?: dustCap(name)
?: gps(name)
?: thermometer(name)
}
Expand Down
51 changes: 51 additions & 0 deletions api/src/main/kotlin/nebulosa/api/dustcap/DustCapController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package nebulosa.api.dustcap

import nebulosa.api.connection.ConnectionService
import nebulosa.indi.device.dustcap.DustCap
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("dust-caps")
class DustCapController(
private val connectionService: ConnectionService,
private val dustCapService: DustCapService,
) {

@GetMapping
fun dustCaps(): List<DustCap> {
return connectionService.dustCaps().sorted()
}

@GetMapping("{dustCap}")
fun dustCap(dustCap: DustCap): DustCap {
return dustCap
}

@PutMapping("{dustCap}/connect")
fun connect(dustCap: DustCap) {
dustCapService.connect(dustCap)
}

@PutMapping("{dustCap}/disconnect")
fun disconnect(dustCap: DustCap) {
dustCapService.disconnect(dustCap)
}

@PutMapping("{dustCap}/park")
fun park(dustCap: DustCap) {
dustCapService.park(dustCap)
}

@PutMapping("{dustCap}/unpark")
fun unpark(dustCap: DustCap) {
dustCapService.unpark(dustCap)
}

@PutMapping("{dustCap}/listen")
fun listen(dustCap: DustCap) {
dustCapService.listen(dustCap)
}
}
16 changes: 16 additions & 0 deletions api/src/main/kotlin/nebulosa/api/dustcap/DustCapDeserializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package nebulosa.api.dustcap

import nebulosa.api.connection.ConnectionService
import nebulosa.api.devices.DeviceDeserializer
import nebulosa.indi.device.dustcap.DustCap
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Lazy
import org.springframework.stereotype.Component

@Component
class DustCapDeserializer : DeviceDeserializer<DustCap>(DustCap::class.java) {

@Autowired @Lazy private lateinit var connectionService: ConnectionService

override fun deviceFor(name: String) = connectionService.dustCap(name)
}
8 changes: 8 additions & 0 deletions api/src/main/kotlin/nebulosa/api/dustcap/DustCapEventAware.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package nebulosa.api.dustcap

import nebulosa.indi.device.dustcap.DustCapEvent

fun interface DustCapEventAware {

fun handleDustCapEvent(event: DustCapEvent)
}
36 changes: 36 additions & 0 deletions api/src/main/kotlin/nebulosa/api/dustcap/DustCapEventHub.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nebulosa.api.dustcap

import nebulosa.api.beans.annotations.Subscriber
import nebulosa.api.devices.DeviceEventHub
import nebulosa.api.message.MessageService
import nebulosa.indi.device.DeviceType
import nebulosa.indi.device.PropertyChangedEvent
import nebulosa.indi.device.dustcap.DustCap
import nebulosa.indi.device.dustcap.DustCapAttached
import nebulosa.indi.device.dustcap.DustCapDetached
import nebulosa.indi.device.dustcap.DustCapEvent
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.springframework.stereotype.Component

@Component
@Subscriber
class DustCapEventHub(
private val messageService: MessageService,
) : DeviceEventHub<DustCap, DustCapEvent>(DeviceType.DUST_CAP), DustCapEventAware {

@Subscribe(threadMode = ThreadMode.ASYNC)
override fun handleDustCapEvent(event: DustCapEvent) {
if (event.device.type == DeviceType.DUST_CAP) {
when (event) {
is PropertyChangedEvent -> onNext(event)
is DustCapAttached -> onAttached(event.device)
is DustCapDetached -> onDetached(event.device)
}
}
}

override fun sendMessage(eventName: String, device: DustCap) {
messageService.sendMessage(DustCapMessageEvent(eventName, device))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package nebulosa.api.dustcap

import nebulosa.api.devices.DeviceMessageEvent
import nebulosa.indi.device.dustcap.DustCap

data class DustCapMessageEvent(override val eventName: String, override val device: DustCap) : DeviceMessageEvent<DustCap>
16 changes: 16 additions & 0 deletions api/src/main/kotlin/nebulosa/api/dustcap/DustCapSerializer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package nebulosa.api.dustcap

import com.fasterxml.jackson.core.JsonGenerator
import nebulosa.api.devices.DeviceSerializer
import nebulosa.indi.device.dustcap.DustCap
import org.springframework.stereotype.Component

@Component
class DustCapSerializer : DeviceSerializer<DustCap>(DustCap::class.java) {

override fun JsonGenerator.serialize(value: DustCap) {
writeBooleanField("canPark", value.canPark)
writeBooleanField("parking", value.parking)
writeBooleanField("parked", value.parked)
}
}
28 changes: 28 additions & 0 deletions api/src/main/kotlin/nebulosa/api/dustcap/DustCapService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package nebulosa.api.dustcap

import nebulosa.indi.device.dustcap.DustCap
import org.springframework.stereotype.Service

@Service
class DustCapService(private val dustCapEventHub: DustCapEventHub) {

fun connect(dustCap: DustCap) {
dustCap.connect()
}

fun disconnect(dustCap: DustCap) {
dustCap.disconnect()
}

fun park(dustCap: DustCap) {
dustCap.park()
}

fun unpark(dustCap: DustCap) {
dustCap.unpark()
}

fun listen(dustCap: DustCap) {
dustCapEventHub.listen(dustCap)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package nebulosa.api.focusers
import nebulosa.api.devices.DeviceMessageEvent
import nebulosa.indi.device.focuser.Focuser

data class FocuserMessageEvent(override val eventName: String, override val device: Focuser) :
DeviceMessageEvent<Focuser>
data class FocuserMessageEvent(override val eventName: String, override val device: Focuser) : DeviceMessageEvent<Focuser>
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package nebulosa.api.guiding
import nebulosa.api.devices.DeviceMessageEvent
import nebulosa.indi.device.guider.GuideOutput

data class GuideOutputMessageEvent(override val eventName: String, override val device: GuideOutput) :
DeviceMessageEvent<GuideOutput>
data class GuideOutputMessageEvent(override val eventName: String, override val device: GuideOutput) : DeviceMessageEvent<GuideOutput>
3 changes: 1 addition & 2 deletions api/src/main/kotlin/nebulosa/api/wheels/WheelMessageEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package nebulosa.api.wheels
import nebulosa.api.devices.DeviceMessageEvent
import nebulosa.indi.device.filterwheel.FilterWheel

data class WheelMessageEvent(override val eventName: String, override val device: FilterWheel) :
DeviceMessageEvent<FilterWheel>
data class WheelMessageEvent(override val eventName: String, override val device: FilterWheel) : DeviceMessageEvent<FilterWheel>
8 changes: 8 additions & 0 deletions desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ The complete integrated solution for all of your astronomical imaging needs.

![](rotator.png)

## Light Box

![](light-box.png)

## Dust Cap

![](dust-cap.png)

## Guider

![](guider.png)
Expand Down
Binary file added desktop/dust-cap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified desktop/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added desktop/light-box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions desktop/src/app/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export class AboutComponent {
this.icons.push({ link: `${FLAT_ICON_URL}/blackhole_6704410`, name: 'Blackhole', author: 'Freepik - Flaticon' })
this.icons.push({ link: `${FLAT_ICON_URL}/calibration_2364169`, name: 'Calibration', author: 'Freepik - Flaticon' })
this.icons.push({ link: `${FLAT_ICON_URL}/idea_3351801`, name: 'Bulb', author: 'Good Ware - Flaticon' })
this.icons.push({ link: `${FLAT_ICON_URL}/lid_7558659`, name: 'Lid', author: 'Nikita Golubev - Flaticon' })
this.icons.push({ link: `${FLAT_ICON_URL}/toolkit_4229807`, name: 'Toolkit', author: 'Freepik - Flaticon' })
}

private mapDependencies() {
Expand Down
5 changes: 5 additions & 0 deletions desktop/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AutoFocusComponent } from './autofocus/autofocus.component'
import { CalculatorComponent } from './calculator/calculator.component'
import { CalibrationComponent } from './calibration/calibration.component'
import { CameraComponent } from './camera/camera.component'
import { DustCapComponent } from './dustcap/dustcap.component'
import { FilterWheelComponent } from './filterwheel/filterwheel.component'
import { FlatWizardComponent } from './flat-wizard/flat-wizard.component'
import { FocuserComponent } from './focuser/focuser.component'
Expand Down Expand Up @@ -57,6 +58,10 @@ const routes: Routes = [
path: 'light-box',
component: LightBoxComponent,
},
{
path: 'dust-cap',
component: DustCapComponent,
},
{
path: 'guider',
component: GuiderComponent,
Expand Down
2 changes: 2 additions & 0 deletions desktop/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import { FormulaComponent } from './calculator/formula/formula.component'
import { CalibrationComponent } from './calibration/calibration.component'
import { CameraComponent } from './camera/camera.component'
import { ExposureTimeComponent } from './camera/exposure-time.component'
import { DustCapComponent } from './dustcap/dustcap.component'
import { FilterWheelComponent } from './filterwheel/filterwheel.component'
import { FlatWizardComponent } from './flat-wizard/flat-wizard.component'
import { FocuserComponent } from './focuser/focuser.component'
Expand Down Expand Up @@ -123,6 +124,7 @@ import { StackerComponent } from './stacker/stacker.component'
DeviceNameComponent,
DialogMenuComponent,
DropdownOptionsPipe,
DustCapComponent,
EnumPipe,
EnumDropdownPipe,
EnvPipe,
Expand Down
Loading

0 comments on commit b9d51ed

Please sign in to comment.