public static void CalibrateTouchscreen(NwazetGoImaging.VirtualCanvas canvas) { try { var sd = new NwazetGoSD.SDCardReader(); sd.Initialize(GoSockets.Socket8); var calibrationDataFilename = @"SD\TouchscreenCalibration.bin"; // If the touchscreen calibration data was previously retrieved from the display module and was stored to an SD card, // the calibration data can be sent to the display module instead of calling TouchscreenCalibration() before using // the touchscreen for the first time. if (File.Exists(calibrationDataFilename)) { using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Open)) { var context = new NwazetGoHelpers.BasicTypeDeSerializerContext(calibrationDataFile); var matrix = new NwazetGoDisplayTouchScreen.CalibrationMatrix(); matrix.Get(context); canvas.SetTouchscreenCalibrationMatrix(matrix); } } else { // No pre-existing calibration data, create it... using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Create)) { var matrix = canvas.GetTouchscreenCalibrationMatrix(); var context = new NwazetGoHelpers.BasicTypeSerializerContext(calibrationDataFile); matrix.Put(context); } } sd.Dispose(); } catch (Exception) { Debug.Print("SD Card or file I/O error: manual calibration required."); canvas.TouchscreenCalibration(); } }
public void SetTouchscreenCalibrationMatrix(CalibrationMatrix matrix) { BasicTypeSerializer.Put(SendContext, (byte)Command.TouchscreenSetCalibrationMatrix); matrix.Put(SendContext); Execute(); }
public CalibrationMatrix GetTouchscreenCalibrationMatrix() { BasicTypeSerializer.Put(SendContext, (byte)Command.TouchscreenGetCalibrationMatrix); Execute(); Receive(); TouchScreenDataType eventType = (TouchScreenDataType)BasicTypeDeSerializer.Get(ReceiveContext); if (eventType != TouchScreenDataType.CalibrationMatrix) { throw new ApplicationException("eventType"); } var matrix = new CalibrationMatrix(); matrix.Get(ReceiveContext); return matrix; }