Skip to content

Commit b7b1c6b

Browse files
sebgodclaude
andcommitted
Seed filter slot names from hardware during ZWO EFW discovery
ListDevice now accepts an optional seedQueryParams delegate to extract extra URI query params while the device is briefly open during discovery. For EFW devices, this seeds filter1=Filter 1&...&filterN=Filter N from the hardware NumberOfSlots, giving the equipment tab the correct slot count immediately without requiring a full connect. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6a3328a commit b7b1c6b

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

src/TianWen.Lib/Devices/ZWO/ZWODeviceSource.cs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,32 +68,48 @@ public IEnumerable<ZWODevice> RegisteredDevices(DeviceType deviceType)
6868

6969
static IEnumerable<ZWODevice> ListEAFs() => ListDevice<EAF_INFO>(DeviceType.Focuser);
7070

71-
static IEnumerable<ZWODevice> ListEFWs() => ListDevice<EFW_INFO>(DeviceType.FilterWheel);
71+
static IEnumerable<ZWODevice> ListEFWs() => ListDevice<EFW_INFO>(DeviceType.FilterWheel, SeedFilterParams);
7272

73-
static IEnumerable<ZWODevice> ListDevice<TDeviceInfo>(DeviceType deviceType) where TDeviceInfo : struct, INativeDeviceInfo
73+
/// <summary>
74+
/// Builds query params seeding default filter names from the hardware slot count
75+
/// (available while the EFW is open during discovery).
76+
/// </summary>
77+
private static string? SeedFilterParams(EFW_INFO efwInfo)
78+
{
79+
var slotCount = efwInfo.NumberOfSlots;
80+
if (slotCount <= 0)
81+
{
82+
return null;
83+
}
84+
85+
var parts = new string[slotCount];
86+
for (var i = 0; i < slotCount; i++)
87+
{
88+
parts[i] = $"{DeviceQueryKeyExtensions.FilterKey(i + 1)}={Uri.EscapeDataString($"Filter {i + 1}")}";
89+
}
90+
return string.Join("&", parts);
91+
}
92+
93+
static IEnumerable<ZWODevice> ListDevice<TDeviceInfo>(DeviceType deviceType, Func<TDeviceInfo, string?>? seedQueryParams = null) where TDeviceInfo : struct, INativeDeviceInfo
7494
{
7595
var ids = new HashSet<int>();
7696

77-
var cameraIterator = new DeviceIterator<TDeviceInfo>();
97+
var iterator = new DeviceIterator<TDeviceInfo>();
7898

79-
foreach (var deviceInfo in cameraIterator)
99+
foreach (var deviceInfo in iterator)
80100
{
81101
if (!ids.Contains(deviceInfo.ID) && deviceInfo.Open())
82102
{
83103
try
84104
{
85-
if (deviceInfo.SerialNumber is { Length: > 0 } serialNumber)
86-
{
87-
yield return new ZWODevice(deviceType, serialNumber, deviceInfo.Name);
88-
}
89-
else if (deviceInfo.IsUSB3Device && deviceInfo.CustomId is { Length: > 0 } customId)
90-
{
91-
yield return new ZWODevice(deviceType, customId, deviceInfo.Name);
92-
}
93-
else
94-
{
95-
yield return new ZWODevice(deviceType, deviceInfo.Name, deviceInfo.Name);
96-
}
105+
var deviceId = deviceInfo.SerialNumber is { Length: > 0 } sn ? sn
106+
: deviceInfo.IsUSB3Device && deviceInfo.CustomId is { Length: > 0 } cid ? cid
107+
: deviceInfo.Name;
108+
109+
var extraQuery = seedQueryParams?.Invoke(deviceInfo);
110+
var queryPart = extraQuery is { Length: > 0 } ? $"?{extraQuery}" : "";
111+
var uri = new Uri($"{deviceType}://{typeof(ZWODevice).Name}/{deviceId}{queryPart}#{deviceInfo.Name}");
112+
yield return new ZWODevice(uri);
97113

98114
ids.Add(deviceInfo.ID);
99115
}

0 commit comments

Comments
 (0)