adding xbox support and sACN output

This commit is contained in:
Vincent BOUQUET
2024-02-18 00:49:24 +01:00
parent 07830df99d
commit 0bdc646973
5 changed files with 396 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
using LibVLCSharp.Shared;
using Haukcode.sACN;
using LibVLCSharp.Shared;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@@ -10,6 +11,7 @@ using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using XboxControllerTest;
namespace robospot_camera_finder
{
@@ -18,6 +20,11 @@ namespace robospot_camera_finder
public LibVLC _libVLC;
public MediaPlayer _mp;
private static readonly Guid acnSourceId = new Guid("{B32625A6-C280-4389-BD25-E0D13F5B50E0}");
private static readonly string acnSourceName = "RoboSpotCamViewer";
static SACNClient sendClient = new SACNClient(senderId: acnSourceId, senderName: acnSourceName, localAddress: SACNCommon.GetFirstBindAddress().IPAddress);
string username = "admin";
string password = "RoboSpot10";
string cam_ip = "";
@@ -25,6 +32,10 @@ namespace robospot_camera_finder
int max_zoom_pulse = 9999;
int min_zoom_pulse = 10;
byte[] dmx_universe = new byte[512];
Xbox360Controller controller;
public StreamViewer(string name, string ip)
{
InitializeComponent();
@@ -35,12 +46,18 @@ namespace robospot_camera_finder
timerUpdateZoom.Start();
updateZoomSlider();
timerDMX.Start();
videoView.MediaPlayer = _mp;
var media = new Media(_libVLC, new Uri("rtsp://" + ip + "/profile2/media.smp"));
media.AddOption(":network-caching=25");
_mp.Play(media);
media.Dispose();
this.Text = name;
controller = new Xbox360Controller();
controller.update();
cbEnableXboxCtrl.Enabled = controller.connected;
}
private void updateZoomSlider()
@@ -106,5 +123,114 @@ namespace robospot_camera_finder
tbZoom.Value = min_zoom_pulse;
sendZoomValue(tbZoom.Value.ToString());
}
private void timerDMX_Tick(object sender, EventArgs e)
{
controller.update();
if (!controller.connected)
{
cbEnableXboxCtrl.Checked = false;
cbEnableXboxCtrl.Enabled = false;
}
else
{
cbEnableXboxCtrl.Enabled = true;
}
if (cbEnableXboxCtrl.Checked)
{
Point ls = controller.leftThumb;
Point rs = controller.rightThumb;
bool fast_pt = controller.buttons.LeftStick;
if ((tbPan.Value + ls.X) < 0 )
{
tbPan.Value = 0;
} else if ((tbPan.Value + ls.X) > 65535)
{
tbPan.Value = 65535;
} else
{
if (fast_pt)
{
tbPan.Value += (ls.X) * 5;
} else
{
tbPan.Value += ls.X;
}
}
if ((tbTilt.Value + ls.Y) < 0)
{
tbTilt.Value = 0;
}
else if ((tbTilt.Value + ls.Y) > 65535)
{
tbTilt.Value = 65535;
}
else
{
if (fast_pt)
{
tbTilt.Value += (ls.Y) * 5;
}
else
{
tbTilt.Value += ls.Y;
}
}
if ((tbZoom.Value + rs.Y) < min_zoom_pulse)
{
tbZoom.Value = min_zoom_pulse;
}
else if ((tbZoom.Value + rs.Y) > max_zoom_pulse)
{
tbZoom.Value = max_zoom_pulse;
}
else
{
tbZoom.Value += (rs.Y) * 5;
}
sendZoomValue(tbZoom.Value.ToString());
if (controller.buttons.LB)
{
tbZoom.Value = min_zoom_pulse;
sendZoomValue(tbZoom.Value.ToString());
}
if (controller.buttons.RB)
{
tbZoom.Value = max_zoom_pulse;
sendZoomValue(tbZoom.Value.ToString());
}
}
byte[] pan = BitConverter.GetBytes(tbPan.Value);
byte[] tilt = BitConverter.GetBytes(tbTilt.Value);
int dmx_addr = int.Parse(numDMXAddr.Value.ToString());
dmx_universe[dmx_addr - 1] = pan[1];
dmx_universe[dmx_addr] = pan[0];
dmx_universe[dmx_addr + 1] = tilt[1];
dmx_universe[dmx_addr + 2] = tilt[0];
sendClient.SendMulticast(Convert.ToUInt16(numUniv.Value.ToString()), dmx_universe);
}
private void numDMXAddr_ValueChanged(object sender, EventArgs e)
{
tbPan.Value = 128;
tbTilt.Value = 128;
for (int i = 0; i < dmx_universe.Length; i++)
{
dmx_universe[i] = 0;
}
}
}
}