diff options
author | Humberto Alfonso Díaz <humberto.alfonso@asvito.es> | 2019-12-10 14:06:17 +0100 |
---|---|---|
committer | Lorenzo Tilve <ltilve@igalia.com> | 2020-02-04 19:03:18 +0100 |
commit | 427a12e11932716a87741686e558a0ad8b49bb03 (patch) | |
tree | 3658eb3e12a0380b8ed2f77baa5e052f63762ebe /src/js/app.js | |
parent | aa8165f9173cf95c18deaaf0ce4e685d2cce3775 (diff) |
FUNCT First Dashboard version
Diffstat (limited to 'src/js/app.js')
-rw-r--r-- | src/js/app.js | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/src/js/app.js b/src/js/app.js index 9269de5..7ce31f9 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -1,9 +1,32 @@ import { load as load_template } from './templates'; import Mustache from 'mustache'; +import { lowcan } from 'agl-js-api'; + var template; var page = { - + speed: 0, + tires: { + front: { + left: 21, + right: 22 + }, + rear: { + left: 23, + right: 24 + } + }, + rpm: { + value: 0, + percent: 0 + }, + isWarning: true, + fuel: { + percent: 100, + level: 14, + range: 650, + avg: 25.5 + } }; export function show() { @@ -11,6 +34,24 @@ export function show() { } export function init() { + + lowcan.list().then( function( result ) { + console.log(result.length); + for( var i=0;i<result.length; i++) { + if( result[i].startsWith('messages') ) { + (function(event) { + lowcan.get(event).then( function( result ) { + console.log(result[0].event, result[0].value); + }, function(error){ + console.error(event, error); + }); + })(result[i]); + } + } + }, function(error){ + console.error(error); + }); + load_template('main.template.html').then(function(result) { template = result; Mustache.parse(template); @@ -18,4 +59,36 @@ export function init() { }, function(error) { console.error('ERRROR loading main template', error); }); +} + +export function simulate() { + console.log('SIMULATE'); + var counter = 0; + var interval = setInterval(function() { + counter ++; + if( page.speed < 60 ) { + page.speed += Math.floor(Math.random()*10); + if( page.rpm.percent < 80 ) { + page.rpm.percent += Math.floor(Math.random()*25); + } else { + page.rpm.percent = 40; + } + } else if (Math.random() > 0.5 ) { + page.speed += Math.floor(Math.random()*10); + page.rpm.percent = Math.min(80, Math.floor(Math.random()*90)); + } else { + page.speed -= Math.floor(Math.random()*10); + page.rpm.percent = Math.min(80, Math.floor(Math.random()*90)); + } + + page.fuel.percent = Math.round(page.fuel.percent - 0.01); + page.fuel.level = Math.round(page.fuel.level - 0.01); + page.fuel.range = Math.round(page.fuel.range - 0.01); + + show(); + + if( counter > 600 ) { + clearInterval(interval); + } + }, 1000); }
\ No newline at end of file |