Thank you very much!
Ok, yes, I’m using a capacitive touch screen.
Could you be so kind to post me a link to start ? I’m a bit newbie, I tried a lot of pieces of code from codeshare following the links found on the old forum, but no one of them worked for me…
Thanks again!
Matteo
UPDATE:
I’ve found this promising class:
#region Event Delegates
public delegate void OnTouchDown(object sender, int x, int y, int finger, int touchId);
public delegate void OnTouchUp(object sender, int x, int y, int finger, int touchId);
public delegate void OnTouchMove(object sender, int x, int y, int finger, int touchId);
#endregion
public class NewHavenCapTouch
{
#region Enumerations
public enum DeviceModes
{
Normal = 0,
SystemInfo = 1,
TestMode = 4,
}
public enum GestureId
{
ZoomIn = 0x48,
ZoomOut = 0x49,
None = 0x00
}
#endregion
#region Variables
private InterruptPort _touchInterrupt;
private I2CDevice _i2cBus;
private I2CDevice.I2CTransaction[] _transactions;
private byte[] _addressBuffer, _resultBuffer;
private bool[] _touching;
private int[] _x, _y;
private bool _singleTouch;
#endregion
#region Constructor
public NewHavenCapTouch(Cpu.Pin interruptPin)
{
_addressBuffer = new byte[1];
_resultBuffer = new byte[1];
_transactions = new I2CDevice.I2CTransaction[2];
_touching = new bool[5];
_x = new int[5];
_y = new int[5];
_i2cBus = new I2CDevice(new I2CDevice.Configuration(0x38, 400));
_touchInterrupt = new InterruptPort(interruptPin, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
_touchInterrupt.OnInterrupt += (a, b, c) => touchEvent();
}
#endregion
#region Properties
public DeviceModes DeviceMode
{
get
{
// Bits 6 & 5
return (DeviceModes)ReadRegister(0x00);
}
}
public GestureId GestureID
{
get
{
return (GestureId)ReadRegister(0x01);
}
}
public bool SingleTouchMode
{
get { return _singleTouch; }
set { _singleTouch = value; }
}
public int TouchDownCount
{
get
{
// Bits 3 - 0
return (int)ReadRegister(0x02);
}
}
public int VendorId
{
get { return (int)ReadRegister(0xA3); }
}
public Version Version
{
get
{
return new Version(ReadRegister(0xA1), ReadRegister(0xA2));
}
}
#endregion
#region Events
public event OnTouchDown TouchDown;
protected virtual void OnTouchDown(object sender, int x, int y, int finger, int touchId)
{
if (TouchDown != null)
TouchDown(sender, x, y, finger, touchId);
}
public event OnTouchUp TouchUp;
protected virtual void OnTouchUp(object sender, int x, int y, int finger, int touchId)
{
if (TouchUp != null)
TouchUp(sender, x, y, finger, touchId);
}
public event OnTouchMove TouchMove;
protected virtual void OnTouchMove(object sender, int x, int y, int finger, int touchId)
{
if (TouchMove != null)
TouchMove(sender, x, y, finger, touchId);
}
#endregion
#region Private Methods
private byte ReadRegister(byte address)
{
_addressBuffer[0] = address;
_transactions[0] = I2CDevice.CreateWriteTransaction(_addressBuffer);
_transactions[1] = I2CDevice.CreateReadTransaction(_resultBuffer);
_i2cBus.Execute(this._transactions, 1000);
return _resultBuffer[0];
}
private void touchEvent()
{
byte reg = 0x03;
byte val;
int x, y;
int status;
int touchId;
int tc = 5;
if (_singleTouch)
tc = 1;
// New Haven allows for up to 5 touches
for (int i = 0; i < tc; i++)
{
val = ReadRegister(reg++);
status = val >> 6; // 0 = Down, 1 = Up, 2 = Contact, 3 = Reserved
x = ((val & 0x0F) << 8) + ReadRegister(reg++);
val = ReadRegister(reg++);
touchId = val >> 4;
y = ((val & 0x0F) << 8) + ReadRegister(reg++);
switch (status)
{
case 0: //Down
_touching[i] = true;
OnTouchDown(this, x, y, i, touchId);
break;
case 1: // Up
case 3: // Reserved
_touching[i] = false;
OnTouchUp(this, x, y, i, touchId);
break;
case 2: // Contact
// Make sure not to keep raising move
// unless we've actually moved
if (_x[i] != x || _y[i] != y)
{
OnTouchMove(this, x, y, i, touchId);
}
break;
}
_x[i] = x;
_y[i] = y;
reg += 2;
}
}
#endregion
}
but i don’t know which is the interrupt pin to be passed to the constructor in my configuration…
the example says:
touch = new NewHavenCapTouch((Cpu.Pin)43);
but in my case i get a unhandled exception…
Thanks again !
Matteo