#!/usr/bin/python3
'''
M110

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.,
51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

This macro is designed to control the gas periphery of the machine.
'''

# Parametres P is number pin Q is state of pin

# For THC GAS
# P=1 - THC UP signal Q=0 is disable pin, Q=1 is enable pin
# P=2 - THC DOWN signal Q=0 is disable pin, Q=1 is enable pin
# P=3 - THC MODE signal Q=0 is manual Q=1 is auto

# For Torch periphery
# P=4 Valve Heat Oxy Q=0 is disable pin, Q=1 is enable pin
# P=5 Valve Cut Oxy  Q=0 is disable pin, Q=1 is enable pin
# P=6 Valve Gas      Q=0 is disable pin, Q=1 is enable pin
# P=7 Valve Ign Gas  Q=0 is disable pin, Q=1 is enable pin
# P=8 Ign Pulse      Q=0 is disable pin, Q=1 is enable pin

import sys
import time
from subprocess import run as RUN

command = int(float(sys.argv[1]))
argument = int(float(sys.argv[2]))

try:
    # THC GAS signal UP
    if command == 1:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:pout-torch-up', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:pout-torch-up', 'False'])
    # THC GAS signal DOWN
    if command == 2:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:pout-torch-down', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:pout-torch-down', 'Flase'])
    # THC GAS signal mode
    if command == 3:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:pout-hf100_mode', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:pout-hf100_mode', 'False'])

    # Valve Heat Oxy
    if command == 4:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:dout-heat-oxy', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:dout-heat-oxy', 'False'])
    # Valve Cut Oxy
    if command == 5:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:dout-cut-oxy', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:dout-cut-oxy', 'False'])
    # Valve Gas
    if command == 6:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:dout-gas', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:dout-gas', 'False'])
    # Valve Ign Gas
    if command == 7:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:dout_ign_gas', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:dout_ign_gas', 'False'])
    # Ign Pulse
    if command == 8:
        if argument == 1:
            RUN(['halcmd', 'sets', 'rg:dout_ign_pulse', 'True'])
        if argument == 0:
            RUN(['halcmd', 'sets', 'rg:dout_ign_pulse', 'False'])
except:
    pass
#print('---debug M110: cmd = {}'.format(command), ' arg = {}'.format(argument))
exit()