var DVMTriggers = { inputs:
{ trigger0: { config: '02' },
trigger1: { config: '01' },
trigger2: { config: '01' },
trigger3: { config: '01' },
trigger4: { config: '01' },
trigger5: { config: '00' } },
outputs: {} }
// Define dummy functions in the global scope.
mirror_trigger_zero = function(toggle) {
console.log('mirror_trigger_zero');
}
mirror_trigger_one = function(toggle) {
console.log('mirror_trigger_one');
}
mirror_trigger_two = function(toggle) {
console.log('mirror_trigger_two');
}
mirror_trigger_three = function(toggle) {
console.log('mirror_trigger_three');
}
mirror_trigger_four = function(toggle) {
console.log('mirror_trigger_four');
}
mirror_trigger_five = function(toggle) {
console.log('mirror_trigger_five');
}
function getConfigOfTrigger(triggerNum) {
var setting = DVMTriggers["inputs"]["trigger" + String(triggerNum)]["config"];
return setting;
}
function flipFlopMachine(configString) {
/**
* Build function based on a configuration string value.
* Returned function looks to see if trigger is held down,
* based on initially passed in config settings.
* Returns boolean of whether the trigger is active or inactive.
* Input: Expected valid config value of '00', '01', or '02'.
* Output: Function.
* Returned Function Input: true case for a sensor value. Assume a boolean state.
*/
let result = null;
switch (configString) {
case '00': // Not used
result = function(pinMessageValue) {
// Trigger will never be active.
return false;
}
break;
case '01': // Low to High
result = function(pinMessageValue) {
// Return true for high messages.
return pinMessageValue;
}
break;
case '02': // High to Low
result = function(pinMessageValue) {
// Return true for low messages.
return !pinMessageValue;
}
break;
default:
console.error('Unexpected configString', configString, 'passed into function makeTriggerCheckFunction.');
break;
}
return...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.