angular.module('gaugesScreen', [])
.controller('GaugesScreenController', function($scope, $window) {
  var unit = null;
  $scope.data = {}
  // overwriting plain javascript function so we can access from within the controller
  $window.setUnits = (data) => {
    unit = data.unitType;
  }
  
  $window.updateData = (data) => {
    $scope.$evalAsync(function() {

        if (data.enginerunning != 0 ) {
			if (data.topscreenunit != 1 ) {
		$scope.data.speedometergauge = (data.speedometergauge).toFixed(0) + "km/h"
		$scope.data.dategauge = data.dategauge
		$scope.data.timegauge = data.timegauge 

		}
		else  {
		$scope.data.speedometergauge = (data.speedometergauge * 0.621371).toFixed(0) + "mph"
		$scope.data.dategauge = data.dategauge
		$scope.data.timegauge = data.timegauge 

		}
        }
		else {
		$scope.data.speedometergauge = " "
		$scope.data.dategauge = " "
		$scope.data.timegauge = " " 

		}

    }
	)
 }
});    