From 6f63629119a8efb13613dbcb25eb5a76f29096d5 Mon Sep 17 00:00:00 2001 From: Johnathon Slightham Date: Wed, 4 Mar 2026 07:55:35 -0500 Subject: [PATCH 1/2] Add control library for distance sensor and display --- Assets/ControlLibrary/ControlLibrary.cs | 6 +++ Assets/DisplayModule.cs | 2 + Assets/DistanceSensorModule.cs | 46 ++++++++++++++++++----- Assets/Module/DistanceSensorModule.prefab | 7 ++-- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/Assets/ControlLibrary/ControlLibrary.cs b/Assets/ControlLibrary/ControlLibrary.cs index d36f6ef..749e36e 100644 --- a/Assets/ControlLibrary/ControlLibrary.cs +++ b/Assets/ControlLibrary/ControlLibrary.cs @@ -19,6 +19,12 @@ public class ControlLibrary : MonoBehaviour [DllImport("libc_control")] private static extern IntPtr get_configuration(out int module_id); // the data this points to will be invalidated when called again + [DllImport("libc_control")] + public static extern int send_string_control(int module_id, string s); + + [DllImport("libc_control")] + public static extern double get_distance_control(int module_id); + [DllImport("libc_control")] public static extern bool control_sentry_init( string dsn, diff --git a/Assets/DisplayModule.cs b/Assets/DisplayModule.cs index 07d98fe..b74aec9 100644 --- a/Assets/DisplayModule.cs +++ b/Assets/DisplayModule.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System; public class DisplayModule : ModuleBase { @@ -17,5 +18,6 @@ public class DisplayModule : ModuleBase // Replace with actual hardware communication logic Debug.Log($"[DisplayModule] Sending display text: {text}"); // Example: ControlLibrary.send_display_text(Int32.Parse(moduleID), text); + ControlLibrary.send_string_control(Int32.Parse(moduleID), text); } } diff --git a/Assets/DistanceSensorModule.cs b/Assets/DistanceSensorModule.cs index 66d8c25..3dc16f4 100644 --- a/Assets/DistanceSensorModule.cs +++ b/Assets/DistanceSensorModule.cs @@ -1,20 +1,48 @@ +using System; +using UnityEngine; + public class DistanceSensorModule : ModuleBase { - public bool objectDetected; - public float distanceMeters; - public string[] infoLines = new string[0]; + // Keep a fixed-size array (no GC alloc every frame) + public string[] infoLines = new string[2]; + public override string moduleType => "Distance"; public override string moduleName => "Distance Sensor Module"; + // Optional: slow down polling to avoid spamming hardware + [SerializeField] float pollHz = 10f; + float nextPollTime; + void Update() { - // Replace with your ControlLibrary call pattern - // var reading = ControlLibrary.get_distance(...) + // Always show something immediately + infoLines[0] = $"ModuleID raw: '{moduleID}'"; - if (!objectDetected) - infoLines = new[] {"Object: Not detected" }; - else - infoLines = new[] { "Object: Detected", $"Distance: {distanceMeters:F2} m" }; + // Poll at a fixed rate (avoids frame spam) + if (Time.unscaledTime < nextPollTime) return; + nextPollTime = Time.unscaledTime + (1f / Mathf.Max(1f, pollHz)); + + if (!int.TryParse(moduleID, out var id)) + { + infoLines[1] = "ERROR: moduleID is not an int"; + return; + } + + try + { + // Control library call + double distance = ControlLibrary.get_distance_control(id); + + infoLines[1] = $"Distance: {distance:F0} mm"; + } + catch (Exception e) + { + // SHOW THE PROBLEM ON SCREEN (works in release builds) + infoLines[1] = $"EXCEPTION: {e.GetType().Name}: {e.Message}"; + + // Also log to Player.log (works in builds) + Debug.LogException(e); + } } public string[] GetInfoLines() => infoLines; diff --git a/Assets/Module/DistanceSensorModule.prefab b/Assets/Module/DistanceSensorModule.prefab index 4a76439..7b73ce3 100644 --- a/Assets/Module/DistanceSensorModule.prefab +++ b/Assets/Module/DistanceSensorModule.prefab @@ -77,9 +77,10 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e4735e9a5ae30490bba1dc35e4603bce, type: 3} m_Name: m_EditorClassIdentifier: '::' - objectDetected: 0 - distanceMeters: 0 - infoLines: [] + infoLines: + - + - + pollHz: 10 --- !u!1 &5041994602013865196 GameObject: m_ObjectHideFlags: 0 From d318b238efb18503c18b793ae8d359a03e4f68db Mon Sep 17 00:00:00 2001 From: Leo Qu Date: Wed, 4 Mar 2026 10:42:37 -0500 Subject: [PATCH 2/2] Main camera adjustments in SampleScene Made-with: Cursor --- Assets/Scenes/SampleScene.unity | 135 +------------------------------- 1 file changed, 4 insertions(+), 131 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 380703b..e39ba37 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -713,24 +713,11 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 8f54eee4d6fe643ba98e080c86deb5d1, type: 3} ---- !u!1 &119477699 +--- !u!1 &119477699 stripped GameObject: - m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 2070925441746177671, guid: a1a802ecaf6775746bb2a929fb554ad8, type: 3} m_PrefabInstance: {fileID: 507316325} m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 119477707} - - component: {fileID: 119477706} - - component: {fileID: 119477705} - m_Layer: 0 - m_Name: PlayerFollowCamera - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 --- !u!114 &119477705 MonoBehaviour: m_ObjectHideFlags: 0 @@ -747,61 +734,6 @@ MonoBehaviour: cameraController: {fileID: 0} focusCameraOnSelection: 1 inverseKinematicsViewRoot: {fileID: 0} ---- !u!114 &119477706 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 2070925441746177913, guid: a1a802ecaf6775746bb2a929fb554ad8, type: 3} - m_PrefabInstance: {fileID: 507316325} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 119477699} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 45e653bab7fb20e499bda25e1b646fea, type: 3} - m_Name: - m_EditorClassIdentifier: - m_ExcludedPropertiesInInspector: - - m_Script - m_LockStageInInspector: - m_StreamingVersion: 20170927 - m_Priority: 10 - m_StandbyUpdate: 2 - m_LookAt: {fileID: 0} - m_Follow: {fileID: 0} - m_Lens: - FieldOfView: 40 - OrthographicSize: 10 - NearClipPlane: 0.2 - FarClipPlane: 500 - Dutch: 0 - ModeOverride: 0 - LensShift: {x: 0, y: 0} - GateFit: 2 - FocusDistance: 10 - m_SensorSize: {x: 1, y: 1} - m_Transitions: - m_BlendHint: 0 - m_InheritPosition: 0 - m_OnCameraLive: - m_PersistentCalls: - m_Calls: [] - m_LegacyBlendHint: 0 - m_ComponentOwner: {fileID: 1135363932} ---- !u!4 &119477707 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 2070925441746177912, guid: a1a802ecaf6775746bb2a929fb554ad8, type: 3} - m_PrefabInstance: {fileID: 507316325} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 119477699} - serializedVersion: 2 - m_LocalRotation: {x: 0.022258926, y: -0.6409151, z: 0.018598305, w: 0.7670636} - m_LocalPosition: {x: 628.26337, y: 0.588705, z: 925.5157} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: - - {fileID: 1135363932} - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &131686076 GameObject: m_ObjectHideFlags: 0 @@ -8693,10 +8625,10 @@ MonoBehaviour: handCursor: {fileID: 0} eyeCursor: {fileID: 0} cursorHotspot: {x: 0, y: 0} - panSpeed: 3.5 + panSpeed: 10 zoomSpeed: 10 moveSmoothTime: 0.12 - orbitSpeed: 20 + orbitSpeed: 5 minPitch: -80 maxPitch: 80 orbitSmoothTime: 0.08 @@ -10125,26 +10057,11 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1133813083} m_CullTransparentMesh: 1 ---- !u!1 &1135363928 +--- !u!1 &1135363928 stripped GameObject: - m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 2070925442191277755, guid: a1a802ecaf6775746bb2a929fb554ad8, type: 3} m_PrefabInstance: {fileID: 507316325} m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1135363932} - - component: {fileID: 1135363934} - - component: {fileID: 1135363933} - - component: {fileID: 1135363931} - - component: {fileID: 1135363930} - m_Layer: 0 - m_Name: cm - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 --- !u!114 &1135363930 MonoBehaviour: m_ObjectHideFlags: 3 @@ -10194,50 +10111,6 @@ MonoBehaviour: m_YawDamping: 0 m_RollDamping: 0 m_AngularDamping: 0 ---- !u!4 &1135363932 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 2070925442191277756, guid: a1a802ecaf6775746bb2a929fb554ad8, type: 3} - m_PrefabInstance: {fileID: 507316325} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1135363928} - serializedVersion: 2 - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 119477707} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &1135363933 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 2070925442191277753, guid: a1a802ecaf6775746bb2a929fb554ad8, type: 3} - m_PrefabInstance: {fileID: 507316325} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1135363928} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 68bb026fafb42b14791938953eaace77, type: 3} - m_Name: - m_EditorClassIdentifier: - m_NoiseProfile: {fileID: 11400000, guid: 46965f9cbaf525742a6da4c2172a99cd, type: 2} - m_PivotOffset: {x: 0, y: 0, z: 1} - m_AmplitudeGain: 0.5 - m_FrequencyGain: 0.3 - mNoiseOffsets: {x: -451.37964, y: 684.7062, z: 648.0488} ---- !u!114 &1135363934 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 2070925442191277757, guid: a1a802ecaf6775746bb2a929fb554ad8, type: 3} - m_PrefabInstance: {fileID: 507316325} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1135363928} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ac0b09e7857660247b1477e93731de29, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &1140898551 GameObject: m_ObjectHideFlags: 0