/********************************************************************* * Function: WORD GetPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: pixel position * * Output: pixel color * * Side Effects: none * * Overview: returns pixel at given position * * Note: none * ********************************************************************/ GFX_COLOR GetPixel(SHORT x, SHORT y) { BYTE columnPixel[3]; // 3 Pixels in each column DisplayEnable(); // Set Row and Column Address DisplaySetCommand(); DeviceWrite(LASET); DisplaySetData(); DeviceWrite(y + 16); DeviceWrite(0x8f); DisplaySetCommand(); DeviceWrite(CASET); DisplaySetData(); DeviceWrite(x / 3); DeviceWrite(0x54); // Read Column DisplaySetCommand(); DeviceWrite(RMWIN); DisplaySetData(); columnPixel[0] = DeviceRead(); // Dummy columnPixel[0] = DeviceRead(); // Start reading cycle for pixel 0 columnPixel[1] = DeviceRead(); // Start reading cycle for pixel 1 columnPixel[2] = DeviceRead(); // Start reading cycle for pixel 2 DisplaySetCommand(); DeviceWrite(RMWOUT); DisplayDisable(); DisplaySetData(); return (columnPixel[x % 3]); }
/********************************************************************* * Function: void PutPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: pixel position * * Output: none * * Side Effects: none * * Overview: puts pixel with current color at given position * * Note: none * ********************************************************************/ void PutPixel(SHORT x, SHORT y) { BYTE columnPixel[3]; // 3 Pixels in each column if(_clipRgn) { if(x < _clipLeft) return; if(x > _clipRight) return; if(y < _clipTop) return; if(y > _clipBottom) return; } DisplayEnable(); // Set Row and Column Address DisplaySetCommand(); DeviceWrite(LASET); DisplaySetData(); DeviceWrite(y + 16); DeviceWrite(0x8f); DisplaySetCommand(); DeviceWrite(CASET); DisplaySetData(); DeviceWrite(x / 3); DeviceWrite(0x54); // Read Column DisplaySetCommand(); DeviceWrite(RMWIN); DisplaySetData(); columnPixel[0] = DeviceRead(); // Dummy reading columnPixel[0] = DeviceRead(); // Start reading cycle for pixel 0 columnPixel[1] = DeviceRead(); // Start reading cycle for pixel 1 columnPixel[2] = DeviceRead(); // Start reading cycle for pixel 2 // Modify pixel columnPixel[x % 3] = _color; // Write Column DeviceWrite(columnPixel[0]); DeviceWrite(columnPixel[1]); DeviceWrite(columnPixel[2]); DisplaySetCommand(); DeviceWrite(RMWOUT); DisplayDisable(); DisplaySetData(); }
////////////////////////////////////////////////////////////////////////////// /// /// Send data to UART /// ////////////////////////////////////////////////////////////////////////////// void output_writer::send2UART(unsigned long data) { unsigned long status; DeviceRead(8, 0x00000008ul /*|< Status Register*/, &status); while((status & 0x08 /*|< bit 28 : indicates if transmit FIFO is full*/) == 0x08 /*|< bit 28 : indicates if transmit FIFO is full*/) { wait(1); DeviceRead(8, 0x00000008ul /*|< Status Register*/, &status); } DeviceWrite(8, 0x00000004ul /*|< Transmit FIFO*/, &data); }
/********************************************************************* * Function: WORD GetPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: x,y - pixel coordinates * * Output: pixel color * * Side Effects: none * * Overview: return pixel color at x,y position * * Note: none * ********************************************************************/ WORD GetPixel(SHORT x, SHORT y) { WORD_VAL result; DeviceSelect(); SetAddress(x, y); DeviceSetCommand(); DeviceWrite(CMD_READ); DeviceSetData(); result.v[0] = DeviceRead(); result.v[1] = DeviceRead(); DeviceDeselect(); return (result.Val); }
inline UINT8 EXTR::read_8_bits() { UINT8 inputValue; UINT8 alignment = (m_inputAdd & 0x3); if(alignment == 0 || !m_bufferValid) { // Address is a multiple of 4: need to read a new word from memory DeviceRead(JPEGRAM_ID, m_inputAdd & 0xFFFFFFFC, &m_inputBuffer[0], 4); m_bufferValid = true; } inputValue = m_inputBuffer[alignment]; m_inputAdd+=1; computeFor(1); return inputValue; }
// Main Program int main( int nArgs, char **args ) { // Read command line parameters if ( nArgs < 3 ) { std::cout << "Please specify output filename and run time (seconds)." << std::endl; return 1; } std::string outFileName(args[1]); int runTime(30); { std::stringstream tmp; tmp << std::string(args[2]); tmp >> runTime; } std::cout << "LED triggered run for " << runTime << " seconds: " << outFileName << std::endl; // Create the ROOT Application (to draw canvases) TApplication *theApp = new TApplication("LEDRun",&nArgs,args); //gStyle->SetPalette(1); // Configure the Argonne Board int err(0); uint nSamples = 600; //1024; // max = 2046 uint preTrigSamples = 50; err = ConfigArgoBoard_ExtTrig( nSamples, preTrigSamples ); if ( err != 0 ) { std::cout << "Failed to configure ANL Digitizer." << std::endl; return err; } // Get ANL Digitizer configuration info uint ANL_nSamples(0); DeviceRead(lbneReg.readout_window[0],&ANL_nSamples); uint ANL_preTrigSize(0); DeviceRead(lbneReg.readout_pretrigger[0],&ANL_preTrigSize); uint ANL_eventSize = sizeof(Event_Header) + 2*nSamples; // in bytes uint m1Size(0); DeviceRead(lbneReg.m1_window[0],&m1Size); uint m2Size(0); DeviceRead(lbneReg.m2_window[0],&m2Size); uint pWindow(0); DeviceRead(lbneReg.p_window[0],&pWindow); uint kWindow(0); DeviceRead(lbneReg.k_window[0],&kWindow); uint iWindow(0); DeviceRead(lbneReg.i_window[0],&iWindow); uint dWindow(0); DeviceRead(lbneReg.d_window[0],&dWindow); // Output File TFile *outFile = new TFile(outFileName.c_str(),"RECREATE"); TDirectory *waveDir = outFile->mkdir("waveforms"); std::vector<TH1D*> waveformExamples; // Set up output ROOT tree for ANL Digitizer TTree *ANLTree = new TTree("ANLTree","ANLTree"); Event_Packet ArPacket; Event ArEvent; ANLTree->Branch("channelID",&(ArEvent.channelID),"channelID/s"); ANLTree->Branch("syncDelay",&(ArEvent.syncDelay),"syncDelay/i"); ANLTree->Branch("syncCount",&(ArEvent.syncCount),"syncCount/i"); ANLTree->Branch("timestamp",&(ArEvent.intTimestamp),"timestamp/l"); ANLTree->Branch("peakSum",&(ArEvent.peakSum),"peakSum/I"); ANLTree->Branch("peakTime",&(ArEvent.peakTime),"peakTime/C"); ANLTree->Branch("prerise",&(ArEvent.prerise),"prerise/i"); ANLTree->Branch("integratedSum",&(ArEvent.integratedSum),"integratedSum/i"); ANLTree->Branch("baseline",&(ArEvent.baseline),"baseline/s"); ANLTree->Branch("cfdPoint",&(ArEvent.cfdPoint),"cfdPoint[4]/S"); ANLTree->Branch("nSamples",&(ArEvent.waveformWords),"nSamples/s"); std::stringstream waveformDescr; waveformDescr << "waveform[" << nSamples << "]/s"; ANLTree->Branch("waveform",&(ArEvent.waveform),waveformDescr.str().c_str()); // Set up configuration ROOT tree TTree *configTree = new TTree("configTree","configTree"); configTree->Branch("runTime",&runTime,"runTime/I"); configTree->Branch("ANL_nSamples",&ANL_nSamples,"ANL_nSamples/i"); configTree->Branch("ANL_preTrigSize",&ANL_preTrigSize,"ANL_preTrigSize/i"); configTree->Branch("m1Size",&m1Size,"m1Size/i"); configTree->Branch("m2Size",&m2Size,"m2Size/i"); configTree->Branch("pWindow",&pWindow,"pWindow/i"); configTree->Branch("kWindow",&kWindow,"kWindow/i"); configTree->Branch("iWindow",&iWindow,"iWindow/i"); configTree->Branch("dWindow",&dWindow,"dWindow/i"); configTree->Fill(); configTree->Write(); // Monitoring histograms TH1D *ANL_pulseAmp[32]; for ( int chan = 0; chan < 12; ++chan ) { std::stringstream histName; histName << "ANL_pulseAmp_CH" << chan; std::stringstream histTitle; histTitle << "Pulse Amplitudes, ANL Channel " << chan << ";ADC Counts"; ANL_pulseAmp[chan] = new TH1D(histName.str().c_str(),histTitle.str().c_str(),3000,0,3000); } std::cout << "Starting acquisition." << std::endl; // Enable boards err = DeviceTimeout(500); err = DeviceStart(); // Loop for specified time int totArEvts(0); time_t tStart(0), tEnd(0); time(&tStart); time(&tEnd); while ( tEnd - tStart < runTime ) { /*** ANL Digitizer Readout ***/ uint dataSize; err = DeviceQueueStatus(&dataSize); // How many full events have been collected? if ( err != 0 ) { std::cout << "Failed device queue status check." << std::endl; break; } uint ANL_nEvts = uint(dataSize) / ANL_eventSize; //if ( ANL_nEvts > 0 ) std::cout << "Received " << ANL_nEvts << " events on the Argonne Digitizer (" << dataSize << " bytes)." << std::endl; for ( uint evt = 0; evt < ANL_nEvts; ++evt ) { totArEvts++; uint dataReceived = 0; err = DeviceReceive(&ArPacket,&dataReceived); if ( err != 0 ) { std::cout << "Failed device receive." << std::endl; break; } err = LBNE_EventUnpack(&ArPacket,&ArEvent); if ( err != 0 ) { std::cout << "Failed to unpack data." << std::endl; break; } ANLTree->Fill(); ANL_pulseAmp[ArEvent.channelID]->Fill(ArEvent.prerise/double(kWindow)-ArEvent.peakSum/double(m1Size)); /* std::stringstream waveHistName; waveHistName << "waveform_" << totArEvts; TH1D *hist = new TH1D(waveHistName.str().c_str(),waveHistName.str().c_str(),nSamples,0,nSamples); for ( uint samp = 0; samp < nSamples; ++samp ) { hist->SetBinContent(samp+1,ArEvent.waveform[samp] & 0x3FFF); // 0x3FFF drops time marks on waveform, not necessary in next firmware upgrade } waveformExamples.push_back(hist); */ } //std::cout << tEnd-tStart << std::endl; time(&tEnd); } //// Finalize // Finalize Argonne Digitizer err = DeviceStopReset(); if ( err != 0 ) { std::cout << "Failed to stop and reset board 0. ErrorCode " << err << std::endl; return 1; } err = DeviceDisconnect(commUSB); // Write and close output file ANLTree->Write(); for ( int chan = 0; chan < 12; ++chan ) ANL_pulseAmp[chan]->Write(); waveDir->cd(); for ( uint i = 0; i < waveformExamples.size(); ++i ) { waveformExamples[i]->Write(); } outFile->cd(); outFile->Close(); // Done! std::cout << "Done! Collected " << totArEvts/12 << " events" << std::endl; return 0; }