1 // parse location to get security token
3 location.search.substr(1).split("&").forEach(function(item) {
4 var k = item.split("=")[0];
5 var v = decodeURIComponent(item.split("=")[1]);
6 if (k in urlParams) urlParams[k].push(v); else urlParams[k] = [v];
9 var afb = new AFB("api"/*root*/, urlParams.token[0]);
11 var vspeed = 0, espeed = 0, torque = 0;
12 var R2D = 180.0 / Math.PI;
13 var D2R = Math.PI / 180.0;
15 var con,cons,consa = [ ];
18 var wdgTem, wdgVsp, wdgEsp, wdgTrq;
19 var wdgFue, wdgGpred, wdgGpblack;
25 function initGauges() {
26 gauges.speed = new steelseries.Radial('speedGauge', {
27 gaugeType: steelseries.GaugeType.TYPE4,
28 frameDesign: steelseries.FrameDesign.BLACK_METAL,
29 backgroundColor: steelseries.BackgroundColor.CARBON,
37 maxMeasuredValueVisible: true,
38 thresholdVisible: false,
40 pointerType: steelseries.PointerType.TYPE11,
47 gauges.rpm = new steelseries.Radial('rpmGauge', {
48 gaugeType: steelseries.GaugeType.TYPE4,
49 frameDesign: steelseries.FrameDesign.BLACK_METAL,
50 backgroundColor: steelseries.BackgroundColor.CARBON,
58 maxMeasuredValueVisible: false,
60 steelseries.Section(4, 8, 'rgba(255, 0, 0, 0.7)')
63 steelseries.Section(5, 8, 'rgba(255, 0, 0, 0.3)')
65 thresholdVisible: false,
67 pointerType: steelseries.PointerType.TYPE11
70 gauges.maf = new steelseries.Radial('MAFGauge', {
71 gaugeType: steelseries.GaugeType.TYPE4,
72 frameDesign: steelseries.FrameDesign.BLACK_METAL,
73 backgroundColor: steelseries.BackgroundColor.CARBON,
75 titleString: "Air flow Rate",
76 unitString: "grams/sec",
78 lcdColor: steelseries.LcdColor.STANDARD,
84 maxMeasuredValue: conscale,
85 maxMeasuredValueVisible: true,
87 steelseries.Section(0, 255, 'rgba(0, 255, 0, 0.5)'),
88 steelseries.Section(256, 326, 'rgba(255, 255, 0, 0.5)'),
89 steelseries.Section(327, 600, 'rgba(255, 128, 0, 0.5)'),
90 steelseries.Section(601, 655, 'rgba(255, 0, 0, 0.5)')
92 useValueGradient: true,
93 thresholdVisible: false,
95 pointerType: steelseries.PointerType.TYPE11
98 gauges.iatemp = new steelseries.Radial('IATempGauge', {
99 gaugeType: steelseries.GaugeType.TYPE4,
100 frameDesign: steelseries.FrameDesign.BLACK_METAL,
101 backgroundColor: steelseries.BackgroundColor.CARBON,
103 titleString: "Intake air temp",
106 lcdColor: steelseries.LcdColor.STANDARD,
112 maxMeasuredValue: 100,
113 maxMeasuredValueVisible: true,
115 steelseries.Section(0, 30, 'rgba(0, 255, 0, 0.5)'),
116 steelseries.Section(31, 50, 'rgba(255, 255, 0, 0.5)'),
117 steelseries.Section(51, 70, 'rgba(255, 128, 0, 0.5)'),
118 steelseries.Section(71, 100, 'rgba(255, 0, 0, 0.5)')
120 useValueGradient: true,
121 thresholdVisible: false,
123 pointerType: steelseries.PointerType.TYPE11
126 gauges.torque = new steelseries.Radial('torqueGauge', {
127 gaugeType: steelseries.GaugeType.TYPE2,
128 frameDesign: steelseries.FrameDesign.BLACK_METAL,
129 backgroundColor: steelseries.BackgroundColor.CARBON,
138 maxMeasuredValueVisible: false,
140 steelseries.Section(0, 0, 'rgba(0, 255, 0, 0.7)'),
141 steelseries.Section(50, 1500, 'rgba(255, 128, 0, 0.7)')
144 steelseries.Section(0, 0, 'rgba(0, 255, 0, 0.3)'),
145 steelseries.Section(50, 1500, 'rgba(255, 128, 0, 0.3)')
148 thresholdVisible: true,
150 pointerType: steelseries.PointerType.TYPE4
153 /* adjust cluster background size upon resize */
154 // TODO: could be doable through CSS, but a bit tricky
155 function adjustCluster() {
156 var qh=$("#quad1").outerHeight();
157 var sh=$("#speedGauge").outerHeight();
158 var pct=Math.ceil((1000*sh/qh))/10+1;
159 $('#cluster').css("height",pct+"%");
161 $(window).resize(adjustCluster);
165 function clearGauges() {
166 for (var g in gauges) {
169 gauges[g].setValue("-");
172 gauges[g].setValue(0);
175 gauges[g].setValue(0);
181 function gotVehicleSpeed(obj) {
182 vspeed = Math.round(obj.data.value);
183 wdgVsp.innerHTML = /* wdgVspeed.innerHTML = */ String(vspeed);
184 //gauges.speed.setValueAnimated(vspeed);
185 gauges.speed.setValue(vspeed);
188 function gotTorque(obj) {
189 torque=Math.round(obj.data.value);
190 wdgTrq.innerHTML=String(torque);
191 gauges.torque.setValue(torque);
194 function gotEngineSpeed(obj) {
195 espeed = Math.round(obj.data.value);
196 wdgEsp.innerHTML = /* wdgEspeed.innerHTML = */ String(espeed);
197 //gauges.rpm.setValueAnimated(espeed/1000);
198 gauges.rpm.setValue(espeed/1000);
201 function gotFuelLevel(obj) {
202 fuel = Math.round(obj.data.value);
203 wdgFue.innerHTML = fuel;
204 gauges.maf.setValue(fuel);
207 function gotTemp(obj) {
208 temp = Math.round(obj.data.value);
209 wdgTem.innerHTML = temp;
210 gauges.iatemp.setValue(temp);
213 function gotStart(obj) {
214 document.body.className = "started";
221 wdgVsp.innerHTML = /*wdgVspeed.innerHTML = */
222 wdgEsp.innerHTML = /*wdgEspeed.innerHTML = */
223 wdgTem.innerHTML = wdgFue.innerHTML = "?";
224 for (var i = 0 ; i < 9 ; i++) {
225 wdgConX[i].style.height = "0%";
226 wdgConX[i].innerHTML = "";
230 function gotStop(obj) {
231 document.body.className = "connected";
238 function gotAny(obj) {
239 if (obj.event != "low-can/STOP") {
240 document.body.className = "started";
244 wdgTem.innerHTML = temp;
245 gauges.iatemp.setValue(temp);
246 // updateClock(obj.data.timestamp);
249 function updateMsgRate() {
253 msgrate=Math.round((msgcnt-msgprv)*10000/dt)/10;
254 wdgMsg.innerHTML=String(msgrate);
261 function gotStat(obj) {
262 wdgStat.innerHTML = obj.data;
266 document.body.className = "not-connected";
270 ws.call("low-can/subscribe", {event:[
271 "diagnostic_messages.vehicle.speed",
272 "diagnostic_messages.mass.airflow",
273 "diagnostic_messages.engine.speed",
274 "diagnostic_messages.engine.load",
275 "diagnostic_messages.intake.air.temperature"]},
276 onSubscribed, onAbort);
277 ws.call("stat/subscribe", true);
278 ws.onevent("stat/stat", gotStat);
282 ws.call("low-can/unsubscribe", {event:[
283 "diagnostic_messages.engine.speed",
284 "diagnostic_messages.mass.airflow",
285 "diagnostic_messages.vehicle.speed",
286 "diagnostic_messages.engine.load",
287 "diagnostic_messages.intake.air.temperature"]},
288 onUnsubscribed, onAbort);
289 ws.call("stat/unsubscribe", true);
290 ws.onevent("stat/stat", gotStat);
293 function onSubscribed() {
294 document.body.className = "connected";
295 ws.onevent("low-can/diagnostic_messages.engine.speed", gotEngineSpeed);
296 ws.onevent("low-can/diagnostic_messages.mass.airflow", gotFuelLevel);
297 ws.onevent("low-can/diagnostic_messages.vehicle.speed", gotVehicleSpeed);
298 ws.onevent("low-can/diagnostic_messages.engine.load", gotTorque);
299 ws.onevent("low-can/diagnostic_messages.intake.air.temperature", gotTemp);
300 ws.onevent("low-can",gotAny);
303 function onUnsubscribed() {
304 document.body.className = "disconnected";
305 ws.onevent("low-can/diagnostic_messages.engine.speed", gotEngineSpeed);
306 ws.onevent("low-can/diagnostic_messages.mass.airflow", gotFuelLevel);
307 ws.onevent("low-can/diagnostic_messages.vehicle.speed", gotVehicleSpeed);
308 ws.onevent("low-can/diagnostic_messages.engine.load", gotTorque);
309 ws.onevent("low-can/diagnostic_messages.intake.air.temperature", gotTemp);
310 ws.onevent("low-can",gotAny);
313 function replyok(obj) {
314 document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj);
316 function replyerr(obj) {
317 document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj);
319 function send(message) {
320 var api = document.getElementById("api").value;
321 var verb = document.getElementById("verb").value;
322 ws.call(api+"/"+verb, {data:message}, replyok, replyerr);
325 function doConnect() {
326 document.body.className = "connecting";
327 ws = new afb.ws(onOpen, onAbort);
330 function doDisconnect() {
331 document.body.className = "connecting";
332 ws = new afb.ws(onClose, onAbort);
336 wdgVsp = document.getElementById("vsp");
337 wdgEsp = document.getElementById("esp");
338 wdgTrq = document.getElementById("trq");
339 wdgFue = document.getElementById("fue");
340 wdgTem = document.getElementById("tem");
341 wdgStat = document.getElementById("stat");
342 wdgMsg = document.getElementById("msg");
348 // init interval to compute message rate
349 setInterval(updateMsgRate,250);