Skip to content

Commit

Permalink
[api][desktop]: Fix Alpaca Filter Wheel and Focuser
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagohm committed Apr 19, 2024
1 parent 7597dab commit be504df
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 34 deletions.
2 changes: 1 addition & 1 deletion desktop/src/app/filterwheel/filterwheel.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</div>
<div class="col-12 flex align-items-center justify-content-between gap-1">
<neb-device-list-button title="FOCUSER" icon="mdi mdi-image-filter-center-focus" [devices]="focusers" [(device)]="focuser"
(deviceChange)="focuserChanged()" />
(deviceChange)="focuserChanged()" style="max-width: 60%" />

<span class="p-float-label">
<p-inputNumber [disabled]="!wheel.connected || moving || !focuser" [(ngModel)]="focusOffset" [min]="focusOffsetMin"
Expand Down
5 changes: 4 additions & 1 deletion desktop/src/app/filterwheel/filterwheel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export class FilterWheelComponent implements AfterContentInit, OnDestroy {
if (offset < 0) this.api.focuserMoveIn(this.focuser, -offset)
else this.api.focuserMoveOut(this.focuser, offset)
}
} catch {
} catch (e) {
console.error(e)
this.moving = false
}
}
Expand Down Expand Up @@ -241,6 +242,8 @@ export class FilterWheelComponent implements AfterContentInit, OnDestroy {
this.position = this.request.filterPosition || 1
}

if (this.moving) return

let filters: FilterSlot[] = []

if (this.wheel.count <= 0) {
Expand Down
1 change: 1 addition & 0 deletions desktop/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ p-dropdown,

.p-button {
white-space: nowrap;
max-width: 100%;

&.p-button-icon-only {
min-width: fit-content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface AlpacaFilterWheelService : AlpacaDeviceService {
@GET("api/v1/filterwheel/{id}/position")
fun position(@Path("id") id: Int): Call<IntResponse>

@GET("api/v1/filterwheel/{id}/alignmentmode")
@FormUrlEncoded
@PUT("api/v1/filterwheel/{id}/position")
fun position(@Path("id") id: Int, @Field("Position") position: Int): Call<NoneResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -585,16 +585,14 @@ data class ASCOMCamera(
private fun processTemperature(init: Boolean) {
if (hasThermometer || init) {
service.ccdTemperature(device.number).doRequest {
if (it.errorNumber == 0) {
if (!hasThermometer) {
hasThermometer = true
sender.registerThermometer(this)
}
if (!hasThermometer) {
hasThermometer = true
sender.registerThermometer(this)
}

if (it.value != temperature) {
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 @@ -148,16 +148,14 @@ data class ASCOMFocuser(
private fun processTemperature(init: Boolean) {
if (hasThermometer || init) {
service.temperature(device.number).doRequest {
if (it.errorNumber == 0) {
if (!hasThermometer) {
hasThermometer = true
sender.registerThermometer(this)
}

if (it.value != temperature) {
temperature = it.value
sender.fireOnEventReceived(FocuserTemperatureChanged(this))
}
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 @@ -5,9 +5,7 @@ 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.filterwheel.FilterWheel
import nebulosa.indi.device.filterwheel.FilterWheelNamesChanged
import nebulosa.indi.device.filterwheel.FilterWheelPositionChanged
import nebulosa.indi.device.filterwheel.*
import nebulosa.indi.protocol.INDIProtocol

@Suppress("RedundantModalityModifier")
Expand All @@ -22,6 +20,8 @@ data class ASCOMFilterWheel(
@Volatile final override var moving = false
@Volatile final override var names = emptyList<String>()

@Volatile private var targetPosition = 0

override val snoopedDevices = emptyList<Device>()

override fun onConnected() {
Expand All @@ -32,8 +32,15 @@ data class ASCOMFilterWheel(
override fun onDisconnected() {}

override fun moveTo(position: Int) {
if (position != this.position) {
service.position(device.number, position).doRequest()
val newPosition = position - 1

if (newPosition >= 0 && position != this.position) {
targetPosition = newPosition

if (service.position(device.number, newPosition).doRequest() != null) {
moving = true
sender.fireOnEventReceived(FilterWheelMovingChanged(this))
}
}
}

Expand All @@ -42,36 +49,44 @@ data class ASCOMFilterWheel(

if (connected) {
processPosition()
processMoving()
}
}

override fun names(names: Iterable<String>) {
this.names = names.toList()
sender.fireOnEventReceived(FilterWheelNamesChanged(this))
}

override fun snoop(devices: Iterable<Device?>) {}

override fun handleMessage(message: INDIProtocol) {}

private fun processMoving() {}

private fun processPosition() {
service.position(device.number).doRequest {
if (it.value != position) {
val prevPosition = position
position = it.value
val value = it.value + 1

if (value > 0 && value != position) {
val prevPosition = position
position = value
sender.fireOnEventReceived(FilterWheelPositionChanged(this, prevPosition))

if (moving && value == targetPosition) {
moving = false
sender.fireOnEventReceived(FilterWheelMovingChanged(this))
}
}
}
}

private fun processNames() {
service.names(device.number).doRequest {
if (it.value.size != names.size) {
count = it.value.size
sender.fireOnEventReceived(FilterWheelCountChanged(this))
}

if (it.value != names) {
names = it.value

sender.fireOnEventReceived(FilterWheelNamesChanged(this))
}
}
Expand Down

0 comments on commit be504df

Please sign in to comment.