-
Notifications
You must be signed in to change notification settings - Fork 0
/
oled_printing.cpp
118 lines (97 loc) · 2.42 KB
/
oled_printing.cpp
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
#include "oled_printing.h"
PrintHPS::PrintHPS()
{
oled = new Adafruit_SSD1306(4);
size = 0;
index = 0;
data = new HPSVals[size];
}
PrintHPS::PrintHPS(int size)
{
oled = new Adafruit_SSD1306(4);
this->size = size;
index = 0;
data = new HPSVals[size];
}
void PrintHPS::setSize(int size)
{
this->size = size;
delete data;
data = new HPSVals[size];
}
const char* PrintHPS::add(HPSVals newEntry)
{
if (index < size)
{
data[index] = newEntry;
index++;
return "Entry added.";
}
return "Addition failed - No more room in the array.";
}
void PrintHPS::resetIndex()
{
index = 0;
}
void PrintHPS::setIndex(int index)
{
this->index = index;
}
int PrintHPS::getNext()
{
int output = index;
output++;
if (output == size) output = 0; //wrap back to the beginning if we advance too far
return output;
}
int PrintHPS::getPrev()
{
int output = index;
output--;
if (output < 0) output = size-1; //go to the last element if we go back too far
return output;
}
//does not print the value of the varible, only sets up the screen with the title and prev/next indicators
void PrintHPS::printHeaders()
{
oled->clearDisplay();
oled->setTextColor(WHITE, BLACK);
oled->setCursor(0,0);
oled->setTextSize(2);
oled->println(data[index].name_of_variable);
oled->setCursor(0,56);
oled->setTextSize(1);
oled->print("< ");
oled->print(data[getPrev()].name_of_variable);
oled->print(" ");
oled->print(data[getNext()].name_of_variable);
oled->print(" >");
oled->display();
}
void PrintHPS::initialize_oled(byte addr)
{
//Adafruit splash screen is in the buffer by default
oled->begin(SSD1306_SWITCHCAPVCC, addr);
oled->display();
}
void PrintHPS::printsomething(){
oled->clearDisplay();
uint8_t color = WHITE;
for (int16_t i=0; i<oled->height()/2-2; i+=2)
{
oled->fillRoundRect(i, i, oled->width()-2*i, oled->height()-2*i, oled->height()/4, color);
if (color == WHITE) color = BLACK;
else color = WHITE;
oled->display();
}
}
void PrintHPS::refresh()
{
oled->setCursor(0,16);
oled->setTextSize(3);
if (data[index].decimal_places == 0) oled->print(*(int*)data[index].variable);
else oled->print(*(double*)data[index].variable, data[index].decimal_places);
oled->setTextSize(1);
oled->println(data[index].unit);
oled->display();
}