1) If I do a touch calib in debug mode and capture the calibration matrix, can it be "good enough" for other displays? I bought two and tested this and at least with these two, the calibration profiles seem to work.
private static void CalibrateTouchScreen() { byte[] calib=new byte[33]{0 ,0 ,3 ,0 ,33 ,0 ,5 ,229 ,192 ,0 ,0 ,1 ,128 ,174 ,6 ,50 ,80 ,255 ,255 ,133 ,0 ,0 ,7 ,133 ,128 ,148 ,104 ,208 ,64 ,255 ,177 ,35 ,14 }; // change to =null or new byte[0] to get initial calibration if (calib != null && calib.Length > 0) { BasicTypeDeSerializerContext b = new BasicTypeDeSerializerContext(calib); var matrix = new CalibrationMatrix(); matrix.Get(B); Screen.SetTouchscreenCalibrationMatrix(matrix); } else { Screen.TouchscreenCalibration(); var matrix = Screen.GetTouchscreenCalibrationMatrix(); if (matrix != null) { BasicTypeSerializerContext b = new BasicTypeSerializerContext(); matrix.Put(B); int x; calib = b.GetBuffer(out x); // break point here in debug mode and view calib } } }
2) How do you poll for a touch event so you don't block your main thread? I tried
Screen.TouchscreenWaitForEvent(); Screen.Execute(Synchronicity.Asynchronous);
Which seems to work the very first time, but doesn't get any touch events after that.
static int CenterX=240/2; static int CenterY=320/2; static int CircleRadius = 240 / 4; static BasicColor BottomColor=BasicColor.White; static BasicColor TopColor=BasicColor.Green; private static void ScreenTouched(object o, TouchEvent e) { if(BottomColor==BasicColor.White) BottomColor=BasicColor.Blue; else BottomColor=BasicColor.White; Screen.DrawCircleFilled(CenterX, CenterY+CircleRadius, CircleRadius, (ushort)BottomColor); } public static void Main() { Screen.Initialize(GoSockets.Socket1); CalibrateTouchScreen(); Screen.SetOrientation(Orientation.Portrait); Screen.DrawFill((ushort)BasicColor.Black); Screen.Execute(); while(true) { Screen.TouchscreenWaitForEvent(); Screen.Execute(Synchronicity.Asynchronous); // if I get rid of Asynchronous, it blocks here if(TopColor==BasicColor.Green) TopColor=BasicColor.Red; else TopColor=BasicColor.Green; Screen.DrawCircleFilled(CenterX, CenterY-CircleRadius, CircleRadius, (ushort)TopColor); Screen.Execute(); } }
3) GetStringWidth may be broken on different fonts. Verdana9 seems to be offset 20 pixels too far to the left when I try this, but Verdana14 works perfectly.
Screen.SetOrientation(Orientation.Portrait); Screen.DrawFill((ushort)BasicColor.Black); string Message = "Center Test"; int ScreenWidth = 240; FontInfo TextFont = new Verdana9().GetFontInfo(); Screen.DrawString((ScreenWidth / 2) - (TextFont.GetStringWidth(Message) / 2), 0, (ushort)BasicColor.Red, TextFont.ID, Message); TextFont = new Verdana14().GetFontInfo(); Screen.DrawString((ScreenWidth / 2) - (TextFont.GetStringWidth(Message) / 2), 100, (ushort)BasicColor.White, TextFont.ID, Message);