Skip to content

Commit

Permalink
Minor web page issue fix and SOC on TFT display (#67)
Browse files Browse the repository at this point in the history
* Fix issue #64
* SOC on TFT display #66
  • Loading branch information
stuartpittaway authored Nov 26, 2021
1 parent 61a7bf6 commit 460ce63
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 96 deletions.
16 changes: 1 addition & 15 deletions ESPController/src/DIYBMSServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,21 +1438,7 @@ void DIYBMSServer::settings(AsyncWebServerRequest *request)
settings["totalseriesmodules"] = _mysettings->totalNumberOfSeriesModules;
settings["baudrate"] = _mysettings->baudRate;

uint8_t numberOfV440OrNewer = 0;
uint8_t totalModules = _mysettings->totalNumberOfBanks * _mysettings->totalNumberOfSeriesModules;
for (uint8_t i = 0; i < totalModules; i++)
{
if (cmi[i].valid)
{
//Count of v440 or newer modules
if (cmi[i].BoardVersionNumber >= 440)
{
numberOfV440OrNewer++;
}
}
}
//Only true if all modules have communicated and are all v440 or newer
settings["supportSpeedChange"] = numberOfV440OrNewer == totalModules;


settings["bypassthreshold"] = _mysettings->BypassThresholdmV;
settings["bypassovertemp"] = _mysettings->BypassOverTempShutdown;
Expand Down
179 changes: 104 additions & 75 deletions ESPController/src/tft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,24 +456,120 @@ void PrepareTFT_CurrentMonitor()
int16_t w = tft.width();
//Take off the wifi banner height
int16_t h = tft.height() - fontHeight_2;
int16_t yhalfway = h / 2;
//int16_t yhalfway = h / 2;

int16_t y_row0 = 0;
int16_t y_row1 = h / 3;
int16_t y_row2 = y_row1 * 2;

//Grid lines
tft.drawLine(w / 2, 0, w / 2, h, TFT_DARKGREY);
tft.drawLine(0, yhalfway, w, yhalfway, TFT_DARKGREY);
tft.drawLine(0, y_row1, w, y_row1, TFT_DARKGREY);
tft.drawLine(0, y_row2, w, y_row2, TFT_DARKGREY);
tft.drawLine(0, h, w, h, TFT_DARKGREY);

//Skip over horizontal line
y_row1 += 2;
y_row2 += 2;

tft.setTextFont(2);
//Need to think about multilingual strings in the longer term
tft.setTextColor(TFT_LIGHTGREY, TFT_BLACK);
tft.drawString("Current (A)", 0, 0);
tft.drawString("Voltage", 0, yhalfway + 2);
tft.drawString("Power (W)", 2 + (w / 2), 0);
tft.drawString("Current (A)", 0, y_row0);
tft.drawString("Power (W)", 2 + (w / 2), y_row0);
tft.drawString("Voltage", 0, y_row1);
tft.drawString("State of charge %", 2 + (w / 2), y_row1);
tft.drawString("Amp/hour Out", 0, y_row2);
tft.drawString("Amp/hour In", 2 + (w / 2), y_row2);
TFTDrawWifiDetails();
}

tft.drawString("Amp/hour Out", 2 + (w / 2), yhalfway + 2);
void DrawTFT_CurrentMonitor()
{
int16_t w = tft.width();
//Take off the wifi banner height
int16_t h = tft.height() - fontHeight_2;
//int16_t yhalfway = h / 2;
int16_t half_w = w / 2;

tft.drawString("Amp/hour In", 2 + (w / 2), fontHeight_4 + fontHeight_4 + yhalfway + 2);
TFTDrawWifiDetails();
int16_t y_row0 = 0;
int16_t y_row1 = h / 3;
int16_t y_row2 = y_row1 * 2;

//Skip over horizontal line and font titles
y_row0 += 0 + fontHeight_2;
y_row1 += 2 + fontHeight_2;
y_row2 += 2 + fontHeight_2;

// Position of text in X axis
int16_t middle_x = 2 + w / 2;

tft.setTextColor(TFT_GREEN, TFT_BLACK);

//Top left
tft.setTextDatum(TL_DATUM);
tft.setTextFont(7);
//Skip over title
int16_t y = y_row0;
int16_t x = 0;

uint8_t decimals = 2;

if (currentMonitor.modbus.current > 99)
{
decimals = 1;
}

x += tft.drawFloat(currentMonitor.modbus.current, decimals, x, y);
//Clear out surrounding background (to black)
tft.fillRect(x, y, half_w - x, tft.fontHeight(), TFT_BLACK);

y = y_row1;
x = middle_x;
x += tft.drawFloat(currentMonitor.stateofcharge, 1, x, y);
x += tft.drawString("%", x, y);
//Clear out surrounding background (to black)
tft.fillRect(x, y, w - x, tft.fontHeight(), TFT_BLACK);

decimals = 2;
if (currentMonitor.modbus.voltage > 99)
{
decimals = 1;
}
y = y_row1;
x = 0;
x += tft.drawFloat(currentMonitor.modbus.voltage, decimals, x, y);
tft.fillRect(x, y, half_w - x, tft.fontHeight(), TFT_BLACK);

y = y_row0;
x = middle_x;
x += tft.drawNumber(currentMonitor.modbus.power, x, y);
tft.fillRect(x, y, w - x, tft.fontHeight(), TFT_BLACK);

y = y_row2;
x = 0;
decimals = 1;
tft.setTextFont(4);
float ahout = (float)currentMonitor.modbus.milliamphour_out / 1000.0;
if (ahout < 100)
{
decimals = 2;
}
x += tft.drawFloat(ahout, decimals, x, y);
tft.fillRect(x, y, half_w - x, tft.fontHeight(), TFT_BLACK);

//Amp hour in
y = y_row2;
x = middle_x;
decimals = 1;
float ahin = (float)currentMonitor.modbus.milliamphour_in / 1000.0;

if (ahin < 100)
{
decimals = 2;
}
x += tft.drawFloat(ahin, decimals, x, y);
tft.fillRect(x, y, w - x, tft.fontHeight(), TFT_BLACK);
}

void PrepareTFT_VoltageFourBank()
Expand Down Expand Up @@ -611,73 +707,6 @@ void DrawTFT_VoltageFourBank()
tft.fillRect(x, y, w - x, fontHeight_2, TFT_BLACK);
}

void DrawTFT_CurrentMonitor()
{
int16_t w = tft.width();
//Take off the wifi banner height
int16_t h = tft.height() - fontHeight_2;
int16_t yhalfway = h / 2;

tft.setTextColor(TFT_GREEN, TFT_BLACK);

//Top left
tft.setTextDatum(TL_DATUM);
tft.setTextFont(7);
int16_t y = fontHeight_2;
int16_t x = 0;

uint8_t decimals = 2;

if (currentMonitor.modbus.current > 99)
{
decimals = 1;
}

x += tft.drawFloat(currentMonitor.modbus.current, decimals, x, y);
tft.fillRect(x, y, (w / 2) - x, tft.fontHeight(), TFT_BLACK);

decimals = 2;
if (currentMonitor.modbus.voltage > 99)
{
decimals = 1;
}
y = 2 + yhalfway + fontHeight_2;
x = 0;
x += tft.drawFloat(currentMonitor.modbus.voltage, decimals, x, y);
tft.fillRect(x, y, (w / 2) - x, tft.fontHeight(), TFT_BLACK);

y = fontHeight_2;
x = 2 + w / 2;
decimals = 1;
x += tft.drawFloat(currentMonitor.modbus.power, decimals, x, y);
tft.fillRect(x, y, w - x, tft.fontHeight(), TFT_BLACK);

y = 2 + yhalfway + fontHeight_2;
x = 2 + w / 2;
decimals = 1;
tft.setTextFont(4);
float ahout = (float)currentMonitor.modbus.milliamphour_out / 1000.0;
if (ahout < 10)
{
decimals = 3;
}
x += tft.drawFloat(ahout, decimals, x, y);
tft.fillRect(x, y, w - x, tft.fontHeight(), TFT_BLACK);

//Amp hour in
y = fontHeight_2 + fontHeight_4 + fontHeight_4 + yhalfway + 2;
x = 2 + w / 2;
decimals = 1;
float ahin = (float)currentMonitor.modbus.milliamphour_in / 1000.0;

if (ahin < 10)
{
decimals = 3;
}
x += tft.drawFloat(ahin, decimals, x, y);
tft.fillRect(x, y, w - x, tft.fontHeight(), TFT_BLACK);
}

void DrawTFT_VoltageOneBank()
{
//Single bank, large font
Expand Down
2 changes: 1 addition & 1 deletion ESPController/web_src/default.htm
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ <h2 id="mb1">Modules &amp; Banks</h2>
<p id="mb2">DIYBMS supports up to <span id='labelMaxModules'>X</span> modules in total. These modules can be
split into banks to support parallel configurations.</p>
<p id="mb3">Example: You have 16 cells configured as 8 in series and 2 in parallel (8S2P).</p>
<p id="mb4">Only hardware module version 4.4 or newer support faster communication speeds. You will need to reboot the controller manually if you change the speed.</p>
<p id="mb4">Only hardware module version 4.4 or newer support faster communication speeds. You will need to reboot the controller manually if you change the speed, and also ensure all modules are using the correct firmware.</p>
<form id="banksForm" method="POST" action="savebankconfig.json" autocomplete="off">
<div class="settings">
<div>
Expand Down
7 changes: 2 additions & 5 deletions ESPController/web_src/pagecode.js
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,8 @@ $(function () {

$("#baudrate").empty();
$("#baudrate").append('<option value="2400">Standard</option>')

if (data.settings.supportSpeedChange) {
$("#baudrate").append('<option value="5000">5K</option>')
$("#baudrate").append('<option value="9600">9K6</option>')
}
$("#baudrate").append('<option value="5000">5K</option>')
$("#baudrate").append('<option value="9600">9K6</option>')

$("#baudrate").val(data.settings.baudrate);

Expand Down

0 comments on commit 460ce63

Please sign in to comment.