-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2106 from xodio/feat-stdlib-interrupts-and-micros
Add interrupt nodes and `micros` type with some utility nodes in the standard library
- Loading branch information
Showing
19 changed files
with
796 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
workspace/__lib__/xod/core/cast-to-string(micros)/patch.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
#pragma XOD dirtieness disable | ||
|
||
node { | ||
void uint32ToCharArray(uint32_t value, char* str) { | ||
if (value == 0) { | ||
str[0] = '0'; | ||
str[1] = '\0'; | ||
} | ||
|
||
uint8_t idx = 0; | ||
uint8_t len = 0; | ||
|
||
auto v = value; | ||
while (v > 0) { | ||
len++; | ||
v = v / 10; | ||
} | ||
v = value; | ||
while (v > 0) { | ||
auto q = v % 10; | ||
v = (v - q) / 10; | ||
str[len - idx - 1] = '0' + q; | ||
idx++; | ||
} | ||
str[len] = '\0'; | ||
} | ||
|
||
char str[11]; | ||
CStringView view = CStringView(str); | ||
|
||
void evaluate(Context ctx) { | ||
auto micros = getValue<input_IN>(ctx); | ||
uint32ToCharArray(micros, str); | ||
emitValue<output_OUT>(ctx, XString(&view)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
workspace/__lib__/xod/core/cast-to-string(micros)/patch.xodp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"description": "Transforms micros to a string", | ||
"nodes": [ | ||
{ | ||
"id": "HJR1uifqM", | ||
"position": { | ||
"units": "slots", | ||
"x": 5, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/utility" | ||
}, | ||
{ | ||
"id": "__in__", | ||
"position": { | ||
"units": "slots", | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"type": "@/input-micros" | ||
}, | ||
{ | ||
"id": "__out__", | ||
"position": { | ||
"units": "slots", | ||
"x": 0, | ||
"y": 3 | ||
}, | ||
"type": "xod/patch-nodes/output-string" | ||
}, | ||
{ | ||
"id": "noNativeImpl", | ||
"position": { | ||
"units": "slots", | ||
"x": 3, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/not-implemented-in-xod" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
node { | ||
typeof_IN lastMicros = 0; | ||
|
||
void evaluate(Context ctx) { | ||
if (!isInputDirty<input_UPD>(ctx)) return; | ||
|
||
typeof_IN newLast = getValue<input_IN>(ctx); | ||
emitValue<output_OUT>(ctx, newLast - lastMicros); | ||
lastMicros = newLast; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"description": "Outputs time difference in microseconds between the current and previous updates.", | ||
"nodes": [ | ||
{ | ||
"description": "Time in microseconds", | ||
"id": "S1dci4Szu", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 0 | ||
}, | ||
"type": "@/input-micros" | ||
}, | ||
{ | ||
"description": "Delta time in microseconds", | ||
"id": "ryooiEHfd", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 2 | ||
}, | ||
"type": "@/output-micros" | ||
}, | ||
{ | ||
"id": "Syy2iEBGd", | ||
"position": { | ||
"units": "slots", | ||
"x": 2, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/not-implemented-in-xod" | ||
}, | ||
{ | ||
"description": "Triggers new update", | ||
"id": "ryC6nNSMd", | ||
"label": "UPD", | ||
"position": { | ||
"units": "slots", | ||
"x": 3, | ||
"y": 0 | ||
}, | ||
"type": "xod/patch-nodes/input-pulse" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
node { | ||
meta { | ||
using Type = uint32_t; | ||
} | ||
void evaluate(Context ctx) { | ||
if (isInputDirty<input_UPD>(ctx)) { | ||
emitValue<output_OUT>(ctx, micros()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"description": "Outputs time spent since the program start in microseconds.", | ||
"nodes": [ | ||
{ | ||
"id": "S1Dx-ZNzd", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/not-implemented-in-xod" | ||
}, | ||
{ | ||
"description": "Time in microseconds.", | ||
"id": "BJ5gWbEfu", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 2 | ||
}, | ||
"type": "xod/patch-nodes/output-self" | ||
}, | ||
{ | ||
"description": "Trigger updating the time in microseconds.", | ||
"id": "S1DmXHHfu", | ||
"label": "UPD", | ||
"position": { | ||
"units": "slots", | ||
"x": 1, | ||
"y": 0 | ||
}, | ||
"type": "xod/patch-nodes/input-pulse" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
node { | ||
void evaluate(Context ctx) { | ||
Number micros = getValue<input_IN>(ctx); | ||
emitValue<output_OUT>(ctx, micros / 1000000 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"description": "Transforms micros to a Number as seconds. The value may lose accuracy.", | ||
"nodes": [ | ||
{ | ||
"id": "HkqdI2iMu", | ||
"position": { | ||
"units": "slots", | ||
"x": 0, | ||
"y": 0 | ||
}, | ||
"type": "@/input-micros" | ||
}, | ||
{ | ||
"id": "ryROL3jz_", | ||
"position": { | ||
"units": "slots", | ||
"x": 0, | ||
"y": 1 | ||
}, | ||
"type": "xod/patch-nodes/not-implemented-in-xod" | ||
}, | ||
{ | ||
"id": "SJbYIhsGO", | ||
"position": { | ||
"units": "slots", | ||
"x": 0, | ||
"y": 2 | ||
}, | ||
"type": "xod/patch-nodes/output-number" | ||
} | ||
] | ||
} |
Oops, something went wrong.