Skip to content

Commit 877f372

Browse files
committed
Move rotator to match selected database entry
1 parent b6060f3 commit 877f372

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

shinysdr/i/webstatic/client/coordination.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919

2020
define([
2121
'require',
22+
'geodesy/latlon-spherical',
2223
'./types',
2324
'./values',
2425
], (
2526
require,
27+
LatLon,
2628
import_types,
2729
import_values
2830
) => {
@@ -36,6 +38,7 @@ define([
3638
ConstantCell,
3739
LocalCell,
3840
StorageCell,
41+
findImplementersInBlockCell,
3942
makeBlock,
4043
} = import_values;
4144

@@ -115,7 +118,32 @@ define([
115118
// (This will require knowledge of retuning which is currently done implicitly on the server side.)
116119

117120
if (record) {
121+
// TODO: The server really needs to track the selected record because both the source and the record can move, and something needs to constantly recalculate the bearing and drive the rotator.
122+
// TODO: Provide a way for the user to disable this (e.g. in EME).
118123
selectedRecord.set(record);
124+
if (record.location) {
125+
const componentsCell = radio.source.get().components;
126+
const positionedDevices = findImplementersInBlockCell(
127+
undefined,
128+
componentsCell,
129+
'shinysdr.devices.IPositionedDevice').get();
130+
const rotators = findImplementersInBlockCell(
131+
undefined,
132+
componentsCell,
133+
'shinysdr.plugins.hamlib.IRotator').get();
134+
if (positionedDevices.length && rotators.length) {
135+
const track = positionedDevices[0].track.get();
136+
const start = new LatLon(track.latitude.value, track.longitude.value);
137+
let bearing = start.bearingTo(new LatLon(record.location[0], record.location[1]));
138+
rotators.forEach(rotator => {
139+
// TODO: It doesn't seem like I should have to do this here; the azimuth cell should know how to unwrap bearings.
140+
if (bearing > rotator.Azimuth.type.getMax()) {
141+
bearing -= 360;
142+
}
143+
rotator.Azimuth.set(bearing);
144+
});
145+
}
146+
}
119147
}
120148

121149
return receiver;
@@ -172,4 +200,4 @@ define([
172200
exports.ClientStateObject = ClientStateObject;
173201

174202
return Object.freeze(exports);
175-
});
203+
});

0 commit comments

Comments
 (0)