Skip to content

Commit

Permalink
add switch setting
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-photo committed Aug 17, 2024
1 parent 0716bb2 commit cb3caf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ninaAPI/WebService/V2/ControllerV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion ninaAPI/WebService/V2/EquipmentControllerV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -477,7 +478,7 @@ public static async Task<HttpResponse> Dome(string action)
}
}

public static async Task<HttpResponse> Switch(string action)
public static async Task<HttpResponse> Switch(string action, short index, double value)
{
HttpResponse response = new HttpResponse();
ISwitchMediator switches = AdvancedAPI.Controls.Switch;
Expand All @@ -501,6 +502,14 @@ public static async Task<HttpResponse> 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);
Expand Down

0 comments on commit cb3caf9

Please sign in to comment.