示例#1
0
        public static void CalibrateTouchscreen(VirtualCanvas canvas)
        {
            var sd = new SDCardReader();

            try {
                sd.Initialize(SDSocket);
                var calibrationDataFilename = @"SD\TouchscreenCalibration.bin";
                if (File.Exists(calibrationDataFilename))
                {
                    using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Open)) {
                        var context = new BasicTypeDeSerializerContext(calibrationDataFile);
                        var matrix  = new CalibrationMatrix();
                        matrix.Get(context);
                        canvas.SetTouchscreenCalibrationMatrix(matrix);
                    }
                }
                else
                {
                    using (var calibrationDataFile = new FileStream(calibrationDataFilename, FileMode.Create)) {
                        var matrix  = canvas.GetTouchscreenCalibrationMatrix();
                        var context = new BasicTypeSerializerContext(calibrationDataFile);
                        matrix.Put(context);
                    }
                }
            } catch (Exception e) {
                Debug.Print(e.Message);
                Debug.Print("SD Card or file I/O error: manual calibration required.");
                canvas.TouchscreenCalibration();
            }
            sd.Dispose();
        }
示例#2
0
 public static void CalibrateTouchscreen(VirtualCanvas canvas)
 {
     try {
         //var sd = new SDCardReader();
         //sd.Initialize(SPI.SPI_module.SPI1,Pins.GPIO_PIN_D10);
         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 BasicTypeDeSerializerContext(calibrationDataFile);
                 var matrix  = new 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 BasicTypeSerializerContext(calibrationDataFile);
                 matrix.Put(context);
             }
         }
         //sd.Dispose();
     } catch (Exception) {
         Debug.Print("SD Card or file I/O error: manual calibration required.");
         canvas.TouchscreenCalibration();
     }
 }
示例#3
0
 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;
 }