#include "kraftsensor.h"
#include "avrIOhelper/io-helper.h"
#include <stdint.h>
#include <stdio.h>
#include "notaus.h"

uint8_t notaus_state = POWER_OFF;

void do_notaus(){
    if(!read_Input(IN_NOTAUS_ANLAGE, LEVEL) || read_Input(IN_NOTAUS_SCHRANK, LEVEL) || read_Input(IN_NOTAUS_DISPLAY, LEVEL)){
        /* at least one pressed */
        notaus_state = POWER_OFF;

        ioHelperSetBit(outStates, AMPEL_ROT,  1);
        ioHelperSetBit(outStates, AMPEL_GELB,  0);
        ioHelperSetBit(outStates, AMPEL_GRUEN,  0);

        set_Output(LED_GRN_NOTAUS_SCHRANK,   OFF);
        set_Output(LED_GRN_NOTAUS_ANLAGE,    OFF);
        set_Output(LED_GRN_NOTAUS_DISPLAY,   OFF);

        if(!read_Input(IN_NOTAUS_ANLAGE, LEVEL)){
            set_Output(LED_ROT_NOTAUS_ANLAGE, BLINK);
            set_Output(LED_ROT_NOTAUS_SCHRANK,   ON);
            set_Output(LED_ROT_NOTAUS_DISPLAY,   ON);
        }

        if(read_Input(IN_NOTAUS_SCHRANK, LEVEL)){
            set_Output(LED_ROT_NOTAUS_ANLAGE,    ON);
            set_Output(LED_ROT_NOTAUS_SCHRANK, BLINK);
            set_Output(LED_ROT_NOTAUS_DISPLAY,   ON);
        }

        if(read_Input(IN_NOTAUS_DISPLAY, LEVEL)){
            set_Output(LED_ROT_NOTAUS_ANLAGE,    ON);
            set_Output(LED_ROT_NOTAUS_SCHRANK,   ON);
            set_Output(LED_ROT_NOTAUS_DISPLAY, BLINK);
        }

    }
    else if(!read_Input(IN_ANLAGE_EIN, LEVEL)){
        /* nothing pressed, but power not on */
        notaus_state = ARMED;

        ioHelperSetBit(outStates, AMPEL_ROT,  0);
        ioHelperSetBit(outStates, AMPEL_GELB,  1);
        ioHelperSetBit(outStates, AMPEL_GRUEN,  0);

        set_Output(LED_ROT_NOTAUS_ANLAGE,  ON);
        set_Output(LED_ROT_NOTAUS_SCHRANK, ON);
        set_Output(LED_ROT_NOTAUS_DISPLAY, ON);

        set_Output(LED_GRN_NOTAUS_SCHRANK, ON);
        set_Output(LED_GRN_NOTAUS_ANLAGE,  ON);
        set_Output(LED_GRN_NOTAUS_DISPLAY, ON);
    }
    else{
        /* powered on */
        notaus_state = POWER_ON;

        ioHelperSetBit(outStates, AMPEL_ROT,  0);
        ioHelperSetBit(outStates, AMPEL_GELB,  0);
        ioHelperSetBit(outStates, AMPEL_GRUEN,  1);

        set_Output(LED_GRN_NOTAUS_SCHRANK,   ON);
        set_Output(LED_GRN_NOTAUS_ANLAGE,    ON);
        set_Output(LED_GRN_NOTAUS_DISPLAY,   ON);

        set_Output(LED_ROT_NOTAUS_ANLAGE,    OFF);
        set_Output(LED_ROT_NOTAUS_SCHRANK,   OFF);
        set_Output(LED_ROT_NOTAUS_DISPLAY,   OFF);
    }

    if(!kraftsensor_valid)
    {
        set_Output(LED_FEHLER, ON);
    }
    else
        set_Output(LED_FEHLER, OFF);

}


