import RPi.GPIO as GPIO

class Kran:

    def __init__(self, minus, plus, greifer, handgelenk, ellenbogen, armgelenk, basis, licht):
        self.__Minus = minus
        self.__Plus = plus
        self.__Greifer = greifer
        self.__Handgelenk = handgelenk
        self.__Ellenbogen = ellenbogen
        self.__Armgelenk = armgelenk
        self.__Basis = basis
        self.__Licht = licht
        self.__pin_list = [minus, plus, greifer, handgelenk, ellenbogen, armgelenk, basis, licht]
        self.__pin_list_plus = [greifer, handgelenk, ellenbogen, armgelenk, basis, licht]

        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(self.__pin_list, GPIO.OUT)
        self.move(0, 0)

    def cleanup(self):
        GPIO.cleanup(1)

    def reset(self):
        GPIO.output(self.__pin_list, 1)

    def __on(self, on_pin):
        GPIO.output(on_pin, 0)
        GPIO.output(self.__Plus, 0)

    def __off(self, out_pin):
        GPIO.output(self.__pin_list_plus, 0)
        GPIO.output(out_pin, 1)
        GPIO.output(self.__Minus, 0)

    def move(self, was, wie):
        if was == "G" and wie == 1:
            self.__on(self.__Greifer)
        elif was == "G" and wie == 2:
            self.__off(self.__Greifer)
        elif was == "H" and wie == 1:
            self.__on(self.__Handgelenk)
        elif was == "H" and wie == 2:
            self.__off(self.__Handgelenk)
        elif was == "E" and wie == 1:
            self.__on(self.__Ellenbogen)
        elif was == "E" and wie == 2:
            self.__off(self.__Ellenbogen)
        elif was == "A" and wie == 1:
            self.__on(self.__Armgelenk)
        elif was == "A" and wie == 2:
            self.__off(self.__Armgelenk)
        elif was == "B" and wie == 1:
            self.__on(self.__Basis)
        elif was == "B" and wie == 2:
            self.__off(self.__Basis)

        elif was == "L" and wie == 1:
            self.__on(self.__Licht)

        else:
            print "no match!!!!!"
