Skip to content

Commit 441adaf

Browse files
committed
gmoccapy/hal_bridge -allow hal_bridge to call macros in gmoccapy
This is a proof of concept to allow 3rd party (hal_bridge) to call macros. The macros are run from Gmoccapy so no timing problems should occur and and pre checks or post changes can be covered. There needs to be agreement on where to put macro definitions in the INI. Gmoccapy puts them under [MACROS], iniinfo under [DISPLAY] python ZMQ module package must be available for this to work
1 parent e8099b3 commit 441adaf

3 files changed

Lines changed: 48 additions & 2 deletions

File tree

configs/sim/gmoccapy/gmoccapy_right_panel.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ INTRO_TIME = 5
3131
# list of selectable jog increments
3232
INCREMENTS = 1mm, 0.1mm, 0.01mm, 0.001mm, 1.2345in
3333

34+
MACRO = i_am_lost
35+
MACRO = halo_world
36+
MACRO = jog_around
37+
MACRO = increment xinc yinc
38+
MACRO = go_to_position X-pos Y-pos Z-pos
39+
3440
[FILTER]
3541
PROGRAM_EXTENSION = .png,.gif,.jpg Grayscale Depth Image
3642
PROGRAM_EXTENSION = .py Python Script
@@ -75,7 +81,7 @@ HALFILE = simulated_home.hal
7581
POSTGUI_HALFILE = gmoccapy_postgui.hal
7682

7783
HALUI = halui
78-
84+
HALBRIDGE = hal_bridge -d
7985
# Trajectory planner section --------------------------------------------------
8086
[HALUI]
8187
#No Content

src/emc/usr_intf/gmoccapy/getiniinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def get_tool_sensor_data(self):
393393

394394
def get_macros(self):
395395
# lets look in the INI file, if there are any entries
396-
macros = self.inifile.findall("MACROS", "MACRO")
396+
macros = self.inifile.findall("DISPLAY", "MACRO")
397397
# If there are no entries we will return False
398398
if not macros:
399399
return False

src/emc/usr_intf/gmoccapy/gmoccapy.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ def __init__(self, argv):
417417
self.GSTAT = Status()
418418
self.GSTAT.connect("graphics-gcode-properties", self.on_gcode_properties)
419419
self.GSTAT.connect("file-loaded", self.on_hal_status_file_loaded)
420+
self.GSTAT.connect('macro-call-request', lambda w, name: self.request_macro_call(name))
420421

421422
# get if run from line should be used
422423
self.run_from_line = self.prefs.getpref("run_from_line", "no_run", str)
@@ -1350,6 +1351,33 @@ def _make_joints_button(self):
13501351

13511352
self.joints_button_dic[name] = btn
13521353

1354+
# call INI macro (from hal_glib message)
1355+
def request_macro_call(self, data):
1356+
1357+
# some error checking
1358+
if not self.GSTAT.is_mdi_mode():
1359+
message = _("You must be in MDI mode to run macros")
1360+
self.dialogs.warning_dialog(self, _("Important Warning!"), message)
1361+
return
1362+
1363+
# look thru the INI macros
1364+
macros = self.get_ini_info.get_macros()
1365+
num_macros = len(macros)
1366+
if num_macros > 14:
1367+
num_macros = 14
1368+
for pos in range(0, num_macros):
1369+
# extract just the macro name
1370+
name = macros[pos].split()[0]
1371+
if data == name:
1372+
# get the button instance and click it
1373+
button = self["button_macro_{0}".format(pos)]
1374+
button.emit("clicked")
1375+
break
1376+
else:
1377+
# didn't match a name - give a hint
1378+
message = _("Macro {} not found ".format(data))
1379+
self.dialogs.warning_dialog(self, _("Important Warning!"), message)
1380+
13531381
# check if macros are in the INI file and add them to MDI Button List
13541382
def _make_macro_button(self):
13551383
LOG.debug("Entering make macro button")
@@ -1391,6 +1419,8 @@ def _make_macro_button(self):
13911419
btn.set_halign(Gtk.Align.CENTER)
13921420
btn.set_valign(Gtk.Align.CENTER)
13931421
btn.set_property("name","macro_{0}".format(pos))
1422+
# keep a reference of the button
1423+
self["button_macro_{0}".format(pos)] = btn
13941424
btn.set_property("tooltip-text", _("Press to run macro {0}".format(name)))
13951425
btn.connect("clicked", self._on_btn_macro_pressed, name)
13961426
btn.position = pos
@@ -6391,6 +6421,16 @@ def _make_hal_pins(self):
63916421
hal_glib.GPin(pin).connect("value_changed", self._blockdelete)
63926422

63936423

6424+
##############################
6425+
# required class boiler code #
6426+
# for subscriptable objects #
6427+
##############################
6428+
def __getitem__(self, item):
6429+
return getattr(self, item)
6430+
6431+
def __setitem__(self, item, value):
6432+
return setattr(self, item, value)
6433+
63946434
# Hal Pin Handling End
63956435
# =========================================================
63966436

0 commit comments

Comments
 (0)