@@ -98,45 +98,50 @@ function getOnSuccessConfigOrDefault(startupData: any) {
9898 } ;
9999}
100100
101+ function getOnFailConfigOrDefault ( startupData : any ) {
102+ if ( startupData . config . onFail ) {
103+ return startupData . config . onFail ;
104+ }
105+
106+ return {
107+ "audioPatternIndex" : 0 ,
108+ "audioDuration" : 1000 ,
109+ "ledPatternIndex" : 0 ,
110+ "ledPlayDuration" : 5000
111+ } ;
112+ }
113+
101114function getMode ( patterns , patternIndex ?: number )
102115{
103116 if ( patternIndex === null ) return null ;
104117 return patterns [ patternIndex ] . id ;
105118}
106119
120+ function playConfig ( sosDeviceInfo , playConfig , sosDevice ) {
121+ var controlPacket = {
122+ audioMode : getMode ( sosDeviceInfo . audioPatterns , playConfig . audioPatternIndex ) ,
123+ audioPlayDuration : playConfig . audioDuration ,
124+ ledMode : getMode ( sosDeviceInfo . ledPatterns , playConfig . ledPatternIndex ) ,
125+ ledPlayDuration : playConfig . ledPlayDuration
126+ } ;
127+ console . log ( controlPacket ) ;
128+ sosDevice . sendControlPacket ( controlPacket , ( err ?) => {
129+ if ( err ) {
130+ console . error ( "Could not send SoS control packet" , err ) ;
131+ }
132+ } ) ;
133+ }
134+
107135function updateSiren ( startupData : IStartupData , pollResult : PluginBase . PollResult ) {
108136 var sosDevice = startupData . sosDevice ;
109137 var sosDeviceInfo = startupData . sosDeviceInfo ;
110138
111- var controlPacket :SosDeviceControlPacket ;
112139 if ( pollResult . status === PluginBase . PollResultStatus . FAILURE ) {
113- controlPacket = {
114- audioMode : sosDeviceInfo . audioPatterns [ 0 ] . id ,
115- audioPlayDuration : 1000 ,
116- ledMode : sosDeviceInfo . ledPatterns [ 0 ] . id ,
117- ledPlayDuration : 5000
118- } ;
119- console . log ( controlPacket ) ;
120- sosDevice . sendControlPacket ( controlPacket , ( err ?) => {
121- if ( err ) {
122- console . error ( "Could not send SoS control packet" , err ) ;
123- }
124- } ) ;
140+ var onFailConfig = getOnFailConfigOrDefault ( startupData ) ;
141+ playConfig ( sosDeviceInfo , onFailConfig , sosDevice ) ;
125142 } else if ( pollResult . status === PluginBase . PollResultStatus . SUCCESS ) {
126143 var onSuccessConfig = getOnSuccessConfigOrDefault ( startupData ) ;
127-
128- controlPacket = {
129- audioMode : getMode ( sosDeviceInfo . audioPatterns , onSuccessConfig . audioPatternIndex ) ,
130- audioPlayDuration : onSuccessConfig . audioDuration ,
131- ledMode : getMode ( sosDeviceInfo . ledPatterns , onSuccessConfig . ledPatternIndex ) ,
132- ledPlayDuration : onSuccessConfig . ledPlayDuration
133- } ;
134- console . log ( controlPacket ) ;
135- sosDevice . sendControlPacket ( controlPacket , ( err ?) => {
136- if ( err ) {
137- console . error ( "Could not send SoS control packet" , err ) ;
138- }
139- } ) ;
144+ playConfig ( sosDeviceInfo , onSuccessConfig , sosDevice ) ;
140145 }
141146}
142147
0 commit comments