ERIS CORE

◆ update()

void FLASHMEM Touch::update ( void  )

Definition at line 34 of file touch.cpp.

35 {
36  //Serial.println("Touch:update");
37  int16_t data[6];
38 
39  if (!isrWake) return;
40  uint32_t now = millis();
41  if (now - msraw < MSEC_THRESHOLD) return;
42 
43  SPI1.beginTransaction(SPI_SETTING);
44  digitalWrite(csPin, LOW);
45  SPI1.transfer(0xB1 /* Z1 */);
46  int16_t z1 = SPI1.transfer16(0xC1 /* Z2 */) >> 3;
47  int z = z1 + 4095;
48  int16_t z2 = SPI1.transfer16(0x91 /* X */) >> 3;
49  z -= z2;
50  if (z >= Z_THRESHOLD) {
51  SPI1.transfer16(0x91 /* X */); // dummy X measure, 1st is always noisy
52  data[0] = SPI1.transfer16(0xD1 /* Y */) >> 3;
53  data[1] = SPI1.transfer16(0x91 /* X */) >> 3; // make 3 x-y measurements
54  data[2] = SPI1.transfer16(0xD1 /* Y */) >> 3;
55  data[3] = SPI1.transfer16(0x91 /* X */) >> 3;
56  }
57  else data[0] = data[1] = data[2] = data[3] = 0; // Compiler warns these values may be used unset on early exit.
58  data[4] = SPI1.transfer16(0xD0 /* Y */) >> 3; // Last Y touch power down
59  data[5] = SPI1.transfer16(0) >> 3;
60  digitalWrite(csPin, HIGH);
61  SPI1.endTransaction();
62  //Serial.printf("z=%d :: z1=%d, z2=%d ", z, z1, z2);
63  if (z < 0) z = 0;
64  if (z < Z_THRESHOLD) { // if ( !touched ) {
65  // Serial.println();
66  zraw = 0;
67  if (z < Z_THRESHOLD_INT) { // if ( !touched ) {
68  if (255 != tirqPin) isrWake = false;
69  }
70  return;
71  }
72  zraw = z;
73 
74  // Average pair with least distance between each measured x then y
75  //Serial.printf(" z1=%d,z2=%d ", z1, z2);
76  //Serial.printf("p=%d, %d,%d %d,%d %d,%d", zraw,
77  //data[0], data[1], data[2], data[3], data[4], data[5]);
78  int16_t x = besttwoavg( data[0], data[2], data[4] );
79  int16_t y = besttwoavg( data[1], data[3], data[5] );
80 
81  //Serial.printf(" %d,%d", x, y);
82  //Serial.println();
83  if (z >= Z_THRESHOLD) {
84  msraw = now; // good read completed, set wait
85  switch (rotation) {
86  case 0:
87  xraw = 4095 - y;
88  yraw = x;
89  break;
90  case 1:
91  xraw = x;
92  yraw = y;
93  break;
94  case 2:
95  xraw = y;
96  yraw = 4095 - x;
97  break;
98  default: // 3
99  xraw = 4095 - x;
100  yraw = 4095 - y;
101  }
102  }
103 }
uint8_t rotation
Definition: Touch.h:41
uint32_t msraw
Definition: Touch.h:42
uint8_t csPin
Definition: Touch.h:41
int16_t yraw
Definition: Touch.h:19
uint8_t tirqPin
Definition: Touch.h:41
int16_t zraw
Definition: Touch.h:19
int16_t xraw
Definition: Touch.h:19
static int16_t besttwoavg(int16_t x, int16_t y, int16_t z)
Definition: touch.cpp:22

References besttwoavg(), csPin, msraw, rotation, tirqPin, xraw, yraw, and zraw.

Referenced by AppManager::update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: