diff --git a/workspace/lcd-time/__fixtures__/arduino.cpp b/workspace/lcd-time/__fixtures__/arduino.cpp index bd9ef4cd..792ead5d 100644 --- a/workspace/lcd-time/__fixtures__/arduino.cpp +++ b/workspace/lcd-time/__fixtures__/arduino.cpp @@ -631,7 +631,7 @@ template class List { * =============================================================================*/ -#define NODE_COUNT 12 +#define NODE_COUNT 11 #define MAX_OUTPUT_COUNT 1 // Uncomment to trace the program in the Serial Monitor @@ -1011,54 +1011,6 @@ void evaluate(NodeId nid, State* state) { } // namespace xod__common_hardware__text_lcd_16x2 -//----------------------------------------------------------------------------- -// xod/core/clock implementation -//----------------------------------------------------------------------------- -namespace xod__core__clock { - -struct State { - TimeMs nextTrig; -}; - -struct Storage { - State state; - PinRef input_IVAL; - PinRef input_RST; - OutputPin output_TICK; -}; - -namespace Inputs { - using IVAL = InputDescriptor; - using RST = InputDescriptor; -} - -namespace Outputs { - using TICK = OutputDescriptor; -} - -void evaluate(NodeId nid, State* state) { - TimeMs tNow = transactionTime(); - TimeMs dt = getValue(nid) * 1000; - TimeMs tNext = tNow + dt; - - if (isInputDirty(nid)) { - if (dt == 0) { - state->nextTrig = 0; - clearTimeout(nid); - } else if (state->nextTrig < tNow || state->nextTrig > tNext) { - state->nextTrig = tNext; - setTimeout(nid, dt); - } - } else { - // It was a scheduled tick - emitValue(nid, 1); - state->nextTrig = tNext; - setTimeout(nid, dt); - } -} - -} // namespace xod__core__clock - //----------------------------------------------------------------------------- // xod/core/cast_number_to_string implementation //----------------------------------------------------------------------------- @@ -1091,6 +1043,33 @@ void evaluate(NodeId nid, State* state) { } // namespace xod__core__cast_number_to_string +//----------------------------------------------------------------------------- +// xod/core/continuously implementation +//----------------------------------------------------------------------------- +namespace xod__core__continuously { + +struct State { +}; + +struct Storage { + State state; + OutputPin output_TICK; +}; + +namespace Inputs { +} + +namespace Outputs { + using TICK = OutputDescriptor; +} + +void evaluate(NodeId nid, State* state) { + emitValue(nid, 1); + setTimeout(nid, 0); +} + +} // namespace xod__core__continuously + //----------------------------------------------------------------------------- // xod/core/constant_number implementation //----------------------------------------------------------------------------- @@ -1153,10 +1132,10 @@ void evaluate(NodeId nid, State* state) { namespace _program { - NodeId links_0_TIME[] = { 3, NO_NODE }; + NodeId links_0_TIME[] = { 2, NO_NODE }; xod__core__system_time::Storage storage_0 = { { }, // state - { NodeId(2), xod__core__clock::Outputs::TICK::KEY }, // input_UPD + { NodeId(3), xod__core__continuously::Outputs::TICK::KEY }, // input_UPD { 0, links_0_TIME } // output_TIME }; @@ -1168,23 +1147,21 @@ namespace _program { { NodeId(7), xod__core__constant_number::Outputs::VAL::KEY }, // input_D5 { NodeId(6), xod__core__constant_number::Outputs::VAL::KEY }, // input_D6 { NodeId(10), xod__core__constant_number::Outputs::VAL::KEY }, // input_D7 - { NodeId(3), xod__core__cast_number_to_string::Outputs::OUT::KEY }, // input_L1 + { NodeId(2), xod__core__cast_number_to_string::Outputs::OUT::KEY }, // input_L1 { NodeId(5), xod__core__constant_string::Outputs::VAL::KEY }, // input_L2 }; - NodeId links_2_TICK[] = { 0, NO_NODE }; - xod__core__clock::Storage storage_2 = { - { }, // state - { NodeId(11), xod__core__constant_number::Outputs::VAL::KEY }, // input_IVAL - { NO_NODE, 0 }, // input_RST - { false, links_2_TICK } // output_TICK - }; - - NodeId links_3_OUT[] = { 1, NO_NODE }; - xod__core__cast_number_to_string::Storage storage_3 = { + NodeId links_2_OUT[] = { 1, NO_NODE }; + xod__core__cast_number_to_string::Storage storage_2 = { { }, // state { NodeId(0), xod__core__system_time::Outputs::TIME::KEY }, // input_IN - { ::xod::List::empty(), links_3_OUT } // output_OUT + { ::xod::List::empty(), links_2_OUT } // output_OUT + }; + + NodeId links_3_TICK[] = { 0, NO_NODE }; + xod__core__continuously::Storage storage_3 = { + { }, // state + { ::xod::List::fromPlainArray("CONTINUOUSLY", 12), links_3_TICK } // output_TICK }; NodeId links_4_VAL[] = { 1, NO_NODE }; @@ -1229,12 +1206,6 @@ namespace _program { { 13, links_10_VAL } // output_VAL }; - NodeId links_11_VAL[] = { 2, NO_NODE }; - xod__core__constant_number::Storage storage_11 = { - { }, // state - { 0.01, links_11_VAL } // output_VAL - }; - void* storages[NODE_COUNT] = { &storage_0, &storage_1, @@ -1246,22 +1217,20 @@ namespace _program { &storage_7, &storage_8, &storage_9, - &storage_10, - &storage_11 + &storage_10 }; EvalFuncPtr evaluationFuncs[NODE_COUNT] = { (EvalFuncPtr)&xod__core__system_time::evaluate, (EvalFuncPtr)&xod__common_hardware__text_lcd_16x2::evaluate, - (EvalFuncPtr)&xod__core__clock::evaluate, (EvalFuncPtr)&xod__core__cast_number_to_string::evaluate, + (EvalFuncPtr)&xod__core__continuously::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate, (EvalFuncPtr)&xod__core__constant_string::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate, - (EvalFuncPtr)&xod__core__constant_number::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate }; @@ -1276,12 +1245,11 @@ namespace _program { DirtyFlags(-1), DirtyFlags(-1), DirtyFlags(-1), - DirtyFlags(-1), DirtyFlags(-1) }; NodeId topology[NODE_COUNT] = { - 4, 5, 6, 7, 8, 9, 10, 11, 2, 0, 3, 1 + 3, 4, 5, 6, 7, 8, 9, 10, 0, 2, 1 }; TimeMs schedule[NODE_COUNT] = { 0 }; diff --git a/workspace/lcd-time/main/patch.xodp b/workspace/lcd-time/main/patch.xodp index 91b7e567..a5479b14 100644 --- a/workspace/lcd-time/main/patch.xodp +++ b/workspace/lcd-time/main/patch.xodp @@ -1,17 +1,6 @@ { "description": "", "links": [ - { - "id": "HkFX79KZZ", - "input": { - "nodeId": "H1lzQqY-W", - "pinKey": "Bk74I0_SPyb" - }, - "output": { - "nodeId": "rJGQ7qYZ-", - "pinKey": "HJU8CE2lW" - } - }, { "id": "HyDiN9YbW", "input": { @@ -27,7 +16,7 @@ "nodes": [ { "boundValues": { - "Bk74I0_SPyb": false + "Bk74I0_SPyb": "CONTINUOUSLY" }, "description": "", "id": "H1lzQqY-W", @@ -57,20 +46,6 @@ "y": 328 }, "type": "xod/common-hardware/text-lcd-16x2" - }, - { - "boundValues": { - "B13SCNhl-": 0.01, - "BJJICN2lW": false - }, - "description": "", - "id": "rJGQ7qYZ-", - "label": "", - "position": { - "x": 266, - "y": 120 - }, - "type": "xod/core/clock" } ] } \ No newline at end of file diff --git a/workspace/two-button-switch/__fixtures__/arduino.cpp b/workspace/two-button-switch/__fixtures__/arduino.cpp index f478e117..0e141127 100644 --- a/workspace/two-button-switch/__fixtures__/arduino.cpp +++ b/workspace/two-button-switch/__fixtures__/arduino.cpp @@ -631,7 +631,7 @@ template class List { * =============================================================================*/ -#define NODE_COUNT 11 +#define NODE_COUNT 10 #define MAX_OUTPUT_COUNT 2 // Uncomment to trace the program in the Serial Monitor @@ -912,54 +912,6 @@ void loop() { namespace _program { -//----------------------------------------------------------------------------- -// xod/core/clock implementation -//----------------------------------------------------------------------------- -namespace xod__core__clock { - -struct State { - TimeMs nextTrig; -}; - -struct Storage { - State state; - PinRef input_IVAL; - PinRef input_RST; - OutputPin output_TICK; -}; - -namespace Inputs { - using IVAL = InputDescriptor; - using RST = InputDescriptor; -} - -namespace Outputs { - using TICK = OutputDescriptor; -} - -void evaluate(NodeId nid, State* state) { - TimeMs tNow = transactionTime(); - TimeMs dt = getValue(nid) * 1000; - TimeMs tNext = tNow + dt; - - if (isInputDirty(nid)) { - if (dt == 0) { - state->nextTrig = 0; - clearTimeout(nid); - } else if (state->nextTrig < tNow || state->nextTrig > tNext) { - state->nextTrig = tNext; - setTimeout(nid, dt); - } - } else { - // It was a scheduled tick - emitValue(nid, 1); - state->nextTrig = tNext; - setTimeout(nid, dt); - } -} - -} // namespace xod__core__clock - //----------------------------------------------------------------------------- // xod/core/gate implementation //----------------------------------------------------------------------------- @@ -1125,6 +1077,33 @@ void evaluate(NodeId nid, State* state) { } // namespace xod__core__digital_output +//----------------------------------------------------------------------------- +// xod/core/continuously implementation +//----------------------------------------------------------------------------- +namespace xod__core__continuously { + +struct State { +}; + +struct Storage { + State state; + OutputPin output_TICK; +}; + +namespace Inputs { +} + +namespace Outputs { + using TICK = OutputDescriptor; +} + +void evaluate(NodeId nid, State* state) { + emitValue(nid, 1); + setTimeout(nid, 0); +} + +} // namespace xod__core__continuously + //----------------------------------------------------------------------------- // xod/core/constant_number implementation //----------------------------------------------------------------------------- @@ -1162,87 +1141,79 @@ void evaluate(NodeId nid, State* state) { namespace _program { - NodeId links_0_TICK[] = { 5, 1, 2, 4, NO_NODE }; - xod__core__clock::Storage storage_0 = { + NodeId links_0_T[] = { NO_NODE }; + NodeId links_0_F[] = { 2, NO_NODE }; + xod__core__gate::Storage storage_0 = { { }, // state - { NodeId(7), xod__core__constant_number::Outputs::VAL::KEY }, // input_IVAL - { NO_NODE, 0 }, // input_RST - { false, links_0_TICK } // output_TICK + { NodeId(1), xod__core__digital_input::Outputs::SIG::KEY }, // input_GATE + { NodeId(9), xod__core__continuously::Outputs::TICK::KEY }, // input_TRIG + { false, links_0_T }, // output_T + { false, links_0_F } // output_F }; - NodeId links_1_T[] = { NO_NODE }; - NodeId links_1_F[] = { 3, NO_NODE }; - xod__core__gate::Storage storage_1 = { + NodeId links_1_SIG[] = { 0, NO_NODE }; + xod__core__digital_input::Storage storage_1 = { { }, // state - { NodeId(2), xod__core__digital_input::Outputs::SIG::KEY }, // input_GATE - { NodeId(0), xod__core__clock::Outputs::TICK::KEY }, // input_TRIG - { false, links_1_T }, // output_T - { false, links_1_F } // output_F + { NodeId(6), xod__core__constant_number::Outputs::VAL::KEY }, // input_PORT + { NodeId(9), xod__core__continuously::Outputs::TICK::KEY }, // input_UPD + { false, links_1_SIG } // output_SIG }; - NodeId links_2_SIG[] = { 1, NO_NODE }; - xod__core__digital_input::Storage storage_2 = { + NodeId links_2_MEM[] = { 5, NO_NODE }; + xod__core__flip_flop::Storage storage_2 = { + { }, // state + { NodeId(3), xod__core__gate::Outputs::F::KEY }, // input_SET + { NO_NODE, 0 }, // input_TGL + { NodeId(0), xod__core__gate::Outputs::F::KEY }, // input_RST + { false, links_2_MEM } // output_MEM + }; + + NodeId links_3_T[] = { NO_NODE }; + NodeId links_3_F[] = { 2, NO_NODE }; + xod__core__gate::Storage storage_3 = { + { }, // state + { NodeId(4), xod__core__digital_input::Outputs::SIG::KEY }, // input_GATE + { NodeId(9), xod__core__continuously::Outputs::TICK::KEY }, // input_TRIG + { false, links_3_T }, // output_T + { false, links_3_F } // output_F + }; + + NodeId links_4_SIG[] = { 3, NO_NODE }; + xod__core__digital_input::Storage storage_4 = { + { }, // state + { NodeId(7), xod__core__constant_number::Outputs::VAL::KEY }, // input_PORT + { NodeId(9), xod__core__continuously::Outputs::TICK::KEY }, // input_UPD + { false, links_4_SIG } // output_SIG + }; + + xod__core__digital_output::Storage storage_5 = { { }, // state { NodeId(8), xod__core__constant_number::Outputs::VAL::KEY }, // input_PORT - { NodeId(0), xod__core__clock::Outputs::TICK::KEY }, // input_UPD - { false, links_2_SIG } // output_SIG + { NodeId(2), xod__core__flip_flop::Outputs::MEM::KEY }, // input_SIG }; - NodeId links_3_MEM[] = { 6, NO_NODE }; - xod__core__flip_flop::Storage storage_3 = { + NodeId links_6_VAL[] = { 1, NO_NODE }; + xod__core__constant_number::Storage storage_6 = { { }, // state - { NodeId(4), xod__core__gate::Outputs::F::KEY }, // input_SET - { NO_NODE, 0 }, // input_TGL - { NodeId(1), xod__core__gate::Outputs::F::KEY }, // input_RST - { false, links_3_MEM } // output_MEM + { 12, links_6_VAL } // output_VAL }; - NodeId links_4_T[] = { NO_NODE }; - NodeId links_4_F[] = { 3, NO_NODE }; - xod__core__gate::Storage storage_4 = { - { }, // state - { NodeId(5), xod__core__digital_input::Outputs::SIG::KEY }, // input_GATE - { NodeId(0), xod__core__clock::Outputs::TICK::KEY }, // input_TRIG - { false, links_4_T }, // output_T - { false, links_4_F } // output_F - }; - - NodeId links_5_SIG[] = { 4, NO_NODE }; - xod__core__digital_input::Storage storage_5 = { - { }, // state - { NodeId(9), xod__core__constant_number::Outputs::VAL::KEY }, // input_PORT - { NodeId(0), xod__core__clock::Outputs::TICK::KEY }, // input_UPD - { false, links_5_SIG } // output_SIG - }; - - xod__core__digital_output::Storage storage_6 = { - { }, // state - { NodeId(10), xod__core__constant_number::Outputs::VAL::KEY }, // input_PORT - { NodeId(3), xod__core__flip_flop::Outputs::MEM::KEY }, // input_SIG - }; - - NodeId links_7_VAL[] = { 0, NO_NODE }; + NodeId links_7_VAL[] = { 4, NO_NODE }; xod__core__constant_number::Storage storage_7 = { { }, // state - { 0.02, links_7_VAL } // output_VAL + { 11, links_7_VAL } // output_VAL }; - NodeId links_8_VAL[] = { 2, NO_NODE }; + NodeId links_8_VAL[] = { 5, NO_NODE }; xod__core__constant_number::Storage storage_8 = { { }, // state - { 12, links_8_VAL } // output_VAL + { 13, links_8_VAL } // output_VAL }; - NodeId links_9_VAL[] = { 5, NO_NODE }; - xod__core__constant_number::Storage storage_9 = { + NodeId links_9_TICK[] = { 0, 1, 3, 4, NO_NODE }; + xod__core__continuously::Storage storage_9 = { { }, // state - { 11, links_9_VAL } // output_VAL - }; - - NodeId links_10_VAL[] = { 6, NO_NODE }; - xod__core__constant_number::Storage storage_10 = { - { }, // state - { 13, links_10_VAL } // output_VAL + { ::xod::List::fromPlainArray("CONTINUOUSLY", 12), links_9_TICK } // output_TICK }; void* storages[NODE_COUNT] = { @@ -1255,12 +1226,10 @@ namespace _program { &storage_6, &storage_7, &storage_8, - &storage_9, - &storage_10 + &storage_9 }; EvalFuncPtr evaluationFuncs[NODE_COUNT] = { - (EvalFuncPtr)&xod__core__clock::evaluate, (EvalFuncPtr)&xod__core__gate::evaluate, (EvalFuncPtr)&xod__core__digital_input::evaluate, (EvalFuncPtr)&xod__core__flip_flop::evaluate, @@ -1270,7 +1239,7 @@ namespace _program { (EvalFuncPtr)&xod__core__constant_number::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate, (EvalFuncPtr)&xod__core__constant_number::evaluate, - (EvalFuncPtr)&xod__core__constant_number::evaluate + (EvalFuncPtr)&xod__core__continuously::evaluate }; DirtyFlags dirtyFlags[NODE_COUNT] = { @@ -1283,12 +1252,11 @@ namespace _program { DirtyFlags(-1), DirtyFlags(-1), DirtyFlags(-1), - DirtyFlags(-1), DirtyFlags(-1) }; NodeId topology[NODE_COUNT] = { - 7, 8, 9, 10, 0, 2, 5, 1, 4, 3, 6 + 6, 7, 8, 9, 1, 4, 0, 3, 2, 5 }; TimeMs schedule[NODE_COUNT] = { 0 }; diff --git a/workspace/two-button-switch/main/patch.xodp b/workspace/two-button-switch/main/patch.xodp index 4511d5c9..e753f758 100644 --- a/workspace/two-button-switch/main/patch.xodp +++ b/workspace/two-button-switch/main/patch.xodp @@ -23,17 +23,6 @@ "pinKey": "SyM2ATB-b" } }, - { - "id": "Hk84gASZ-", - "input": { - "nodeId": "rkrQlRrWb", - "pinKey": "SyLCdSwJZ" - }, - "output": { - "nodeId": "B1vglRB--", - "pinKey": "HJU8CE2lW" - } - }, { "id": "Hkf8xCrZ-", "input": { @@ -56,28 +45,6 @@ "pinKey": "HkyxURuSPyW" } }, - { - "id": "r1ABVRsNb", - "input": { - "nodeId": "HJqHeCBb-", - "pinKey": "HkDgIRdrv1W" - }, - "output": { - "nodeId": "B1vglRB--", - "pinKey": "HJU8CE2lW" - } - }, - { - "id": "rJFExCSWW", - "input": { - "nodeId": "HkKQlCr-W", - "pinKey": "SyLCdSwJZ" - }, - "output": { - "nodeId": "B1vglRB--", - "pinKey": "HJU8CE2lW" - } - }, { "id": "rJNUgASZW", "input": { @@ -88,37 +55,12 @@ "nodeId": "HkKQlCr-W", "pinKey": "B1gI0urv1W" } - }, - { - "id": "rJjHV0i4b", - "input": { - "nodeId": "SyVrxRS-W", - "pinKey": "HkDgIRdrv1W" - }, - "output": { - "nodeId": "B1vglRB--", - "pinKey": "HJU8CE2lW" - } } ], "nodes": [ { "boundValues": { - "B13SCNhl-": 0.02, - "BJJICN2lW": false - }, - "description": "", - "id": "B1vglRB--", - "label": "", - "position": { - "x": 138, - "y": 120 - }, - "type": "xod/core/clock" - }, - { - "boundValues": { - "HkDgIRdrv1W": false, + "HkDgIRdrv1W": "CONTINUOUSLY", "S1OlUAuBD1-": false }, "description": "", @@ -133,7 +75,7 @@ { "boundValues": { "B1ZUA_Hv1W": 12, - "SyLCdSwJZ": false + "SyLCdSwJZ": "CONTINUOUSLY" }, "description": "", "id": "HkKQlCr-W", @@ -161,7 +103,7 @@ }, { "boundValues": { - "HkDgIRdrv1W": false, + "HkDgIRdrv1W": "CONTINUOUSLY", "S1OlUAuBD1-": false }, "description": "", @@ -176,7 +118,7 @@ { "boundValues": { "B1ZUA_Hv1W": 11, - "SyLCdSwJZ": false + "SyLCdSwJZ": "CONTINUOUSLY" }, "description": "", "id": "rkrQlRrWb",