using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Linq;
using Crestron;
using Crestron.Logos.SplusLibrary;
using Crestron.Logos.SplusObjects;
using Crestron.SimplSharp;

namespace UserModule_BG_4K_VP44PRO
{
    public class UserModuleClass_BG_4K_VP44PRO : SplusObject
    {
        static CCriticalSection g_criticalSection = new CCriticalSection();
        
        
        Crestron.Logos.SplusObjects.BufferInput RX_MATRIX;
        Crestron.Logos.SplusObjects.AnalogInput CLEAR_PRESET_MODE;
        Crestron.Logos.SplusObjects.AnalogInput STORE_PRESET_MODE;
        Crestron.Logos.SplusObjects.AnalogInput RECALL_PRESET_MODE;
        Crestron.Logos.SplusObjects.AnalogInput CLEAR_PRESET_SCENE;
        Crestron.Logos.SplusObjects.AnalogInput STORE_PRESET_SCENE;
        Crestron.Logos.SplusObjects.AnalogInput RECALL_PRESET_SCENE;
        Crestron.Logos.SplusObjects.AnalogInput ALL_OUTPUT;
        InOutArray<Crestron.Logos.SplusObjects.AnalogInput> OUTPUT;
        Crestron.Logos.SplusObjects.StringOutput TX_MATRIX;
        Crestron.Logos.SplusObjects.StringOutput TO_SIO;
        object RX_MATRIX_OnChange_0 ( Object __EventInfo__ )
        
            { 
            Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
            try
            {
                SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
                CrestronString MESSAGE;
                MESSAGE  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 65534, this );
                
                CrestronString INFO;
                INFO  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 65534, this );
                
                ushort P1 = 0;
                ushort P2 = 0;
                ushort P3 = 0;
                ushort P4 = 0;
                
                
                __context__.SourceCodeLine = 171;
                MESSAGE  .UpdateValue ( MESSAGE + RX_MATRIX  ) ; 
                __context__.SourceCodeLine = 172;
                Functions.Delay (  (int) ( 100 ) ) ; 
                __context__.SourceCodeLine = 173;
                Functions.Delay (  (int) ( 100 ) ) ; 
                __context__.SourceCodeLine = 174;
                P1 = (ushort) ( Functions.Find( "Output" , MESSAGE ) ) ; 
                __context__.SourceCodeLine = 175;
                INFO  .UpdateValue ( Functions.Mid ( MESSAGE ,  (int) ( P1 ) ,  (int) ( 100 ) )  ) ; 
                __context__.SourceCodeLine = 177;
                TO_SIO  .UpdateValue ( INFO  ) ; 
                __context__.SourceCodeLine = 179;
                Functions.ClearBuffer ( RX_MATRIX ) ; 
                
                
            }
            catch(Exception e) { ObjectCatchHandler(e); }
            finally { ObjectFinallyHandler( __SignalEventArg__ ); }
            return this;
            
        }
        
    object CLEAR_PRESET_MODE_OnChange_1 ( Object __EventInfo__ )
    
        { 
        Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
        try
        {
            SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
            CrestronString STRINGOUT1;
            STRINGOUT1  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 2, this );
            
            
            __context__.SourceCodeLine = 191;
            MakeString ( STRINGOUT1 , "{0:d}", (ushort)CLEAR_PRESET_MODE  .UshortValue) ; 
            __context__.SourceCodeLine = 192;
            TX_MATRIX  .UpdateValue ( "#preset mode" + STRINGOUT1 + " exe=0"  ) ; 
            
            
        }
        catch(Exception e) { ObjectCatchHandler(e); }
        finally { ObjectFinallyHandler( __SignalEventArg__ ); }
        return this;
        
    }
    
object STORE_PRESET_MODE_OnChange_2 ( Object __EventInfo__ )

    { 
    Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
    try
    {
        SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
        CrestronString STRINGOUT1;
        STRINGOUT1  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 2, this );
        
        
        __context__.SourceCodeLine = 202;
        MakeString ( STRINGOUT1 , "{0:d}", (ushort)STORE_PRESET_MODE  .UshortValue) ; 
        __context__.SourceCodeLine = 203;
        TX_MATRIX  .UpdateValue ( "#preset mode" + STRINGOUT1 + " exe=1"  ) ; 
        
        
    }
    catch(Exception e) { ObjectCatchHandler(e); }
    finally { ObjectFinallyHandler( __SignalEventArg__ ); }
    return this;
    
}

object RECALL_PRESET_MODE_OnChange_3 ( Object __EventInfo__ )

    { 
    Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
    try
    {
        SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
        CrestronString STRINGOUT1;
        STRINGOUT1  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 2, this );
        
        
        __context__.SourceCodeLine = 212;
        MakeString ( STRINGOUT1 , "{0:d}", (ushort)RECALL_PRESET_MODE  .UshortValue) ; 
        __context__.SourceCodeLine = 213;
        TX_MATRIX  .UpdateValue ( "#preset mode" + STRINGOUT1 + " exe=2"  ) ; 
        
        
    }
    catch(Exception e) { ObjectCatchHandler(e); }
    finally { ObjectFinallyHandler( __SignalEventArg__ ); }
    return this;
    
}

object CLEAR_PRESET_SCENE_OnChange_4 ( Object __EventInfo__ )

    { 
    Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
    try
    {
        SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
        CrestronString STRINGOUT1;
        STRINGOUT1  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 2, this );
        
        
        __context__.SourceCodeLine = 222;
        MakeString ( STRINGOUT1 , "{0:d}", (ushort)CLEAR_PRESET_SCENE  .UshortValue) ; 
        __context__.SourceCodeLine = 223;
        TX_MATRIX  .UpdateValue ( "#preset scene" + STRINGOUT1 + " exe=0"  ) ; 
        
        
    }
    catch(Exception e) { ObjectCatchHandler(e); }
    finally { ObjectFinallyHandler( __SignalEventArg__ ); }
    return this;
    
}

object STORE_PRESET_SCENE_OnChange_5 ( Object __EventInfo__ )

    { 
    Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
    try
    {
        SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
        CrestronString STRINGOUT1;
        STRINGOUT1  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 2, this );
        
        
        __context__.SourceCodeLine = 234;
        MakeString ( STRINGOUT1 , "{0:d}", (ushort)STORE_PRESET_SCENE  .UshortValue) ; 
        __context__.SourceCodeLine = 235;
        TX_MATRIX  .UpdateValue ( "#preset scene" + STRINGOUT1 + " exe=1"  ) ; 
        
        
    }
    catch(Exception e) { ObjectCatchHandler(e); }
    finally { ObjectFinallyHandler( __SignalEventArg__ ); }
    return this;
    
}

object RECALL_PRESET_SCENE_OnChange_6 ( Object __EventInfo__ )

    { 
    Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
    try
    {
        SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
        CrestronString STRINGOUT1;
        STRINGOUT1  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 2, this );
        
        
        __context__.SourceCodeLine = 246;
        MakeString ( STRINGOUT1 , "{0:d}", (ushort)RECALL_PRESET_SCENE  .UshortValue) ; 
        __context__.SourceCodeLine = 247;
        TX_MATRIX  .UpdateValue ( "#preset scene" + STRINGOUT1 + " exe=2"  ) ; 
        
        
    }
    catch(Exception e) { ObjectCatchHandler(e); }
    finally { ObjectFinallyHandler( __SignalEventArg__ ); }
    return this;
    
}

object OUTPUT_OnChange_7 ( Object __EventInfo__ )

    { 
    Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
    try
    {
        SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
        ushort LASTNUM = 0;
        
        CrestronString SINPUT;
        CrestronString SOUTPUT;
        SINPUT  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 1, this );
        SOUTPUT  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 1, this );
        
        
        __context__.SourceCodeLine = 257;
        LASTNUM = (ushort) ( Functions.GetLastModifiedArrayIndex( __SignalEventArg__ ) ) ; 
        __context__.SourceCodeLine = 258;
        if ( Functions.TestForTrue  ( ( Functions.BoolToInt (LASTNUM == 1))  ) ) 
            {
            __context__.SourceCodeLine = 258;
            SOUTPUT  .UpdateValue ( "0"  ) ; 
            }
        
        else 
            {
            __context__.SourceCodeLine = 259;
            SOUTPUT  .UpdateValue ( Functions.ItoA (  (int) ( (LASTNUM - 1) ) )  ) ; 
            }
        
        __context__.SourceCodeLine = 260;
        if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( OUTPUT[ LASTNUM ] .UshortValue < 1 ))  ) ) 
            {
            __context__.SourceCodeLine = 260;
            SINPUT  .UpdateValue ( "0" + Functions.ItoA (  (int) ( OUTPUT[ LASTNUM ] .UshortValue ) )  ) ; 
            }
        
        else 
            {
            __context__.SourceCodeLine = 261;
            if ( Functions.TestForTrue  ( ( Functions.BoolToInt (OUTPUT[ LASTNUM ] .UshortValue == 9))  ) ) 
                {
                __context__.SourceCodeLine = 261;
                SINPUT  .UpdateValue ( "0"  ) ; 
                }
            
            else 
                {
                __context__.SourceCodeLine = 262;
                SINPUT  .UpdateValue ( Functions.ItoA (  (int) ( OUTPUT[ LASTNUM ] .UshortValue ) )  ) ; 
                }
            
            }
        
        __context__.SourceCodeLine = 263;
        MakeString ( TX_MATRIX , "#video_d out{0} source={1}", SOUTPUT , SINPUT ) ; 
        
        
    }
    catch(Exception e) { ObjectCatchHandler(e); }
    finally { ObjectFinallyHandler( __SignalEventArg__ ); }
    return this;
    
}

object ALL_OUTPUT_OnChange_8 ( Object __EventInfo__ )

    { 
    Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
    try
    {
        SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
        CrestronString STRINGOUT1;
        STRINGOUT1  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 1, this );
        
        
        __context__.SourceCodeLine = 272;
        MakeString ( STRINGOUT1 , "{0:d}", (ushort)ALL_OUTPUT  .UshortValue) ; 
        __context__.SourceCodeLine = 273;
        TX_MATRIX  .UpdateValue ( "#video_d out255 matrix=" + STRINGOUT1  ) ; 
        
        
    }
    catch(Exception e) { ObjectCatchHandler(e); }
    finally { ObjectFinallyHandler( __SignalEventArg__ ); }
    return this;
    
}


public override void LogosSplusInitialize()
{
    SocketInfo __socketinfo__ = new SocketInfo( 1, this );
    InitialParametersClass.ResolveHostName = __socketinfo__.ResolveHostName;
    _SplusNVRAM = new SplusNVRAM( this );
    
    CLEAR_PRESET_MODE = new Crestron.Logos.SplusObjects.AnalogInput( CLEAR_PRESET_MODE__AnalogSerialInput__, this );
    m_AnalogInputList.Add( CLEAR_PRESET_MODE__AnalogSerialInput__, CLEAR_PRESET_MODE );
    
    STORE_PRESET_MODE = new Crestron.Logos.SplusObjects.AnalogInput( STORE_PRESET_MODE__AnalogSerialInput__, this );
    m_AnalogInputList.Add( STORE_PRESET_MODE__AnalogSerialInput__, STORE_PRESET_MODE );
    
    RECALL_PRESET_MODE = new Crestron.Logos.SplusObjects.AnalogInput( RECALL_PRESET_MODE__AnalogSerialInput__, this );
    m_AnalogInputList.Add( RECALL_PRESET_MODE__AnalogSerialInput__, RECALL_PRESET_MODE );
    
    CLEAR_PRESET_SCENE = new Crestron.Logos.SplusObjects.AnalogInput( CLEAR_PRESET_SCENE__AnalogSerialInput__, this );
    m_AnalogInputList.Add( CLEAR_PRESET_SCENE__AnalogSerialInput__, CLEAR_PRESET_SCENE );
    
    STORE_PRESET_SCENE = new Crestron.Logos.SplusObjects.AnalogInput( STORE_PRESET_SCENE__AnalogSerialInput__, this );
    m_AnalogInputList.Add( STORE_PRESET_SCENE__AnalogSerialInput__, STORE_PRESET_SCENE );
    
    RECALL_PRESET_SCENE = new Crestron.Logos.SplusObjects.AnalogInput( RECALL_PRESET_SCENE__AnalogSerialInput__, this );
    m_AnalogInputList.Add( RECALL_PRESET_SCENE__AnalogSerialInput__, RECALL_PRESET_SCENE );
    
    ALL_OUTPUT = new Crestron.Logos.SplusObjects.AnalogInput( ALL_OUTPUT__AnalogSerialInput__, this );
    m_AnalogInputList.Add( ALL_OUTPUT__AnalogSerialInput__, ALL_OUTPUT );
    
    OUTPUT = new InOutArray<AnalogInput>( 4, this );
    for( uint i = 0; i < 4; i++ )
    {
        OUTPUT[i+1] = new Crestron.Logos.SplusObjects.AnalogInput( OUTPUT__AnalogSerialInput__ + i, OUTPUT__AnalogSerialInput__, this );
        m_AnalogInputList.Add( OUTPUT__AnalogSerialInput__ + i, OUTPUT[i+1] );
    }
    
    TX_MATRIX = new Crestron.Logos.SplusObjects.StringOutput( TX_MATRIX__AnalogSerialOutput__, this );
    m_StringOutputList.Add( TX_MATRIX__AnalogSerialOutput__, TX_MATRIX );
    
    TO_SIO = new Crestron.Logos.SplusObjects.StringOutput( TO_SIO__AnalogSerialOutput__, this );
    m_StringOutputList.Add( TO_SIO__AnalogSerialOutput__, TO_SIO );
    
    RX_MATRIX = new Crestron.Logos.SplusObjects.BufferInput( RX_MATRIX__AnalogSerialInput__, 255, this );
    m_StringInputList.Add( RX_MATRIX__AnalogSerialInput__, RX_MATRIX );
    
    
    RX_MATRIX.OnSerialChange.Add( new InputChangeHandlerWrapper( RX_MATRIX_OnChange_0, false ) );
    CLEAR_PRESET_MODE.OnAnalogChange.Add( new InputChangeHandlerWrapper( CLEAR_PRESET_MODE_OnChange_1, false ) );
    STORE_PRESET_MODE.OnAnalogChange.Add( new InputChangeHandlerWrapper( STORE_PRESET_MODE_OnChange_2, false ) );
    RECALL_PRESET_MODE.OnAnalogChange.Add( new InputChangeHandlerWrapper( RECALL_PRESET_MODE_OnChange_3, false ) );
    CLEAR_PRESET_SCENE.OnAnalogChange.Add( new InputChangeHandlerWrapper( CLEAR_PRESET_SCENE_OnChange_4, false ) );
    STORE_PRESET_SCENE.OnAnalogChange.Add( new InputChangeHandlerWrapper( STORE_PRESET_SCENE_OnChange_5, false ) );
    RECALL_PRESET_SCENE.OnAnalogChange.Add( new InputChangeHandlerWrapper( RECALL_PRESET_SCENE_OnChange_6, false ) );
    for( uint i = 0; i < 4; i++ )
        OUTPUT[i+1].OnAnalogChange.Add( new InputChangeHandlerWrapper( OUTPUT_OnChange_7, false ) );
        
    ALL_OUTPUT.OnAnalogChange.Add( new InputChangeHandlerWrapper( ALL_OUTPUT_OnChange_8, false ) );
    
    _SplusNVRAM.PopulateCustomAttributeList( true );
    
    NVRAM = _SplusNVRAM;
    
}

public override void LogosSimplSharpInitialize()
{
    
    
}

public UserModuleClass_BG_4K_VP44PRO ( string InstanceName, string ReferenceID, Crestron.Logos.SplusObjects.CrestronStringEncoding nEncodingType ) : base( InstanceName, ReferenceID, nEncodingType ) {}




const uint RX_MATRIX__AnalogSerialInput__ = 0;
const uint CLEAR_PRESET_MODE__AnalogSerialInput__ = 1;
const uint STORE_PRESET_MODE__AnalogSerialInput__ = 2;
const uint RECALL_PRESET_MODE__AnalogSerialInput__ = 3;
const uint CLEAR_PRESET_SCENE__AnalogSerialInput__ = 4;
const uint STORE_PRESET_SCENE__AnalogSerialInput__ = 5;
const uint RECALL_PRESET_SCENE__AnalogSerialInput__ = 6;
const uint ALL_OUTPUT__AnalogSerialInput__ = 7;
const uint OUTPUT__AnalogSerialInput__ = 8;
const uint TX_MATRIX__AnalogSerialOutput__ = 0;
const uint TO_SIO__AnalogSerialOutput__ = 1;

[SplusStructAttribute(-1, true, false)]
public class SplusNVRAM : SplusStructureBase
{

    public SplusNVRAM( SplusObject __caller__ ) : base( __caller__ ) {}
    
    
}

SplusNVRAM _SplusNVRAM = null;

public class __CEvent__ : CEvent
{
    public __CEvent__() {}
    public void Close() { base.Close(); }
    public int Reset() { return base.Reset() ? 1 : 0; }
    public int Set() { return base.Set() ? 1 : 0; }
    public int Wait( int timeOutInMs ) { return base.Wait( timeOutInMs ) ? 1 : 0; }
}
public class __CMutex__ : CMutex
{
    public __CMutex__() {}
    public void Close() { base.Close(); }
    public void ReleaseMutex() { base.ReleaseMutex(); }
    public int WaitForMutex() { return base.WaitForMutex() ? 1 : 0; }
}
 public int IsNull( object obj ){ return (obj == null) ? 1 : 0; }
}


}
