Skip to content

Commit

Permalink
Bargraph functionality is implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
jafarigit committed Nov 29, 2023
1 parent 1e35413 commit 2c4d5f1
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 5 deletions.
31 changes: 26 additions & 5 deletions Assets/MirageXR/Player/Prefabs/eROBSON/Prefabs/o9_bargraph.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ GameObject:
- component: {fileID: 3602013116561168751}
- component: {fileID: 8365970246065829508}
m_Layer: 0
m_Name: Line003
m_Name: led5
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -507,7 +507,7 @@ GameObject:
- component: {fileID: 2250746998940470243}
- component: {fileID: 3878434631385909016}
m_Layer: 0
m_Name: Line005
m_Name: led4
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -590,7 +590,7 @@ GameObject:
- component: {fileID: 6502004952187121599}
- component: {fileID: 1276829913763581589}
m_Layer: 0
m_Name: Line007
m_Name: led3
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -839,7 +839,7 @@ GameObject:
- component: {fileID: 7408299993418523812}
- component: {fileID: 7380300605935270615}
m_Layer: 0
m_Name: Line011
m_Name: led1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -1287,7 +1287,7 @@ GameObject:
- component: {fileID: 6127392726229386877}
- component: {fileID: 8225208080581790013}
m_Layer: 0
m_Name: Line009
m_Name: led2
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
Expand Down Expand Up @@ -1404,6 +1404,7 @@ GameObject:
- component: {fileID: 5018361853446732302}
- component: {fileID: 5104182535571999677}
- component: {fileID: 484503428188708966}
- component: {fileID: 91869103912858566}
m_Layer: 0
m_Name: o9_bargraph
m_TagString: Untagged
Expand Down Expand Up @@ -1584,6 +1585,26 @@ AudioSource:
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!114 &91869103912858566
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8503723872563970172}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7aa4ce0f82cc57145a4ca433e2a551c9, type: 3}
m_Name:
m_EditorClassIdentifier:
lightRenderers:
- {fileID: 7380300605935270615}
- {fileID: 8225208080581790013}
- {fileID: 1276829913763581589}
- {fileID: 3878434631385909016}
- {fileID: 8365970246065829508}
onMaterial: {fileID: 2100000, guid: 57315aa7aea1fd948b6f2ead88d80900, type: 2}
offMaterial: {fileID: 2100000, guid: 877908f016616ae409870e24c1a4147b, type: 2}
--- !u!1 &8824843978635763748
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using UnityEngine;

public class BargraphController : MonoBehaviour
{
[SerializeField] private Renderer[] lightRenderers;
[SerializeField] private Material onMaterial;
[SerializeField] private Material offMaterial;


/// <summary>
/// turn on the bargraph light depends on the power
/// </summary>
/// <param name="status">is connected or not</param>
/// <param name="power">the power received to this bit</param>
public void TurnOnLights(bool status, float power)
{
// Turn off all lights first
TurnOffAllLights();

//bit is disconnected
if (!status)
{
return;
}

// Determine how many lights to turn on based on the power level
var lightsToTurnOn = power switch
{
> 0f and <= 0.2f => 1,
> 0.2f and <= 0.4f => 2,
> 0.4f and <= 0.6f => 3,
> 0.6f and <= 0.8f => 4,
> 0.8f and <= 1.0f => 5,
_ => 0
};

// Turn on the appropriate number of lights
for (var i = 0; i < lightsToTurnOn; i++)
{
lightRenderers[i].material = onMaterial;
}
}


private void Start()
{
TurnOffAllLights();
}



/// <summary>
/// Turn off all lights first
/// </summary>
private void TurnOffAllLights()
{
foreach (var led in lightRenderers)
{
led.material = offMaterial;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ private async void BitActionToggle(eROBSONItems bit, bool status)
await ControlBuzzerSound(bit, status, averageValue);
break;
case BitID.O9BARGRAPH:
await ControlBarGraph(bit, status, averageValue);
break;
case BitID.O13FAN:
case BitID.O25DCMOTOR:
Expand All @@ -386,6 +387,13 @@ private async void BitActionToggle(eROBSONItems bit, bool status)



/// <summary>
/// Turn on/off the led light
/// </summary>
/// <param name="bit"></param>
/// <param name="status"></param>
/// <param name="averageValue"></param>
/// <returns></returns>
private async Task ControlLedLight(eROBSONItems bit, bool status, float averageValue)
{
var light = bit.GetComponentInChildren<Light>();
Expand All @@ -410,6 +418,13 @@ private async Task ControlLedLight(eROBSONItems bit, bool status, float averageV



/// <summary>
/// control the buzzer and play the buzz sound regarding to the power
/// </summary>
/// <param name="bit"></param>
/// <param name="status"></param>
/// <param name="averageValue"></param>
/// <returns></returns>
private async Task ControlBuzzerSound(eROBSONItems bit, bool status, float averageValue)
{
var audios = bit.GetComponentsInChildren<AudioSource>();
Expand All @@ -434,6 +449,26 @@ private async Task ControlBuzzerSound(eROBSONItems bit, bool status, float avera



/// <summary>
/// Control the bargraph and turn on/off the lights
/// </summary>
/// <param name="bit"></param>
/// <param name="averageValue"></param>
/// <returns></returns>
private async Task ControlBarGraph(eROBSONItems bit, bool status, float averageValue)
{
bit.TryGetComponent<BargraphController>(out var bargraphController);
if (!bargraphController)
{
return;
}

var power = averageValue / 2; //normalized
bargraphController.TurnOnLights(status, power);

await Task.CompletedTask;
}




Expand Down

0 comments on commit 2c4d5f1

Please sign in to comment.