//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

#include "./SDK/SL04.h" //only include our header file


//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

unsigned char U0_DMXData[512], U1_DMXData[512], U2_DMXData[512], U3_DMXData[512]; //save 4 PORT dmx data, each is 512 channels

unsigned char box0_DMXData[2048]; //save box1 2048 channels data
unsigned char box1_DMXData[2048]; //save box2 2048 channels data

AnsiString IP1 = "2.0.0.44";
AnsiString IP2 = "2.0.0.45";

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)   //Allto255
{
	for(int i=0; i<512; i++)
	{
		U0_DMXData[ i ] = 255;	//all to 255, light on
		U1_DMXData[ i ] = 255;	//all to 255, light on
		U2_DMXData[ i ] = 255;	//all to 255, light on
		U3_DMXData[ i ] = 255;	//all to 255, light on
	}

	DMXSendBox(0,U0_DMXData); //Send 512 byte(channels) DMX data to PORT0
	DMXSendBox(1,U1_DMXData); //Send 512 byte(channels) DMX data to PORT1
	DMXSendBox(2,U2_DMXData); //Send 512 byte(channels) DMX data to PORT2
	DMXSendBox(3,U3_DMXData); //Send 512 byte(channels) DMX data to PORT3
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender) //Allto0
{
	for(int i=0; i<512; i++)
	{
		U0_DMXData[ i ] = 0;	//all to 0, light off
		U1_DMXData[ i ] = 0;	//all to 0, light off
		U2_DMXData[ i ] = 0;	//all to 0, light off
		U3_DMXData[ i ] = 0;	//all to 0, light off
	}

	DMXSendBox(0,U0_DMXData); //Send 512 byte(channels) DMX data to PORT0
	DMXSendBox(1,U1_DMXData); //Send 512 byte(channels) DMX data to PORT1
	DMXSendBox(2,U2_DMXData); //Send 512 byte(channels) DMX data to PORT2
	DMXSendBox(3,U3_DMXData); //Send 512 byte(channels) DMX data to PORT3

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)//AllTo128
{
	for(int i=0; i<2048; i++)
	{
		box0_DMXData[ i ] = 128;	//all to 128, light on
		box1_DMXData[ i ] = 128;	//all to 128, light on
	}


	for(int i=0; i<4; i++)
	{
		DMXSendUniverse( IP1.c_str(), i, &box0_DMXData[ i*512 ]); //send to box0 each universe 0,1,2,3
		DMXSendUniverse( IP2.c_str(), i+4, &box1_DMXData[ i*512 ]); //send to box1 each universe 4,5,6,7
	}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)//AllTo0
{
    for(int i=0; i<2048; i++)
	{
		box0_DMXData[ i ] = 0;	//all to 0, light off
		box1_DMXData[ i ] = 0;	//all to 0, light off
	}

	for(int i=0; i<4; i++)
	{
		DMXSendUniverse( IP1.c_str(), i, &box0_DMXData[ i*512 ]); //send to box0 each universe 0,1,2,3
		DMXSendUniverse( IP2.c_str(), i+4, &box1_DMXData[ i*512 ]); //send to box1 each universe 4,5,6,7
	}
}
//---------------------------------------------------------------------------
