Skip to content

Commit

Permalink
2023.9.1-122: Fix double conversion and log output
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjswan authored Nov 3, 2023
1 parent e54cdc6 commit e8a0875
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions components/ehmtxv2/EHMTX_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ namespace esphome
EHMTX_queue::EHMTX_queue(EHMTX *config)
{
this->config_ = config;
this->endtime = 0;
this->last_time = 0;
this->screen_time_ = 0;
this->endtime = 0.0;
this->last_time = 0.0;
this->screen_time_ = 0.0;
this->mode = MODE_EMPTY;
this->icon_name = "";
this->icon = 0;
Expand All @@ -92,72 +92,72 @@ namespace esphome
ESP_LOGD(TAG, "empty slot");
break;
case MODE_BLANK:
ESP_LOGD(TAG, "queue: blank screen for %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: blank screen for %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_COLOR:
ESP_LOGD(TAG, "queue: color screen for %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: color screen for %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_CLOCK:
ESP_LOGD(TAG, "queue: clock for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: clock for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_DATE:
ESP_LOGD(TAG, "queue: date for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: date for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_GRAPH_SCREEN:
ESP_LOGD(TAG, "queue: graph for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: graph for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_FULL_SCREEN:
ESP_LOGD(TAG, "queue: full screen: \"%s\" for: %d sec", this->icon_name.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: full screen: \"%s\" for: %d sec", this->icon_name.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_ICON_SCREEN:
ESP_LOGD(TAG, "queue: icon screen: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: icon screen: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_ICON_PROGRESS:
ESP_LOGD(TAG, "queue: icon progress: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: icon progress: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_ICON_CLOCK:
ESP_LOGD(TAG, "queue: icon clock: \"%s\" for: %d sec", this->icon_name.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: icon clock: \"%s\" for: %d sec", this->icon_name.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_ICON_DATE:
ESP_LOGD(TAG, "queue: icon date: \"%s\" for: %d sec", this->icon_name.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: icon date: \"%s\" for: %d sec", this->icon_name.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_ALERT_SCREEN:
ESP_LOGD(TAG, "queue: icon: \"%s\" for: %d sec", this->icon_name.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: icon: \"%s\" for: %d sec", this->icon_name.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_TEXT_SCREEN:
ESP_LOGD(TAG, "queue: text text: \"%s\" for: %d sec", this->text.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: text text: \"%s\" for: %d sec", this->text.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_RAINBOW_ICON:
ESP_LOGD(TAG, "queue: rainbow icon: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: rainbow icon: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_RAINBOW_TEXT:
ESP_LOGD(TAG, "queue: rainbow text: \"%s\" for: %d sec", this->text.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: rainbow text: \"%s\" for: %d sec", this->text.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_RAINBOW_CLOCK:
ESP_LOGD(TAG, "queue: rainbow clock for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: rainbow clock for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_RAINBOW_DATE:
ESP_LOGD(TAG, "queue: rainbow date for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: rainbow date for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_ICON_TEXT_SCREEN:
ESP_LOGD(TAG, "queue: icon text screen: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: icon text screen: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_RAINBOW_ICON_TEXT_SCREEN:
ESP_LOGD(TAG, "queue: rainbow icon text screen: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), this->screen_time_);
ESP_LOGD(TAG, "queue: rainbow icon text screen: \"%s\" text: %s for: %d sec", this->icon_name.c_str(), this->text.c_str(), static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_FIRE:
ESP_LOGD(TAG, "queue: fire for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: fire for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;

#ifndef USE_ESP8266
case MODE_BITMAP_SCREEN:
ESP_LOGD(TAG, "queue: bitmap for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: bitmap for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_BITMAP_SMALL:
ESP_LOGD(TAG, "queue: small bitmap for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: small bitmap for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
case MODE_RAINBOW_BITMAP_SMALL:
ESP_LOGD(TAG, "queue: rainbow small bitmap for: %d sec", this->screen_time_);
ESP_LOGD(TAG, "queue: rainbow small bitmap for: %d sec", static_cast<uint16_t>(this->screen_time_ / 1000));
break;
#endif

Expand Down Expand Up @@ -743,7 +743,7 @@ namespace esphome

void EHMTX_queue::hold_slot(uint8_t _sec)
{
this->endtime += _sec * 1000.0;
this->endtime += 1000.0 * _sec;
ESP_LOGD(TAG, "hold for %d secs", _sec);
}

Expand All @@ -754,7 +754,7 @@ namespace esphome
{
int x, y, w, h;
float display_duration;
float requested_time = screen_time * 1000.0;
float requested_time = 1000.0 * screen_time;

uint8_t width = 32;
uint8_t startx = 0;
Expand All @@ -777,17 +777,17 @@ namespace esphome
case MODE_RAINBOW_TEXT:
#ifdef EHMTXv2_SCROLL_SMALL_TEXT
max_steps = EHMTXv2_SCROLL_COUNT * (width - startx) + EHMTXv2_SCROLL_COUNT * this->pixels_;
display_duration = (double)max_steps * (double)EHMTXv2_SCROLL_INTERVALL;
display_duration = static_cast<double>(max_steps * EHMTXv2_SCROLL_INTERVALL);
this->screen_time_ = (display_duration > requested_time) ? display_duration : requested_time;
#else
if (this->pixels_ < 32)
{
this->screen_time_ = screen_time * 1000.0;
this->screen_time_ = requested_time;
}
else
{
max_steps = EHMTXv2_SCROLL_COUNT * (width - startx) + EHMTXv2_SCROLL_COUNT * this->pixels_;
display_duration = (double)max_steps * (double)EHMTXv2_SCROLL_INTERVALL;
display_duration = static_cast<double>(max_steps * EHMTXv2_SCROLL_INTERVALL);
this->screen_time_ = (display_duration > requested_time) ? display_duration : requested_time;
}
#endif
Expand All @@ -801,25 +801,25 @@ namespace esphome
startx = 8;
if (this->pixels_ < 23)
{
this->screen_time_ = screen_time * 1000.0;
this->screen_time_ = requested_time;
}
else
{
max_steps = EHMTXv2_SCROLL_COUNT * (width - startx) + EHMTXv2_SCROLL_COUNT * this->pixels_;
display_duration = (double)max_steps * (double)EHMTXv2_SCROLL_INTERVALL;
display_duration = static_cast<double>(max_steps * EHMTXv2_SCROLL_INTERVALL);
this->screen_time_ = (display_duration > requested_time) ? display_duration : requested_time;
}
break;
case MODE_ICON_TEXT_SCREEN:
case MODE_RAINBOW_ICON_TEXT_SCREEN:
if (this->pixels_ < 23)
{
this->screen_time_ = screen_time * 1000.0;
this->screen_time_ = requested_time;
}
else
{
max_steps = EHMTXv2_SCROLL_COUNT * (width - startx) + EHMTXv2_SCROLL_COUNT * this->pixels_;
display_duration = (double)max_steps * (double)EHMTXv2_SCROLL_INTERVALL;
display_duration = static_cast<double>(max_steps * EHMTXv2_SCROLL_INTERVALL);
this->screen_time_ = (display_duration > requested_time) ? display_duration : requested_time;
}
break;
Expand All @@ -830,7 +830,7 @@ namespace esphome
this->scroll_reset = (width - startx) + this->pixels_;
;

ESP_LOGD(TAG, "calc_scroll_time: mode: %d text: \"%s\" pixels %d calculated: %d defined: %d max_steps: %d", this->mode, text.c_str(), this->pixels_, this->screen_time_, screen_time, this->scroll_reset);
ESP_LOGD(TAG, "calc_scroll_time: mode: %d text: \"%s\" pixels %d calculated: %.1f defined: %d max_steps: %d", this->mode, text.c_str(), this->pixels_, this->screen_time_ / 1000.0, screen_time, this->scroll_reset);
}

}

0 comments on commit e8a0875

Please sign in to comment.