From 6f4ea80080b42303ea15283f174fba998b50d377 Mon Sep 17 00:00:00 2001 From: Jake Read <jake.read@cba.mit.edu> Date: Thu, 15 Nov 2018 14:16:46 -0500 Subject: [PATCH] add init possibility for modules' default vals --- README.md | 1 + modules/hardware/atkseriallink.js | 4 ++++ modules/motion/planner.js | 7 +++++++ programs.js | 5 +++++ views.js | 4 ++++ 5 files changed, 21 insertions(+) diff --git a/README.md b/README.md index 98ce70b..e3f2c10 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,7 @@ To assemble a representation of these, we want to have a kind of 'netlist' that, ## Desires - heirarchy zoom - architectural clarity betwixt UI and Heap +- some auto load / save currently.json file so that we can restart program w/o pain ... maybe just save on new user inputs ? - states / uis / etc - one off / one-at-a-time for updates - i.e. all f'n update calls are to single module-global state update - ! diff --git a/modules/hardware/atkseriallink.js b/modules/hardware/atkseriallink.js index 207dc86..a42a6e2 100644 --- a/modules/hardware/atkseriallink.js +++ b/modules/hardware/atkseriallink.js @@ -26,6 +26,10 @@ function ATKSerialLink() { state.connect = Button('click to find and connect', findSerialPort) state.portStatus = 'closed' // or we hope it will be + atkSerialLink.init = function(){ + findSerialPort() + } + /* ------------------------------------------------------ HOOKING UP diff --git a/modules/motion/planner.js b/modules/motion/planner.js index 1ff4fe6..aec37ff 100644 --- a/modules/motion/planner.js +++ b/modules/motion/planner.js @@ -54,6 +54,13 @@ function Planner() { moveComplete: Output('number') } + // we'll use one of these to assert / do things + // after the module is loaded, and state is copied etc + // i.e. one thing we can do is assert a starting value + planner.init = function(){ + state.isRunning = 0 + } + /* ------------------------------------------------------ UPDATING / SETUP diff --git a/programs.js b/programs.js index 8f0f80d..9582a6e 100644 --- a/programs.js +++ b/programs.js @@ -271,6 +271,11 @@ function openProgram(path) { } } + // and let's run init if it's there + if(mdl.init != null){ + mdl.init() + } + //console.log('mdlRep', mdlRep) //console.log('mdl', mdl) // restore position / UI state diff --git a/views.js b/views.js index 4741979..689eb3d 100644 --- a/views.js +++ b/views.js @@ -230,6 +230,10 @@ function uiRequestNewModule(data) { // just burn it down socketSend('restart', '') } + // TODO: questionable init - here and in loadProgram, should be better handled across board + if(program.modules[latest].init != null){ + program.modules[latest].init() + } socketSend('put module', Reps.makeFromModule(program.modules[keys[keys.length - 1]])) } -- GitLab