// This file contains the DCC and LED definitions.
//
// It was automatically generated by the program ProgGenerator Ver. 3.4.0B2      by Hardi
// File creation: 08/19/25 13:09:39
// (Attention: The display in the Arduino IDE is not updated if Options/External Editor is disabled)

#ifndef __LEDS_AUTOPROG_H__
#define __LEDS_AUTOPROG_H__

#ifndef CONFIG_ONLY
#ifndef ARDUINO_RASPBERRY_PI_PICO
#ifndef FASTLED_ESP32_I2S
#define FASTLED_INTERNAL       // Disable version number message in FastLED library (looks like an error)
#endif
#include <FastLED.h>           // The FastLED library must be installed in addition if you got the error message "..fatal error: FastLED.h: No such file or directory"
                               // Arduino IDE: Sketch / Include library / Manage libraries                    Deutsche IDE: Sketch / Bibliothek einbinden / Bibliothek verwalten
                               //              Type "FastLED" in the "Filter your search..." field                          "FastLED" in das "Grenzen Sie ihre Suche ein" Feld eingeben
                               //              Select the entry and click "Install"                                         Gefundenen Eintrag auswaehlen und "Install" anklicken
#else
#include <PicoFastLED.h>       // Juergens minimum version or FastLED for Raspberry Pico
#endif
#endif // CONFIG_ONLY

#include <MobaLedLib.h>

#define START_MSG "LEDs_AutoProg Ver 3: ESP32 3.4.0B2 08.19.25 13:09"

#define TWO_BUTTONS_PER_ADDRESS 1      // Two buttons (Red/Green) are used (DCC/LNet/CAN)
#ifdef NUM_LEDS
  #warning "'NUM_LEDS' definition in the main program is replaced by the included 'LEDs_AutoProg.h' with 29"
  #undef NUM_LEDS
#endif

#define NUM_LEDS 29                    // Number of LEDs (Maximal 256 RGB LEDs could be used)

#define LEDS_PER_CHANNEL ",4,1,2,2,2,2,0,16"

#define USE_PROTOCOL_DCC

#define RECEIVE_LED_COLOR_PER_RS232

#define GEN_BUTTON_RELEASE
#define GEN_BUTTON_RELEASE_COM GEN_OFF
// Input channel defines for local inputs and expert users


//*** Direct connected switches ***

#define START_SWITCHES_D  0                                        // Define the start number for the first mainboard switch
#define SwitchD1                0                                        // Z21-RM-Rckmelder: Adresse:1 Eingang:1
#define SwitchD2                1                                        // Z21-RM-Rckmelder: Adresse:1 Eingang:2
#define SwitchD3                2                                        // Z21-RM-Rckmelder: Adresse:1 Eingang:3

//*** Output Channels ***
#define START_VARIABLES   3                                        // Define the start number for the variables.
#define D1                      3                                        // Z21-RM-Rckmelder: Adresse:1 Eingang:4
#define D2                      4                                        // Z21-RM-Rckmelder: Adresse:1 Eingang:5
#define D3                      5                                        // Z21-RM-Rckmelder: Adresse:1 Eingang:6

const PROGMEM uint8_t SwitchD_Pins[] = { 12,26,25 };               // Array of pins which read switches 'D'
#define SWITCH_D_INP_CNT sizeof(SwitchD_Pins)


#define START_SEND_INPUTS 0                                        // Start address of all switches/variables
#define TOTAL_SEND_INPUTS 6                                        // Number of used switches/variables
#define TOTAL_SWITCHES_A  0                                        // Number of used inputs for analog keyboard
#define TOTAL_SWITCHES_B  0                                        // Number of used inputs for keyboard 1
#define TOTAL_SWITCHES_C  0                                        // Number of used inputs for keyboard 2
#define TOTAL_SWITCHES_D  3                                        // Number of used inputs for main board switches
#define TOTAL_VARIABLES   3                                        // Number of used variables
/*********************/
#define SETUP_FASTLED()                                                      \
/*********************/                                                      \
  CLEDController& controller0 = FastLED.addLeds<NEOPIXEL, 27>(leds+  0,  4); \
  CLEDController& controller1 = FastLED.addLeds<NEOPIXEL, 32>(leds+  4,  1); \
  CLEDController& controller2 = FastLED.addLeds<NEOPIXEL, 16>(leds+  5,  2); \
  CLEDController& controller3 = FastLED.addLeds<NEOPIXEL, 14>(leds+  7,  2); \
  CLEDController& controller4 = FastLED.addLeds<NEOPIXEL, 18>(leds+  9,  2); \
  CLEDController& controller5 = FastLED.addLeds<NEOPIXEL, 19>(leds+ 11,  2); \
  CLEDController& controller7 = FastLED.addLeds<NEOPIXEL,  0>(leds+ 13, 16); \
                                                                             \
  controller0.clearLeds(256);                                                \
  controller1.clearLeds(256);                                                \
  controller2.clearLeds(256);                                                \
  controller3.clearLeds(256);                                                \
  controller4.clearLeds(256);                                                \
  controller5.clearLeds(256);                                                \
  controller7.clearLeds(256);                                                \
  FastLED.setDither(DISABLE_DITHER);       // avoid sending slightly modified brightness values
/*End*/

#define USE_ADDITIONAL_SETUP_PROC                                  // Activate the usage of the Additional_Setup_Proc()

//--------------------------
void Additional_Setup_Proc()
//--------------------------
{

  for (uint8_t i = 0; i < SWITCH_D_INP_CNT; i++)
    pinMode(pgm_read_byte_near(&SwitchD_Pins[i]), INPUT_PULLUP);
}

/****************************/
#define Additional_Loop_Proc() \
/****************************/ \
{                              \
  for (uint8_t i = 0; i < 3; i++) \
      MobaLedLib.Set_Input(SwitchD1 + i, !digitalRead(pgm_read_byte_near(&SwitchD_Pins[i])));\
}


//*******************************************************************
// *** Configuration array which defines the behavior of the LEDs ***
MobaLedLib_Configuration()
  {
  RGB_Heartbeat(0)                                                                                            /* LED auf dem Mainboard                                                                                                                                                                       */
  #ifdef ESP32                                                                                                /* Excel row 4                                                                                                                                                                                 */
     #define USE_ESP32_EXTENSIONS                                                                             /*     "                                                                                                                                                                                       */
     #define USE_UI                                                                                           /*     "                                                                                                                                                                                       */
  #endif                                                                                                      /*     "                                                                                                                                                                                       */
  T_FlipFlopReset(D1, SwitchD1, SI_0)                                                                         /* Schalter D1 (einmal drcken = an, nochmal drcken = aus)                                                                                                                                    */
  T_FlipFlopReset(D2, SwitchD2, SI_0)                                                                         /* Schalter D2 (einmal drcken = an, nochmal drcken = aus)                                                                                                                                    */
  T_FlipFlopReset(D3, SwitchD3, SI_0)                                                                         /* Schalter D3 (einmal drcken = an, nochmal drcken = aus)                                                                                                                                    */
  RGB_Heartbeat_Color(1, 5, 120, 150, 1 Sek)                                                                  /* Ch 0 Heartbeat (grn blinkende Heartbeats #0 bis 7)                                                                                                                                         */
  RGB_Heartbeat_Color(5, 5, 120, 150, 1 Sek)                                                                  /* Ch 2 Heartbeat                                                                                                                                                                              */
  RGB_Heartbeat_Color(7, 5, 120, 150, 1 Sek)                                                                  /* Ch 3 Heartbeat                                                                                                                                                                              */
  RGB_Heartbeat_Color(9, 5, 120, 150, 1 Sek)                                                                  /* Ch 4 Heartbeat                                                                                                                                                                              */
  RGB_Heartbeat_Color(11, 5, 120, 150, 1 Sek)                                                                 /* Ch 5 Heartbeat                                                                                                                                                                              */
  Const(13, C1, D1, 9, 255)                                                                                   /* Status-LED gelb (leuchtet schwach wenn D1 = aus, hell wenn D1 = an)                                                                                                                         */
  Const(13, C2, D2, 3, 90)                                                                                    /* Status-LED wei (leuchtet schwach wenn D2 = aus, hell wenn D2 = an)                                                                                                                         */
  Const(13, C3, D3, 5, 180)                                                                                   /* Status-LED blau (leuchtet schwach wenn D3 = aus, hell wenn D3 = an)                                                                                                                         */
  RGB_Ring(14, SI_1, 30, 80)                                                                                  /* MLL-Ring (pc)                                                                                                                                                                               */
  RGB_Heartbeat_Color(26, 5, 120, 150, 1 Sek)                                                                 /* Ch 7 Heartbeat                                                                                                                                                                              */
  House(2, SI_1, 1, 1, ROOM_WARM_W)                                                                           /* Beispiel auf Kanal 0 (Zeile ersetzen durch eigene Programmierung)                                                                                                                           */
  House(4, SI_1, 1, 1, ROOM_WARM_W)                                                                           /* Beispiel auf Kanal 1 (Zeile lschen, wenn Kanal 1 nicht genutzt wird)                                                                                                                       */
  House(27, SI_1, 1, 1, ROOM_WARM_W)                                                                          /* Beispiel auf Kanal 7 (Zeile lschen, wenn Kanal 7 nicht genutzt wird)                                                                                                                       */
  RGB_Heartbeat_Color(3, 5, 120, 205, 1 Sek)                                                                  /* Ch 0N Heartbeat Rckmeldung (gelb blinkende Heartbeats #0N bis 7N)                                                                                                                          */
  RGB_Heartbeat_Color(6, 5, 120, 205, 1 Sek)                                                                  /* Ch 2N Heartbeat Rckmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(8, 5, 120, 205, 1 Sek)                                                                  /* Ch 3N Heartbeat Rckmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(10, 5, 120, 205, 1 Sek)                                                                 /* Ch 4N Heartbeat Rckmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(12, 5, 120, 205, 1 Sek)                                                                 /* Ch 5N Heartbeat Rckmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(28, 5, 120, 205, 1 Sek)                                                                 /* Ch 7N Heartbeat Rckmeldung                                                                                                                                                                 */

  EndCfg // End of the configuration
  };
//*******************************************************************

#ifndef COPYLED_OFF
#define COPYLED_OFF 0
#endif

#ifndef COPYLED_OFF_ONCE
#define COPYLED_OFF_ONCE 1
#endif

//---------------------------------------------
void Set_Start_Values(MobaLedLib_C &MobaLedLib)
//---------------------------------------------
{
}


// if function returns TRUE the calling loop stops
typedef bool(*HandleValue_t) (uint8_t CallbackType, uint8_t ValueId, uint8_t* Value, uint16_t EEPromAddr, uint8_t TargetValueId, uint8_t Options);


#define InCnt_MSK  0x003F  // 6 bits are used for the InCnt, 2 bits for the type ttcc cccc => Max InCnt=63
#define IS_COUNTER (uint8_t)0x80
#define IS_PULSE   (uint8_t)0x40
#define IS_TOGGLE  (uint8_t)0x00
#define COUNTER_ID

typedef struct
    {
    uint8_t TypAndInCnt; // Type bits 7 & 6, InCnt 0..5
    uint8_t Channel;
    } __attribute__ ((packed)) Store_Channel_T;

// Definition of channels and counters that need to store state in EEProm
const PROGMEM Store_Channel_T Store_Values[] =
         { // Mode + InCnt , Channel
           { IS_COUNTER    , COUNTER_ID 1        },      // Schalter D1 (einmal drcken = an, nochmal drcken = aus)
           { IS_COUNTER    , COUNTER_ID 2        },      // Schalter D2 (einmal drcken = an, nochmal drcken = aus)
           { IS_COUNTER    , COUNTER_ID 3        },      // Schalter D3 (einmal drcken = an, nochmal drcken = aus)
         };

#ifndef CONFIG_ONLY
#endif // CONFIG_ONLY





#endif // __LEDS_AUTOPROG_H__
