Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #43 from lubeda/2023.3.0
Browse files Browse the repository at this point in the history
2023.3.0
  • Loading branch information
lubeda committed Mar 2, 2023
2 parents 15594c4 + 34eeba1 commit 5cc5c84
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ components/ehmtx/EHMTX_icons._cpp
ehmtx8266-select.yaml
svganimtest.html
servicetest
.DS_Store
47 changes: 45 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ font:
```

## icons/animations
Download and install all needed icons (.jpg/.png)/animations (.gif) under the "ehmtx"-key. All icons are automagically scaled to 8x8 on compile-time. You can also specify an url to directly download an image file. The urls will only be downloaded once at compile time, so there is no additional traffic on the hosting website.
Download and install all needed icons (.jpg/.png)/animations (.gif) under the "ehmtx"-key. All icons are automagically scaled to 8x8 on compile-time. But this doesn't work well for gif's!
You can also specify an url to directly download an image file. The urls will only be downloaded once at compile time, so there is no additional traffic on the hosting website.

```
emhtx:
Expand Down Expand Up @@ -231,6 +232,8 @@ _Configuration variables:_

**show_clock (Optional, seconds):** duration to display the clock after this time the date is display until next "show_screen". If `show_date` is false `show_clock` is false and the clock will be display as long as a normal screen!

**clock_interval (Optional, seconds):** show the clock at least each x seconds, (default=60)

**show_screen (Optional, seconds):** duration to display a screen or a clock/date sequence, a long text will be scrolled at least two times

![timing](./images/timing.png)
Expand Down Expand Up @@ -555,6 +558,28 @@ Service **indicator_off**

removes the indicator

Service **display_on** / **display_off**

turns the display on or off

There's an easier way in using a switch component:

```
switch:
- platform: template
name: "$devicename Display"
icon: "mdi:power"
restore_mode: ALWAYS_ON
lambda: |-
return id(rgb8x32)->show_display;
turn_on_action:
lambda: |-
id(rgb8x32)->set_display_on();
turn_off_action:
lambda: |-
id(rgb8x32)->set_display_off();
```

Service **skip**

skips to the next screen
Expand Down Expand Up @@ -624,6 +649,24 @@ number:
id(rgb8x32)->set_brightness(x);
```

#### display switch

```
switch:
- platform: template
name: "$devicename Display"
icon: "mdi:power"
restore_mode: ALWAYS_ON
lambda: |-
return id(rgb8x32)->show_display;
turn_on_action:
lambda: |-
id(rgb8x32)->set_display_on();
turn_off_action:
lambda: |-
id(rgb8x32)->set_display_off();
```

#### force screen

With the select component you can select, from a dropdown, which screen to show next. As with the force service if the chosen screen/icon isn't active nothing will happen. The state of the select componenten doesn't reflect the actual display because it is published only all 30s. You should also consider to not record this state in your history.
Expand Down Expand Up @@ -696,7 +739,7 @@ The integration works with the homeassistant api so, after boot of the device, i
THE SOFTWARE IS PROVIDED "AS IS", use at your own risk!

# Thanks

- **[andrew-codechimp](https://github.com/andrew-codechimp)** for his contribution (display on/off)
- **[jd1](https://github.com/jd1)** for his contributions
- **[aptonline](https://github.com/aptonline)** for his work on the ulanzi hardware
- **[wsbtak](https://github.com/wsbtak)** for the work on the ulanzi hardware
Expand Down
24 changes: 23 additions & 1 deletion UlanziTC001.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,15 @@ api:
then:
- ehmtx.indicator.off:
id: rgb8x32

- service: display_on
then:
- ehmtx.display.on:
id: rgb8x32
- service: display_off
then:
- ehmtx.display.off:
id: rgb8x32

number:
- platform: template
name: "$devicename brightness"
Expand All @@ -156,6 +164,20 @@ number:
lambda: |-
id(rgb8x32)->set_brightness(x);
switch:
- platform: template
name: "$devicename Display"
icon: "mdi:power"
restore_mode: ALWAYS_ON
lambda: |-
return id(rgb8x32)->show_display;
turn_on_action:
lambda: |-
id(rgb8x32)->set_display_on();
turn_off_action:
lambda: |-
id(rgb8x32)->set_display_off();
sensor:
- platform: sht3xd
temperature:
Expand Down
61 changes: 44 additions & 17 deletions components/ehmtx/EHMTX.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ namespace esphome
ESP_LOGD(TAG, "indicator on");
}

void EHMTX::set_display_off()
{
this->show_display = false;
ESP_LOGD(TAG, "display off");
}

void EHMTX::set_display_on()
{
this->show_display = true;
ESP_LOGD(TAG, "display on");
}

void EHMTX::set_gauge_off()
{
this->show_gauge = false;
Expand Down Expand Up @@ -194,7 +206,7 @@ namespace esphome
{
this->show_screen = false;

if (!(ts - this->last_clock_time > 60)) // force clock if last time more the 60s old
if (!(ts - this->last_clock_time > this->clock_interval)) // force clock if last time more the 60s old
{
bool has_next_screen = this->store->move_next();
if (has_next_screen)
Expand Down Expand Up @@ -251,6 +263,14 @@ namespace esphome
{
ESP_LOGI(TAG, "status indicator off");
}
if (this->show_display)
{
ESP_LOGI(TAG, "status display on");
}
else
{
ESP_LOGI(TAG, "status display off");
}

this->store->log_status();

Expand Down Expand Up @@ -373,6 +393,11 @@ namespace esphome
this->clock_time = t;
}

void EHMTX::set_clock_interval(uint16_t t)
{
this->clock_interval = t;
}

void EHMTX::set_display(addressable_light::AddressableLightDisplay *disp)
{
this->display = disp;
Expand Down Expand Up @@ -467,28 +492,30 @@ namespace esphome

void EHMTX::draw()
{
if (this->show_icons)
{
this->icon_screen->draw();
}
else
{
if (this->show_screen)
if (this->show_display) {
if (this->show_icons)
{
this->store->current()->draw();
this->icon_screen->draw();
}
else
{
this->draw_clock();
if (this->show_screen)
{
this->store->current()->draw();
}
else
{
this->draw_clock();
}
}
}

if (this->show_indicator)
{
this->display->line(31, 5, 29, 7, this->indicator_color);
this->display->draw_pixel_at(30, 7, this->indicator_color);
this->display->draw_pixel_at(31, 6, this->indicator_color);
this->display->draw_pixel_at(31, 7, this->indicator_color);
if (this->show_indicator)
{
this->display->line(31, 5, 29, 7, this->indicator_color);
this->display->draw_pixel_at(30, 7, this->indicator_color);
this->display->draw_pixel_at(31, 6, this->indicator_color);
this->display->draw_pixel_at(31, 7, this->indicator_color);
}
}
}

Expand Down
40 changes: 38 additions & 2 deletions components/ehmtx/EHMTX.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const uint8_t TEXTSCROLLSTART = 8;
const uint8_t TEXTSTARTOFFSET = (32 - 8);

const uint16_t TICKINTERVAL = 1000; // each 1000ms
static const char *const EHMTX_VERSION = "Version: 2023.2.0";
static const char *const EHMTX_VERSION = "Version: 2023.3.0";
static const char *const TAG = "EHMTX";

namespace esphome
Expand Down Expand Up @@ -50,6 +50,7 @@ namespace esphome
EHMTX_Icon *icons[MAXICONS];
EHMTX_screen *icon_screen;
void add_icon(EHMTX_Icon *icon);
bool show_display;
#ifdef USE_EHMTX_SELECT
std::vector<std::string> select_options;
esphome::EhmtxSelect *select;
Expand All @@ -64,6 +65,7 @@ namespace esphome
uint16_t scroll_intervall; // ms to between scrollsteps
uint16_t anim_intervall; // ms to next_frame()
uint16_t clock_time; // seconds display of screen_time - clock_time = date_time
uint16_t clock_interval; // seconds display of screen_time - clock_time = date_time
uint16_t screen_time; // seconds display of screen
uint8_t icon_count; // max iconnumber -1
unsigned long last_scroll_time;
Expand All @@ -80,6 +82,7 @@ namespace esphome
void set_display(addressable_light::AddressableLightDisplay *disp);
void set_screen_time(uint16_t t);
void set_clock_time(uint16_t t);
void set_clock_interval(uint16_t t);
void set_show_day_of_week(bool b);
void set_show_date(bool b);
void set_font_offset(int8_t x, int8_t y);
Expand Down Expand Up @@ -112,6 +115,8 @@ namespace esphome
void add_on_next_screen_trigger(EHMTXNextScreenTrigger *t) { this->on_next_screen_triggers_.push_back(t); }
void setup();
void update();
void set_display_on();
void set_display_off();
};

class EHMTX_store
Expand Down Expand Up @@ -155,6 +160,7 @@ namespace esphome
void draw();
void draw_();
bool isfree();
void reset_shiftx();
bool update_slot(uint8_t _icon);
void update_screen();
bool del_slot(uint8_t _icon);
Expand Down Expand Up @@ -369,6 +375,36 @@ namespace esphome
this->parent_->set_indicator_off();
}

protected:
EHMTX *parent_;
};

template <typename... Ts>
class SetDisplayOn : public Action<Ts...>
{
public:
SetDisplayOn(EHMTX *parent) : parent_(parent) {}

void play(Ts... x) override
{
this->parent_->set_display_on();
}

protected:
EHMTX *parent_;
};

template <typename... Ts>
class SetDisplayOff : public Action<Ts...>
{
public:
SetDisplayOff(EHMTX *parent) : parent_(parent) {}

void play(Ts... x) override
{
this->parent_->set_display_off();
}

protected:
EHMTX *parent_;
};
Expand Down Expand Up @@ -419,4 +455,4 @@ namespace esphome
};
}

#endif
#endif
6 changes: 6 additions & 0 deletions components/ehmtx/EHMTX_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ namespace esphome
return false;
}

void EHMTX_screen::reset_shiftx()
{
this->shiftx_ = 0;
}


void EHMTX_screen::update_screen()
{
if (millis() - this->config_->last_scroll_time >= this->config_->scroll_intervall && this->pixels_ > TEXTSTARTOFFSET)
Expand Down
3 changes: 3 additions & 0 deletions components/ehmtx/EHMTX_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace esphome
EHMTX_screen *screen = this->slots[slot];
if (screen->active())
{
screen->reset_shiftx();
this->active_slot = slot;
return true;
}
Expand All @@ -86,6 +87,7 @@ namespace esphome
EHMTX_screen *screen = this->slots[slot];
if (screen->active())
{
screen->reset_shiftx();
this->active_slot = slot;
return true;
}
Expand All @@ -97,6 +99,7 @@ namespace esphome
EHMTX_screen *screen = this->slots[slot];
if (screen->active())
{
screen->reset_shiftx();
this->active_slot = slot;
return true;
}
Expand Down
Loading

0 comments on commit 5cc5c84

Please sign in to comment.