Skip to content

Commit

Permalink
introducinb clipping and cleaning memory size
Browse files Browse the repository at this point in the history
  • Loading branch information
lubeda committed Nov 28, 2024
1 parent 4596bd2 commit 8d6557a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions components/ehmtxv2/EHMTX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ namespace esphome
if (strcmp(this->icons[i]->name.c_str(), name.c_str()) == 0)
{
ESP_LOGD(TAG, "icon: %s found id: %d", name.c_str(), i);
ESP_LOGD(TAG, "icon: %s has transparency: %d", this->icons[i]->);
return i;
}
}
Expand Down
6 changes: 6 additions & 0 deletions components/ehmtxv2/EHMTX_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,9 @@ namespace esphome
case MODE_RAINBOW_ICON:
case MODE_ICON_PROGRESS:
case MODE_PROGNOSIS_SCREEN:
this->config_->display->start_clipping(8,0,31,7);
if (this->config_->display->is_clipping())

color_ = (this->mode == MODE_RAINBOW_ICON || this->mode == MODE_RAINBOW_ALERT_SCREEN) ? this->config_->rainbow_color : this->text_color;
#ifdef EHMTXv2_USE_RTL
this->config_->display->print(this->xpos() + xoffset, this->ypos() + yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT,
Expand All @@ -898,6 +901,7 @@ namespace esphome
this->config_->display->print(this->xpos() + xoffset, this->ypos() + yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT,
this->text.c_str());
#endif
this->config_->display->end_clipping();
if (this->mode == MODE_ICON_PROGRESS)
{
if (this->icon != BLANKICON)
Expand Down Expand Up @@ -1033,6 +1037,7 @@ namespace esphome

case MODE_ICON_TEXT_SCREEN:
case MODE_RAINBOW_ICON_TEXT_SCREEN:

color_ = (this->mode == MODE_RAINBOW_ICON_TEXT_SCREEN) ? this->config_->rainbow_color : this->text_color;
#ifdef EHMTXv2_USE_RTL
this->config_->display->print(this->xpos() + xoffset, this->ypos() + yoffset, font, color_, esphome::display::TextAlign::BASELINE_RIGHT,
Expand All @@ -1046,6 +1051,7 @@ namespace esphome
this->config_->display->print(this->xpos() + xoffset, this->ypos() + yoffset, font, color_, esphome::display::TextAlign::BASELINE_LEFT,
this->text.c_str());
#endif

if (this->icon != BLANKICON)
{
int x = 0;
Expand Down
23 changes: 12 additions & 11 deletions components/ehmtxv2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

DEPENDENCIES = ["display", "light", "api"]
AUTO_LOAD = ["ehmtxv2","json"]
IMAGE_TYPE_RGB565 = 4
MAXFRAMES = 110
MAXICONS = 120
ICONWIDTH = 8
ICONHEIGHT = 8
ICONBUFFERSIZE = ICONWIDTH * ICONHEIGHT * 4
ICONBUFFERBYTES = ICONWIDTH * ICONHEIGHT * 3
SVG_ICONSTART = '<svg width="80px" height="80px" viewBox="0 0 80 80">'
SVG_FULL_SCREEN_START = '<svg width="320px" height="80px" viewBox="0 0 320 80">'
SVG_END = "</svg>"
Expand Down Expand Up @@ -420,6 +419,9 @@ def thumbnails(frames):

width, height = image.size

if image.has_transparency_data:
logging.info(f" ICONS: {conf[CONF_ID]} has transparancy")

if CONF_RESIZE in conf:
new_width_max, new_height_max = conf[CONF_RESIZE]
ratio = min(new_width_max / width, new_height_max / height)
Expand All @@ -446,23 +448,23 @@ def thumbnails(frames):
pos = 0
frameIndex = 0
html_string += f"<DIV ID={conf[CONF_ID]}>"
data = [0 for _ in range(ICONBUFFERSIZE * 2 * frames)]
data = [0 for _ in range(ICONBUFFERBYTES * frames)]
for frameIndex in range(frames):

image.seek(frameIndex)
frame = image.convert("RGBA")

if CONF_RESIZE in conf:
frame = frame.resize([width, height])

pixels = list(frame.getdata())


# width, height = image.size
if width == 8:
html_string += SVG_ICONSTART
else:
html_string += SVG_FULL_SCREEN_START
i = 0

for pix in pixels:
R = pix[0] >> 3
G = pix[1] >> 2
Expand All @@ -479,25 +481,24 @@ def thumbnails(frames):
pos += 1
data[pos] = rgb & 255
pos += 1

html_string += SVG_END
html_string += f"</DIV>"

rhs = [HexInt(x) for x in data]

prog_arr = cg.progmem_array(conf[CONF_RAW_DATA_ID], rhs)

prog_arr = cg.progmem_array(conf[CONF_RAW_DATA_ID], data)

cg.new_Pvariable(
conf[CONF_ID],
prog_arr,
width,
height,
frames,
espImage.IMAGE_TYPE["RGB565"],
espImage.IMAGE_TYPE["RGB565icvon"],
str(conf[CONF_ID]),
conf[CONF_PINGPONG],
duration,
)

)
cg.add(var.add_icon(RawExpression(str(conf[CONF_ID]))))

html_string += "</BODY></HTML>"
Expand Down

0 comments on commit 8d6557a

Please sign in to comment.