-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenSmart32.cpp
More file actions
74 lines (60 loc) · 2.24 KB
/
Copy pathOpenSmart32.cpp
File metadata and controls
74 lines (60 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <Arduino.h>
#include "OpenSmart32.h"
//----------------------------------------------
// Constructor
//----------------------------------------------
OpenSmart32::OpenSmart32() {}
//----------------------------------------------
// Initialize the TFT display
//----------------------------------------------
void OpenSmart32::Initialize()
{
uint16_t ID;
//-----------------------------
// Screen initialization
//-----------------------------
ID = tft.readID();
// Screen equivalences
if (ID == 0x0D3D3) ID = 0x9481;
// Initialization
tft.begin(ID);
// if (tft.height() > tft.width())
tft.setRotation(Orientation);
// Touchscreen initialization
// switch (Orientation) // adjust for different aspects
// {
// case 0: break; //no change, calibrated for PORTRAIT
// case 1: tmp = TS_LEFT, TS_LEFT = TS_BOT, TS_BOT = TS_RT, TS_RT = TS_TOP, TS_TOP = tmp; break;
// case 2:
SWAP(TS_LEFT, TS_RT); SWAP(TS_TOP, TS_BOT); // break;
// case 3: tmp = TS_LEFT, TS_LEFT = TS_TOP, TS_TOP = TS_RT, TS_RT = TS_BOT, TS_BOT = tmp; break;
// }
ts = TouchScreen(XP, YP, XM, YM, 260); // call the constructor AGAIN with new values.
}
//----------------------------------------------
// Check for touchscreen press
//----------------------------------------------
void OpenSmart32::Dispatch()
{
tp = ts.getPoint(); // tp.x, tp.y are ADC values
// if sharing pins, you'll need to fix the directions of the touchscreen pins
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
pinMode(XP, OUTPUT);
pinMode(YM, OUTPUT);
if (tp.z > MINPRESSURE && tp.z < MAXPRESSURE)
{
delay(100);
// is controller wired for Landscape ? or are we oriented in Landscape?
if (SwapXY != (Orientation & 1)) SWAP(tp.x, tp.y);
if (OnDisplayClick)
{
// scale from 0->1023 to tft.width i.e. left = 0, rt = width
// most mcufriend have touch (with icons) that extends below the TFT
// screens without icons need to reserve a space for "erase"
// scale the ADC values from ts.getPoint() to screen values e.g. 0-239
OnDisplayClick(map(tp.x, TS_LEFT, TS_RT, tft.width(), 0),
map(tp.y, TS_TOP, TS_BOT, tft.height(), 0));
}
}
}