summaryrefslogtreecommitdiff
path: root/configs/sim/gmoccapy/gmoccapy_plasma/plasma.py
blob: afac23ca68a34659e37b993e960c37f65cda482e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
"""
    This file will control some options of the gmoccapy plasma screen
    and demonstrats at the same time the possibilities you have introducing
    your own handler files and functions to that screen, showing the
    possibilities to modify the layout and behavior

    Copyright 2013 Norbert Schechner
    nieson@web.de

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

"""

import hal_glib                           # needed to make our own hal pins
import hal                                # needed to make our own hal pins
from gladevcp.persistence import IniFile  # we use this one to save the states of the widgets on shut down and restart
from gladevcp.persistence import widget_defaults
from gladevcp.persistence import select_widgets
import gtk
from gmoccapy import preferences
from gmoccapy import getiniinfo

class PlasmaClass:

    def __init__(self, halcomp, builder, useropts):
        self.builder = builder
        self.halcomp = halcomp
        self.defaults = { IniFile.vars : { "thcspeedval"       : 15.0 ,
                                           "thcspeedmax"       : 20.0 ,
                                           "thcspeedmin"       : 1.0  ,
                                           "thcspeedincr"      : 1.0  ,

                                           "cutgapval"         : 4.0  ,
                                           "cutgapmax"         : 10.0 ,
                                           "cutgapmin"         : 0.1  ,
                                           "cutgapincr"        : 0.1  ,

                                           "g0gapval"          : 45.0 ,
                                           "g0gapmax"          : 55.0 ,
                                           "g0gapmin"          : 0.5  ,
                                           "g0gapincr"         : 0.5  ,

                                           "pierceutostart"    : True ,

                                           "piercegapval"      : 5.0  ,
                                           "piercegapmax"      : 12.0 ,
                                           "piercegapmin"      : 2.0  ,
                                           "piercegapincr"     : 0.5  ,

                                           "piercedelayval"    : 0.5  ,
                                           "piercedelaymax"    : 10.0 ,
                                           "piercedelaymin"    : 0.01 ,
                                           "piercedelayincr"   : 0.01 ,

                                           "enableheightlock"  : False,

                                           "chlthresholdval"   : 60.0 ,
                                           "chlthresholdmax"   : 100.0,
                                           "chlthresholdmin"   : 10.0 ,
                                           "chlthresholdincr"  : 10.0 ,

                                           "thctargetvoltval"  : 100.0,
                                           "thctargetvoltmax"  : 255.0,
                                           "thctargetvoltmin"  : 55.0 ,
                                           "thctargetvoltincr" : 5.0  ,
                                         },
                          IniFile.widgets: widget_defaults(select_widgets([self.builder.get_object("hal-btn-THC"),
                                                                          ], hal_only = True, output_only = True)),
                        }

        get_ini_info = getiniinfo.GetIniInfo()
        prefs = preferences.preferences(get_ini_info.get_preference_file_path())
        theme_name = prefs.getpref("gtk_theme", "Follow System Theme", str)
        if theme_name == "Follow System Theme":
            theme_name = gtk.settings_get_default().get_property("gtk-theme-name")
        gtk.settings_get_default().set_string_property("gtk-theme-name", theme_name, "")

        self.ini_filename = __name__ + ".var"
        self.ini = IniFile(self.ini_filename, self.defaults, self.builder)
        self.ini.restore_state(self)

        # lets make our pins
        self.THC_speed = hal_glib.GPin(halcomp.newpin("THC-Speed", hal.HAL_FLOAT, hal.HAL_OUT))
        self.cut_gap = hal_glib.GPin(halcomp.newpin("Cut-Gap", hal.HAL_FLOAT, hal.HAL_OUT))
        self.g0_gap = hal_glib.GPin(halcomp.newpin("G0-Gap", hal.HAL_FLOAT, hal.HAL_OUT))
        self.pierce_deley = hal_glib.GPin(halcomp.newpin("Pierce-Delay", hal.HAL_FLOAT, hal.HAL_OUT))
        self.pierce_gap = hal_glib.GPin(halcomp.newpin("Pierce-Gap", hal.HAL_FLOAT, hal.HAL_OUT))
        self.target_voltage = hal_glib.GPin(halcomp.newpin("Target-Voltage", hal.HAL_FLOAT, hal.HAL_OUT))

        # get all widgets and connect them
        self.lbl_prog_volt = self.builder.get_object("lbl_prog_volt")
        self.lbl_cut_speed = self.builder.get_object("lbl_cut_speed")
        self.lbl_cut_gap = self.builder.get_object("lbl_cut_gap")
        self.lbl_g0_gap = self.builder.get_object("lbl_g0_gap")
        self.lbl_pierce_gap = self.builder.get_object("lbl_pierce_gap")
        self.lbl_pierce_delay = self.builder.get_object("lbl_pierce_delay")

        self.btn_THC_speed_minus = self.builder.get_object("btn_THC_speed_minus")
        self.btn_THC_speed_minus.connect("pressed", self.on_btn_THC_speed_pressed, -1)

        self.btn_THC_speed_plus = self.builder.get_object("btn_THC_speed_plus")
        self.btn_THC_speed_plus.connect("pressed", self.on_btn_THC_speed_pressed, 1)

        self.adj_THC_speed = self.builder.get_object("adj_THC_speed")
        self.adj_THC_speed.connect("value_changed", self.on_adj_THC_speed_value_changed)

        self.adj_THC_speed.upper = self.thcspeedmax
        self.adj_THC_speed.lower = self.thcspeedmin
        self.adj_THC_speed.set_value(self.thcspeedval)

        self.tbl_cutting = self.builder.get_object("tbl_cutting")
        self.tbl_cutting.connect("destroy", self._on_destroy)

        self.btn_cut_gap_minus = self.builder.get_object("btn_cut_gap_minus")
        self.btn_cut_gap_minus.connect("pressed", self.on_btn_cut_gap_pressed, -1)

        self.btn_cut_gap_plus = self.builder.get_object("btn_cut_gap_plus")
        self.btn_cut_gap_plus.connect("pressed", self.on_btn_cut_gap_pressed, 1)

        self.adj_cut_gap = self.builder.get_object("adj_cut_gap")
        self.adj_cut_gap.connect("value_changed", self.on_adj_cut_gap_value_changed)
        self.adj_cut_gap.upper = self.cutgapmax
        self.adj_cut_gap.lower = self.cutgapmin
        self.adj_cut_gap.set_value(self.cutgapval)

        self.btn_g0_minus = self.builder.get_object("btn_g0_minus")
        self.btn_g0_minus.connect("pressed", self.on_btn_g0_pressed, -1)

        self.btn_g0_plus = self.builder.get_object("btn_g0_plus")
        self.btn_g0_plus.connect("pressed", self.on_btn_g0_pressed, 1)

        self.adj_G0_gap = self.builder.get_object("adj_G0_gap")
        self.adj_G0_gap.connect("value_changed", self.on_adj_G0_gap_value_changed)
        self.adj_G0_gap.upper = self.g0gapmax
        self.adj_G0_gap.lower = self.g0gapmin
        self.adj_G0_gap.set_value(self.g0gapval)

        self.Piercing_autostart = self.builder.get_object("Piercing-autostart")
        self.Piercing_autostart.connect("toggled", self.on_Piercing_autostart_toggled)
        self.Piercing_autostart.set_active(self.pierceutostart)

        self.btn_pierce_gap_minus = self.builder.get_object("btn_pierce_gap_minus")
        self.btn_pierce_gap_minus.connect("pressed", self.on_btn_pierce_gap_pressed, -1)

        self.btn_pierce_gap_plus = self.builder.get_object("btn_pierce_gap_plus")
        self.btn_pierce_gap_plus.connect("pressed", self.on_btn_pierce_gap_pressed, 1)

        self.adj_pierce_gap = self.builder.get_object("adj_pierce_gap")
        self.adj_pierce_gap.connect("value_changed", self.on_adj_pierce_gap_value_changed)
        self.adj_pierce_gap.upper = self.piercegapmax
        self.adj_pierce_gap.lower = self.piercegapmin
        self.adj_pierce_gap.set_value(self.piercegapval)

        self.btn_pierce_delay_minus = self.builder.get_object("btn_pierce_delay_minus")
        self.btn_pierce_delay_minus.connect("pressed", self.on_btn_pierce_delay_pressed, -1)

        self.btn_pierce_delay_plus = self.builder.get_object("btn_pierce_delay_plus")
        self.btn_pierce_delay_plus.connect("pressed", self.on_btn_pierce_delay_pressed, 1)

        self.adj_pierce_delay = self.builder.get_object("adj_pierce_delay")
        self.adj_pierce_delay.connect("value_changed", self.on_adj_pierce_delay_value_changed)
        self.adj_pierce_delay.upper = self.piercedelaymax
        self.adj_pierce_delay.lower = self.piercedelaymin
        self.adj_pierce_delay.set_value(self.piercedelayval)

        self.enable_HeightLock = self.builder.get_object("enable-HeightLock")
        self.enable_HeightLock.connect("toggled", self.on_enable_HeightLock_toggled)
        self.enable_HeightLock.set_active(self.enableheightlock)

        self.adj_CHL_threshold = self.builder.get_object("adj_CHL_threshold")
        self.adj_CHL_threshold.connect("value_changed", self.on_adj_CHL_threshold_value_changed)
        self.adj_CHL_threshold.upper = self.chlthresholdmax
        self.adj_CHL_threshold.lower = self.chlthresholdmin
        self.adj_CHL_threshold.set_value(self.chlthresholdval)

        self.btn_THC_target_minus = self.builder.get_object("btn_THC_target_minus")
        self.btn_THC_target_minus.connect("pressed", self.on_btn_THC_target_pressed, -1)

        self.btn_THC_target_plus = self.builder.get_object("btn_THC_target_plus")
        self.btn_THC_target_plus.connect("pressed", self.on_btn_THC_target_pressed, 1)

        self.adj_THC_Voltage = self.builder.get_object("adj_THC_Voltage")
        self.adj_THC_Voltage.connect("value_changed", self.on_adj_THC_Voltage_value_changed)
        self.adj_THC_Voltage.upper = self.thctargetvoltmax
        self.adj_THC_Voltage.lower = self.thctargetvoltmin
        self.adj_THC_Voltage.set_value(self.thctargetvoltval)

    def _on_destroy(self, obj, data = None):
        self.ini.save_state(self)

    # What to do on button pres events?
    def on_btn_THC_speed_pressed(self, widget, dir):
        increment = self.thcspeedincr * dir
        self.thcspeedval = self.adj_THC_speed.get_value() + increment
        self.adj_THC_speed.set_value(self.thcspeedval)

    def on_btn_cut_gap_pressed(self, widget, dir):
        increment = self.cutgapincr * dir
        self.cutgapval = self.adj_cut_gap.get_value() + increment
        self.adj_cut_gap.set_value(self.cutgapval)

    def on_btn_g0_pressed(self, widget, dir):
        increment = self.g0gapincr * dir
        self.g0gapval = self.adj_G0_gap.get_value() + increment
        self.adj_G0_gap.set_value(self.g0gapval)

    def on_btn_pierce_gap_pressed(self, widget, dir):
        increment = self.piercegapincr * dir
        self.piercegapval = self.adj_pierce_gap.get_value() + increment
        self.adj_pierce_gap.set_value(self.piercegapval)

    def on_btn_pierce_delay_pressed(self, widget, dir):
        increment = self.piercedelayincr * dir
        self.piercedelayval = self.adj_pierce_delay.get_value() + increment
        self.adj_pierce_delay.set_value(self.piercedelayval)

    def on_btn_THC_target_pressed(self, widget, dir):
        increment = self.thctargetvoltincr * dir
        self.thctargetvoltval = self.adj_THC_Voltage.get_value() + increment
        self.adj_THC_Voltage.set_value(self.thctargetvoltval)

    # and the behavior of the adjustments to control max and min values
    def on_adj_THC_speed_value_changed(self, widget, data = None):
        if widget.get_value() >= widget.upper:
            self.btn_THC_speed_plus.set_sensitive(False)
        elif widget.get_value() <= widget.lower:
            self.btn_THC_speed_minus.set_sensitive(False)
        else:
            self.btn_THC_speed_plus.set_sensitive(True)
            self.btn_THC_speed_minus.set_sensitive(True)
        self.halcomp["THC-Speed"] = widget.get_value()
        self.lbl_cut_speed.set_label("%.1f" % (widget.get_value()))

    def on_adj_cut_gap_value_changed(self, widget, data = None):
        if widget.get_value() >= widget.upper:
            self.btn_cut_gap_plus.set_sensitive(False)
        elif widget.get_value() <= widget.lower:
            self.btn_cut_gap_minus.set_sensitive(False)
        else:
            self.btn_cut_gap_plus.set_sensitive(True)
            self.btn_cut_gap_minus.set_sensitive(True)
        self.halcomp["Cut-Gap"] = widget.get_value()
        self.lbl_cut_gap.set_label("%.3f" % (widget.get_value()))

    def on_adj_G0_gap_value_changed(self, widget, data = None):
        if widget.get_value() >= widget.upper:
            self.btn_g0_plus.set_sensitive(False)
        elif widget.get_value() <= widget.lower:
            self.btn_g0_minus.set_sensitive(False)
        else:
            self.btn_g0_plus.set_sensitive(True)
            self.btn_g0_minus.set_sensitive(True)
        self.halcomp["G0-Gap"] = widget.get_value()
        self.lbl_g0_gap.set_label("%.3f" % (widget.get_value()))

    def on_adj_pierce_gap_value_changed(self, widget, data = None):
        if widget.get_value() >= widget.upper:
            self.btn_pierce_gap_plus.set_sensitive(False)
        elif widget.get_value() <= widget.lower:
            self.btn_pierce_gap_minus.set_sensitive(False)
        else:
            self.btn_pierce_gap_plus.set_sensitive(True)
            self.btn_pierce_gap_minus.set_sensitive(True)
        self.halcomp["Pierce-Gap"] = widget.get_value()
        self.lbl_pierce_gap.set_label("%.3f" % (widget.get_value()))

    def on_adj_pierce_delay_value_changed(self, widget, data = None):
        if widget.get_value() >= widget.upper:
            self.btn_pierce_delay_plus.set_sensitive(False)
        elif widget.get_value() <= widget.lower:
            self.btn_pierce_delay_minus.set_sensitive(False)
        else:
            self.btn_pierce_delay_plus.set_sensitive(True)
            self.btn_pierce_delay_minus.set_sensitive(True)
        self.halcomp["Pierce-Delay"] = widget.get_value()
        self.lbl_pierce_delay.set_label("%.2f" % (widget.get_value()))

    def on_adj_CHL_threshold_value_changed(self, widget, data = None):
        self.chlthresholdval = widget.get_value()

    def on_adj_THC_Voltage_value_changed(self, widget, data = None):
        if widget.get_value() >= widget.upper:
            self.btn_THC_target_plus.set_sensitive(False)
        elif widget.get_value() <= widget.lower:
            self.btn_THC_target_minus.set_sensitive(False)
        else:
            self.btn_THC_target_plus.set_sensitive(True)
            self.btn_THC_target_minus.set_sensitive(True)
        self.halcomp["Target-Voltage"] = widget.get_value()
        self.lbl_prog_volt.set_label("%d" % (widget.get_value()))

    def on_Piercing_autostart_toggled(self, widget, data = None):
        self.pierceutostart = widget.get_active()

    def on_enable_HeightLock_toggled(self, widget, data = None):
        self.enableheightlock = widget.get_active()

def get_handlers(halcomp, builder, useropts):
    return(PlasmaClass(halcomp, builder, useropts))