@@ -177,7 +177,7 @@ void Touch::tsShutdown()
177
177
*/
178
178
void Touch::tsGetRawData (uint8_t *b)
179
179
{
180
- tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, b, 16 );
180
+ tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, b, 16 );
181
181
}
182
182
183
183
/* *
@@ -200,7 +200,8 @@ uint8_t Touch::tsGetData(uint16_t *xPos, uint16_t *yPos, uint8_t *z)
200
200
struct cypressTouchData _touchReport;
201
201
202
202
// Check for the null-pointer.
203
- if (xPos == NULL || yPos == NULL ) return 0 ;
203
+ if (xPos == NULL || yPos == NULL )
204
+ return 0 ;
204
205
205
206
// Fill the array with zeros.
206
207
xPos[0 ] = 0 ;
@@ -216,14 +217,16 @@ uint8_t Touch::tsGetData(uint16_t *xPos, uint16_t *yPos, uint8_t *z)
216
217
}
217
218
218
219
// Check the flag for the new data.
219
- if (!_tsFlag) return 0 ;
220
+ if (!_tsFlag)
221
+ return 0 ;
220
222
221
223
// If there is new data, clear the interrupt flag.
222
224
_tsFlag = false ;
223
225
224
226
// Read the new data from the touchscreen controller IC.
225
227
// Return zero detected fingers if reading has failed.
226
- if (!tsGetTouchData (&_touchReport)) return 0 ;
228
+ if (!tsGetTouchData (&_touchReport))
229
+ return 0 ;
227
230
228
231
// Scale it to fit the screen.
229
232
tsScale (&_touchReport, E_INK_WIDTH - 1 , E_INK_HEIGHT - 1 , false , true , true );
@@ -252,25 +255,25 @@ uint8_t Touch::tsGetData(uint16_t *xPos, uint16_t *yPos, uint8_t *z)
252
255
// Check for each finger.
253
256
for (int i = 0 ; i < _touchReport.fingers ; i++)
254
257
{
255
- switch (getRotation ())
258
+ switch (getRotation ())
256
259
{
257
- case 1 :
258
- // Rotation clockwise (to the right - aka. portrait mode).
259
- _temp = xPos[i];
260
- xPos[i] = map (yPos[i], 0 , E_INK_HEIGHT, 0 , E_INK_HEIGHT);
261
- yPos[i] = map (_temp, 0 , E_INK_WIDTH - 1 , E_INK_WIDTH - 1 , 0 );
262
- break ;
263
- case 2 :
264
- // Flipped by 180 deg.
265
- xPos[i] = map (xPos[i], 0 , E_INK_WIDTH - 1 , E_INK_WIDTH - 1 , 0 );
266
- yPos[i] = map (yPos[i], 0 , E_INK_HEIGHT - 1 , E_INK_HEIGHT - 1 , 0 );
267
- break ;
268
- case 3 :
269
- // Rotation counter-clockwise from default rotation (90 degs to the left).
270
- _temp = xPos[i];
271
- xPos[i] = map (yPos[i], 0 , E_INK_HEIGHT - 1 , E_INK_HEIGHT - 1 , 0 );
272
- yPos[i] = map (_temp, 0 , E_INK_WIDTH - 1 , 0 , E_INK_WIDTH - 1 );
273
- break ;
260
+ case 1 :
261
+ // Rotation clockwise (to the right - aka. portrait mode).
262
+ _temp = xPos[i];
263
+ xPos[i] = map (yPos[i], 0 , E_INK_HEIGHT, 0 , E_INK_HEIGHT);
264
+ yPos[i] = map (_temp, 0 , E_INK_WIDTH - 1 , E_INK_WIDTH - 1 , 0 );
265
+ break ;
266
+ case 2 :
267
+ // Flipped by 180 deg.
268
+ xPos[i] = map (xPos[i], 0 , E_INK_WIDTH - 1 , E_INK_WIDTH - 1 , 0 );
269
+ yPos[i] = map (yPos[i], 0 , E_INK_HEIGHT - 1 , E_INK_HEIGHT - 1 , 0 );
270
+ break ;
271
+ case 3 :
272
+ // Rotation counter-clockwise from default rotation (90 degs to the left).
273
+ _temp = xPos[i];
274
+ xPos[i] = map (yPos[i], 0 , E_INK_HEIGHT - 1 , E_INK_HEIGHT - 1 , 0 );
275
+ yPos[i] = map (_temp, 0 , E_INK_WIDTH - 1 , 0 , E_INK_WIDTH - 1 );
276
+ break ;
274
277
}
275
278
}
276
279
}
@@ -281,19 +284,20 @@ uint8_t Touch::tsGetData(uint16_t *xPos, uint16_t *yPos, uint8_t *z)
281
284
282
285
/* *
283
286
* @brief Get the new touch event data from the touchscreen controller.
284
- *
287
+ *
285
288
* @param struct cypressTouchData _touchData
286
289
* Pointer to the structure for the touch report data (such as X, Y and
287
- * Z values of each touch channel, nuber of fingers etc.)
288
- *
290
+ * Z values of each touch channel, nuber of fingers etc.)
291
+ *
289
292
* @return bool
290
293
* true - Touch data is successfully read and the data is valid.
291
294
* false - Touch data read has failed.
292
295
*/
293
296
bool Touch::tsGetTouchData (struct cypressTouchData *_touchData)
294
297
{
295
298
// Check for the null-pointer trap.
296
- if (_touchData == NULL ) return false ;
299
+ if (_touchData == NULL )
300
+ return false ;
297
301
298
302
// Clear struct for touchscreen data.
299
303
memset (_touchData, 0 , sizeof (cypressTouchData));
@@ -303,7 +307,8 @@ bool Touch::tsGetTouchData(struct cypressTouchData *_touchData)
303
307
304
308
// Read registers for the touch data (32 bytes of data).
305
309
// If read failed for some reason, return false.
306
- if (!tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, _regs, sizeof (_regs))) return false ;
310
+ if (!tsReadI2CRegs (CYPRESS_TOUCH_BASE_ADDR, _regs, sizeof (_regs)))
311
+ return false ;
307
312
308
313
// Send a handshake.
309
314
tsHandshake ();
@@ -335,21 +340,22 @@ bool Touch::tsGetTouchData(struct cypressTouchData *_touchData)
335
340
336
341
/* *
337
342
* @brief Method scales, flips and swaps X and Y cooridinates to ensure X and Y matches the screen.
338
- *
343
+ *
339
344
* @param struct cypressTouchData _touchData
340
- * Defined in cypressTouchTypedefs.h. Filled touch data report.
345
+ * Defined in cypressTouchTypedefs.h. Filled touch data report.
341
346
* @param uint16_t _xSize
342
347
* Screen size in pixels for X axis.
343
348
* @param uint16_t _ySize
344
349
* Screen size in pixels for Y axis.
345
350
* @param bool _flipX
346
351
* Flip the direction of the X axis.
347
- * @param bool _flipY
352
+ * @param bool _flipY
348
353
* Flip the direction of the Y axis.
349
354
* @param bool _swapXY
350
355
* Swap X and Y cooridinates.
351
356
*/
352
- void Touch::tsScale (struct cypressTouchData *_touchData, uint16_t _xSize, uint16_t _ySize, bool _flipX, bool _flipY, bool _swapXY)
357
+ void Touch::tsScale (struct cypressTouchData *_touchData, uint16_t _xSize, uint16_t _ySize, bool _flipX, bool _flipY,
358
+ bool _swapXY)
353
359
{
354
360
// Temp. variables for the mapped value.
355
361
uint16_t _mappedX = 0 ;
@@ -359,8 +365,10 @@ void Touch::tsScale(struct cypressTouchData *_touchData, uint16_t _xSize, uint16
359
365
for (int i = 0 ; i < _touchData->fingers ; i++)
360
366
{
361
367
// Check for the flip.
362
- if (_flipX) _touchData->x [i] = CYPRESS_TOUCH_MAX_X - _touchData->x [i];
363
- if (_flipY) _touchData->y [i] = CYPRESS_TOUCH_MAX_Y - _touchData->y [i];
368
+ if (_flipX)
369
+ _touchData->x [i] = CYPRESS_TOUCH_MAX_X - _touchData->x [i];
370
+ if (_flipY)
371
+ _touchData->y [i] = CYPRESS_TOUCH_MAX_Y - _touchData->y [i];
364
372
365
373
// Check for X and Y swap.
366
374
if (_swapXY)
0 commit comments