Repository navigation
Expand file tree
/
Copy pathControlRingSegmentDisplay.cpp
More file actions
127 lines (99 loc) · 4.09 KB
/
Copy pathControlRingSegmentDisplay.cpp
File metadata and controls
127 lines (99 loc) · 4.09 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
//
// Created by codexzier on 29.04.26.
//
#include "ControlRingSegmentDisplay.h"
#include <math.h>
void ControlRingSegmentDisplay::drawInitGaugeSetup(int countSegments) {
_segmentsCount = countSegments;
float segmentWidth = 3.0; // Breite des Segments in Grad für die Optik
float angle = 0;
_segmentMultiplicator = 360.0 / _segmentsCount;
segmentWidth = _segmentMultiplicator / 2.0;
for (int index = 0; index < _segmentsCount; index++) {
_segmentsOnRing[index] = false;
angle = _startAngle + (index * _segmentMultiplicator);
drawGaugeSegment(angle, _colorOff, segmentWidth);
}
}
void ControlRingSegmentDisplay::setValue(int value)
{
if (value < 0 || value > _segmentsCount) {
return;
}
_segmentValueOn = value / _angleStep;
}
void ControlRingSegmentDisplay::setColor(uint16_t color) {
_colorOn = color;
}
int ControlRingSegmentDisplay::GetValue() {
return static_cast<int>(_segmentValueOn * _angleStep);
}
void ControlRingSegmentDisplay::drawGaugeUpdate() {
if (_withBuffer) {
for (int segmentIndex = 0; segmentIndex < _segmentsCount; segmentIndex++) {
float angle = _startAngle + (static_cast<float>(segmentIndex) * _segmentMultiplicator);
uint16_t color1 = _colorOn;
bool segmentOn = true;
if(_segmentValueOn <= segmentIndex) {
color1 = _colorOff;
segmentOn = false;
}
if (_segmentsOnRing[segmentIndex] == segmentOn) {
continue;
}
_segmentsOnRing[segmentIndex] = segmentOn;
drawGaugeSegment(angle, color1, _segmentMultiplicator / 2.0);
}
}
else {
if (_segmentIndex >= _segmentsCount) {
_segmentIndex = 0;
}
float angle = _startAngle + (_segmentIndex * _segmentMultiplicator);
uint16_t color1 = _colorOn;
bool segmentOn = true;
if(_segmentValueOn <= _segmentIndex) {
color1 = _colorOff;
segmentOn = false;
}
// if (_segmentsOnRing[_segmentIndex] == segmentOn) {
// _segmentIndex++;
// return;
// }
_segmentsOnRing[_segmentIndex] = segmentOn;
drawGaugeSegment(angle, color1, _segmentMultiplicator / 2.0);
_segmentIndex++;
}
}
// ========================================================================================
// Zeichnet ein einzelnes Segment für die Anzeige (Licht oder Lautstärke)
// @param angleDeg Der Winkel in Grad (0° ist rechts/3 Uhr, 270° ist oben/12 Uhr)
// @param color Die Farbe des Segments (RGB565)
// @param Äußerer Rand des Balkens (fast am Glas)
// @param Innerer Rand (Dicke des Balkens = 15px)
void ControlRingSegmentDisplay::drawGaugeSegment(
const float angleDeg,
const uint16_t color,
const float segmentWidth) {
// Feste Werte für das Design der Camping-Lampe
constexpr int centerX = 120; // Mitte des 240x240 Displays
constexpr int centerY = 120;
// Umrechnung von Winkeln zwischen Grad und Radiant.
float shiftAngle = angleDeg - 90.0;
const float rad = M_PI * shiftAngle / 180.0;
const float radOffset = (segmentWidth / 2.0) * M_PI / 180.0;
// Berechnung der 4 Eckpunkte des Segments für ein sauberes Rechteck
// Punkt A & B (Innen), Punkt C & D (Außen)
const int xA = centerX + cos(rad - radOffset) * _radiusInner;
const int yA = centerY + sin(rad - radOffset) * _radiusInner;
const int xB = centerX + cos(rad + radOffset) * _radiusInner;
const int yB = centerY + sin(rad + radOffset) * _radiusInner;
const int xC = centerX + cos(rad - radOffset) * _radiusOuter;
const int yC = centerY + sin(rad - radOffset) * _radiusOuter;
const int xD = centerX + cos(rad + radOffset) * _radiusOuter;
const int yD = centerY + sin(rad + radOffset) * _radiusOuter;
// Zeichnen des Segments.
// Wir füllen das Segment, indem wir zwei Dreiecke zeichnen (Standard-Verfahren für Polygone)
_tft->fillTriangle(xA, yA, xB, yB, xC, yC, color);
_tft->fillTriangle(xB, yB, xC, yC, xD, yD, color);
}