Skip to main content
1-Visitor
September 13, 2019
Question

Simulate Live Data in Vuforia Studio using Java Script

  • September 13, 2019
  • 1 reply
  • 5485 views

I am looking to change the data in a 3D gauge using Java Script to simulate live data. Any suggestions?

1 reply

21-Topaz I
September 13, 2019

Hi @dallen3 ,

 

here a very simple example simulating a value:

So following demo project :

 

2019-09-13_17-29-50.gif

 

In this project I have a 3D gauge "3DGauge-1" and application parameter RPM

Then added the following script:

 

 

////////simulate properties
 //this will set the applicaiton parameter "RPM" to random value between 1-100
 function setRPMValue()
{
 
 var retValue = Math.floor(Math.random() * 100)+1
 $scope.app.params['RPM']= retValue;
//print in the debugging consol 
console.log("rpm callback to value="+retValue)
 }
//will call this function every 1 sec
var timerId= setInterval(setRPMValue,1000,true)
//////// watch construct which watch the change of the app parameter "RPM"
$scope.$watch(
 function() 
 { return $scope.app.params['RPM']; }
 ,
 function() 
 { //set the value of the gauge
$scope.view.wdg['3DGauge-1']['text']= $scope.app.params['RPM']
 });

 

The code will change the value of the application parameter RPM to random value in range 1-100 

The interval callback will call the  setRPMValue function every 1 sec

The $watch construct will bind the value to the gauge text property. Of course, you can use direct binding from application parameter "RPM" to 3DGauge-1 .text. In this case the $watch construct is not required e.g:

 

 

2019-09-13_17-45-21.gif

 

Additionally, you can add a filter for example to use some units in the display.  About detail for using a binding filter you can see the topic: “Using Connection Filters for state-based rendering and value formatting”

 

dallen31-VisitorAuthor
1-Visitor
September 13, 2019

Great and thank you!