A controller for a 5 wire resistive touch screen

Revision:
1:ed8485a78c6a
Parent:
0:a3b5665b0a24
Child:
2:d0930962a3bb
--- a/TouchController.hpp	Thu Sep 15 13:27:01 2016 +0000
+++ b/TouchController.hpp	Thu Sep 15 15:38:12 2016 +0200
@@ -0,0 +1,58 @@
+#ifndef TOUCHCONTROLLER_H
+#define TOUCHCONTROLLER_H
+
+// Macros for calibration function
+#define X_T1 t[0][0]
+#define X_T2 t[1][0]
+#define X_T3 t[2][0]
+
+#define Y_T1 t[0][1]
+#define Y_T2 t[1][1]
+#define Y_T3 t[2][1]
+
+#define X_D1 d[0][0]
+#define X_D2 d[1][0]
+#define X_D3 d[2][0]
+
+#define Y_D1 d[0][1]
+#define Y_D2 d[1][1]
+#define Y_D3 d[2][1]
+
+//Includes
+#include "mbed.h"
+
+class TouchController
+{
+public:
+  TouchController(PinName ur, PinName lr, PinName s, PinName ul, PinName ll, int num_of_samples = 5, uint32_t settle = 80);
+
+  int TouchDetected();
+
+  float RawX();
+  float RawY();
+
+  float X();
+  float Y();
+
+  void Calibrate(float t[3][2], float d[3][2]);
+private:
+  DigitalInOut _UR;
+  DigitalInOut _LR;
+  PinName _S;
+  DigitalInOut _UL;
+  DigitalInOut _LL;
+
+  static const char DETECT_MODE = 1;
+  static const char X_MODE = 2;
+  static const char Y_MODE = 3;
+
+  float A,B,C,D,E,F;
+
+  int _samples;
+  uint32_t _settle;
+
+  void ConfigPins(char mode);
+  float MeasureS();
+
+};
+#endif