Skip to content

Commit 0137dcf

Browse files
committed
docs: moved GladeVCP related part to GladeVCP page
1 parent 1e8a44a commit 0137dcf

2 files changed

Lines changed: 36 additions & 92 deletions

File tree

docs/src/gui/gladevcp.adoc

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,6 +3032,42 @@ def get_handlers(halcomp,builder,useropts):
30323032
return [HandlerClass(halcomp,builder,useropts)]
30333033
----
30343034

3035+
=== Value-changed callback with hal_glib
3036+
3037+
GladeVCP uses the hal_glib library, which can be used to connect a "watcher" signal on a HAL input pin. +
3038+
This signal can be used to register a function to call when the HAL pin changes state. +
3039+
3040+
One must import the `hal_glib` and the `hal` modules:
3041+
3042+
[source,python]
3043+
----
3044+
import hal_glib
3045+
import hal
3046+
----
3047+
3048+
Then make a pin and connect a 'value-changed' (the watcher) signal to a function call:
3049+
3050+
[source,python]
3051+
----
3052+
class HandlerClass:
3053+
def __init__(self, halcomp,builder,useropts):
3054+
self.example_trigger = hal_glib.GPin(halcomp.newpin('example-trigger', hal.HAL_BIT, hal.HAL_IN))
3055+
self.example_trigger.connect('value-changed', self._on_example_trigger_change)
3056+
----
3057+
3058+
And have a function to be called:
3059+
3060+
[source,python]
3061+
----
3062+
def _on_example_trigger_change(self,pin,userdata=None):
3063+
print("pin value changed to: {}".format(pin.get()))
3064+
print("pin name= {}".format(pin.get_name()))
3065+
print("pin type= {}".format(pin.get_type()))
3066+
3067+
# this can be called outside the function
3068+
self.example_trigger.get()
3069+
----
3070+
30353071
=== Examples, and rolling your own GladeVCP application
30363072

30373073
Visit `linuxcnc_root_directory/configs/apps/gladevcp` for running

docs/src/hal/halmodule.adoc

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -193,96 +193,4 @@ Read these to acquire information about the realtime system.
193193
* is_sim
194194
* is_userspace
195195

196-
== Use with hal_glib in GladeVCP Handler
197-
198-
GladeVCP uses the hal_glib library, which can be used to connect a "watcher" signal on a HAL input pin. +
199-
This signal can be used to register a function to call when the HAL pin changes state. +
200-
201-
One must import the `hal_glib` and the `hal` modules:
202-
203-
[source,python]
204-
----
205-
import hal_glib
206-
import hal
207-
----
208-
209-
Then make a pin and connect a 'value-changed' (the watcher) signal to a function call:
210-
211-
[source,python]
212-
----
213-
class HandlerClass:
214-
def __init__(self, halcomp,builder,useropts):
215-
self.example_trigger = hal_glib.GPin(halcomp.newpin('example-trigger', hal.HAL_BIT, hal.HAL_IN))
216-
self.example_trigger.connect('value-changed', self._on_example_trigger_change)
217-
----
218-
219-
And have a function to be called:
220-
221-
[source,python]
222-
----
223-
def _on_example_trigger_change(self,pin,userdata=None):
224-
print("pin value changed to: {}".format(pin.get()))
225-
print("pin name= {}".format(pin.get_name()))
226-
print("pin type= {}".format(pin.get_type()))
227-
228-
# this can be called outside the function
229-
self.example_trigger.get()
230-
----
231-
232-
== Use with hal_glib in QtVCP Handler
233-
234-
QtVCP uses the hal_glib library, which can be used to connect a "watcher" signal on a HAL input pin.
235-
This signal can be used to register a function to call when the HAL pin changes state.
236-
237-
One must import the `hal` module:
238-
239-
[source,python]
240-
----
241-
import hal
242-
----
243-
244-
Then make a pin and connect a 'value_changed' (the watcher) signal to a function call:
245-
246-
[source,python]
247-
----
248-
########################
249-
# **** INITIALIZE **** #
250-
########################
251-
# widgets allows access to widgets from the qtvcp files
252-
# at this point the widgets and HAL pins are not instantiated
253-
def __init__(self, halcomp,widgets,paths):
254-
self.hal = halcomp
255-
self.testPin = self.hal.newpin('test-pin', hal.HAL_BIT, hal.HAL_IN)
256-
self.testPin.value_changed.connect(lambda s: self.setTestPin(s))
257-
----
258-
259-
And have a function to be called.
260-
This shows ways to get the pin value and information.
261-
262-
[source,python]
263-
----
264-
#####################
265-
# general functions #
266-
#####################
267-
def setTestPin(self, data):
268-
print("Test pin value changed to:" % (data))
269-
print('halpin object =', self.w.sender())
270-
print('halpin name: ',self.sender().text())
271-
print('halpin type: ',self.sender().get_type())
272-
273-
# this can be called outside the function
274-
print(self.testPin.get())
275-
----
276-
277-
== Project ideas
278-
279-
* Create an external control panel with buttons, switches, and indicators.
280-
Connect everything to a microcontroller, and connect the microcontroller to the PC using a serial interface.
281-
Python has a very capable serial interface module called https://pyserial.readthedocs.io/en/latest/[pyserial]
282-
(Ubuntu package name "python3-serial", in the universe repository).
283-
* Attach a http://lcdproc.omnipotent.net/[LCDProc]-compatible LCD module
284-
and use it to display a digital readout with information of your choice
285-
(Ubuntu package name "lcdproc", in the universe repository).
286-
* Create a virtual control panel using any GUI library supported by Python (gtk, Qt, wxWindows, etc.).
287-
288196
// vim: set syntax=asciidoc:

0 commit comments

Comments
 (0)