-
Notifications
You must be signed in to change notification settings - Fork 4
Develop your own: decoder.js
##What does this file do? This file is the "translator" for specific DCC decoders. It allows locoThrottle.js as a whole to remain decoder-agnostic. Everything related to decoder functions (sound, lights, etc) is a function in this file. The functions are the same in every decoder.js file, but can contain whatever is needed to make the decoder do whatever it needs to do.
##How do I write my own?
Basically you duplicate the bundled loksound.js
script, with the functions adjusted for your decoder. You can find information on each function below. More detailed instructions? Yeah...let me get back to you on that...
#Functions:
##sound_notch(direction)
###Arguments:
- Direction - This is a string and can be either
"up"
,"down"
, or"reset"
.-
"up"
- Should raise the notch sound up one notch. -
"down"
- Should lower the notch sound down one notch. -
"reset"
- Should set the notch sound to 0 (Idle) and shut off the engine sounds completely.
-
###Returns:
"notchSuccess"
- This is a little bit odd to deal with, and I would remove it except for the fact that my decoder misbehaves without this option. Basically, if it returns false
, it means that the decoder needs more time to pass before it can change its notch sound again. Conversely, true
is returned if the action was successful.
###Requirements: This doesn't have any specific required tasks/functions to call.
###What does it do?
This function is responsible for keeping the notch sound accurate on your decoder (when applicable). Not all decoders support this, but I (I being k4kfh
) was fortunate enough to have a LokSound decoder for an EMD FT-A that does support it. I thought this was a super cool feature, so I wanted to make sure I didn't leave out the option to harness it.
This function is called by the other functions responsible for notching, and is only called with the arguments "up"
or "down"
normally, however the decoder.js
standard does have a "reset"
option which resets the sound notch to 0 (Idle).
##setEngine(dowhat)
###Arguments:
-
dowhat
- Boolean value telling whether to start the compressor (true
) or stop it (false
).
###Returns: Nothing. This function returns nothing. Easy huh?
###What does it do? This function is responsible for enabling and disabling the compressor sound on your decoder when applicable. If your decoder does not have this feature, simply make a "dummy" function that doesn't actually send any commands to your decoder.
###Requirements
After changing the compressor's state, you must run compressor = true
you must call updateHTML("compressor")
to keep the UI in tune with what's going on.
##setBell(dowhat)
###Arguments:
-
dowhat
- Boolean value telling whether to enable the bell (true
) or disable it (false
).
###Returns: Nothing.
###What does it do? This function is responsible for enabling and disabling the bell sound on your decoder when applicable. If your decoder does not have this feature, simply make a "dummy" function that doesn't actually send any commands to your decoder.
###Requirements
After changing the bell's state, you must run bell = true
and you must call updateHTML("bell")
to keep the UI in tune with what's going on.
##setEngine(dowhat)
###Arguments:
-
dowhat
- Boolean value telling whether to enable the horn (true
) or disable it (false
).
###Returns: This function returns nothing at all.
###What does it do? This function is responsible for enabling and disabling the compressor sound on your decoder when applicable. If your decoder does not have this feature, simply make a "dummy" function that doesn't actually send any commands to your decoder.
###Requirements
Set horn = true
. You don't have to call updateHTML()
for this because the horn is represented by a button instead of a switch, so we don't have to change any UI elements.
##setHeadlight(dowhat)
###Arguments:
-
dowhat
- Boolean value telling whether to switch the headlight on or off;true
orfalse
, respectively.
###Returns: Nothing. This function returns nothing. Easy huh?
###What does it do? This function is responsible for enabling and disabling the light on your DCC decoder.
###Requirements
After changing the compressor's state, set headlight = true
. Also, you must call updateHTML("headlight")
to keep the UI in tune with what's going on.
##JSONhandleType_throttle_functions(json)
###Arguments:
-
json
- Input (in json format, incredibly enough) for the received WebSockets throttle data.
###Returns: Nothing. This function returns nothing. Easy huh?
###What does it do? This function handles the incoming data from JMRI's WebSockets server (in JSON format) regarding the throttle functions on your decoder.
###Requirements Based on the throttle data, you must set the corresponding function variable to its correct value.
###NOTE: If done wrong, this function can cause a weird infinite loop thing which will lock up your entire browser. (Bet y'all can't guess how I know this...) As a result, I HIGHLY SUGGEST SIMPLY MODIFYING THE CODE BELOW! You should just be able to change the functions to fit your decoder.
if (json.F1 !=undefined) {
if (bell != json.F1) {
setBell(json.F1)
debugToast("JSON handler ran setBell(), with JSON value " + json.F1, 4000)
}
}
if (json.F2 != undefined) {
if (horn != json.F2) {
//nothing here, just for organization and potential future feature...but since the horn is a button its not workable like the switches
debugToast("JSON handler ran setHorn() dummy, with JSON value " + json.F2, 4000)
}
}
if (json.F8 != undefined) {
if (engine != json.F8) {
setEngine(json.F8)
debugToast("JSON handler ran setEngine(), with JSON value " + json.F8, 4000)
}
}
if (json.F20 != undefined) {
if (compressor != json.F20) {
setCompressor(json.F20)
debugToast("JSON handler ran setCompressor(), with JSON value " + json.F20, 4000)
}
}
####Acknowledgements:
- ZephyrCab's UI would not be possible without MaterializeCSS
-
Physics Engine
- Mr. Bruce Kingsley of BruceKModelTrains.com was unbelievably helpful with the physics engine. Without him it would not have been possible (at least not for MANY more years).
- Mr. Chris Jakeman of the Open Rails Dev Team was also very helpful with the physics engine.
###Support the project: "Support the project", says the wiki page. Those words are somewhat misleading. God has blessed me with resources and time to work on this project, so I have decided I do not need donations for myself. It would be amazing if you would donate to Blood:Water Mission instead though! They help give clean water to people in third-world countries. Trust me, these folks need the money more than I do!