spec/fixtures/edit_fixture.cr @ trunk
../../src/gpcr
scale = 0.75 fontscale = 1.500 box wid 1.930 ht 0.340 with .nw at (0.035, -0.035) fill 0xCBD5E1 color 0xCBD5E1 box wid 1.930 ht 0.340 with .nw at (0.000, 0.000) fill 0x7C83E6 color 0x7C83E6 box wid 0.300 ht 0.065 rad 0.018 at (0.370, -0.022) fill 0xffffff color 0xffffff line from (0.140, 0.000) to (0.140, -0.340) color white line from (1.790, 0.000) to (1.790, -0.340) color white text "require '../../src/gpcr'" color white at (0.965, -0.170)→ /pikchrshow
crystal source
require "../../src/gpcr"
json block
{
"kind": "require",
"name": "../../src/gpcr",
"doc": null,
"children": []
}
GPCR_START = Channel(Nil).new(0)
on_start
native primitive: a hat that blocks the fiber on the start-event Channel
scale = 0.75 fontscale = 1.500 box wid 0.870 ht 0.340 with .nw at (0.035, -0.455) fill 0xCBD5E1 color 0xCBD5E1 box wid 0.870 ht 0.340 with .nw at (0.000, -0.420) fill 0xFFAB19 color 0xFFAB19 ellipse wid 1.600 ht 0.340 at (0.800, -0.420) fill 0xFFAB19 color 0xFFAB19 text "on start" color white at (0.435, -0.590) box wid 0.240 ht 0.220 rad 0.110 at (0.720, -0.560) fill 0x334155 color 0x334155 text "1" at (0.720, -0.560) color 0xf8fafc→ /pikchrshow
crystal source
@[GPCR::Primitive(shape: :hat, label: "on start", category: "Events")]
def on_start
GPCR_START.receive
end
json block
{
"kind": "primitive",
"name": "on_start",
"doc": "native primitive: a hat that blocks the fiber on the start-event Channel",
"label": "on start",
"shape": "hat",
"category": "Events",
"returns": null,
"children": []
}
set_user_led
native primitive: a command backed by the (here: simulated) hardware op
scale = 0.75 fontscale = 1.500 box wid 2.106 ht 0.340 rad 0.035 with .nw at (0.035, -0.875) fill 0xCBD5E1 color 0xCBD5E1 box wid 2.106 ht 0.340 rad 0.035 with .nw at (0.000, -0.840) fill 0x4C97FF color 0x4C97FF box wid 0.300 ht 0.065 rad 0.018 at (0.370, -0.863) fill 0xffffff color 0xffffff text "set user LED " color white at (0.676, -1.010) box wid 0.634 ht 0.205 rad 0.102 with .nw at (1.272, -0.907) fill 0xFFFFFF color 0xFFFFFF text "state" color 0x263238 at (1.589, -1.010) box wid 0.240 ht 0.220 rad 0.110 at (1.956, -0.980) fill 0x334155 color 0x334155 text "2" at (1.956, -0.980) color 0xf8fafc→ /pikchrshow
crystal source
@[GPCR::Primitive(shape: :command, label: "set user LED #{state}")]
def set_user_led(state : Bool)
print state ? "\e[93m*\e[0m" : "."
end
json block
{
"kind": "primitive",
"name": "set_user_led",
"doc": "native primitive: a command backed by the (here: simulated) hardware op",
"label": "set user LED [state]",
"shape": "command",
"category": null,
"returns": null,
"inputs": [
{
"name": "state",
"type": "Bool"
}
],
"children": []
}
wait
native primitive: timed yield to the event loop
scale = 0.75 fontscale = 1.500 box wid 2.131 ht 0.340 rad 0.035 with .nw at (0.035, -1.295) fill 0xCBD5E1 color 0xCBD5E1 box wid 2.131 ht 0.340 rad 0.035 with .nw at (0.000, -1.260) fill 0xFFAB19 color 0xFFAB19 box wid 0.300 ht 0.065 rad 0.018 at (0.370, -1.283) fill 0xffffff color 0xffffff text "wait " color white at (0.322, -1.430) box wid 0.614 ht 0.205 rad 0.102 with .nw at (0.609, -1.328) fill 0xFFFFFF color 0xFFFFFF text "secs" color 0x263238 at (0.916, -1.430) text " seconds" color white at (1.637, -1.430) box wid 0.240 ht 0.220 rad 0.110 at (1.981, -1.400) fill 0x334155 color 0x334155 text "3" at (1.981, -1.400) color 0xf8fafc→ /pikchrshow
crystal source
@[GPCR::Primitive(shape: :command, label: "wait #{secs} seconds", category: "Control")]
def wait(secs : Float64)
sleep secs.seconds
end
json block
{
"kind": "primitive",
"name": "wait",
"doc": "native primitive: timed yield to the event loop",
"label": "wait [secs] seconds",
"shape": "command",
"category": "Control",
"returns": null,
"inputs": [
{
"name": "secs",
"type": "Float64"
}
],
"children": []
}
forever
native primitive: infinite loop around its body
scale = 0.75 fontscale = 1.500 box wid 0.831 ht 0.340 rad 0.035 with .nw at (0.035, -1.715) fill 0xCBD5E1 color 0xCBD5E1 box wid 0.831 ht 0.340 rad 0.035 with .nw at (0.000, -1.680) fill 0xFFAB19 color 0xFFAB19 box wid 0.300 ht 0.065 rad 0.018 at (0.370, -1.703) fill 0xffffff color 0xffffff text "forever" color white at (0.415, -1.850) box wid 0.240 ht 0.220 rad 0.110 at (0.681, -1.820) fill 0x334155 color 0x334155 text "4" at (0.681, -1.820) color 0xf8fafc→ /pikchrshow
crystal source
@[GPCR::Primitive(shape: :command, label: "forever", category: "Control")]
def forever(&)
loop { yield }
end
json block
{
"kind": "primitive",
"name": "forever",
"doc": "native primitive: infinite loop around its body",
"label": "forever",
"shape": "command",
"category": "Control",
"returns": null,
"children": []
}
blink
blink: LED on/off loop after start
scale = 0.75 fontscale = 1.500 box wid 0.870 ht 0.340 with .nw at (0.035, -2.135) fill 0xCBD5E1 color 0xCBD5E1 box wid 0.870 ht 0.340 with .nw at (0.000, -2.100) fill 0xFFAB19 color 0xFFAB19 ellipse wid 1.600 ht 0.340 at (0.800, -2.100) fill 0xFFAB19 color 0xFFAB19 box wid 0.300 ht 0.065 rad 0.018 at (0.370, -2.472) fill 0xFFAB19 color 0xFFAB19 text "on start" color white at (0.435, -2.270) box wid 0.240 ht 0.220 rad 0.110 at (0.720, -2.240) fill 0x334155 color 0x334155 text "6" at (0.720, -2.240) color 0xf8fafc box wid 2.720 ht 2.470 rad 0.035 with .nw at (0.035, -2.555) fill 0xCBD5E1 color 0xCBD5E1 box wid 2.720 ht 2.470 rad 0.035 with .nw at (0.000, -2.520) fill 0xFFAB19 color 0xFFAB19 box wid 2.340 ht 1.800 rad 0.035 with .nw at (0.320, -2.980) fill 0xFFFDE7 color 0xFFFDE7 box wid 0.300 ht 0.065 rad 0.018 at (0.370, -2.542) fill 0xffffff color 0xffffff box wid 0.300 ht 0.065 rad 0.018 at (0.370, -5.022) fill 0xFFAB19 color 0xFFAB19 text "forever" color white at (1.360, -2.750) box wid 0.240 ht 0.220 rad 0.110 at (2.570, -2.660) fill 0x334155 color 0x334155 text "7" at (2.570, -2.660) color 0xf8fafc box wid 2.027 ht 0.340 rad 0.035 with .nw at (0.455, -3.075) fill 0xCBD5E1 color 0xCBD5E1 box wid 2.027 ht 0.340 rad 0.035 with .nw at (0.420, -3.040) fill 0x4C97FF color 0x4C97FF box wid 0.300 ht 0.065 rad 0.018 at (0.790, -3.062) fill 0xFFFDE7 color 0xFFFDE7 box wid 0.300 ht 0.065 rad 0.018 at (0.790, -3.412) fill 0x4C97FF color 0x4C97FF text "set user LED " color white at (1.096, -3.210) box wid 0.555 ht 0.205 rad 0.102 with .nw at (1.692, -3.107) fill 0xFFFFFF color 0xFFFFFF text "true" color 0x263238 at (1.970, -3.210) box wid 0.240 ht 0.220 rad 0.110 at (2.297, -3.180) fill 0x334155 color 0x334155 text "8" at (2.297, -3.180) color 0xf8fafc box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.455, -3.495) fill 0xCBD5E1 color 0xCBD5E1 box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.420, -3.460) fill 0xFFAB19 color 0xFFAB19 box wid 0.300 ht 0.065 rad 0.018 at (0.790, -3.482) fill 0xFFFDE7 color 0xFFFDE7 box wid 0.300 ht 0.065 rad 0.018 at (0.790, -3.832) fill 0xFFAB19 color 0xFFAB19 text "wait " color white at (0.742, -3.630) box wid 0.496 ht 0.205 rad 0.102 with .nw at (1.029, -3.527) fill 0xFFFFFF color 0xFFFFFF text "0.5" color 0x263238 at (1.277, -3.630) text " seconds" color white at (1.939, -3.630) box wid 0.240 ht 0.220 rad 0.110 at (2.283, -3.600) fill 0x334155 color 0x334155 text "9" at (2.283, -3.600) color 0xf8fafc box wid 2.096 ht 0.340 rad 0.035 with .nw at (0.455, -3.915) fill 0xCBD5E1 color 0xCBD5E1 box wid 2.096 ht 0.340 rad 0.035 with .nw at (0.420, -3.880) fill 0x4C97FF color 0x4C97FF box wid 0.300 ht 0.065 rad 0.018 at (0.790, -3.902) fill 0xFFFDE7 color 0xFFFDE7 box wid 0.300 ht 0.065 rad 0.018 at (0.790, -4.252) fill 0x4C97FF color 0x4C97FF text "set user LED " color white at (1.096, -4.050) box wid 0.624 ht 0.205 rad 0.102 with .nw at (1.692, -3.947) fill 0xFFFFFF color 0xFFFFFF text "false" color 0x263238 at (2.004, -4.050) box wid 0.240 ht 0.220 rad 0.110 at (2.366, -4.020) fill 0x334155 color 0x334155 text "10" at (2.366, -4.020) color 0xf8fafc box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.455, -4.335) fill 0xCBD5E1 color 0xCBD5E1 box wid 2.013 ht 0.340 rad 0.035 with .nw at (0.420, -4.300) fill 0xFFAB19 color 0xFFAB19 box wid 0.300 ht 0.065 rad 0.018 at (0.790, -4.322) fill 0xFFFDE7 color 0xFFFDE7 box wid 0.300 ht 0.065 rad 0.018 at (0.790, -4.672) fill 0xFFAB19 color 0xFFAB19 text "wait " color white at (0.742, -4.470) box wid 0.496 ht 0.205 rad 0.102 with .nw at (1.029, -4.367) fill 0xFFFFFF color 0xFFFFFF text "0.5" color 0x263238 at (1.277, -4.470) text " seconds" color white at (1.939, -4.470) box wid 0.240 ht 0.220 rad 0.110 at (2.283, -4.440) fill 0x334155 color 0x334155 text "11" at (2.283, -4.440) color 0xf8fafc box wid 0.300 ht 0.065 rad 0.018 at (0.790, -3.412) fill 0x4C97FF color 0x4C97FF box wid 0.300 ht 0.065 rad 0.018 at (0.790, -3.832) fill 0xFFAB19 color 0xFFAB19 box wid 0.300 ht 0.065 rad 0.018 at (0.790, -4.252) fill 0x4C97FF color 0x4C97FF box wid 0.300 ht 0.065 rad 0.018 at (0.790, -4.672) fill 0xFFAB19 color 0xFFAB19→ /pikchrshow
crystal source
@[GPCR::Graph(x: 10, y: 30)]
def blink
on_start
forever do
set_user_led true
wait 0.5
set_user_led false
wait 0.5
end
end
json block
{
"kind": "graph",
"name": "blink",
"doc": "blink: LED on/off loop after start",
"children": [
{
"kind": "call",
"name": "on_start",
"receiver": null,
"op_index": 6,
"args": [],
"label": "on start",
"shape": "hat",
"category": "Events",
"children": []
},
{
"kind": "c_call",
"name": "forever",
"op_index": 7,
"args": [],
"body": [
{
"kind": "call",
"name": "set_user_led",
"receiver": null,
"op_index": 8,
"args": [
"true"
],
"label": "set user LED [true]",
"shape": "command",
"category": null,
"children": []
},
{
"kind": "call",
"name": "wait",
"receiver": null,
"op_index": 9,
"args": [
"0.5"
],
"label": "wait [0.5] seconds",
"shape": "command",
"category": "Control",
"children": []
},
{
"kind": "call",
"name": "set_user_led",
"receiver": null,
"op_index": 10,
"args": [
"false"
],
"label": "set user LED [false]",
"shape": "command",
"category": null,
"children": []
},
{
"kind": "call",
"name": "wait",
"receiver": null,
"op_index": 11,
"args": [
"0.5"
],
"label": "wait [0.5] seconds",
"shape": "command",
"category": "Control",
"children": []
}
]
}
]
}
spawn { blink }
GPCR_START.send(nil)
sleep 2.1.seconds
puts