summaryrefslogtreecommitdiff
path: root/webapp/js/back_up.js
blob: 1badc02d2b41da97ee910b266f86632c0fe200b3 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
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');
    $notification = $('#notification-div');

    var gauge;

    FusionCharts.ready(function () {
        gauge = new FusionCharts({
            'id': 'chart',
            'type': 'angulargauge',
            'renderAt': 'fusioncharts-div',
            'width': '800',
            'height': '500',
            'dataFormat': 'json',
            'dataSource': {
                'chart': {
                    //'caption': 'Inclinaison',
                    'lowerLimit': '-50',
                    'upperLimit': '50',
                    'theme': 'fint',
                    "gaugeFillMix": "{dark-40},{light-40},{dark-20}",
                    'bgColor': '#00b0c0',
                },
                'colorRange': {
                    'color': [
                    {
                        'minValue': '-50',
                        'maxValue': '-15',
                        'code': '#b41527',
                    }, {
                        'minValue': '-15',
                        'maxValue': '-5',
                        'code': '#e48739',
                    }, {
                        'minValue': '-5',
                        'maxValue': '5',
                        'code': '#399e38',
                    }, {
                        'minValue': '5',
                        'maxValue': '15',
                        'code': '#e48739',
                    }, {
                        'minValue': '15',
                        'maxValue': '50',
                        'code': '#b41527',
                    },
                    ],
                },
                'dials': {
                    'dial': [ {
                        'id': 'Dial1',
                        'value': '0',
                        '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;
                console.log('angle: ' + angle);

                ref = FusionCharts.getObjectReference('chart');

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

            if (message['pressure_top']) {
                pressure_top = parseInt(message['pressure_top'], 10);
            } 
            if (message['pressure_bottom']) {
                pressure_bottom = parseInt(message['pressure_bottom'], 10);
            } 

            console.log(pressure_top);
            if (pressure_top < 900) {
                $notification.show();
            } else {
                $notification.hide();
            }
        };
    };
};

var back_up;

window.back_up = back_up;

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

    back_up.run();
});