Exemple #1
0
 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();
     }
 }