summaryrefslogtreecommitdiff
path: root/webapp/js/back_up.js
blob: d242506286e90b83d77152468968f43038f707b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var BackUp = function() {
    var ws;

    var self = this;

    var $pressionTop = $('#pression-top-val');
    var $pressionBottom = $('#pression-bottom-val');
    var $flexion = $('#flexion-val');
    var $angleX = $('#angle-x-val');
    var $angleY = $('#angle-y-val');
    var $angleZ = $('#angle-z-val');

    var gauge;

    FusionCharts.ready(function () {
        gauge = new FusionCharts({
            'id': 'chart',
            'type': 'angulargauge',
            'renderAt': 'fusioncharts-div',
            'width': '1000',
            'height': '500',
            'dataFormat': 'json',
            'dataSource': {
                'chart': {
                    //'caption': 'Inclinaison',
                    'lowerLimit': '160',
                    'upperLimit': '200',
                    'theme': 'fint',
                    "gaugeFillMix": "{dark-40},{light-40},{dark-20}",
                    'bgColor': '#00b0c0',
                },
                'colorRange': {
                    'color': [
                    {
                        'minValue': '160',
                        'maxValue': '171',
                        'code': '#b41527',
                    }, {
                        'minValue': '171',
                        'maxValue': '175',
                        'code': '#e48739',
                    }, {
                        'minValue': '175',
                        'maxValue': '185',
                        'code': '#399e38',
                    }, {
                        'minValue': '185',
                        'maxValue': '189',
                        'code': '#e48739',
                    }, {
                        'minValue': '189',
                        'maxValue': '200',
                        'code': '#b41527',
                    },
                    ],
                },
                'dials': {
                    'dial': [ {
                        'id': 'Dial1',
                        'value': '180',
                        'borderalpha': '0',
                        'bgColor': '0,#aaaaaa,0',
                        'basewidth': '40',
                        'topwidth': '1',
                        'radius': '300',
                    }, ],
                },
            },
        });

        gauge.render();

        window.gauge = gauge;
    });

    this.run = function() {
        var uri = 'ws://' + document.location.hostname + ':1234';

        ws = new WebSocket(uri);

        ws.onopen = function() {
            console.log('open');
        };

        ws.onerror = function(evt) {
            console.log(evt);
        };

        ws.onclose = function() {
            console.log('connection closed by remote host')
        };

        ws.onmessage = function(evt) {
            /* TODO */

            var message = JSON.parse(evt.data);

            //console.log(message);

            $pressionTop.text(message['pressure_top']);
            $pressionBottom.text(message['pressure_bottom']);
            $flexion.text(message['flexion']);

            if (message['angle_x']) {
                angle = parseInt(message['angle_x'], 10) + 90;

                ref = FusionCharts.getObjectReference('chart');

                ref.feedData('value=' + angle);
                $angleX.text(angle);
            }

            $angleY.text(message['angle_y']);
            $angleZ.text(message['angle_z']);
        };
    };
};

var back_up;

window.back_up = back_up;

$(document).ready(function() {
    back_up = new BackUp();

    back_up.run();
});