step-addition 17.7 KB
Newer Older
Jake Read's avatar
Jake Read committed
1
{"modules":{"0.37807284615053505":{"definition":"//\n// character input output\n//\n// Neil Gershenfeld \n// (c) Massachusetts Institute of Technology 2016\n// \n// This work may be reproduced, modified, distributed, performed, and \n// displayed for any purpose, but must acknowledge the mods\n// project. Copyright is retained and must be preserved. The work is \n// provided as is; no warranty is provided, and users accept all \n// liability.\n//\n// closure\n//\n(function() {\n   //\n   // module globals\n   //\n   var mod = {}\n   //\n   // name\n   //\n   var name = 'stepper'\n   //\n   // initialization\n   //\n   var init = function() {\n      mod.path = [1, 2] // path on net\n      mod.delimiters = [254, 255]\n      mod.steps = [129, 0, 0, 0, 240]\n      mod.speed = [130, 0, 0, 2, 255]\n      mod.packet = []\n   }\n   //\n   // inputs\n   //\n   var inputs = {\n      sync: {\n         type: 'event',\n         event: function(evt) {\n            console.log('stepper triggered')\n            outputs.packet.event()\n         }\n      },\n      position: {\n         type: 'float, units',\n         event: function(evt) {\n            console.log('steps input: ')\n            console.log(evt.detail)\n            mod.steps[1] = (evt.detail >> 24) & 255\n            mod.steps[2] = (evt.detail >> 16) & 255\n            mod.steps[3] = (evt.detail >> 8) & 255\n            mod.steps[4] = evt.detail & 255\n         }\n      },\n      speed: {\n         type: 'float, units/s',\n         event: function(evt) {\n            console.log('speed input: ')\n            console.log(evt.detail)\n            mod.speed[1] = (evt.detail >> 24) & 255\n            mod.speed[2] = (evt.detail >> 16) & 255\n            mod.speed[3] = (evt.detail >> 8) & 255\n            mod.speed[4] = evt.detail & 255\n         }\n      }\n   }\n   //\n   // outputs\n   //\n   var outputs = {\n      packet: {\n         type: 'packet',\n         event: function(something) {\n            /*\n            apa_end_addr_delimiter 255\n            apa_addr_pointer 254\n            apa_addr_flood 253\n\n            steps: 127\n            speed: 128\n\n            uint8_t: 0\n            int8_t: 1\n            uint32_t: 2\n            int32_t: 3\n            float: 4\n            double: 8\n            */\n            mod.packet = [] // clear\n            mod.packet = mod.packet.concat(mod.path, mod.delimiters, mod.steps, mod.speed);\n            mod.packet.splice(0, 0, mod.packet.length + 1)\n            console.log(mod.packet);\n            mods.output(mod, 'packet', mod.packet)\n         }\n      }\n   }\n   //\n   // interface\n   //\n   var interface = function(div) {\n      mod.div = div\n\n      div.appendChild(document.createTextNode('path to stepper:'))\n      div.appendChild(document.createElement('br'))\n      var addrIn = document.createElement('input')\n      addrIn.type = 'text'\n      addrIn.size = mods.ui.cols\n      addrIn.addEventListener('change', function() {\n         mod.path = addrIn.value.split(',')\n         if(mod.path[0] == ''){\n            mod.path = []\n            console.log('zero length')\n         } else {\n            for(var i = 0; i < mod.path.length; i ++){\n               mod.path[i] = parseFloat(mod.path[i])\n            }\n         }\n         // trigger func that looks at mod.in[]s and checks length, builds array of arrays?\n         console.log('new path: ', mod.path)\n      })\n      div.appendChild(addrIn)\n      mod.path = [1, 2]\n      addrIn.value = mod.path.toString()\n\n      div.appendChild(document.createElement('br'))\n      var btn = document.createElement('button')\n      btn.style.padding = mods.ui.padding\n      btn.style.margin = 1\n      btn.appendChild(document.createTextNode('pump'))\n      btn.addEventListener('click', function() {\n         outputs.packet.event()\n      })\n      div.appendChild(btn)\n\n   }\n   //\n   // local functions\n   //\n   function local_func() {\n      console.log('internal func')\n   }\n   //\n   // return values\n   //\n   return ({\n      name: name,\n      init: init,\n      inputs: inputs,\n      outputs: outputs,\n      interface: interface\n   })\n}())","top":"306","left":"5981","inputs":{},"outputs":{}},"0.38985999719909814":{"definition":"//\n// character input output\n//\n// Neil Gershenfeld \n// (c) Massachusetts Institute of Technology 2016\n// \n// This work may be reproduced, modified, distributed, performed, and \n// displayed for any purpose, but must acknowledge the mods\n// project. Copyright is retained and must be preserved. The work is \n// provided as is; no warranty is provided, and users accept all \n// liability.\n//\n// closure\n//\n(function() {\n   //\n   // module globals\n   //\n   var mod = {}\n   //\n   // name\n   //\n   var name = 'stepsequencer'\n   /*\n   onedof takes a position triplet and feedrate\n   and outputs three step commands, in sync\n   */\n   //\n   // initialization\n   //\n   var init = function() {\n      mod.sequencePosition = 0\n   }\n   //\n   // inputs\n   //\n   var inputs = {\n      sync: {\n         type: 'event',\n         event: function(evt) {\n            // do beat sync\n            trigger_func() // serves the justice\n         }\n      }\n   }\n   //\n   // outputs\n   //\n   var outputs = {\n      trigger: {\n         type: 'event',\n         event: function() {\n            mods.output(mod, 'trigger', 1)\n         }\n      },\n      steps: {\n         type: 'steps',\n         event: function(val) {\n            mods.output(mod, 'steps', val)\n         }\n      },\n      speed: {\n         type: 'steps/s',\n         event: function(val) {\n            mods.output(mod, 'speed', val)\n         }\n      }\n   }\n   //\n   // interface\n   //\n   var interface = function(div) {\n      mod.div = div\n      mod.in = [] // inputs\n\n      div.appendChild(document.createTextNode('first position, speed:'))\n      div.appendChild(document.createElement('br'))\n      var in1 = document.createElement('input')\n      in1.type = 'text'\n      in1.size = mods.ui.cols\n      in1.addEventListener('change', function() {\n         mod.in[0] = in1.value.split(',')\n         // trigger func that looks at mod.in[]s and checks length, builds array of arrays?\n         console.log(mod.in[0])\n      })\n      div.appendChild(in1)\n      mod.in[0] = ['0', '1000']\n      in1.value = mod.in[0].toString()\n\n      div.appendChild(document.createElement('br'))\n      div.appendChild(document.createTextNode('second position, speed:'))\n      div.appendChild(document.createElement('br'))\n      var in2 = document.createElement('input')\n      in2.type = 'text'\n      in2.size = mods.ui.cols\n      in2.addEventListener('change', function() {\n         mod.in[1] = in2.value.split(',')\n         // trigger func that looks at mod.in[]s and checks length, builds array of arrays?\n         console.log(mod.in[1])\n      })\n      div.appendChild(in2)\n      mod.in[1] = ['1000', '2000']\n      in2.value = mod.in[1].toString()\n\n      /*\n      div.appendChild(document.createElement('br'))\n      div.appendChild(document.createTextNode('third position, speed:'))\n      div.appendChild(document.createElement('br'))\n      var in3 = document.createElement('input')\n      in3.type = 'text'\n      in3.size = mods.ui.cols\n      in3.addEventListener('change', function() {\n         mod.in[2] = in1.value.split(',')\n         // trigger func that looks at mod.in[]s and checks length, builds array of arrays?\n         console.log(mod.in[2])\n      })\n      div.appendChild(in3)\n      mod.in[2] = ['0', '400']\n      in3.value = mod.in[2].toString()\n      */\n\n      div.appendChild(document.createElement('br'))\n      var btn = document.createElement('button')\n      btn.style.padding = mods.ui.padding\n      btn.style.margin = 1\n      btn.appendChild(document.createTextNode('clear'))\n      btn.addEventListener('click', function() {\n         in1.value = ''\n         in2.value = ''\n         //in3.value = ''\n      })\n      div.appendChild(btn)\n\n      div.appendChild(document.createElement('br'))\n      var btn = document.createElement('button')\n      btn.style.padding = mods.ui.padding\n      btn.style.margin = 1\n      btn.appendChild(document.createTextNode('pump'))\n      btn.addEventListener('click', function() {\n         trigger_func()\n      })\n      div.appendChild(btn)\n   }\n   //\n   // local functions\n   //\n   function trigger_func() {\n      // decrement count, trigger next in seq. if not 0, loop around sequence agnostic to trigger logic\n      outputs.steps.event(mod.in[mod.sequencePosition][0])\n      outputs.speed.event(mod.in[mod.sequencePosition][1])\n      outputs.trigger.event()\n      mod.sequencePosition++;\n      if (mod.sequencePosition >= mod.in.length) {\n         mod.sequencePosition = 0\n      }\n   }\n   //\n   // return values\n   //\n   return ({\n      name: name,\n      init: init,\n      inputs: inputs,\n      outputs: outputs,\n      interface: interface\n   })\n}())","top":"302","left":"5224","inputs":{},"outputs":{}},"0.6300206027264619":{"definition":"//\n// delay event\n//\n// Neil Gershenfeld \n// (c) Massachusetts Institute of Technology 2016\n// \n// This work may be reproduced, modified, distributed, performed, and \n// displayed for any purpose, but must acknowledge the mods\n// project. Copyright is retained and must be preserved. The work is \n// provided as is; no warranty is provided, and users accept all \n// liability.\n//\n// closure\n//\n(function() {\n   //\n   // module globals\n   //\n   var mod = {}\n   //\n   // name\n   //\n   var name = 'delay event'\n   //\n   // initialization\n   //\n   var init = function() {\n      mod.delay.value = 1000\n      mod.countdown.value = 10\n      mod.countdownBegin = 10\n      mod.loop.checked = true\n   }\n   //\n   // inputs\n   //\n   var inputs = {\n      sync: {\n         type: 'event',\n         event: function(evt) {\n            mod.input = evt.detail\n            mod.event.value = evt.detail\n            trigger_if()\n         }\n      },\n      countdown: {\n         type: 'count',\n         event: function(evt) {\n            mod.countdownBegin = evt.detail\n            mod.countdown.value = evt.detail\n            //console.log('count in: ', evt.detail)\n            trigger_oncount()\n         }\n      }\n   }\n   //\n   // outputs\n   //\n   var outputs = {\n      trigger: {\n         type: 'event',\n         event: function() {\n            mods.output(mod, 'trigger', mod.input)\n         }\n      }\n   }\n   //\n   // interface\n   //\n   var interface = function(div) {\n      mod.div = div\n      //\n      // delay label\n      //\n      var span = document.createElement('span')\n      var text = document.createTextNode('waiting for event')\n      mod.label = text\n      span.appendChild(text)\n      mod.labelspan = span\n      div.appendChild(span)\n      //\n      // delay value\n      //\n      div.appendChild(document.createElement('br'))\n      div.appendChild(document.createTextNode('delay (ms): '))\n      var delayInput = document.createElement('input')\n      delayInput.type = 'text'\n      delayInput.size = 6\n      delayInput.addEventListener('change', function() {})\n      div.appendChild(delayInput)\n      mod.delay = delayInput\n      //\n      // counts\n      //\n      div.appendChild(document.createElement('br'))\n      div.appendChild(document.createTextNode('count down: '))\n      var countInput = document.createElement('input')\n      countInput.type = 'text'\n      countInput.size = 6\n      countInput.addEventListener('change', function() {\n         mod.countdownBegin = countInput.value\n         mod.countdown = countInput\n      })\n      div.appendChild(countInput)\n      mod.countdownBegin = countInput.value\n      mod.countdown = countInput\n      // save countdown from for reset\n      // implement reset\n      //\n      // loop or don't\n      //\n      div.appendChild(document.createElement('br'))\n      div.appendChild(document.createTextNode('loop: '))\n      var loopInput = document.createElement('input')\n      loopInput.type = 'checkbox'\n      //input.id = mod.div.id + 'loop'\n      div.appendChild(loopInput)\n      mod.loop = loopInput\n      div.appendChild(document.createElement('br'))\n      //\n      // event value\n      //\n      div.appendChild(document.createElement('br'))\n      div.appendChild(document.createTextNode('event value: '))\n      var eventInput = document.createElement('input')\n      eventInput.type = 'text'\n      eventInput.size = 6\n      eventInput.addEventListener('change', function() {})\n      div.appendChild(eventInput)\n      mod.event = eventInput\n   }\n   //\n   // local functions\n   //\n   function delay_event() {\n      mod.label.nodeValue = 'delaying event'\n      mod.labelspan.style.fontWeight = 'bold'\n      var delay = parseFloat(mod.delay.value)\n      window.setTimeout(after_delay, delay)\n   }\n\n   function after_delay() {\n      mod.label.nodeValue = 'waiting for event'\n      mod.labelspan.style.fontWeight = 'normal'\n      mod.countdown.value--\n      outputs.trigger.event()\n   }\n\n   function trigger_if() {\n      if (mod.countdown.value < 1) {\n         if (mod.loop.checked) {\n            mod.countdown.value = mod.countdownBegin\n            delay_event()\n         }\n      } else {\n         delay_event()\n      }\n   }\n\n   function trigger_oncount() {\n      console.log('trigger oncount, ', mod.countdown.value)\n      if(mod.countdown.value < 1){\n         // loop begin is also 0, nothing\n      } else {\n         //console.log('coundown begin')\n         outputs.trigger.event()\n         mod.countdown.value --\n      }\n   }\n   //\n   // return values\n   //\n   return ({\n      name: name,\n      init: init,\n      inputs: inputs,\n      outputs: outputs,\n      interface: interface\n   })\n}())","top":"297","left":"4756","inputs":{},"outputs":{}},"0.8730984119702436":{"definition":"//\n// event gate\n//\n// Neil Gershenfeld and Jake Read\n// (c) Massachusetts Institute of Technology 2016\n// \n// This work may be reproduced, modified, distributed, performed, and \n// displayed for any purpose, but must acknowledge the mods\n// project. Copyright is retained and must be preserved. The work is \n// provided as is; no warranty is provided, and users accept all \n// liability.\n//\n// closure\n//\n(function() {\n   //\n   // module globals\n   //\n   var mod = {}\n   //\n   // name\n   //\n   var name = 'event gate'\n   //\n   // initialization\n   //\n   var init = function() {\n      mod.gate = 0\n      mod.button_gate.childNodes[0].nodeValue = 'gate: closed'\n      mod.event_in.value = '1'\n   }\n   //\n   // inputs\n   //\n   var inputs = {\n      trigger: {\n         type: 'event',\n         event: function(evt) {\n            if (mod.gate === 0) {\n               console.log('thou shall not pass')\n            } else {\n               outputs.output.event()\n            }\n         }\n      },\n      close: {\n         type: 'event',\n         event: function(evt){\n            gate_close()\n         }\n      },\n      open: {\n         type: 'event',\n         event: function(evt){\n            gate_open()\n         }\n      }\n   }\n   //\n   // outputs\n   //\n   var outputs = {\n      output: {\n         type: 'event',\n         event: function() {\n            mods.output(mod, 'output', mod.event_in.value)\n         }\n      }\n   }\n   //\n   // interface\n   //\n   var interface = function(div) {\n      mod.div = div\n   \n      // generate button\n      mod.button_generate = make_button_input(div, 'generate')\n      mod.button_generate.addEventListener('click', function(){\n         outputs.output.event()\n      })\n      \n      // gate mode\n      mod.button_gate = make_button_input(div, '')\n      mod.button_gate.addEventListener('click', function(){\n         if(mod.gate === 1){\n            gate_close()\n         } else {\n            gate_open()\n         }\n      })\n      \n      // event value\n      mod.event_in = make_text_input(div, 'value: ', 6)\n      mod.event_in.addEventListener('change', function(){\n         //\n      })\n   }\n   //\n   // local functions\n   //\n\n   function gate_open(){\n      mod.gate = 1\n      mod.button_gate.childNodes[0].nodeValue = \"gate: open\"\n   }\n\n   function gate_close(){\n      mod.gate = 0\n      mod.button_gate.childNodes[0].nodeValue = \"gate: closed\"\n   }\n\n   //\n   // return values\n   //\n   return ({\n      name: name,\n      init: init,\n      inputs: inputs,\n      outputs: outputs,\n      interface: interface\n   })\n}())","top":"691","left":"4764","inputs":{},"outputs":{}}},"links":["{\"source\":\"{\\\"id\\\":\\\"0.38985999719909814\\\",\\\"type\\\":\\\"outputs\\\",\\\"name\\\":\\\"trigger\\\"}\",\"dest\":\"{\\\"id\\\":\\\"0.37807284615053505\\\",\\\"type\\\":\\\"inputs\\\",\\\"name\\\":\\\"sync\\\"}\"}","{\"source\":\"{\\\"id\\\":\\\"0.38985999719909814\\\",\\\"type\\\":\\\"outputs\\\",\\\"name\\\":\\\"steps\\\"}\",\"dest\":\"{\\\"id\\\":\\\"0.37807284615053505\\\",\\\"type\\\":\\\"inputs\\\",\\\"name\\\":\\\"position\\\"}\"}","{\"source\":\"{\\\"id\\\":\\\"0.38985999719909814\\\",\\\"type\\\":\\\"outputs\\\",\\\"name\\\":\\\"speed\\\"}\",\"dest\":\"{\\\"id\\\":\\\"0.37807284615053505\\\",\\\"type\\\":\\\"inputs\\\",\\\"name\\\":\\\"speed\\\"}\"}","{\"source\":\"{\\\"id\\\":\\\"0.6300206027264619\\\",\\\"type\\\":\\\"outputs\\\",\\\"name\\\":\\\"trigger\\\"}\",\"dest\":\"{\\\"id\\\":\\\"0.38985999719909814\\\",\\\"type\\\":\\\"inputs\\\",\\\"name\\\":\\\"sync\\\"}\"}","{\"source\":\"{\\\"id\\\":\\\"0.6300206027264619\\\",\\\"type\\\":\\\"outputs\\\",\\\"name\\\":\\\"trigger\\\"}\",\"dest\":\"{\\\"id\\\":\\\"0.8730984119702436\\\",\\\"type\\\":\\\"inputs\\\",\\\"name\\\":\\\"trigger\\\"}\"}","{\"source\":\"{\\\"id\\\":\\\"0.8730984119702436\\\",\\\"type\\\":\\\"outputs\\\",\\\"name\\\":\\\"output\\\"}\",\"dest\":\"{\\\"id\\\":\\\"0.6300206027264619\\\",\\\"type\\\":\\\"inputs\\\",\\\"name\\\":\\\"sync\\\"}\"}"]}