Skip to content

Commit 3ce92c8

Browse files
committed
CameraServer remove NT-driven settings
matches #467 on allwpilib
1 parent fde9ae1 commit 3ce92c8

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

WPILib/CameraServer.cs

+19-14
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ private static void PutSourcePropertyValue(ITable table, VideoEvent evnt, bool i
293293
string infoName;
294294
if (evnt.Name.StartsWith("raw_"))
295295
{
296-
name = $"RawProperty/{evnt.Name.Substring(4)}";
297-
infoName = $"RawPropertyInfo/{evnt.Name.Substring(4)}";
296+
name = $"RawProperty/{evnt.Name}";
297+
infoName = $"RawPropertyInfo/{evnt.Name}";
298298
}
299299
else
300300
{
@@ -371,9 +371,16 @@ private CameraServer()
371371
NativeMethods.GetSourceDescription(vidEvent.SourceHandle));
372372
table.PutBoolean("connected", NativeMethods.IsSourceConnected(vidEvent.SourceHandle));
373373
table.PutStringArray("streams", GetSourceStreamValues(vidEvent.SourceHandle));
374-
VideoMode mode = NativeMethods.GetSourceVideoMode(vidEvent.SourceHandle);
375-
table.SetDefaultString("mode", VideoModeToString(mode));
376-
table.PutStringArray("modes", GetSourceModeValues(vidEvent.SourceHandle));
374+
try
375+
{
376+
VideoMode mode = NativeMethods.GetSourceVideoMode(vidEvent.SourceHandle);
377+
table.SetDefaultString("mode", VideoModeToString(mode));
378+
table.PutStringArray("modes", GetSourceModeValues(vidEvent.SourceHandle));
379+
}
380+
catch (VideoException)
381+
{
382+
// Do nothing
383+
}
377384
break;
378385
}
379386
case EventKind.SourceDestroyed:
@@ -416,6 +423,7 @@ private CameraServer()
416423
}
417424
case EventKind.SourceVideoModeChanged:
418425
{
426+
419427
ITable table = GetSourceTable(vidEvent.SourceHandle);
420428
if (table != null)
421429
{
@@ -486,11 +494,8 @@ private CameraServer()
486494
string propName;
487495
if (relativeKey == "mode")
488496
{
489-
VideoMode mode = VideoModeFromString(value.GetString());
490-
if (mode.PixelFormat == PixelFormat.Unknown || !source.SetVideoMode(mode))
491-
{
492-
NtCore.SetEntryString(key, VideoModeToString(source.GetVideoMode()));
493-
}
497+
// reset to current mode
498+
NtCore.SetEntryString(key, VideoModeToString(source.GetVideoMode()));
494499
return;
495500
}
496501
else if (relativeKey.StartsWith("Property/"))
@@ -512,17 +517,17 @@ private CameraServer()
512517
case PropertyKind.None:
513518
return;
514519
case PropertyKind.Boolean:
515-
prop.Set(value.GetBoolean() ? 1 : 0);
520+
NtCore.SetEntryBoolean(key, prop.Get() != 0);
516521
break;
517522
case PropertyKind.Integer:
518523
case PropertyKind.Enum:
519-
prop.Set((int)value.GetDouble());
524+
NtCore.SetEntryDouble(key, prop.Get());
520525
break;
521526
case PropertyKind.String:
522-
prop.SetString(value.GetString());
527+
NtCore.SetEntryString(key, prop.GetString());
523528
break;
524529
default:
525-
throw new ArgumentOutOfRangeException();
530+
return;
526531
}
527532

528533
}, NotifyFlags.NotifyImmediate | NotifyFlags.NotifyUpdate);

WPILib/WPILib.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,4 @@
233233
<Target Name="AfterBuild">
234234
</Target>
235235
-->
236-
</Project>
236+
</Project>

0 commit comments

Comments
 (0)