-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppTorchRun.cpp
More file actions
144 lines (116 loc) · 2.86 KB
/
Copy pathAppTorchRun.cpp
File metadata and controls
144 lines (116 loc) · 2.86 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Created by codexzier on 22.05.26.
//
#include "AppTorchRun.h"
#include "GC9A01_LTSM.hpp"
void AppTorchRun::setBackground() {
if (_colorTarget == _colorBackground &&
_brightness >= _brightnessLast - 1 &&
_brightness <= _brightnessLast + 1) {
return;
}
_brightnessLast = _brightness;
_colorBackground = _colorTarget;
int bright = static_cast<float>(_brightness) / 4096.0 * 120.0;
for (int iY = 0; iY < 120; iY++) {
if (iY <= bright) {
_tft->drawCircle(120, 120, iY, _colorBackground);
}
else {
_tft->drawCircle(120, 120, iY, _tft->C_BLACK);
}
}
}
bool AppTorchRun::animationRun(int animationEndCount) {
if (_modeAnimation1 < animationEndCount) {
_modeAnimation1++;
return false;
}
_modeAnimation1 = 0;
return true;
}
void AppTorchRun::setCircleAnimation() {
_tft->drawCircle(120, 120, _modeAnimation1, _colorCircle);
if (animationRun(120)) {
if (_colorCircle == _colorTarget) {
_colorCircle = _tft->C_BLACK;
}
else {
_colorCircle = _colorTarget;
}
}
}
void AppTorchRun::drawUpdate() {
switch (_mode) {
case 1: {
setBackground();
break;
}
case 2: {
setCircleAnimation();
break;
}
case 3: {
if (animationRun(120)) {
if (_colorBackground == _colorTarget) {
_colorTarget = _tft->C_BLUE;
}
else {
_colorTarget = _tft->C_RED;
}
//setBackground();
}
break;
}
}
}
void AppTorchRun::reset() {
_option = 1;
_canBeClosed = false;
_colorTarget = _tft->C_WHITE;
_colorBackground = _tft->C_RED;
_hasDraw = false;
_tft->clearBuffer(_tft->C_BLACK);
}
void AppTorchRun::setValue1(int16_t value) {
_brightness = value;
}
void AppTorchRun::setButton1() {
switch (_option) {
case 1: {
_colorTarget = _tft->C_WHITE;
_option++;
break;
}
case 2: {
_colorTarget = _tft->C_RED;
_option++;
break;
}
case 3: {
_colorTarget = _tft->C_BLUE;
_option = 1;
break;
}
}
}
void AppTorchRun::setButton2() {
if (_mode < 2) {
_mode++;
}
else {
_mode = 1;
}
_modeAnimation1 = 0;
_tft->fillScreen(_tft->C_BLACK);
int positionX = 50;
int positionY = 100;
_tft->setFont(FontDefault);
_tft->setCursor(positionX, positionY);
_tft->setTextColor(_tft->C_GREEN);
_tft->print("Mode");
char buffer[12];
sprintf(buffer, "%d", _mode);
_tft->setCursor(positionX, positionY + 20);
_tft->print(buffer);
}