Touch calibration

This question may have come up before and I’ve searched the forum but no reference…

I’ve a Fez Cobra and 4.3 tft… I’ve configured it for LCD change to 4.3 and its ok, however, the touch calibration sample from microsoft works ok but it doesn’t store the calibration back to the board. After the sample runs the calibration looks good but any program run after this reverts back to the wrong settings…

Any Ideas


Yes you need to save the calibration info. EWR is a good way to do so

Sorry about the novice bit… I used to be a die hard pic man

whats EWR ???

[quote]whats EWR

Yes, What is EWR?
I want to know too! ???

The only reference to EWR was extended weak reference but its unclear what this is for

The Microsoft SDK includes an example for EWR. The example seems to be very clear on EWR usage.

EWR is used to same simple settings on internal flash. You could use an SD card or anything else but EWR will make it easier for you.

Some thing that I can’t understand… If touch calibration data as to be stored and retreived every boot!! How come the LCD size wasn’t lost on boot?

Are there other persistant values I’l have to keep check on?

I do think this is an easy way to produce a marketable product though.

Good question :slight_smile:

Set LCD size is a GHI feature specific feature and we do save that in flash.
Set calibration is Microsoft feature and it is not saved in flash. Maybe this will be saved in future reversions but for now you have to save it.

I have an easier way to save the values, use the battery ram if you like.


If you download the Pyxis beta you’ll find code for saving and loading calibration settings.

        #region Saved Settings

        /// <summary>
        /// This private class is used as a signature to uniquely identify data 
        /// we own.  It is not necessary to create a dedicated class for this 
        /// purpose.
        /// </summary>
        private static class Pyxis2SavedSettings { }

        /// <summary>
        /// Saved user settings
        /// </summary>
        private static ExtendedWeakReference SavedSettings;

        private static Settings uSettings;

        /// <summary>
        /// This is the class that will be stored in Flash memory.  This class 
        /// must be serializable.
        /// </summary>
        private sealed class Settings
            /// <summary>
            /// This method sets the number of boots.
            /// </summary>
            /// <param name="bootCount">The number of times the device has been 
            /// booted.</param>
            public Settings(bool bEnableDHCP, int iCalibrate, int iScreenSet, int iCalibrationPoints, short[] icalibrationSX, short[] icalibrationSY, short[] icalibrationCX, short[] icalibrationCY, Color Desktop, int Wallpaper)
                enableDHCP = bEnableDHCP;
                calibrateLCD = iCalibrate;
                screenSet = iScreenSet;
                calibrationPoints = iCalibrationPoints;
                calibrationSX = icalibrationSX;
                calibrationSY = icalibrationSY;
                calibrationCX = icalibrationCX;
                calibrationCY = icalibrationCY;
                desktop = Desktop;
                wallpaper = Wallpaper;

            // Fields must be serializable.
            public bool enableDHCP;
            public int calibrateLCD;
            public int screenSet;
            public int calibrationPoints;
            public short[] calibrationSX;
            public short[] calibrationSY;
            public short[] calibrationCX;
            public short[] calibrationCY;
            public Color desktop;
            public int wallpaper;

        private static void loadSettings()
            // Grab the data
            SavedSettings = ExtendedWeakReference.RecoverOrCreate(typeof(Pyxis2SavedSettings), 0, ExtendedWeakReference.c_SurvivePowerdown);
            SavedSettings.Priority = (Int32)ExtendedWeakReference.PriorityLevel.Critical;
            uSettings = (Settings)SavedSettings.Target;

            // Work with the data
            if (uSettings == null)
                // First Boot
                uSettings = new Settings(true, 1, 1, 0, null, null, null, null, Colors.Blue, 1);
                switch (uSettings.screenSet)
                    case 0:     // None
                    case 1:     // 320x240
                        uSettings.screenSet = 0;
                        SavedSettings.Target = uSettings;
                    case 2:     // 480x272
                        uSettings.screenSet = 0;
                        SavedSettings.Target = uSettings;
                    case 3:     // 800x600
                        Debug.Print("Changing screen size to 800x600");
                        Debug.Print("Code for 800x600 does not exist yet!");

            // Copy needed data
            _wallpaper = uSettings.wallpaper;
            _desktop = uSettings.desktop;

            // Persist the data
            SavedSettings.Target = uSettings;

            if (uSettings.enableDHCP) ethernet_online = enableDHCP();

        public void saveCalibration(int iCalibrationPoints, short[] icalibrationSX, short[] icalibrationSY, short[] icalibrationCX, short[] icalibrationCY)
            uSettings.calibrateLCD = 2;
            uSettings.calibrationPoints = iCalibrationPoints;
            uSettings.calibrationSX = icalibrationSX;
            uSettings.calibrationSY = icalibrationSY;
            uSettings.calibrationCX = icalibrationCX;
            uSettings.calibrationCY = icalibrationCY;
            SavedSettings.Target = uSettings;

1 Like

Firstly I’dlike to thank you both for all that help.

My project will include an off board 24LC1024 for calibration details specific to individual cranes I will save the settings to that device… but for now I have displayed cx cy sx and sy on screen, jotted them down, and will intialise the touch object each boot. I can get on with porting all my code to c#.

I also have noticed there is an ebook called “ framework” @ they have all the source code examples from the book free for download… quite an extensive library and a munber of sample emulators to boot!!

once again thank for the help

You asked this question in another thread. Please do not repeat questions or reopen a two year old thread.