@@ -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