/
openxc_driver.js
48 lines (44 loc) · 1.24 KB
/
openxc_driver.js
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
var Device = require('zetta').Device;
var util = require('util');
var OpenXC = module.exports = function(emitter) {
Device.call(this);
this._emitter = emitter;
var self = this;
this._emitter.on('data', function(data) {
self.handleDataEvent(data);
});
this.wheel = 0;
this.acceleration = 0;
this.brake = false;
this.parking = false;
this.door = false;
this.highbeam = false;
};
util.inherits(OpenXC, Device);
OpenXC.prototype.init = function(config) {
config
.name('OpenXC')
.type('vehicle')
.state('running')
.monitor('wheel')
.monitor('acceleration')
.monitor('parking')
.monitor('door')
.monitor('highbeam')
.monitor('brake');
};
OpenXC.prototype.handleDataEvent = function(data) {
if(data.name === 'steering_wheel_angle') {
this.wheel = data.value;
} else if (data.name === 'accelerator_pedal_position') {
this.acceleration = data.value;
} else if (data.name === 'brake_pedal_status') {
this.brake = data.value;
} else if (data.name === 'parking_brake_status') {
this.parking = data.value;
} else if (data.name === 'door_status' && data.value === 'driver') {
this.door = data.event;
} else if (data.name === 'high_beam_status') {
this.highbeam = data.value;
}
};