@@ -14,48 +14,56 @@ foo, WebSocket, $, Materialize, console, cfg, train, jmri, ui, air, sim
14
14
15
15
var decoders = {
16
16
//product "LokSound Select"
17
- "ESU LokSound Blardy Blar Select" : {
17
+ "ESU LokSound Select" : {
18
18
//sound project "emd567"
19
- "LokSound Select Blardy Blar EMD 567" : function ( address , trainPosition ) {
19
+ "LokSound Select EMD 567" : function ( address , trainPosition ) {
20
20
//ESU LokSound Select V4
21
21
//decoder object for ESU official EMD 567 Sound project
22
22
//By Hampton Morgan - k4kfh@github - Originally written in May 2015
23
23
//evilgeniustech.com
24
- 'use strict' ;
24
+ console . debug ( "DECODER: Using 'LokSound Select EMD 567' for " + trainPosition )
25
25
train . all [ trainPosition ] . throttle = new jmri . throttle ( address , jmri . throttleName . generate ( ) ) ; //we use the train position as the throttle name for future lookup purposes
26
26
27
27
//FUNCTIONS
28
28
this . f = { } ;
29
29
//light
30
30
this . f . headlight = { } ;
31
- this . f . headlight . set = function ( state ) {
32
- train . all [ trainPosition ] . throttle . f . set ( { "F0" : state } ) ;
31
+ this . f . headlight . set = function ( state ) {
32
+ train . all [ trainPosition ] . throttle . f . set ( {
33
+ "F0" : state
34
+ } ) ;
33
35
train . all [ trainPosition ] . dcc . f . headlight . state = state ;
34
36
console . log ( "DCC: Setting headlight to " + state + " on Train#" + trainPosition )
35
37
} ;
36
38
//bell
37
39
this . f . bell = { } ;
38
- this . f . bell . set = function ( state ) {
39
- train . all [ trainPosition ] . throttle . f . set ( { "F1" : state } ) ;
40
- train . all [ trainPosition ] . dcc . f . bell . state = state ;
41
- console . log ( "DCC: Setting bell to " + state + " on Train#" + trainPosition )
40
+ this . f . bell . set = function ( state ) {
41
+ train . all [ trainPosition ] . throttle . f . set ( {
42
+ "F1" : state
43
+ } ) ;
44
+ train . all [ trainPosition ] . dcc . f . bell . state = state ;
45
+ console . log ( "DCC: Setting bell to " + state + " on Train#" + trainPosition )
42
46
} ;
43
47
this . f . bell . state = false ;
44
48
45
49
//horn
46
50
this . f . horn = { } ;
47
- this . f . horn . set = function ( state ) {
48
- train . all [ trainPosition ] . throttle . f . set ( { "F2" : state } ) ;
49
- train . all [ trainPosition ] . dcc . f . horn . state = state ;
50
- console . log ( "DCC: Setting headlight to " + state + " on Train#" + trainPosition )
51
+ this . f . horn . set = function ( state ) {
52
+ train . all [ trainPosition ] . throttle . f . set ( {
53
+ "F2" : state
54
+ } ) ;
55
+ train . all [ trainPosition ] . dcc . f . horn . state = state ;
56
+ console . log ( "DCC: Setting headlight to " + state + " on Train#" + trainPosition )
51
57
} ;
52
58
this . f . horn . state = false ;
53
59
54
60
//compressor
55
61
this . f . compressor = { } ;
56
- this . f . compressor . set = function ( state ) {
62
+ this . f . compressor . set = function ( state ) {
57
63
if ( state != train . all [ trainPosition ] . dcc . f . compressor . state ) {
58
- train . all [ trainPosition ] . throttle . f . set ( { "F20" :state } ) ;
64
+ train . all [ trainPosition ] . throttle . f . set ( {
65
+ "F20" : state
66
+ } ) ;
59
67
train . all [ trainPosition ] . dcc . f . compressor . state = state ;
60
68
console . log ( "DCC: Setting compressor to " + state + " on Train#" + trainPosition )
61
69
}
@@ -64,37 +72,41 @@ var decoders = {
64
72
65
73
//air release
66
74
this . f . airDump = { } ;
67
- this . f . airDump . set = function ( state ) {
68
- train . all [ trainPosition ] . throttle . f . set ( { "F19" :state } ) ;
69
- console . log ( "DCC: Setting airDump to " + state + " on Train#" + trainPosition )
75
+ this . f . airDump . set = function ( state ) {
76
+ train . all [ trainPosition ] . throttle . f . set ( {
77
+ "F19" : state
78
+ } ) ;
79
+ console . log ( "DCC: Setting airDump to " + state + " on Train#" + trainPosition )
70
80
} ;
71
81
72
82
//dyn brake fans
73
83
this . f . dynBrakes = { } ;
74
- this . f . dynBrakes . set = function ( state ) {
84
+ this . f . dynBrakes . set = function ( state ) {
75
85
76
86
} ;
77
87
this . f . dynBrakes . state = false ;
78
88
79
89
//engine on/off
80
90
this . f . engine = { } ;
81
- this . f . engine . set = function ( state ) {
91
+ this . f . engine . set = function ( state ) {
82
92
//This IF makes the entire function useless if you're out of fuel, or if the state argument is no different than the current actual state
83
93
if ( state !== train . all [ trainPosition ] . dcc . f . engine . state ) {
84
- train . all [ trainPosition ] . throttle . f . set ( { "F8" :state } ) ;
94
+ train . all [ trainPosition ] . throttle . f . set ( {
95
+ "F8" : state
96
+ } ) ;
85
97
train . all [ trainPosition ] . dcc . f . engine . state = state ;
86
98
console . log ( "DCC: Setting engine to " + state + " on Train#" + trainPosition )
87
- //This code sets engineRunning to 0 or 1 depending on the state
99
+ //This code sets engineRunning to 0 or 1 depending on the state
88
100
if ( state === true ) {
89
101
train . all [ trainPosition ] . prototype . engineRunning = 1 ;
90
- }
91
- else if ( state === false ) {
102
+ } else if ( state === false ) {
92
103
train . all [ trainPosition ] . prototype . engineRunning = 0 ;
93
104
}
94
- }
95
- else {
105
+ } else {
96
106
//This code means that if you're out of fuel, regardless of what state you fed into this function it will turn the engine off.
97
- train . all [ trainPosition ] . throttle . f . set ( { "F8" :false } ) ;
107
+ train . all [ trainPosition ] . throttle . f . set ( {
108
+ "F8" : false
109
+ } ) ;
98
110
train . all [ trainPosition ] . prototype . engineRunning = 0 ;
99
111
train . all [ trainPosition ] . dcc . f . engine . state = false ;
100
112
}
@@ -103,30 +115,42 @@ var decoders = {
103
115
104
116
//notch sound stuff.
105
117
this . f . notch = {
106
- up : function ( ) {
118
+ up : function ( ) {
107
119
//Notch up code
108
120
//This is inside an IF statement to make sure we don't try to notch OVER 8. If that happens, ESU decoders get confused.
109
121
var newNotch = ( train . all [ trainPosition ] . dcc . f . notch . state + 1 ) ;
110
122
if ( newNotch <= 8 ) {
111
123
train . all [ trainPosition ] . dcc . f . notch . state ++ ; //THIS HAS TO RUN INSTANTLY OR SIM.JS IS STUPID
112
124
console . log ( "DCC: Increasing notch on Train#" + trainPosition )
113
- setTimeout ( function ( ) {
114
- train . all [ trainPosition ] . throttle . f . set ( { "F9" :true } ) ;
125
+ setTimeout ( function ( ) {
126
+ train . all [ trainPosition ] . throttle . f . set ( {
127
+ "F9" : true
128
+ } ) ;
115
129
} , 500 ) ;
116
- setTimeout ( function ( ) {
117
- train . all [ trainPosition ] . throttle . f . set ( { "F9" :false } ) ;
130
+ setTimeout ( function ( ) {
131
+ train . all [ trainPosition ] . throttle . f . set ( {
132
+ "F9" : false
133
+ } ) ;
118
134
} , 1750 ) ;
119
135
}
120
136
} ,
121
- down : function ( ) {
137
+ down : function ( ) {
122
138
//Notch down code
123
139
//This is inside an IF statement to make sure we don't try to notch LESS THAN idle. If that happens, ESU decoders get confused.
124
140
var newNotch = ( train . all [ trainPosition ] . dcc . f . notch . state - 1 ) ;
125
141
if ( newNotch >= 0 ) {
126
142
train . all [ trainPosition ] . dcc . f . notch . state -- ; //THIS MUST RUN INSTANTLY OR SIM.JS DOES WEIRD STUFF
127
143
console . log ( "DCC: Decreasing notch on Train#" + trainPosition )
128
- setTimeout ( function ( ) { train . all [ trainPosition ] . throttle . f . set ( { "F10" :true } ) ; } , 500 ) ;
129
- setTimeout ( function ( ) { train . all [ trainPosition ] . throttle . f . set ( { "F10" :false } ) ; } , 1750 ) ;
144
+ setTimeout ( function ( ) {
145
+ train . all [ trainPosition ] . throttle . f . set ( {
146
+ "F10" : true
147
+ } ) ;
148
+ } , 500 ) ;
149
+ setTimeout ( function ( ) {
150
+ train . all [ trainPosition ] . throttle . f . set ( {
151
+ "F10" : false
152
+ } ) ;
153
+ } , 1750 ) ;
130
154
}
131
155
} ,
132
156
state : 0 //This should reflect the current notching state of the sound decoder. You should increment this up or down 1 when your up() and down() functions finish, or sim.js's functions will be horribly confused and mess up your sounds.
@@ -136,20 +160,20 @@ var decoders = {
136
160
//SPEED SETTING
137
161
this . speed = { } ;
138
162
this . speed . state = 0 ;
139
- this . speed . set = function ( speed ) {
163
+ this . speed . set = function ( speed ) {
140
164
train . all [ trainPosition ] . throttle . speed . set ( speed ) ;
141
165
train . all [ trainPosition ] . dcc . speed . state = speed ;
142
166
} ;
143
- this . speed . setMPH = function ( mph ) {
167
+ this . speed . setMPH = function ( mph ) {
144
168
var speed = train . all [ trainPosition ] . model . speed ( mph ) ;
145
169
train . all [ trainPosition ] . dcc . speed . set ( speed ) ;
146
170
} ;
147
171
}
148
172
} ,
149
173
150
174
//GENERIC FALLBACK SCRIPT - DO NOT REMOVE!!
151
- "generic" :{
152
- "generic" : function ( address , trainPosition ) {
175
+ "generic" : {
176
+ "generic" : function ( address , trainPosition ) {
153
177
'use strict' ;
154
178
//GENERIC FALLBACK
155
179
train . all [ trainPosition ] . throttle = new jmri . throttle ( address , jmri . throttleName . generate ( ) ) ;
@@ -159,104 +183,101 @@ var decoders = {
159
183
160
184
//light
161
185
this . f . headlight = { } ;
162
- this . f . headlight . set = function ( state ) {
163
- train . all [ trainPosition ] . throttle . f . set ( { "F0" :state } ) ;
186
+ this . f . headlight . set = function ( state ) {
187
+ train . all [ trainPosition ] . throttle . f . set ( {
188
+ "F0" : state
189
+ } ) ;
164
190
train . all [ trainPosition ] . dcc . f . headlight . state = state ;
165
191
} ;
166
192
this . f . headlight . state = false ;
167
193
168
194
//bell
169
195
this . f . bell = { } ;
170
- this . f . bell . set = function ( state ) {
171
- train . all [ trainPosition ] . throttle . f . set ( { "F1" :state } ) ;
196
+ this . f . bell . set = function ( state ) {
197
+ train . all [ trainPosition ] . throttle . f . set ( {
198
+ "F1" : state
199
+ } ) ;
172
200
train . all [ trainPosition ] . dcc . f . bell . state = state ;
173
201
} ;
174
202
this . f . bell . state = false ;
175
203
176
204
//horn
177
205
this . f . horn = { } ;
178
- this . f . horn . set = function ( state ) {
179
- train . all [ trainPosition ] . throttle . f . set ( { "F2" :state } ) ;
206
+ this . f . horn . set = function ( state ) {
207
+ train . all [ trainPosition ] . throttle . f . set ( {
208
+ "F2" : state
209
+ } ) ;
180
210
train . all [ trainPosition ] . dcc . f . horn . state = state ;
181
211
} ;
182
212
this . f . horn . state = false ;
183
213
184
214
//compressor
185
215
this . f . compressor = { } ;
186
- this . f . compressor . set = function ( state ) {
216
+ this . f . compressor . set = function ( state ) {
187
217
//there's no compressor assumed on these generic mystery decoders
188
218
train . all [ trainPosition ] . dcc . f . compressor . state = state ;
189
219
} ;
190
220
this . f . compressor . state = false ;
191
221
192
222
//air release
193
- this . f . airdump = { } ;
194
- this . f . airdump . set = function ( state ) {
223
+ this . f . airDump = { } ;
224
+ this . f . airDump . set = function ( state ) {
195
225
196
226
} ;
197
- this . f . airdump . state = false ;
227
+ this . f . airDump . state = false ;
198
228
199
229
//dyn brake fans
200
- this . f . dynbrakes = { } ;
201
- this . f . dynbrakes . set = function ( state ) {
230
+ this . f . dynBrakes = { } ;
231
+ this . f . dynBrakes . set = function ( state ) {
202
232
203
233
} ;
204
- this . f . dynbrakes . state = false ;
234
+ this . f . dynBrakes . state = false ;
205
235
206
236
//engine on/off
207
237
this . f . engine = { } ;
208
- this . f . engine . set = function ( state ) {
238
+ this . f . engine . set = function ( state ) {
209
239
//This function is almost exactly the same as the one in my ESU LokSound EMD 567 decoder constructor, the difference is this one never actually sends a DCC command (it's basically dummy function that the physics engine thinks is legit)
210
240
211
- //This IF makes the entire function useless if you're out of fuel.
212
- if ( train . all [ trainPosition ] . prototype . realtime . fuel . status !== 0 ) {
213
- train . all [ trainPosition ] . dcc . f . engine . state = state ;
214
- //This code sets engineRunning to 0 or 1 depending on the state
215
- if ( state === true ) {
216
- train . all [ trainPosition ] . prototype . engineRunning = 1 ;
217
- }
218
- else if ( state === false ) {
219
- train . all [ trainPosition ] . prototype . engineRunning = 0 ;
220
- }
221
- }
222
- else {
223
- //This code means that if you're out of fuel, regardless of what state you fed into this function it will turn the engine off.
241
+ train . all [ trainPosition ] . dcc . f . engine . state = state ;
242
+ //This code sets engineRunning to 0 or 1 depending on the state
243
+ if ( state === true ) {
244
+ train . all [ trainPosition ] . prototype . engineRunning = 1 ;
245
+ } else if ( state === false ) {
224
246
train . all [ trainPosition ] . prototype . engineRunning = 0 ;
225
- train . all [ trainPosition ] . dcc . f . engine . state = false ;
226
247
}
227
248
} ;
228
249
this . f . engine . state = false ;
229
250
230
251
//notch sound stuff.
231
252
this . f . notch = {
232
- up : function ( ) {
253
+ up : function ( ) {
233
254
//Notch up code
234
255
//This is inside an IF statement to make sure we don't try to notch OVER 8.
235
256
var newNotch = ( train . all [ trainPosition ] . dcc . f . notch . state + 1 ) ;
236
257
if ( newNotch <= 8 ) {
237
- train . all [ trainPosition ] . dcc . f . notch . state ++ ; //THIS HAS TO RUN INSTANTLY OR SIM.JS IS STUPID
258
+ train . all [ trainPosition ] . dcc . f . notch . state ++ ; //THIS HAS TO RUN INSTANTLY OR SIM.JS IS STUPID
238
259
}
239
260
} ,
240
- down : function ( ) {
261
+ down : function ( ) {
241
262
//Notch down code
242
263
//This is inside an IF statement to make sure we don't try to notch LESS THAN idle.
243
264
var newNotch = ( train . all [ trainPosition ] . dcc . f . notch . state - 1 ) ;
244
265
if ( newNotch >= 0 ) {
245
266
train . all [ trainPosition ] . dcc . f . notch . state -- ; //THIS MUST RUN INSTANTLY OR SIM.JS DOES WEIRD STUFF
246
267
}
247
268
} ,
248
- state : 0 //This should reflect the current notching state of the sound decoder. You should increment this up or down 1 when your up() and down() functions finish, or sim.js's functions will be horribly confused and mess up your sounds.
269
+ state : 0 //This should reflect the current notching state of the sound decoder. You should increment this up or down 1 when your up() and down() functions finish, or sim.js's functions will be horribly confused and mess up your sounds.
249
270
} ;
250
271
251
272
252
273
//SPEED SETTING
253
274
this . speed = { } ;
254
275
this . speed . state = 0 ;
255
- this . speed . set = function ( speed ) {
276
+ this . speed . set = function ( speed ) {
256
277
train . all [ trainPosition ] . throttle . speed . set ( speed ) ;
257
278
train . all [ trainPosition ] . dcc . speed . state = speed ;
258
279
} ;
259
- this . speed . setMPH = function ( mph ) {
280
+ this . speed . setMPH = function ( mph ) {
260
281
var speed = train . all [ trainPosition ] . model . speed ( mph ) ;
261
282
train . all [ trainPosition ] . dcc . speed . set ( speed ) ;
262
283
} ;
@@ -265,14 +286,14 @@ var decoders = {
265
286
//SPEED SETTING
266
287
this . speed = { } ;
267
288
this . speed . state = 0 ;
268
- this . speed . set = function ( speed ) {
269
- train [ trainPosition ] . throttle . speed . set ( speed ) ;
270
- train [ trainPosition ] . dcc . speed . state = speed ;
289
+ this . speed . set = function ( speed ) {
290
+ train . all [ trainPosition ] . throttle . speed . set ( speed ) ;
291
+ train . all [ trainPosition ] . dcc . speed . state = speed ;
271
292
} ;
272
- this . speed . setMPH = function ( mph ) {
273
- var speed = train [ trainPosition ] . model . speed ( mph ) ;
274
- train [ trainPosition ] . dcc . speed . set ( speed ) ;
293
+ this . speed . setMPH = function ( mph ) {
294
+ var speed = train . all [ trainPosition ] . model . speed ( mph ) ;
295
+ train . all [ trainPosition ] . dcc . speed . set ( speed ) ;
275
296
} ;
276
297
}
277
298
}
278
- } ;
299
+ } ;
0 commit comments