diff --git a/ninaAPI/WebService/V2/ControllerV2.cs b/ninaAPI/WebService/V2/ControllerV2.cs index 735bcab..3fc632b 100644 --- a/ninaAPI/WebService/V2/ControllerV2.cs +++ b/ninaAPI/WebService/V2/ControllerV2.cs @@ -443,7 +443,7 @@ public async Task Flatdevice(string action) } [Route(HttpVerbs.Get, "/equipment/switch/{action}")] - public async Task Switch(string action) + public async Task Switch(string action, [QueryField] short index, [QueryField] double value) { Logger.Debug($"API call: {HttpContext.Request.Url.AbsoluteUri}"); try @@ -454,7 +454,7 @@ public async Task Switch(string action) } else { - HttpContext.WriteToResponse(await EquipmentControllerV2.Switch(action)); + HttpContext.WriteToResponse(await EquipmentControllerV2.Switch(action, index, value)); } } catch (Exception ex) diff --git a/ninaAPI/WebService/V2/EquipmentControllerV2.cs b/ninaAPI/WebService/V2/EquipmentControllerV2.cs index 7c2e844..967b0ee 100644 --- a/ninaAPI/WebService/V2/EquipmentControllerV2.cs +++ b/ninaAPI/WebService/V2/EquipmentControllerV2.cs @@ -58,6 +58,7 @@ public class EquipmentControllerV2 private static CancellationTokenSource DomeToken; private static CancellationTokenSource RotatorToken; private static CancellationTokenSource CaptureToken; + private static CancellationTokenSource SwitchToken; private static PlateSolveResult plateSolveResult; private static IRenderedImage renderedImage; @@ -477,7 +478,7 @@ public static async Task Dome(string action) } } - public static async Task Switch(string action) + public static async Task Switch(string action, short index, double value) { HttpResponse response = new HttpResponse(); ISwitchMediator switches = AdvancedAPI.Controls.Switch; @@ -501,6 +502,14 @@ public static async Task Switch(string action) response.Response = "Switch disconnected"; return response; } + else if (action.Equals("set")) + { + SwitchToken?.Cancel(); + SwitchToken = new CancellationTokenSource(); + switches.SetSwitchValue(index, value, AdvancedAPI.Controls.StatusMediator.GetStatus(), SwitchToken.Token); + response.Response = "Switch value updated"; + return response; + } else { response = Utility.CreateErrorTable(CommonErrors.UNKNOWN_ACTION);