Skip to content

Commit

Permalink
CameraServer remove NT-driven settings
Browse files Browse the repository at this point in the history
matches #467 on allwpilib
  • Loading branch information
ThadHouse committed Jan 20, 2017
1 parent fde9ae1 commit 3ce92c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
33 changes: 19 additions & 14 deletions WPILib/CameraServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ private static void PutSourcePropertyValue(ITable table, VideoEvent evnt, bool i
string infoName;
if (evnt.Name.StartsWith("raw_"))
{
name = $"RawProperty/{evnt.Name.Substring(4)}";
infoName = $"RawPropertyInfo/{evnt.Name.Substring(4)}";
name = $"RawProperty/{evnt.Name}";
infoName = $"RawPropertyInfo/{evnt.Name}";
}
else
{
Expand Down Expand Up @@ -371,9 +371,16 @@ private CameraServer()
NativeMethods.GetSourceDescription(vidEvent.SourceHandle));
table.PutBoolean("connected", NativeMethods.IsSourceConnected(vidEvent.SourceHandle));
table.PutStringArray("streams", GetSourceStreamValues(vidEvent.SourceHandle));
VideoMode mode = NativeMethods.GetSourceVideoMode(vidEvent.SourceHandle);
table.SetDefaultString("mode", VideoModeToString(mode));
table.PutStringArray("modes", GetSourceModeValues(vidEvent.SourceHandle));
try
{
VideoMode mode = NativeMethods.GetSourceVideoMode(vidEvent.SourceHandle);
table.SetDefaultString("mode", VideoModeToString(mode));
table.PutStringArray("modes", GetSourceModeValues(vidEvent.SourceHandle));
}
catch (VideoException)
{
// Do nothing
}
break;
}
case EventKind.SourceDestroyed:
Expand Down Expand Up @@ -416,6 +423,7 @@ private CameraServer()
}
case EventKind.SourceVideoModeChanged:
{

ITable table = GetSourceTable(vidEvent.SourceHandle);
if (table != null)
{
Expand Down Expand Up @@ -486,11 +494,8 @@ private CameraServer()
string propName;
if (relativeKey == "mode")
{
VideoMode mode = VideoModeFromString(value.GetString());
if (mode.PixelFormat == PixelFormat.Unknown || !source.SetVideoMode(mode))
{
NtCore.SetEntryString(key, VideoModeToString(source.GetVideoMode()));
}
// reset to current mode
NtCore.SetEntryString(key, VideoModeToString(source.GetVideoMode()));
return;
}
else if (relativeKey.StartsWith("Property/"))
Expand All @@ -512,17 +517,17 @@ private CameraServer()
case PropertyKind.None:
return;
case PropertyKind.Boolean:
prop.Set(value.GetBoolean() ? 1 : 0);
NtCore.SetEntryBoolean(key, prop.Get() != 0);
break;
case PropertyKind.Integer:
case PropertyKind.Enum:
prop.Set((int)value.GetDouble());
NtCore.SetEntryDouble(key, prop.Get());
break;
case PropertyKind.String:
prop.SetString(value.GetString());
NtCore.SetEntryString(key, prop.GetString());
break;
default:
throw new ArgumentOutOfRangeException();
return;
}

}, NotifyFlags.NotifyImmediate | NotifyFlags.NotifyUpdate);
Expand Down
2 changes: 1 addition & 1 deletion WPILib/WPILib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

0 comments on commit 3ce92c8

Please sign in to comment.