Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:otcshare/GhostCluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevron Rees committed Aug 29, 2012
2 parents 3c1fce6 + f3e7057 commit 455c373
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 24 deletions.
109 changes: 93 additions & 16 deletions api.js
Expand Up @@ -34,25 +34,49 @@
* omitted from the returned list
* errorCB: error callback, called with error message string
*
* Function name: get(type, successCB, errorCB)
* Function name: get(eventlist, successCB, errorCB)
* Description:
* Retrieves a list of event/value pairs for a target event or event group
* Retrieves a list of event/value pairs for a target list of event names
* Required arguments:
* type: target event group to query (use empty string for all events)
* eventlist[]: list of events to read (use empty string for all events)
* successCB: success callback, gets called with the event/value pair list
* for all event children of the target. The list is the in the
* for all requested events. The list is the in the
* form of data[n].name/data[n].value
* errorCB: error callback, called with error message string
*
* Function name: set(type, value, successCB, errorCB)
* Function name: set(eventlist, valuelist, successCB, errorCB)
* Description:
* Sets a single event's value (triggers error if it's read-only)
* Sets a gourp of event's values (triggers error on read-only events)
* Required arguments:
* type: target event to set (an event group will trigger an error)
* successCB: success callback, gets called with the event/value pair
* that was successfully set in the form data.name/data.value
* eventlist: target events to set
* valuelist: target event values
* successCB: success callback, gets called with the eventlist
* that was successfully set
* errorCB: error callback, called with error message string
*
* Function name: subscribe(eventlist, successCB, errorCB)
* Description:
* Subscribe to a list of events so you can listen to value changes, they
* can be monitored with document.addEventListener(eventname, callback, false);
* The Event object passed to the callback has two parameters, e.name and
* e.value. Events are sent to the handler individually.
* Required arguments:
* eventlist: target events to listen to
* successCB: success callback, gets called with the eventlist
* that was successfully subscribed
* errorCB: error callback, called with the eventlist that failed to subscribe
*
* Function name: unsubscribe(eventlist, successCB, errorCB)
* Description:
* Unsubscribe to a list of events to let the server know you're not listening,
* they should stop being sent from the server if no other clients are using them,
* but will at least stop being triggered in your app.
* Required arguments:
* eventlist: target events to stop listening to
* successCB: success callback, gets called with the eventlist
* that was successfully unsubscribed
* errorCB: error callback, called with the eventlist that failed to unsubscribe
*
******************************************************************************/

function Vehicle(sCB, eCB, url, protocol)
Expand Down Expand Up @@ -205,28 +229,77 @@ Vehicle.prototype.getSupportedEventTypes = function(type, writeable, successCB,
this.send(obj, successCB, errorCB);
}

Vehicle.prototype.get = function(type, successCB, errorCB)
Vehicle.prototype.get = function(namelist, successCB, errorCB)
{
if(namelist.length <= 0)
{
return;
}

var obj = {
"type" : "method",
"name": "get",
"transactionid" : this.generateTransactionId(),
"data" : type
"data" : namelist
};
this.send(obj, successCB, errorCB);
}

Vehicle.prototype.set = function(type, value, successCB, errorCB)
Vehicle.prototype.set = function(namelist, valuelist, successCB, errorCB)
{
if((namelist.length != valuelist.length)||(namelist.length <= 0))
{
return;
}

var obj = {
"type" : "method",
"name": "set",
"transactionid" : this.generateTransactionId(),
"data" : {"property" : type, "value" : value}
"data" : []
};
var list = [];
for(var i = 0; i < namelist.length; i++)
{
var val = {"property" : namelist[i], "value" : valuelist[i]};
list[list.length] = val;
}
obj.data = list;
this.send(obj, successCB, errorCB);
}

Vehicle.prototype.subscribe = function(namelist, successCB, errorCB)
{
var obj = {
"type" : "method",
"name": "subscribe",
"transactionid" : this.generateTransactionId(),
"data" : namelist
};
this.send(obj, successCB, errorCB);
}

Vehicle.prototype.unsubscribe = function(namelist, successCB, errorCB)
{
var obj = {
"type" : "method",
"name": "unsubscribe",
"transactionid" : this.generateTransactionId(),
"data" : namelist
};
this.send(obj, successCB, errorCB);
}

Vehicle.prototype.sendEvent = function(name, value)
{
var evt = document.createEvent("Event");
evt.initEvent(name, true, true);
evt.name = name;
evt.value = value;
document.dispatchEvent(evt);
console.log(evt);
}

Vehicle.prototype.receive = function(msg)
{
var self = this;
Expand All @@ -240,7 +313,7 @@ Vehicle.prototype.receive = function(msg)
}

if((event == undefined)||(event.type == undefined)||
(event.name == undefined)||(event.transactionid == undefined))
(event.name == undefined))
{
self.iErrorCB("BADLY FORMED MESSAGE: "+msg);
return;
Expand All @@ -256,17 +329,21 @@ Vehicle.prototype.receive = function(msg)
if(call&&(!call.done)&&(call.transactionid === event.transactionid))
{
call.finish();
if(event.error != undefined)
if(event.error !== undefined)
{
call.errorCB(event.error);
}
else
if(event.data !== undefined && call.successCB !== undefined)
{
call.successCB(event.data);
}
return;
}
}
}
else if(event.type === "valuechanged")
{
self.sendEvent(event.name, event.data);
}
}
}
Binary file added assets/wheel.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 59 additions & 3 deletions business.js
Expand Up @@ -37,7 +37,42 @@ function calcAverageVelocity(newVel) {

function connected()
{
setInterval(function() {
vehicle.subscribe(["running_status_speedometer", "running_status_engine_speed", "running_status_transmission_gear_status", "running_status_steering_wheel_angle"]);
vehicle.subscribe(["running_status_engine_speed"]);
vehicle.subscribe(["running_status_transmission_gear_status"]);
vehicle.subscribe(["running_status_steering_wheel_angle"]);

document.addEventListener("running_status_speedometer",function(data) {

adjvalue = data.value;
var velocityUnits = $('#velocityUnits');

if(velocityUnits.text() === "MPH")
adjvalue = Math.floor(data.value * 0.62137);

$('#velocity').text(adjvalue);

calcAverageVelocity(adjvalue);
},false);

document.addEventListener("running_status_engine_speed", function(data) {
var value = data.value;
if(value > 10000) value =10000;
var needleDegs = value / 10000 * 180;
$('#rpms').text(value);
$('#rpmNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
},false);

document.addEventListener("running_status_transmission_gear_status",function(data) {
value = data.value;
$('#gear').text(value);
},false);

document.addEventListener("running_status_steering_wheel_angle", function(data) {
value = data.value;
$('#wheel').css("-webkit-transform","rotate("+value+"deg)");
},false);
/* setInterval(function() {
vehicle.get("running_status_speedometer", function(data) {
adjvalue = data[0].value;
Expand All @@ -50,8 +85,29 @@ function connected()
calcAverageVelocity(adjvalue);
},
function() { });
},1000);
function() { } );
vehicle.get("running_status_engine_speed", function(data) {
var value = data[0].value;
if(value > 10000) value =10000;
var needleDegs = value / 10000 * 180;
$('#rpms').text(value);
$('#rpmNeedle').css("-webkit-transform","rotate("+needleDegs+"deg)");
},
function() { } );
vehicle.get("running_status_transmission_gear_status", function(data) {
value = data[0].value;
$('#gear').text(value);
},
function() { } );
vehicle.get("running_status_steering_wheel_angle", function(data) {
value = data[0].value;
$('#wheel').css("-webkit-transform","rotate("+value+"deg)");
},
function() { } );
},1000);*/
}

window.onload = function()
Expand Down
19 changes: 14 additions & 5 deletions index.html
Expand Up @@ -26,11 +26,16 @@

<div class="vbox">
<div class="hbox">
<div class="gauge" >
<img src="assets/dial-IAT-bg.png" >
<div id="iatNeedle" class="needle"></div>
</img>
</div>
<div id="gaugeRow">
<div class="gauge" >
<img src="assets/dial-IAT-bg.png" >
<div id="iatNeedle" class="needle"></div>
</img>
</div>
<div class="gauge" >
<img id="wheel" src="assets/wheel.png" />
</div>
</div>

<div id="gaugeRow">
<div class="gauge">
Expand All @@ -55,6 +60,10 @@
<div class="rightAlignText middleText">AVG MPG</div>
<div id="avgmpg" class="leftAlignText middleText">0</div>
</div>
<div class="row underborder" >
<div class="rightAlignText middleText">Gear</div>
<div id="gear" class="leftAlignText middleText">0</div>
</div>
<div class="row" >
<div class="rightAlignText middleText">AVG SPEED</div>
<div id="avgspeed" class="leftAlignText middleText">0</div>
Expand Down
6 changes: 6 additions & 0 deletions style.css
Expand Up @@ -145,6 +145,12 @@ body {
position: relative;
}

#wheel {
-webkit-transform:rotate(0deg);
-webkit-transform-origin: 50% 50%;
-webkit-transition: all 1s cubic-bezier(0.25,0.1,0.25,1);
}

#iatNeedle {
z-index: 110;
background-color: red;
Expand Down

0 comments on commit 455c373

Please sign in to comment.