-
-
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
23 changed files
with
614 additions
and
64 deletions.
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
74 changes: 74 additions & 0 deletions
74
api/src/main/kotlin/nebulosa/api/controllers/FocuserController.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,74 @@ | ||
package nebulosa.api.controllers | ||
|
||
import jakarta.validation.Valid | ||
import jakarta.validation.constraints.NotBlank | ||
import jakarta.validation.constraints.PositiveOrZero | ||
import nebulosa.api.data.responses.FocuserResponse | ||
import nebulosa.api.services.FocuserService | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class FocuserController( | ||
private val focuserService: FocuserService, | ||
) { | ||
|
||
@GetMapping("attachedFocusers") | ||
fun attachedFocusers(): List<FocuserResponse> { | ||
return focuserService.attachedFocusers() | ||
} | ||
|
||
@GetMapping("focuser") | ||
fun focuser(@RequestParam @Valid @NotBlank name: String): FocuserResponse { | ||
return focuserService[name] | ||
} | ||
|
||
@PostMapping("focuserConnect") | ||
fun connect(@RequestParam @Valid @NotBlank name: String) { | ||
focuserService.connect(name) | ||
} | ||
|
||
@PostMapping("focuserDisconnect") | ||
fun disconnect(@RequestParam @Valid @NotBlank name: String) { | ||
focuserService.disconnect(name) | ||
} | ||
|
||
@PostMapping("focuserMoveIn") | ||
fun moveIn( | ||
@RequestParam @Valid @NotBlank name: String, | ||
@RequestParam @Valid @PositiveOrZero steps: Int, | ||
) { | ||
focuserService.moveIn(name, steps) | ||
} | ||
|
||
@PostMapping("focuserMoveOut") | ||
fun moveOut( | ||
@RequestParam @Valid @NotBlank name: String, | ||
@RequestParam @Valid @PositiveOrZero steps: Int, | ||
) { | ||
focuserService.moveOut(name, steps) | ||
} | ||
|
||
@PostMapping("focuserMoveTo") | ||
fun moveTo( | ||
@RequestParam @Valid @NotBlank name: String, | ||
@RequestParam @Valid @PositiveOrZero steps: Int, | ||
) { | ||
focuserService.moveTo(name, steps) | ||
} | ||
|
||
@PostMapping("focuserAbort") | ||
fun abort(@RequestParam @Valid @NotBlank name: String) { | ||
focuserService.abort(name) | ||
} | ||
|
||
@PostMapping("focuserSyncTo") | ||
fun syncTo( | ||
@RequestParam @Valid @NotBlank name: String, | ||
@RequestParam @Valid @PositiveOrZero steps: Int, | ||
) { | ||
focuserService.syncTo(name, steps) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
api/src/main/kotlin/nebulosa/api/data/responses/FocuserResponse.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,38 @@ | ||
package nebulosa.api.data.responses | ||
|
||
import nebulosa.indi.device.focuser.Focuser | ||
|
||
data class FocuserResponse( | ||
val name: String, | ||
val connected: Boolean, | ||
val moving: Boolean, | ||
val position: Int, | ||
val canAbsoluteMove: Boolean, | ||
val canRelativeMove: Boolean, | ||
val canAbort: Boolean, | ||
val canReverse: Boolean, | ||
val reverse: Boolean, | ||
val canSync: Boolean, | ||
val hasBackslash: Boolean, | ||
val maxPosition: Int, | ||
val hasThermometer: Boolean, | ||
val temperature: Double, | ||
) { | ||
|
||
constructor(focuser: Focuser) : this( | ||
focuser.name, | ||
focuser.connected, | ||
focuser.moving, | ||
focuser.position, | ||
focuser.canAbsoluteMove, | ||
focuser.canRelativeMove, | ||
focuser.canAbort, | ||
focuser.canReverse, | ||
focuser.reverse, | ||
focuser.canSync, | ||
focuser.hasBackslash, | ||
focuser.maxPosition, | ||
focuser.hasThermometer, | ||
focuser.temperature, | ||
) | ||
} |
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
78 changes: 78 additions & 0 deletions
78
api/src/main/kotlin/nebulosa/api/services/FocuserService.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,78 @@ | ||
package nebulosa.api.services | ||
|
||
import jakarta.annotation.PostConstruct | ||
import nebulosa.api.data.responses.FocuserResponse | ||
import nebulosa.indi.device.PropertyChangedEvent | ||
import nebulosa.indi.device.focuser.FocuserAttached | ||
import nebulosa.indi.device.focuser.FocuserDetached | ||
import nebulosa.indi.device.focuser.FocuserEvent | ||
import org.greenrobot.eventbus.EventBus | ||
import org.greenrobot.eventbus.Subscribe | ||
import org.greenrobot.eventbus.ThreadMode | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class FocuserService( | ||
private val equipmentService: EquipmentService, | ||
private val webSocketService: WebSocketService, | ||
private val eventBus: EventBus, | ||
) { | ||
|
||
@PostConstruct | ||
private fun initialize() { | ||
eventBus.register(this) | ||
} | ||
|
||
@Subscribe(threadMode = ThreadMode.ASYNC) | ||
fun onFocuserEvent(event: FocuserEvent) { | ||
when (event) { | ||
is PropertyChangedEvent -> webSocketService.sendFocuserUpdated(event.device!!) | ||
is FocuserAttached -> webSocketService.sendFocuserAttached(event.device) | ||
is FocuserDetached -> webSocketService.sendFocuserDetached(event.device) | ||
} | ||
} | ||
|
||
fun attachedFocusers(): List<FocuserResponse> { | ||
return equipmentService.focusers().map(::FocuserResponse) | ||
} | ||
|
||
operator fun get(name: String): FocuserResponse { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
return FocuserResponse(focuser) | ||
} | ||
|
||
fun connect(name: String) { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
focuser.connect() | ||
} | ||
|
||
fun disconnect(name: String) { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
focuser.disconnect() | ||
} | ||
|
||
fun moveIn(name: String, steps: Int) { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
focuser.moveFocusIn(steps) | ||
} | ||
|
||
fun moveOut(name: String, steps: Int) { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
focuser.moveFocusOut(steps) | ||
} | ||
|
||
fun moveTo(name: String, steps: Int) { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
focuser.moveFocusTo(steps) | ||
} | ||
|
||
fun abort(name: String) { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
focuser.abortFocus() | ||
} | ||
|
||
fun syncTo(name: String, steps: Int) { | ||
val focuser = requireNotNull(equipmentService.focuser(name)) | ||
focuser.syncFocusTo(steps) | ||
} | ||
} |
Oops, something went wrong.