/*
 * Copyright 2016 Mario Richter
 * This file is part of NeMo.
 *
 * NeMo 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 3 of the License, or
 * (at your option) any later version.
 *
 * NeMo 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 NeMo.  If not, see <http://www.gnu.org/licenses/>.
 */

/*!
 * \file light.h
 * \ingroup light
 * \brief Routinen zur Steuerung der RGB-Stripes
 */

#ifndef __LICHT_H__
#define __LICHT_H__


// --------------------------------------
// Defines

#define KANAL_WEISS         1         //!< 3 oder 4 Kanäle (0=RGB-Stripe, 1=RBGW-Stripe)

#define LIGHT_MODE_OFF      0         //!< Lichtmodus: Aus
#define LIGHT_MODE_ACTIVE   1         //!< Lichtmodus: Programm aktiv
#define LIGHT_MODE_PAUSE    2         //!< Lichtmodus: Programm pausiert
#define LIGHT_MODE_ERROR    3         //!< Lichtmodus: Fehler

#define EEP_AUTOSTART_ON    0x90      //!< EEPROM-Wert für Autostart an
#define EEP_AUTOSTART_OFF   0x60      //!< EEPROM-Wert für Autostart aus

#define TAST_DEBOUNCE_CNT   10        //!< Entprellzählerschwelle

typedef struct
{
  uint8_t   type;                     //!< Typ des Befehls (Set, Fade, Pause, eXit)
  uint16_t  delay;                    //!< Verzögerung (in 10ms)
  uint16_t  red;                      //!< Rot-Wert
  uint16_t  grn;                      //!< Grün-Wert
  uint16_t  blu;                      //!< Blau-Wert
#if KANAL_WEISS == 1
  uint16_t  wht;                      //!< Weiß-Wert
#endif
}lightCmdStruct;


// --------------------------------------
// Funktionsdeklarationen

void lightInit(void);
void lightScheduler(void);

void tastAuswertung(void);
void ledAusgabe(void);

uint8_t lightProgStart(uint8_t progNr);
uint8_t lightGetCommand(uint16_t addr, lightCmdStruct * dest);

void lightSetPWMRed(uint8_t red);
void lightSetPWMGreen(uint8_t green);
void lightSetPWMBlue(uint8_t blue);

#if KANAL_WEISS == 1
void lightSetPWMWhite(uint8_t white);
#endif


// --------------------------------------
// Globale Variablen

extern uint8_t  lightMode;              //!< Aktueller Betriebsmodus
extern uint8_t  lightProgAct;           //!< Aktuell aktives Lichtprogramm (1-16, 0=kein Programm)
extern uint8_t  lightCmdStep;           //!< Nummer des aktuellen Befehls

extern lightCmdStruct lightCmdAct;      //!< Aktuell auszuführender Befehl
extern uint8_t  lightPrograms[16][64];  //!< Namen der 16 Lichtprogramme

extern uint8_t   lightAutoStart;
extern uint8_t   EEMEM eepLightAutoStart;

extern char     lightLocation[];
extern char     EEMEM eepLightLocation[];

extern uint16_t  lightValRed;
extern uint16_t  lightValGrn;
extern uint16_t  lightValBlu;

#if KANAL_WEISS == 1
extern uint16_t  lightValWht;
#endif


#endif
