Skip to content

Commit

Permalink
Get the live delivered power
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypoulter committed Oct 18, 2023
1 parent 8a8e1ba commit 58513a3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/lcd_tft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ void LcdTask::display(const char *msg, int x, int y, int time, uint32_t flags)

void LcdTask::begin(EvseManager &evse, Scheduler &scheduler, ManualOverride &manual)
{
_evse = &evse;
_scheduler = &scheduler;
_manual = &manual;
MicroTask.startTask(this);
}

Expand Down Expand Up @@ -96,22 +99,17 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
case State::Charge:
render_image("/ChargeScreen.png", 0, 0);

// _lcd.setCursor(120, 180);
// _lcd.setTextColor(TFT_BLACK, TFT_WHITE);
// _lcd.setFreeFont(&DejaVu_Sans_72);
// _lcd.setTextSize(1);
// _lcd.setFreeFont(&FreeSans24pt7b);
// _lcd.setTextSize(3);
// _lcd.print("16");

render_right_text("16", 266, 180, &FreeSans24pt7b, TFT_BLACK, 3);
_lcd.setTextSize(1);
_lcd.print("A");

char buffer[32];

render_centered_text(esp_hostname.c_str(), 324, 72, 140, &FreeSans9pt7b, TFT_OPENEVSE_TEXT);
render_centered_text("11/08/2023, 3:45 AM", 324, 92, 140, &FreeSans9pt7b, TFT_OPENEVSE_TEXT);
render_centered_text("00:00:00", 324, 144, 140, &FreeSans9pt7b, TFT_WHITE);
render_centered_text("0 kWh", 324, 196, 140, &FreeSans9pt7b, TFT_WHITE);
get_scaled_number_value(_evse->getSessionEnergy(), 0, "Wh", buffer, sizeof(buffer));
render_centered_text(buffer, 324, 196, 140, &FreeSans9pt7b, TFT_WHITE);
//nextUpdate = 1000;
break;

Expand All @@ -123,6 +121,28 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
return nextUpdate;
}

void LcdTask::get_scaled_number_value(double value, int precision, const char *unit, char *buffer, size_t size)
{
static const char *mod[] = {
"",
"k",
"M",
"G",
"T",
"P"
};

int index = 0;
while (value > 1000 && index < ARRAY_ITEMS(mod))
{
value /= 1000;
index++;
}

snprintf(buffer, size, "%.*f %s%s", precision, value, mod[index], unit);
}


void LcdTask::render_centered_text(const char *text, int16_t x, int16_t y, int16_t width, const GFXfont *font, uint16_t color, uint8_t size)
{
_lcd.setFreeFont(font);
Expand Down
5 changes: 5 additions & 0 deletions src/lcd_tft.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class LcdTask : public MicroTasks::Task
};

State _state = State::Boot;
EvseManager *_evse;
Scheduler *_scheduler;
ManualOverride *_manual;

static void png_draw(PNGDRAW *pDraw);
protected:
Expand All @@ -41,6 +44,8 @@ class LcdTask : public MicroTasks::Task
void render_right_text(const char *text, int16_t x, int16_t y, const GFXfont *font, uint16_t color, uint8_t size = 1);
void load_font(const char *filename);

void get_scaled_number_value(double value, int precision, const char *unit, char *buffer, size_t size);

public:
LcdTask();

Expand Down

0 comments on commit 58513a3

Please sign in to comment.