-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGauge.cpp
More file actions
103 lines (80 loc) · 3.22 KB
/
Gauge.cpp
File metadata and controls
103 lines (80 loc) · 3.22 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
#include "Gauge.h"
/* ------------------------------------------------------------------------- */
/* Constructor */
/* ------------------------------------------------------------------------- */
Gauge::Gauge(Adafruit_ILI9341 * display, Measurement * measurement,
char * name, int32_t range_min, int32_t range_max) {
this->display = display;
this->value = 0;
this->value_last = 0;
this->value_min = range_min;
this->value_max = range_max;
this->has_limit_higher = 0;
this->has_limit_lower = 0;
this->limit_lower = 0;
this->limit_higher = 0;
this->padding = GAUGE_PADDING_DEFAULT;
this->measurement = measurement;
this->requires_redraw = 1;
this->colour_high = RED;
this->colour_low = CYAN;
this->colour_normal = GREEN;
strncpy(this->name, name, 16);
}
/* ------------------------------------------------------------------------- */
/* Drawing */
/* ------------------------------------------------------------------------- */
void Gauge::draw_frame(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
uint16_t colour) {
this->display->drawRect(x, y, w, h, colour);
}
/* ------------------------------------------------------------------------- */
void Gauge::redraw() {
this->requires_redraw = 1;
}
/* ------------------------------------------------------------------------- */
void Gauge::draw_centred_string(const char *buf, int x, int y)
{
int16_t x1, y1;
uint16_t w, h;
this->display->setTextWrap(0);
this->display->getTextBounds(buf, x, y, &x1, &y1, &w, &h);
int16_t final_x = x - (w / 2);
int16_t final_y = y - (h / 2);
this->display->setCursor(final_x, final_y + 1 );
this->display->print(buf);
}
/* ------------------------------------------------------------------------- */
/* Setters and Getters */
/* ------------------------------------------------------------------------- */
void Gauge::set_limit_lower(double value) {
this->has_limit_lower = 1;
this->limit_lower = value;
}
/* ------------------------------------------------------------------------- */
void Gauge::set_limit_higher(double value) {
this->has_limit_higher = 1;
this->limit_higher = value;
this->value_max = this->limit_higher * GAUGE_LIMIT_MULTIPLIER;
}
/* ------------------------------------------------------------------------- */
void Gauge::set_value(double value) {
this->value = value;
}
/* ------------------------------------------------------------------------- */
void Gauge::set_padding(uint8_t value) {
this->padding = value;
}
/* ------------------------------------------------------------------------- */
void Gauge::set_colour_normal(uint16_t value) {
this->colour_normal = value;
}
/* ------------------------------------------------------------------------- */
void Gauge::set_colour_low(uint16_t value) {
this->colour_low = value;
}
/* ------------------------------------------------------------------------- */
void Gauge::set_colour_high(uint16_t value) {
this->colour_high = value;
}
/* ------------------------------------------------------------------------- */