summaryrefslogtreecommitdiff
path: root/grc/blocks/variable_function_probe.block.yml
diff options
context:
space:
mode:
Diffstat (limited to 'grc/blocks/variable_function_probe.block.yml')
-rw-r--r--grc/blocks/variable_function_probe.block.yml54
1 files changed, 54 insertions, 0 deletions
diff --git a/grc/blocks/variable_function_probe.block.yml b/grc/blocks/variable_function_probe.block.yml
new file mode 100644
index 0000000000..702ab5d60e
--- /dev/null
+++ b/grc/blocks/variable_function_probe.block.yml
@@ -0,0 +1,54 @@
+id: variable_function_probe
+label: Function Probe
+
+parameters:
+- id: block_id
+ label: Block ID
+ dtype: string
+ default: my_block_0
+- id: function_name
+ label: Function Name
+ dtype: string
+ default: get_number
+- id: function_args
+ label: Function Args
+ dtype: string
+ hide: ${ ('none' if function_args else 'part') }
+- id: poll_rate
+ label: Poll Rate (Hz)
+ dtype: real
+ default: '10'
+- id: value
+ label: Initial Value
+ dtype: raw
+ default: '0'
+ hide: part
+value: ${ value }
+
+templates:
+ imports: |-
+ import time
+ import threading
+ var_make: self.${id} = ${id} = ${value}
+ make: "\ndef _${id}_probe():\n while True:\n <% obj = 'self' + ('.'\
+ \ + block_id if block_id else '') %>\n val = ${obj}.${function_name}(${function_args})\n\
+ \ try:\n self.set_${id}(val)\n except AttributeError:\n\
+ \ pass\n time.sleep(1.0 / (${poll_rate}))\n_${id}_thread\
+ \ = threading.Thread(target=_${id}_probe)\n_${id}_thread.daemon = True\n_${id}_thread.start()\n\
+ \ "
+ callbacks:
+ - self.set_${id}(${value})
+
+documentation: |-
+ Periodically probe a function and set its value to this variable.
+
+ Set the values for block ID, function name, and function args appropriately: Block ID should be the ID of another block in this flow graph. An empty Block ID references the flow graph itself. Function name should be the name of a class method on that block. Function args are the parameters passed into that function. For a function with no arguments, leave function args blank. When passing a string for the function arguments, quote the string literal: '"arg"'.
+
+ The values will used literally, and generated into the following form:
+ self.block_id.function_name(function_args)
+ or, if the Block ID is empty,
+ self.function_name(function_args)
+
+ To poll a stream for a level, use this with the probe signal block.
+
+file_format: 1