@@ -8,7 +8,7 @@ import sos = module('sos-device');
8
8
import PluginBase = module ( 'plugin' ) ;
9
9
import Bamboo = module ( 'plugins/bamboo' ) ;
10
10
11
- var useMockDevice : boolean = true ;
11
+ var useMockDevice : boolean = false ;
12
12
13
13
interface ConfigBuild {
14
14
name : string ;
@@ -43,6 +43,9 @@ function poll(callback: (err?: Error) => void, startupData: StartupData): void {
43
43
startupData . config . builds . forEach ( ( build ) => {
44
44
build . interval = build . interval || 30000 ;
45
45
build . name = build . name || ( build . type + ( nameId ++ ) ) ;
46
+ build . lastPollResult = build . lastPollResult || {
47
+ status : PluginBase . PollResultStatus . SUCCESS
48
+ } ;
46
49
switch ( build . type ) {
47
50
case 'bamboo' :
48
51
build . plugin = new Bamboo . Bamboo ( ) ;
@@ -62,9 +65,11 @@ function pollBuild(build: ConfigBuild, startupData: StartupData): void {
62
65
console . error ( 'Failed to poll: ' + build . name , err ) ;
63
66
}
64
67
if ( pollResult ) {
65
- build . lastPollResult = pollResult ;
66
- console . log ( 'New poll results:' , pollResult ) ;
67
- updateSiren ( startupData . sosDevice , startupData . sosDeviceInfo , build . lastPollResult ) ;
68
+ if ( pollResult . status != build . lastPollResult . status ) {
69
+ build . lastPollResult = pollResult ;
70
+ console . log ( 'New poll results:' , pollResult ) ;
71
+ updateSiren ( startupData . sosDevice , startupData . sosDeviceInfo , build . lastPollResult ) ;
72
+ }
68
73
}
69
74
setTimeout ( pollBuild . bind ( null , build , startupData ) , build . interval ) ;
70
75
} ) ;
@@ -74,22 +79,24 @@ function updateSiren(sosDevice: SosDevice, sosDeviceInfo: SosDeviceAllInfo, poll
74
79
if ( pollResult . status == PluginBase . PollResultStatus . FAILURE ) {
75
80
var controlPacket : SosDeviceControlPacket = {
76
81
audioMode : sosDeviceInfo . audioPatterns [ 0 ] . id ,
77
- audioPlayDuration : 500 ,
82
+ audioPlayDuration : 1000 ,
78
83
ledMode : sosDeviceInfo . ledPatterns [ 0 ] . id ,
79
- ledPlayDuration : 500 ,
84
+ ledPlayDuration : 5000 ,
80
85
} ;
86
+ console . log ( controlPacket ) ;
81
87
sosDevice . sendControlPacket ( controlPacket , function ( err ?) {
82
88
if ( err ) {
83
89
console . error ( "Could not send SoS control packet" , err ) ;
84
90
}
85
91
} ) ;
86
92
} else if ( pollResult . status == PluginBase . PollResultStatus . SUCCESS ) {
87
93
var controlPacket : SosDeviceControlPacket = {
88
- audioMode : sosDeviceInfo . audioPatterns [ 0 ] . id ,
89
- audioPlayDuration : 100 ,
94
+ audioMode : sosDeviceInfo . audioPatterns [ 1 ] . id ,
95
+ audioPlayDuration : 500 ,
90
96
ledMode : sosDeviceInfo . ledPatterns [ 0 ] . id ,
91
- ledPlayDuration : 100 ,
97
+ ledPlayDuration : 500 ,
92
98
} ;
99
+ console . log ( controlPacket ) ;
93
100
sosDevice . sendControlPacket ( controlPacket , function ( err ?) {
94
101
if ( err ) {
95
102
console . error ( "Could not send SoS control packet" , err ) ;
@@ -172,7 +179,13 @@ function connectToDevice(callback: (err: Error, sosDevice?: SosDevice) => void):
172
179
}
173
180
174
181
function getSosDeviceInfo ( callback : ( err ?: Error , sosDeviceInfo ?: SosDeviceAllInfo ) => void , startupData : StartupData ) : void {
175
- return startupData . sosDevice . readAllInfo ( callback ) ;
182
+ return startupData . sosDevice . readAllInfo ( function ( err ?, deviceInfo ?) {
183
+ if ( err ) {
184
+ return callback ( err ) ;
185
+ }
186
+ console . log ( "deviceInfo:" , deviceInfo ) ;
187
+ return callback ( null , deviceInfo ) ;
188
+ } ) ;
176
189
}
177
190
178
191
run ( function ( err ) {
0 commit comments