-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.cpp
194 lines (174 loc) · 4.51 KB
/
display.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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#include <Wire.h>
#include "Arduino.h"
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
#include "bq769x0.h" // Library for Texas Instruments bq76920 battery management IC
#include "globals.h"
#include "declares.h"
#include "display.h"
#include "settings.h"
void PrintMenu()
{
Serial.println("1: Device Status");
Serial.println("2: Voltage Reading");
Serial.println("3: ...");
Serial.println("4: ...");
Serial.println("cs: Check Status");
Serial.println("rs: ReScan for Devices");
Serial.println("rb: ReBoot BMS");
}
void setupDisplay()
{
#if RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
oled.setFont(Adafruit5x7);
}
void oled_loop()
{
// Control what is currently being displayed
//
oledDisplay = DISPLAYSTATUS;
switch (oledDisplay)
{
case DISPLAYMENU:
displayMenu(); // Displays the menu on screen for user to select option
break;
case DISPLAYSTATUS:
displayStatus(); // Displays the status in intervals of 'displayStatusRefresh'
break;
case DISPLAYVOLTAGES:
break;
default:
oledDisplay = DISPLAYSTATUS;
break;
}
}
void displayMenu()
{
oled.println("1: Device Status");
oled.println("2: Voltage Reading");
oled.println("3: ...");
oled.println("4: ...");
oled.println("r: ReScan for Devices");
}
void displayStatus()
{
static long previousTimer;
unsigned long currentTimer = millis();
static uint8_t currentDisplay;
if (currentTimer - previousTimer > settings.displayStatusRefresh) // rebuild the picture after some delay
{
previousTimer = currentTimer;
oled.clear();
oled.set1X();
oled.println(" System Status");
switch (currentDisplay)
{
case 1:
displaySysStatus();
break;
case 2:
displayVoltage();
break;
case 3:
// displayCondition();
break;
case 4:
break;
default:
currentDisplay = 0;
break;
}
currentDisplay += 1;
}
}
void printScreen(uint8_t x, uint8_t y, String input)
{
char *buf;
input.toCharArray(buf, input.length());
// oled.drawStr( x, y, buf);
}
void displaySysStatus()
{
// oled.println("Hello world!");
// oled.println("A long line may be truncated");
// oled.println();
// oled.set2X();
// oled.println("2X demo");
// oled.set1X();
oled.println( "SS not available");
}
void displayVoltage()
{
// oled.println( "Cell Voltages:");
// for (int i = 0; i < 4; i++) {
// bms.vc_hi[i] = readFrom(deviceAddress, VC_HI[i], 1);
// bms.vc_lo[i] = readFrom(deviceAddress, VC_LO[i], 1);
// }
oled.println( "1.10 | 2.20 | 3.30");
oled.println( "4.40");
}
void output_oled() // OLED SSD1306
{
int balancingStatus = 0; //getBalancingStatus();
// i2c.frequency(400000);
oled.clear();
/*
oled.cursor(0, 0);
oled.printf("%.2f V", getBatteryVoltage()/1000.0);
oled.cursor(64, 0);
oled.printf("%.2f A", getBatteryCurrent()/1000.0);
oled.cursor(0, 8);
oled.printf("T:%.1f C", getTemperatureDegC(1));
oled.cursor(64, 8);
oled.printf("SOC:%.2f", getSOC());
oled.cursor(0, 16);
oled.printf("Load: %.2fV", load_voltage/1000.0);
for (int i = 0; i < getNumberOfCells(); i++) {
if (blinkOn || !(balancingStatus & (1 << i))) {
oled.cursor((i % 2 == 0) ? 0 : 64, 24 + (i / 2) * 8);
oled.printf("%d:%.3f V", i+1, getCellVoltage(i+1)/1000.0);
}
}
oled.display();
*/
/*
oled.print(getBatteryVoltage() / 1000.0);
oled.println(" V");
oled.print(getBatteryCurrent() / 1000.0);
oled.println(" A");
oled.print("T: ");
oled.print(getTemperatureDegC(1));
oled.println(" C");
oled.print("SOC: ");
oled.println(getSOC());
oled.print("Load: ");
oled.print(load_voltage / 1000.0);
oled.println(" V");
for (int i = 0; i < getNumberOfCells(); i++) {
if (blinkOn || !(balancingStatus & (1 << i))) {
//oled.cursor((i % 2 == 0) ? 0 : 64, 24 + (i / 2) * 8);
if ( i % 2 == 0 )
{ // Left column
oled.print(i + 1);
oled.print(": ");
oled.print(getCellVoltage(i + 1) / 1000.0);
oled.print(" V");
}
else // Right column
{
oled.print(" ");
oled.print(i + 1);
oled.print(": ");
oled.print(getCellVoltage(i + 1) / 1000.0);
oled.print(" V");
}
}
oled.println();
}
oled.println();
*/
}