Skip to content

Commit

Permalink
macro (O-call) capability for touchy
Browse files Browse the repository at this point in the history
this awaits better handling of "O[otherfile] call" in MDI mode
in task.  It currently only works for gcodes that don't have to
wait for anything.
  • Loading branch information
cradek committed Jul 29, 2010
1 parent 76b1ed4 commit 2010001
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 22 deletions.
4 changes: 4 additions & 0 deletions configs/sim/touchy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# EMC controller parameters for a simulated machine.
[TOUCHY]
MACRO=increment xinc yinc
MACRO=world xo yo zo
MACRO=asdf xc yc ht

[EMC]

Expand Down
4 changes: 4 additions & 0 deletions nc_files/increment.ngc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
O<increment> sub
g91 g0 x#1 y#2
g90
O<increment> endsub
9 changes: 9 additions & 0 deletions nc_files/world.ngc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
O<world> sub
t2m6
(message,tool #2 loaded)
t3m6
(message,tool #3 loaded)
g91g38.2x1
(message,probed right 1)
g90
O<world> endsub
65 changes: 46 additions & 19 deletions src/emc/usr_intf/touchy/mdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ def __init__(self, emc):
'G92' : [_('Offset all coordinate systems'), 'A'],
'G96' : [_('CSS Mode'), 'S', 'D'],
}
self.ocodes = []

def add_macros(self, macros):
for m in macros:
print "adding macro", m
words = m.split()
call = "O<%s> call" % words[0]
args = [''] + [w + ' ' for w in words[1:]]
self.ocodes.append(call)
self.codes[call] = args

def get_description(self, gcode):
return self.codes[gcode][0]
Expand Down Expand Up @@ -117,16 +127,22 @@ def set_polar(self, p):

def issue(self):
m = self.gcode
w = [i for i in self.words if len(self.words.get(i)) > 0]
if '@' in w:
m += '@' + self.words.get('@')
w.remove('@')
if '^' in w:
m += '^' + self.words.get('^')
w.remove('^')
for i in w:
if len(self.words.get(i)) > 0:
m += i + self.words.get(i)
if m.lower().startswith('o'):
codes = self.codes[m]
for code in self.codes[m][1:]:
v = self.words[code]
m = m + " [%s]" % v
else:
w = [i for i in self.words if len(self.words.get(i)) > 0]
if '@' in w:
m += '@' + self.words.get('@')
w.remove('@')
if '^' in w:
m += '^' + self.words.get('^')
w.remove('^')
for i in w:
if len(self.words.get(i)) > 0:
m += i + self.words.get(i)
self.emcstat.poll()
if self.emcstat.task_mode != self.emc.MODE_MDI:
self.emccommand.mode(self.emc.MODE_MDI)
Expand Down Expand Up @@ -169,22 +185,21 @@ def set_text(self, t, n = -1):
w = self.labels[n]
w.set_text(t)
if n > 0:
if len(t) > 1:
self.mdi.set_word(t[0], t[1:])
if len(t) == 1:
self.mdi.set_word(t, "")
head = t.rstrip("0123456789.-")
tail = t[len(head):]
self.mdi.set_word(head, tail)
if len(t) < 2:
w.set_alignment(1.0, 0.5)
else:
w.set_alignment(0.0, 0.5)

def clear(self, b):
t = self.get_text()
self.set_text(t[:1])
self.set_text(t.rstrip("0123456789.-"))

def back(self, b):
t = self.get_text()
if len(t) > 1:
if t[-1:] in "0123456789.-":
self.set_text(t[:-1])

def fill_out(self):
Expand Down Expand Up @@ -214,10 +229,12 @@ def decimal(self, b):
def minus(self, b):
t = self.get_text()
if self.selected > 0:
if t.find("-") == -1:
self.set_text(t[:1] + "-" + t[1:])
head = t.rstrip("0123456789.-")
tail = t[len(head):]
if tail.find("-") == -1:
self.set_text(head + "-" + tail)
else:
self.set_text(t[:1] + t[2:])
self.set_text(head + tail[1:])

def keypad(self, b):
t = self.get_text()
Expand All @@ -241,6 +258,16 @@ def m(self, b):
def t(self, b):
self.g(b, "T")

def o(self, b):
old_code = self.labels[0].get_text()
ocodes = self.mdi.ocodes
if old_code in ocodes:
j = (ocodes.index(old_code) + 1) % len(ocodes)
else:
j = 0
self.g(b, ocodes[j])
self.next(b)

def select(self, eventbox, event):
n = int(eventbox.get_name()[12:])
if self.selected == 0:
Expand Down
17 changes: 17 additions & 0 deletions src/emc/usr_intf/touchy/touchy.glade
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,23 @@
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="macro">
<property name="label">Macro</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<property name="border_width">11</property>
<property name="use_underline">True</property>
<property name="focus_on_click">False</property>
<signal name="clicked" handler="on_mdi_macro_clicked"/>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="expand">False</property>
Expand Down
27 changes: 24 additions & 3 deletions src/emc/usr_intf/touchy/touchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
except:
sys.exit(1)

import tempfile

empty_program = tempfile.NamedTemporaryFile()
empty_program.write("%\n%\n")
empty_program.flush()

import gettext
LOCALEDIR = os.path.join(BASE, "share", "locale")
gettext.install("emc2", localedir=LOCALEDIR, unicode=True)
Expand Down Expand Up @@ -74,7 +80,7 @@ def set_text(w, t):
invisible = gtk.gdk.Cursor(pix, pix, color, color, 0, 0)

class touchy:
def __init__(self):
def __init__(self, inifile):
#Set the Glade file
self.gladefile = os.path.join(datadir, "touchy.glade")
self.wTree = gtk.glade.XML(self.gladefile)
Expand Down Expand Up @@ -132,6 +138,11 @@ def __init__(self):
mdi_eventboxes.append(self.wTree.get_widget("eventbox_mdi%d" % i))
self.mdi_control = mdi.mdi_control(gtk, emc, mdi_labels, mdi_eventboxes)

if inifile:
ini = emc.ini(inifile)
self.mdi_control.mdi.add_macros(
ini.findall("TOUCHY", "MACRO"))

listing_labels = []
listing_eventboxes = []
for i in range(self.num_listing_labels):
Expand Down Expand Up @@ -208,6 +219,8 @@ def __init__(self):
else:
self.emc.opstop_off(0)

self.emc.emccommand.program_open(empty_program.name)

self.emc.max_velocity(self.mv_val)

gobject.timeout_add(50, self.periodic_status)
Expand Down Expand Up @@ -249,6 +262,7 @@ def __init__(self):
"on_mdi_select" : self.mdi_control.select,
"on_mdi_set_tool_clicked" : self.mdi_set_tool,
"on_mdi_set_origin_clicked" : self.mdi_set_origin,
"on_mdi_macro_clicked" : self.mdi_macro,
"on_filechooser_select" : self.fileselect,
"on_filechooser_up_clicked" : self.filechooser.up,
"on_filechooser_down_clicked" : self.filechooser.down,
Expand Down Expand Up @@ -464,7 +478,7 @@ def setfont(self):
for i in ["1", "2", "3", "4", "5", "6", "7",
"8", "9", "0", "minus", "decimal",
"flood_on", "flood_off", "mist_on", "mist_off",
"g", "gp", "m", "t", "set_tool", "set_origin",
"g", "gp", "m", "t", "set_tool", "set_origin", "macro",
"estop", "estop_reset", "machine_off", "machine_on",
"home_all", "unhome_all", "home_selected", "unhome_selected",
"fo", "so", "mv", "jogging", "wheelinc1", "wheelinc2", "wheelinc3",
Expand Down Expand Up @@ -517,6 +531,9 @@ def mdi_set_tool(self, b):
def mdi_set_origin(self, b):
self.mdi_control.set_origin(self.status.get_current_system())

def mdi_macro(self, b):
self.mdi_control.o(b)

def fileselect(self, eb, e):
if self.wheel == "jogging": self.wheel = "mv"
self.jogsettings_activate(0)
Expand Down Expand Up @@ -616,7 +633,11 @@ def hack_leave(self,w):


if __name__ == "__main__":
hwg = touchy()
if len(sys.argv) > 2 and sys.argv[1] == '-ini':
print "ini", sys.argv[2]
hwg = touchy(sys.argv[2])
else:
hwg = touchy()
res = os.spawnvp(os.P_WAIT, "halcmd", ["halcmd", "-f", "touchy.hal"])
if res: raise SystemExit, res
gtk.main()

0 comments on commit 2010001

Please sign in to comment.