// This file contains the DCC and LED definitions.
//
// It was automatically generated by the program Prog_Generator_MobaLedLib.xlsm Ver. 3.3.2      by Hardi
// File creation: 08.06.2025 12:20:13
// (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
#define FASTLED_INTERNAL       // Disable version number message in FastLED library (looks like an error)
#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 1: Ver_3.3.2 08.06.25 12:20"

#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 28"
  #undef NUM_LEDS
#endif

#define NUM_LEDS 28                    // Number of LEDs (Maximal 256 RGB LEDs could be used)

#define LEDS_PER_CHANNEL ",3,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
#define SwitchD2                1
#define SwitchD3                2

//*** Output Channels ***
#define START_VARIABLES   3                                        // Define the start number for the variables.
#define D1                      3
#define D2                      4
#define D3                      5

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,  3); \
  CLEDController& controller1 = FastLED.addLeds<NEOPIXEL, 32>(leds+  3,  1); \
  CLEDController& controller2 = FastLED.addLeds<NEOPIXEL, 16>(leds+  4,  2); \
  CLEDController& controller3 = FastLED.addLeds<NEOPIXEL, 14>(leds+  6,  2); \
  CLEDController& controller4 = FastLED.addLeds<NEOPIXEL, 18>(leds+  8,  2); \
  CLEDController& controller5 = FastLED.addLeds<NEOPIXEL, 19>(leds+ 10,  2); \
  CLEDController& controller7 = FastLED.addLeds<NEOPIXEL,  0>(leds+ 12, 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()
  {
  // Set_LED_OutpPinLst(27 32 16 14 18 19 23 0)                                                               /* Excel row 3                                                                                                                                                                                 */
  #ifdef ESP32                                                                                                /* Excel row 4                                                                                                                                                                                 */
     #define USE_ESP32_EXTENSIONS                                                                             /*     "                                                                                                                                                                                       */
     #define USE_UI                                                                                           /*     "                                                                                                                                                                                       */
  #endif                                                                                                      /*     "                                                                                                                                                                                       */
  T_FlipFlopReset(D1, SwitchD1, SI_0)                                                                         /* Schalter D1 (einmal drücken = an, nochmal drücken = aus)                                                                                                                                    */
  T_FlipFlopReset(D2, SwitchD2, SI_0)                                                                         /* Schalter D2 (einmal drücken = an, nochmal drücken = aus)                                                                                                                                    */
  T_FlipFlopReset(D3, SwitchD3, SI_0)                                                                         /* Schalter D3 (einmal drücken = an, nochmal drücken = aus)                                                                                                                                    */
  RGB_Heartbeat_Color(0, 5, 120, 150, 1 Sek)                                                                  /* Ch 0 Heartbeat (grün blinkende Heartbeats #0 bis 7)                                                                                                                                         */
  RGB_Heartbeat_Color(4, 5, 120, 150, 1 Sek)                                                                  /* Ch 2 Heartbeat                                                                                                                                                                              */
  RGB_Heartbeat_Color(6, 5, 120, 150, 1 Sek)                                                                  /* Ch 3 Heartbeat                                                                                                                                                                              */
  RGB_Heartbeat_Color(8, 5, 120, 150, 1 Sek)                                                                  /* Ch 4 Heartbeat                                                                                                                                                                              */
  RGB_Heartbeat_Color(10, 5, 120, 150, 1 Sek)                                                                 /* Ch 5 Heartbeat                                                                                                                                                                              */
  Const(12, C1, D1, 9, 255)                                                                                   /* Status-LED gelb (leuchtet schwach wenn D1 = aus, hell wenn D1 = an)                                                                                                                         */
  Const(12, C2, D2, 3, 90)                                                                                    /* Status-LED weiß (leuchtet schwach wenn D2 = aus, hell wenn D2 = an)                                                                                                                         */
  Const(12, C3, D3, 5, 180)                                                                                   /* Status-LED blau (leuchtet schwach wenn D3 = aus, hell wenn D3 = an)                                                                                                                         */
  RGB_Ring(13, SI_1, 30, 80)                                                                                  /* MLL-Ring (pc)                                                                                                                                                                               */
  RGB_Heartbeat_Color(25, 5, 120, 150, 1 Sek)                                                                 /* Ch 7 Heartbeat                                                                                                                                                                              */
  House(1, SI_1, 1, 1, ROOM_WARM_W)                                                                           /* Beispiel auf Kanal 0 (Zeile ersetzen durch eigene Programmierung)                                                                                                                           */
  House(3, SI_1, 1, 1, ROOM_WARM_W)                                                                           /* Beispiel auf Kanal 1 (Zeile löschen, wenn Kanal 1 nicht genutzt wird)                                                                                                                       */
  House(26, SI_1, 1, 1, ROOM_WARM_W)                                                                          /* Beispiel auf Kanal 7 (Zeile löschen, wenn Kanal 7 nicht genutzt wird)                                                                                                                       */
  RGB_Heartbeat_Color(2, 5, 120, 205, 1 Sek)                                                                  /* Ch 0N Heartbeat Rückmeldung (gelb blinkende Heartbeats #0N bis 7N)                                                                                                                          */
  RGB_Heartbeat_Color(5, 5, 120, 205, 1 Sek)                                                                  /* Ch 2N Heartbeat Rückmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(7, 5, 120, 205, 1 Sek)                                                                  /* Ch 3N Heartbeat Rückmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(9, 5, 120, 205, 1 Sek)                                                                  /* Ch 4N Heartbeat Rückmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(11, 5, 120, 205, 1 Sek)                                                                 /* Ch 5N Heartbeat Rückmeldung                                                                                                                                                                 */
  RGB_Heartbeat_Color(27, 5, 120, 205, 1 Sek)                                                                 /* Ch 7N Heartbeat Rückmeldung                                                                                                                                                                 */

  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 drücken = an, nochmal drücken = aus)
           { IS_COUNTER    , COUNTER_ID 2        },      // Schalter D2 (einmal drücken = an, nochmal drücken = aus)
           { IS_COUNTER    , COUNTER_ID 3        },      // Schalter D3 (einmal drücken = an, nochmal drücken = aus)
         };

#ifndef CONFIG_ONLY
#endif // CONFIG_ONLY





#endif // __LEDS_AUTOPROG_H__
