//--------------------------------------------------------------------------- #include #pragma hdrstop #include "DASamp.h" #include "detect.h" #include "aiousb.h" #include #define FullCircle 6.283185307179586476925286766559 //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { TForm2 *form; form = new TForm2(NULL); form->ShowModal(); DeviceIndex = form->DeviceIndex; StopButton->Visible = false; } //--------------------------------------------------------------------------- void __fastcall TForm1::StartButtonClick(TObject *Sender) { double ClockHz; long ErrorCode; char temp[16]; Rot = 0; ClockHz = 40000; LogList->Items->Add("Opening"); ErrorCode = DACOutputOpen(DeviceIndex, &ClockHz); if(ErrorCode == ERROR_SUCCESS) { LogList->Items->Add("Opened for output"); StartButton->Visible = false; StopButton->Visible = true; Application->OnIdle = IdleFrame; } } //--------------------------------------------------------------------------- void __fastcall TForm1::IdleFrame(TObject *Sender, bool &Done) { double ErrorCode; int I; double EC, ES; double magicNum; // while (!done) // { if (!BGotDACData) { Rot += 0.0004; if (Rot > FullCircle) { Rot = Rot - FullCircle; } for (I = 0; I <= 7; I++) { magicNum = Rot + I * (2.0/7.0) * FullCircle; EC = cos(magicNum); ES = sin(magicNum); DACData[I].X = 2048 + ES * 2047; DACData[I].Y = 2048 + EC * 2047; DACData[I].R = DACData[I].G = 0; DACData[I].B = 0xfff; } BGotDACData = true; } ErrorCode = DACOutputFrame(DeviceIndex, sizeof(DACData)/sizeof(TDACPoint), &(DACData[0].X)); if (ErrorCode == ERROR_SUCCESS) { BGotDACData = false; } else if (ErrorCode == ERROR_NOT_READY) { NULL; } else { exit(-1); } // } Done = false; } void __fastcall TForm1::StopButtonClick(TObject *Sender) { Application->OnIdle = NULL; LogList->Items->Add("Closing..."); DACOutputClose(DeviceIndex, 1); LogList->Items->Add("Closed"); StopButton->Visible = false; StartButton->Visible = true; } //---------------------------------------------------------------------------