private void APSCanvas_MouseUp(object sender, MouseButtonEventArgs e) { APSprocessing.calibrate(); }
private void screenUpdate(Object source, ElapsedEventArgs e) { /* * _bw1.DoWork += getmorebytes; //bytes1 * _bw1.RunWorkerCompleted += bw1_RunWorkerCompleted; * _bw2.DoWork += getmorebytes; //bytes2 * _bw2.RunWorkerCompleted += bw2_RunWorkerCompleted; * * void init () * { * _bw1.RunWorkerAsync(ref bytes1) * } * * * bw1_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e) * { * _bw2.RunWorkerAsync(ref bytes2) * processEvents(bytes1); * } * * * bw2_RunWorkerCompleted (object sender, RunWorkerCompletedEventArgs e) * { * _bw1.RunWorkerAsync(ref bytes1) * processEvents(bytes2); * } * * void getmorebytes(ref byte[] bytes) * { * lock(bytes) * { * * } * } * * void processEvents(bytes, APS, TD) * { * lock(bytes) * lock(APS) * { * * } * } * * void updateDisplay(APS, TD) * lock(APS) */ if (_runningAcquisition == false) { _runningAcquisition = true; _pixelData = Enumerable.Repeat((byte)0, 304 * 240).ToArray(); APSprocessing.DrawBox(_pixelDataAPS, _boxSizeX, _boxSizeY); if (ATISinterface.getWire(ATISinterface.ControlSignals.Enable_AER_TD) || ATISinterface.getWire(ATISinterface.ControlSignals.Enable_AER_APS)) { byte[] DataInTD = new byte[1]; int numbytesTD = 0; if (!APSprocessing._calibrated) { System.Threading.Thread.Sleep(50); //allow time to gather enough data for calibration } numbytesTD = ATISinterface.getEvents(ref DataInTD); if (numbytesTD > 0) { var numbytesTD_written = 0; stream = new MemoryStream(DataInTD); reader = new BinaryReader(stream); for (uint i = 0; i < numbytesTD; i += 4) { long timestamp = ((long)(DataInTD[i + 1] & 0x1F) << 8) + DataInTD[i] + timestamp_overflowCounter; var x = ((DataInTD[i + 1] & 0x20) << 3) + DataInTD[i + 2]; var y = DataInTD[i + 3]; var p = (DataInTD[i + 1] & 0x80) >> 7; var type = (DataInTD[i + 1] & 0x40) >> 6; if ((y == 240) && (x == 305)) { timestamp_overflowCounter += 1 << 13; } else if (y > 239) { y_error_Counter++; // these errors occur only at large Y and small X values } else if (type == 1) //if it is an exposure event EM { var evt_valid = APSprocessing.filterAPSEvent(timestamp, x, y, p, type); if (evt_valid) { APSprocessing.updateAPSdisplay(timestamp, x, y, p, type, _pixelDataAPS); } APSprocessing.processAPSevent(timestamp, x, y, p, type, evt_valid); } else if (type == 0) //if it is a TD event { var evt_valid = TDprocessing.filterTDEvent(timestamp, x, y, p, type); if (evt_valid) { TDprocessing.updateTDdisplay(timestamp, x, y, p, type, _pixelData); } TDprocessing.processTDevent(timestamp, x, y, p, type, evt_valid); } /* THIS PART IS IMPORTANT, HANDLES THE SACCADES * if (x == 2) * if (_logging == true) * { * _writerTD.Write(DataInTD, numbytesTD_written, (int)(i) - numbytesTD_written); * numbytesTD_written = (int)(i); * CloseLogging(); * imageSlideshow.databaseImage.saveImageIndex++; * if (imageSlideshow.databaseImage.saveArrayList.Count > imageSlideshow.databaseImage.saveImageIndex) * { * propFsTD = new FileStream(imageSlideshow.databaseImage.saveArrayList[imageSlideshow.databaseImage.saveImageIndex].ToString(), FileMode.Create); * _writerTD = new BinaryWriter(propFsTD); * }else * { * //_logging = false; * motorTimer.DisableTimer(); * //boxRecord.IsChecked = false; * } * } */ // } } if (ControlWindow._logging == true) { lock (ControlWindow.propFsTD) { if (ControlWindow._logging == true) { ControlWindow._writerTD.Write(DataInTD, numbytesTD_written, numbytesTD - numbytesTD_written); } } } reader.Dispose(); stream.Dispose(); } if (ControlWindow.clearPixelData) { _pixelDataAPS = Enumerable.Repeat((byte)0, 304 * 240).ToArray(); ControlWindow.clearPixelData = false; } Dispatcher.Invoke(DispatcherPriority.Send, new Action <byte[], byte[], byte[], byte[], byte[]>(HandleFrameData), _pixelData, _S1Data, _C1Data, _S2Data, _pixelDataAPS); if (!APSprocessing._calibrated) { APSprocessing.calibrate(); } } _runningAcquisition = false; } }