-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.cpp
More file actions
154 lines (143 loc) · 5.28 KB
/
Display.cpp
File metadata and controls
154 lines (143 loc) · 5.28 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
145
146
147
148
149
150
151
152
153
154
#include "Display.h"
void displayStart() { // Überprüfe zum Start die Adresse des Displays und starte Display Library
Wire.begin();
displayAdress = EEPROM.read(0); // lese Display Adresse von EEPROM Adresse 0
#if (DEBUGLEVEL >=3) // Bedingte Kompilierung
SerialUSB.print(F("EEPROM Wert: 0x"));
if (displayAdress<16) {
SerialUSB.print(F("0"));
}
SerialUSB.println(displayAdress,HEX);
#endif
uint8_t error;
if(displayAdress >= 127) {
displayAdress = i2cScan();
EEPROM.update(0, displayAdress); // Speichere Adresse auf EEPROM
} else {
Wire.beginTransmission(displayAdress);
error = Wire.endTransmission(); // Wenn Rückgabewert ungleich 0, dann ist kein Gerät mit der Adresse auf dem Bus
if(error != 0) {
#if (DEBUGLEVEL >=3) // Bedingte Kompilierung
SerialUSB.println(F("Adresse aus EMPROM nicht ansprechbar"));
#endif
displayAdress = i2cScan();
EEPROM.update(0, displayAdress); // Speichere Adresse auf EEPROM
} else {
#if (DEBUGLEVEL >=3) //Bedingte Kompilierung
SerialUSB.println(F("Adresse aus EEPROM ansprechbar!"));
#endif
}
}
// Starte Display, falls nicht möglich setze Fehler
if(!display.begin(SSD1306_SWITCHCAPVCC, displayAdress, true, false)) { // Address 0x3D for 128x64
#if (DEBUGLEVEL >=3)
Serial.println(F("SSD1306 Zuweisung gescheitert"));
#endif
for(;;); // Nicht weiter machen, Dauerschleife
}
// Lösche und aktualisiere Display
display.clearDisplay();
display.display();
}
void displayAnzeigen() { // Darstellung des Display laden
if((millis()%500 >= 250) && (displaySenden == false)) { // Führe nur in bestimmten Zeit Abstand aus
blinkPulse = !blinkPulse;
display.clearDisplay();
display.setCursor(0,0); // Start at top-left corner
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Male weißen text
// if(spannungVoltDEC0 < 10) {
// display.print(F(" "));
// }
// display.print(spannungVoltDEC0);
// display.print(F("."));
// display.print(spannungVoltDEC1);
// display.println(F("V"));
// display.fillRect(65, 4, 4, 6, SSD1306_WHITE); // Batterie Pluspol | x,y,width,height,color
// display.drawRect(69, 0, 58, 15, SSD1306_WHITE); // Batterie Rahmen | x,y,width,height,color
// if(spannungUmgerechnet >= 20000) {
// display.fillRect(71, 3, 12, 9, SSD1306_WHITE); // Batterie 4/4 voll | x,y,width,height,color
// } else {
// }
// if(spannungUmgerechnet >= 19000) {
// display.fillRect(85, 3, 12, 9, SSD1306_WHITE); // Batterie 3/4 voll | x,y,width,height,color
// } else {
// display.drawLine(84, 3, 84, 11, SSD1306_WHITE); // Batterie Trennstrich | x,y,width,height,color
// }
// if(spannungUmgerechnet >= 18000) {
// display.fillRect(99, 3, 12, 9, SSD1306_WHITE); // Batterie 4/4 voll | x,y,width,height,color
// } else {
// display.drawLine(98, 3, 98, 11, SSD1306_WHITE); // Batterie Trennstrich | x,y,width,height,color
// }
// if(spannungUmgerechnet >= 17000) {
// display.fillRect(113, 3, 12, 9, SSD1306_WHITE); // Batterie 1/4 voll | x,y,width,height,color
// } else {
// if(blinkPulse) {
// display.fillRect(113, 3, 12, 9, SSD1306_WHITE); //Batterie 1/4 voll | x,y,width,height,color
// } else {
// display.drawLine(112, 3, 112, 11, SSD1306_WHITE); //Batterie Trennstrich | x,y,width,height,color
// }
// }
display.setCursor(8,20); // Start at top-left corner
display.setTextSize(1);
display.println(F("RAW"));
display.setCursor(8,30); // Start at top-left corner
display.setTextSize(1);
//display.println(inCurrentRAW);
display.setCursor(64,20); // Start at top-left corner
display.setTextSize(1);
display.println(F("AMPS"));
display.setCursor(64,30); // Start at top-left corner
display.setTextSize(1);
//display.println(inCurrentNorm);
display.setCursor(8,50); // Start at top-left corner
display.setTextSize(1);
//display.println(inCurrentVolts);
display.setCursor(64,50); // Start at top-left corner
// display.println(currentNorm);
display.display();
displaySenden = true;
} else if((millis()%500 < 250) && (displaySenden == true)) {
displaySenden = false; //Stellt sicher, dass Code nur einmal je Sekunde ausgeführt wird.
}
}
uint8_t i2cScan() { // Scanne I2C Bus, um Adresse des Display herauszufinden
uint8_t error, address, outValue;
uint8_t nDevices = 0;
#if (DEBUGLEVEL >= 3)
SerialUSB.println(F("--Scane I2C Bus--"));
#endif
for(address = 1; address <=127 ; address++ ) {
// der Scan verwendet den Rückgabewert von Write.endTransmisstion
// um zu sehen ob ein Gerät angewortet hat
Wire.beginTransmission(address);
error = Wire.endTransmission();
#if (DEBUGLEVEL >= 3)
SerialUSB.print(F("Prüfe I2C Adresse: 0x"));
if (address<16) {
SerialUSB.print(F("0"));
}
SerialUSB.println(address, HEX);
#endif
if (error == 0) {
nDevices++;
outValue = address;
address = 127;
}
}
if (nDevices == 0) {
outValue = 0;
#if (DEBUGLEVEL >= 3)
SerialUSB.println(F("--Kein Gerät gefunden--"));
#endif
} else {
#if (DEBUGLEVEL >= 3)
SerialUSB.print(F("Gerät gefunden auf Adresse: 0x"));
if (address<16) {
SerialUSB.print(F("0"));
}
SerialUSB.println(address, HEX);
#endif
}
return outValue;
}