-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguide.js
More file actions
82 lines (69 loc) · 2.45 KB
/
guide.js
File metadata and controls
82 lines (69 loc) · 2.45 KB
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
var mediator = require('./mediator'),
router = require('./router'),
localizer = require('./localizer'),
Sensor = require('./sensor'),
Router = require('./router'),
Vector = require('./vector'),
Destinations = require('./destinations'),
sound = require('./sound'),
logger = require('./logger'),
Environment = require('./environment');
var speak = function(words){
sound.speak(words);
logger.log('speech',words);
}
module.exports.speak = speak;
mediator.pubsub.on('orientationChanged',function(message){
var requiredVector = Router.getPathVector();
if(requiredVector){
//console.log('re-orienting')
//console.dir(message);
var orientation = JSON.parse(message)['orientation'];
//console.log(Vector.getDegree(requiredVector));
//console.log(orientation)
if(Math.abs(Vector.getDegree(requiredVector)-orientation)<6){
speak("Correct");
//logger.log('announce','-----> HOMING! <------');
}
}
});
mediator.pubsub.on('waypointReached',function(message){
});
mediator.pusub.on('pathCalculated',function(message){
setTimeout(function(){speak('Very Good. Scan for new direction.');},1000);
});
mediator.pubsub.on('destinationReached',function(message){
speak('You have reached your destination!');
});
mediator.pubsub.on('leftKeyPressed',function(){
var currentLocationName = localizer.getLocationName();
var currentDestination = Destinations.currentLocationChoice();
var speech = '';
if(currentLocationName){
speech = speech+'You were last near '+ currentLocationName+' and ';
} else {
speech = speech+'Your location is unclear. Seek help!';
}
if(currentDestination){
var beacon = Environment.getBeacon(currentDestination);
if(beacon.btName==currentLocationName){
speech = 'Haha! You want to go where you already are!';
} else {
speech = speech+'You want to go to '+beacon.btName;
}
} else {
speech = speech+'You do not have a destination set.'
}
speak(speech);
});
mediator.pubsub.on('rightKeyPressed',function(){
var choice = Destinations.nextLocationChoice();
logger.log("data","[CHOICE] "+choice);
var beacon = Environment.getBeacon(choice);
if(Router.isReachable(choice)){
speak('Destination '+beacon.btName);
} else {
speak('Destination '+beacon.btName+ 'is not reachable');
}
Router.setDestinationBeaconMacAddress(choice);
})