MAX9621: fix CI errors

This commit is contained in:
endym 2024-08-08 16:06:36 +02:00
parent 567023cf31
commit e3d3e619af
6 changed files with 275 additions and 325 deletions

View file

@ -16,7 +16,6 @@ template<typename... Ts> class SetBrightnessAction : public Action<Ts...>, publi
void play(Ts... x) override { this->parent_->set_brightness(this->brightness_.value(x...)); }
};
template<typename... Ts> class SetTextAction : public Action<Ts...> {
public:
explicit SetTextAction(MAX6921Component *max9621) : max9621_(max9621) {}
@ -34,20 +33,14 @@ template<typename... Ts> class SetTextAction : public Action<Ts...> {
auto cycle_num = this->text_effect_cycle_num_.value(x...);
auto duration = this->text_effect_duration_.value(x...);
auto update_interval = this->text_effect_update_interval_.value(x...);
this->max9621_->display_->set_text(this->text_.value(x...),
pos,
this->text_align_.value(x...),
duration,
this->text_effect_.value(x...),
update_interval,
cycle_num);
this->max9621_->display_->set_text(this->text_.value(x...), pos, this->text_align_.value(x...), duration,
this->text_effect_.value(x...), update_interval, cycle_num);
}
protected:
MAX6921Component *max9621_;
};
#if 0
template<typename... Ts> class SetDemoModeAction : public Action<Ts...>, public Parented<MAX6921Component> {
public:
@ -60,7 +53,6 @@ template<typename... Ts> class SetDemoModeAction : public Action<Ts...>, public
};
#endif
template<typename... Ts> class SetDemoModeAction : public Action<Ts...> {
public:
explicit SetDemoModeAction(MAX6921Component *max9621) : max9621_(max9621) {}
@ -77,16 +69,14 @@ template<typename... Ts> class SetDemoModeAction : public Action<Ts...> {
// } else if (str_equals_case_insensitive(mode, "scroll_font")) {
// this->set_mode(DEMO_MODE_SCROLL_FONT);
// } else {
// ESP_LOGW(TAG, "Invalid demo mode %s", mode.c_str());
// output log message (TAG, "Invalid demo mode %s", mode.c_str());
// }
// }
void play(Ts... x) override {
auto update_interval = this->demo_update_interval_.value(x...);
auto cycle_num = this->demo_cycle_num_.value(x...);
this->max9621_->display_->set_demo_mode(this->mode_.value(x...),
update_interval,
cycle_num);
this->max9621_->display_->set_demo_mode(this->mode_.value(x...), update_interval, cycle_num);
}
protected:
@ -95,6 +85,5 @@ template<typename... Ts> class SetDemoModeAction : public Action<Ts...> {
// DemoMode mode_;
};
} // namespace max9621
} // namespace max6921
} // namespace esphome

View file

@ -8,7 +8,6 @@
namespace esphome {
namespace max6921 {
static const char *const TAG = "max6921.display";
// segments of 7-segment character
@ -121,7 +120,6 @@ const uint8_t ASCII_TO_SEG[FONT_SIZE] PROGMEM = {
SEG_UNSUPPORTED_CHAR, // '~', (0x7E)
};
void Display::setup(std::vector<uint8_t> &seg_to_out_map, std::vector<uint8_t> &pos_to_out_map) {
this->default_update_interval_ = this->max6921_->get_update_interval();
this->seg_to_out_map_ = seg_to_out_map;
@ -147,8 +145,8 @@ void Display::setup(std::vector<uint8_t>& seg_to_out_map, std::vector<uint8_t>&
// calculate refresh period for 60Hz
this->refresh_period_us_ = 1000000 / 60 / this->num_digits_;
ESP_LOGCONFIG(TAG, "Set display refresh period: %" PRIu32 "us for %u digits @ 60Hz",
this->refresh_period_us_, this->num_digits_);
ESP_LOGCONFIG(TAG, "Set display refresh period: %" PRIu32 "us for %u digits @ 60Hz", this->refresh_period_us_,
this->num_digits_);
/* Setup display refresh.
* Using a timer is not an option, because the WiFi component uses timer as
@ -186,10 +184,8 @@ void HOT Display::display_refresh_task_(void *pv) {
}
if (count < display->num_digits_) {
count++;
ESP_LOGVV(TAG, "%s(): SPI transfer for position %u: 0x%02x%02x%02x",
__func__, current_pos,
display->out_buf_[(current_pos-1)*3],
display->out_buf_[(current_pos-1)*3+1],
ESP_LOGVV(TAG, "%s(): SPI transfer for position %u: 0x%02x%02x%02x", __func__, current_pos,
display->out_buf_[(current_pos - 1) * 3], display->out_buf_[(current_pos - 1) * 3 + 1],
display->out_buf_[(current_pos - 1) * 3 + 2]);
}
@ -204,7 +200,6 @@ void HOT Display::display_refresh_task_(void *pv) {
}
}
void Display::dump_config() {
char seg_name[3];
@ -224,7 +219,6 @@ void Display::dump_config() {
ESP_LOGCONFIG(TAG, " Brightness: %.1f", get_brightness());
}
/**
* @brief Checks if the given character activates the point segment only.
*
@ -232,10 +226,7 @@ void Display::dump_config() {
*
* @return true, if character activates the point segment only, otherwise false
*/
bool Display::isPointSegOnly(char c) {
return ((c == ',') || (c == '.'));
}
bool Display::isPointSegOnly(char c) { return ((c == ',') || (c == '.')); }
void Display::init_font__(void) {
uint8_t seg_data;
@ -308,11 +299,11 @@ void Display::restore_update_interval(void) {
void Display::update(void) {
// handle display brightness...
if (this->brightness_cfg_changed_) {
uint32_t inverted_duty = this->brightness_max_duty_ - \
this->brightness_max_duty_ * \
this->brightness_cfg_value_; // calc duty for low-active BLANK pin
ESP_LOGD(TAG, "Change display brightness to %.1f (off-time duty=%u/%u)",
brightness_cfg_value_, inverted_duty, this->brightness_max_duty_);
uint32_t inverted_duty =
this->brightness_max_duty_ -
this->brightness_max_duty_ * this->brightness_cfg_value_; // calc duty for low-active BLANK pin
ESP_LOGD(TAG, "Change display brightness to %.1f (off-time duty=%u/%u)", brightness_cfg_value_, inverted_duty,
this->brightness_max_duty_);
ledcWrite(this->brightness_pwm_channel_, inverted_duty);
this->brightness_cfg_changed_ = false;
}
@ -352,8 +343,7 @@ void Display::update(void) {
void Display::set_demo_mode(demo_mode_t mode, uint32_t interval, uint8_t cycle_num) {
uint text_idx, font_idx;
ESP_LOGD(TAG, "Set demo mode: mode=%i, update-interval=%" PRIu32 "ms, cycle_num=%u",
mode, interval, cycle_num);
ESP_LOGD(TAG, "Set demo mode: mode=%i, update-interval=%" PRIu32 "ms, cycle_num=%u", mode, interval, cycle_num);
switch (mode) {
case DEMO_MODE_SCROLL_FONT:
@ -404,13 +394,12 @@ void Display::set_demo_mode(const std::string& mode, uint32_t interval, uint8_t
*
* @return number of characters displayed
*/
int Display::set_text(const std::string& text, uint8_t start_pos, const std::string& align,
uint32_t duration, const std::string& effect, uint32_t interval,
uint8_t cycle_num) {
ESP_LOGD(TAG, "Set text (given): text=%s, start-pos=%u, align=%s, duration=%" PRIu32 "ms, "\
int Display::set_text(const std::string &text, uint8_t start_pos, const std::string &align, uint32_t duration,
const std::string &effect, uint32_t interval, uint8_t cycle_num) {
ESP_LOGD(TAG,
"Set text (given): text=%s, start-pos=%u, align=%s, duration=%" PRIu32 "ms, "
"effect=%s, effect-update-interval=%" PRIu32 "ms, cycles=%u",
text.c_str(), start_pos, align.c_str(), duration, effect.c_str(),
interval, cycle_num);
text.c_str(), start_pos, align.c_str(), duration, effect.c_str(), interval, cycle_num);
// store new text...
this->disp_text_.set_text(start_pos, this->num_digits_ - 1, text);
@ -427,9 +416,8 @@ int Display::set_text(const std::string& text, uint8_t start_pos, const std::str
// update display mode...
set_mode(DISP_MODE_OTHER, duration);
ESP_LOGD(TAG, "Set text (result): text=%s, start-pos=%u, vi-idx=%u, vi-len=%u",
this->disp_text_.text, this->disp_text_.start_pos,
this->disp_text_.visible_idx, this->disp_text_.visible_len);
ESP_LOGD(TAG, "Set text (result): text=%s, start-pos=%u, vi-idx=%u, vi-len=%u", this->disp_text_.text,
this->disp_text_.start_pos, this->disp_text_.visible_idx, this->disp_text_.visible_len);
return update_out_buf_();
}
@ -480,7 +468,8 @@ int Display::update_out_buf_(void) {
bGetNextChar = false;
if (isPointSegOnly(pos_char)) { // is point segment only?
if (this->disp_text_.visible_idx + visible_idx_offset - 1 > 0) { // not the 1st text character?
if (isPointSegOnly(this->disp_text_.text[this->disp_text_.visible_idx + visible_idx_offset - 2])) { // previous text character wasn't a point?
if (isPointSegOnly(this->disp_text_.text[this->disp_text_.visible_idx + visible_idx_offset -
2])) { // previous text character wasn't a point?
if (pos == 0) { // 1st (most left) display position?
bGetNextChar = true; // yes -> ignore point, get next character
} else {
@ -495,8 +484,7 @@ int Display::update_out_buf_(void) {
clear(pos);
// create segment data...
if ((pos_char >= ' ') &&
((pos_char - ' ') < ARRAY_ELEM_COUNT(ASCII_TO_SEG))) { // supported char?
if ((pos_char >= ' ') && ((pos_char - ' ') < ARRAY_ELEM_COUNT(ASCII_TO_SEG))) { // supported char?
out_data = this->ascii_out_data_[pos_char - ' ']; // yes ->
} else {
ESP_LOGW(TAG, "Encountered unsupported character (0x%02x): %c", pos_char, (pos_char >= 0x20) ? pos_char : ' ');
@ -514,8 +502,8 @@ int Display::update_out_buf_(void) {
// shift data to the smallest segment OUT position...
out_data <<= (this->seg_out_smallest_);
ESP_LOGVV(TAG, "%s(): segment data shifted to first segment bit (OUT%u): 0x%06x",
__func__, this->seg_out_smallest_, out_data);
ESP_LOGVV(TAG, "%s(): segment data shifted to first segment bit (OUT%u): 0x%06x", __func__, this->seg_out_smallest_,
out_data);
// add position data...
out_data |= (1 << this->pos_to_out_map_[pos]);
@ -525,12 +513,11 @@ int Display::update_out_buf_(void) {
this->out_buf_[pos * 3 + 0] |= (uint8_t) ((out_data >> 16) & 0xFF);
this->out_buf_[pos * 3 + 1] |= (uint8_t) ((out_data >> 8) & 0xFF);
this->out_buf_[pos * 3 + 2] |= (uint8_t) (out_data & 0xFF);
ESP_LOGVV(TAG, "%s(): display buffer of position %u: 0x%02x%02x%02x",
__func__, pos+1, this->out_buf_[pos*3+0], this->out_buf_[pos*3+1],
this->out_buf_[pos*3+2]);
ESP_LOGVV(TAG, "%s(): display buffer of position %u: 0x%02x%02x%02x", __func__, pos + 1,
this->out_buf_[pos * 3 + 0], this->out_buf_[pos * 3 + 1], this->out_buf_[pos * 3 + 2]);
ESP_LOGV(TAG, "%s(): pos=%u, char='%c' (0x%02x), vi-idx=%u, vi-idx-off=%u, vi-len=%u",
__func__, pos, pos_char, pos_char, this->disp_text_.visible_idx, visible_idx_offset, this->disp_text_.visible_len);
ESP_LOGV(TAG, "%s(): pos=%u, char='%c' (0x%02x), vi-idx=%u, vi-idx-off=%u, vi-len=%u", __func__, pos, pos_char,
pos_char, this->disp_text_.visible_idx, visible_idx_offset, this->disp_text_.visible_len);
}
this->disp_text_.content_changed = true;
@ -566,8 +553,7 @@ int DisplayText::set_text(uint start_pos, uint max_pos, const std::string& text)
if (start_pos >= max_pos) {
ESP_LOGW(TAG, "Invalid start position: %u");
this->start_pos = 0;
}
else
} else
this->start_pos = start_pos;
this->max_pos = max_pos;
@ -578,7 +564,6 @@ int DisplayText::set_text(uint start_pos, uint max_pos, const std::string& text)
return strlen(this->text);
}
/**
* @brief Inits the text object according to selected align.
*/
@ -623,16 +608,15 @@ void DisplayText::init_text_effect_(void) {
*
* @param align text align
*/
void DisplayText::set_text_align(text_align_t align)
{
void DisplayText::set_text_align(text_align_t align) {
if (align >= TEXT_ALIGN_LAST_ENUM) {
ESP_LOGE(TAG, "Invalid display text align: %i", align);
return;
}
this->align = align;
init_text_align_();
ESP_LOGD(TAG, "Set align: text=%s, align=%i, start-pos=%u, max-pos=%u, vi-idx=%u, vi-len=%u",
this->text, this->align, this->start_pos, this->max_pos, this->visible_idx, this->visible_len);
ESP_LOGD(TAG, "Set align: text=%s, align=%i, start-pos=%u, max-pos=%u, vi-idx=%u, vi-len=%u", this->text, this->align,
this->start_pos, this->max_pos, this->visible_idx, this->visible_len);
}
/**
@ -640,8 +624,7 @@ void DisplayText::set_text_align(text_align_t align)
*
* @param align text align (as string)
*/
void DisplayText::set_text_align(const std::string& align)
{
void DisplayText::set_text_align(const std::string &align) {
text_align_t text_align = TEXT_ALIGN_LAST_ENUM;
if (!align.empty()) {
@ -653,8 +636,7 @@ void DisplayText::set_text_align(const std::string& align)
text_align = TEXT_ALIGN_RIGHT;
else
ESP_LOGW(TAG, "Invalid text align: %s", align);
}
else
} else
ESP_LOGW(TAG, "No text align given");
if (text_align >= TEXT_ALIGN_LAST_ENUM)
return;
@ -667,8 +649,7 @@ void DisplayText::set_text_align(const std::string& align)
* @param effect text effect
* @param cycle_num number of effect cycles (optional, default=endless)
*/
void DisplayText::set_text_effect(text_effect_t effect, uint8_t cycle_num)
{
void DisplayText::set_text_effect(text_effect_t effect, uint8_t cycle_num) {
if (effect >= TEXT_EFFECT_LAST_ENUM) {
ESP_LOGE(TAG, "Invalid display text effect: %i", effect);
return;
@ -680,8 +661,8 @@ void DisplayText::set_text_effect(text_effect_t effect, uint8_t cycle_num)
this->effect_change_count_ = -1;
init_text_effect_();
ESP_LOGD(TAG, "Set effect: text=%s, effect=%i, cycles=%u, start-pos=%u, max-pos=%u, vi-idx=%u, vi-len=%u",
this->text, this->effect, this->cycle_num, this->start_pos,
this->max_pos, this->visible_idx, this->visible_len);
this->text, this->effect, this->cycle_num, this->start_pos, this->max_pos, this->visible_idx,
this->visible_len);
}
}
@ -691,8 +672,7 @@ void DisplayText::set_text_effect(text_effect_t effect, uint8_t cycle_num)
* @param effect text effect (as string)
* @param cycle_num number of effect cycles (optional, default=endless)
*/
void DisplayText::set_text_effect(const std::string& effect, uint8_t cycle_num)
{
void DisplayText::set_text_effect(const std::string &effect, uint8_t cycle_num) {
text_effect_t text_effect = TEXT_EFFECT_LAST_ENUM;
if (!effect.empty()) {
@ -704,8 +684,7 @@ void DisplayText::set_text_effect(const std::string& effect, uint8_t cycle_num)
text_effect = TEXT_EFFECT_SCROLL_LEFT;
else
ESP_LOGW(TAG, "Invalid text effect: %s", effect);
}
else
} else
ESP_LOGW(TAG, "No text effect given");
if (text_effect >= TEXT_EFFECT_LAST_ENUM)
return;
@ -716,8 +695,8 @@ void DisplayText::set_text_effect(const std::string& effect, uint8_t cycle_num)
* @brief Updates the mode "blink". The display buffer must be updated before.
*/
void DisplayText::blink(void) {
ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__,
this->start_pos, this->visible_idx, this->visible_len);
ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx,
this->visible_len);
// update effect mode...
if (++this->effect_change_count_ >= 2) { // one on/off phase complete?
@ -739,16 +718,16 @@ void DisplayText::blink(void) {
init_text_effect_(); // no -> switch to "on" phase
}
ESP_LOGV(TAG, "%s(): EXIT: start-idx=%u, text-idx=%u, text-len=%u", __func__,
this->start_pos, this->visible_idx, this->visible_len);
ESP_LOGV(TAG, "%s(): EXIT: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx,
this->visible_len);
}
/**
* @brief Updates the mode "scroll left". The display buffer must be updated before.
*/
void DisplayText::scroll_left(void) {
ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__,
this->start_pos, this->visible_idx, this->visible_len);
ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx,
this->visible_len);
// update effect mode...
if (this->visible_len == 0) {
@ -774,8 +753,8 @@ void DisplayText::scroll_left(void) {
--this->visible_len; // decrement visible text length (scroll out to left side)
}
ESP_LOGV(TAG, "%s(): EXIT: start-idx=%u, text-idx=%u, text-len=%u", __func__,
this->start_pos, this->visible_idx, this->visible_len);
ESP_LOGV(TAG, "%s(): EXIT: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx,
this->visible_len);
}
/**
@ -788,16 +767,16 @@ void DisplayText::scroll_left(void) {
*
* @return frequency supported by hardware (0 = no support)
*/
uint32_t DisplayBrightness::config_brightness_pwm(uint8_t pwm_pin_no, uint8_t channel,
uint8_t resolution, uint32_t freq) {
uint32_t DisplayBrightness::config_brightness_pwm(uint8_t pwm_pin_no, uint8_t channel, uint8_t resolution,
uint32_t freq) {
uint32_t freq_supported;
if ((freq_supported = ledcSetup(channel, freq, resolution)) != 0) {
ledcAttachPin(pwm_pin_no, channel);
this->brightness_pwm_channel_ = channel;
this->brightness_max_duty_ = pow(2, resolution); // max. duty value for given resolution
ESP_LOGD(TAG, "Prepare brightness PWM: pin=%u, channel=%u, resolution=%ubit, freq=%uHz",
pwm_pin_no, channel, resolution, freq_supported);
ESP_LOGD(TAG, "Prepare brightness PWM: pin=%u, channel=%u, resolution=%ubit, freq=%uHz", pwm_pin_no, channel,
resolution, freq_supported);
} else {
ESP_LOGD(TAG, "Failed to configure brightness PWM");
}
@ -843,12 +822,10 @@ void DisplayMode::set_mode(display_mode_t mode, uint32_t duration_ms) {
this->duration_ms = duration_ms;
if (duration_ms > 0)
this->duration_ms_start_ = millis();
ESP_LOGD(TAG, "Set display mode: mode=%i, duration=%" PRIu32 "ms, duration-start=%" PRIu32 "ms",
this->mode, this->duration_ms, this->duration_ms_start_);
ESP_LOGD(TAG, "Set display mode: mode=%i, duration=%" PRIu32 "ms, duration-start=%" PRIu32 "ms", this->mode,
this->duration_ms, this->duration_ms_start_);
}
}
} // namespace max6921
} // namespace esphome

View file

@ -10,8 +10,8 @@ namespace max6921 {
class MAX6921Component;
#define FONT_SIZE 95
#define DISPLAY_TEXT_LEN FONT_SIZE // at least font size for demo mode "scroll font"
static const uint FONT_SIZE = 95;
static const uint DISPLAY_TEXT_LEN = FONT_SIZE; // at least font size for demo mode "scroll font"
enum display_mode_t {
DISP_MODE_PRINT, // input by it-functions
@ -19,12 +19,7 @@ enum display_mode_t {
DISP_MODE_LAST_ENUM
};
enum text_align_t {
TEXT_ALIGN_LEFT,
TEXT_ALIGN_CENTER,
TEXT_ALIGN_RIGHT,
TEXT_ALIGN_LAST_ENUM
};
enum text_align_t { TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT, TEXT_ALIGN_LAST_ENUM };
enum text_effect_t {
TEXT_EFFECT_NONE, // show text at given position, cut if too long
@ -39,11 +34,9 @@ enum demo_mode_t {
DEMO_MODE_SCROLL_FONT,
};
class DisplayBrightness
{
class DisplayBrightness {
public:
uint32_t config_brightness_pwm(uint8_t pwm_pin_no, uint8_t channel,
uint8_t resolution, uint32_t freq_wanted);
uint32_t config_brightness_pwm(uint8_t pwm_pin_no, uint8_t channel, uint8_t resolution, uint32_t freq_wanted);
float get_brightness(void) { return this->brightness_cfg_value_; }
void set_brightness(float percent);
@ -54,8 +47,7 @@ class DisplayBrightness
uint8_t brightness_pwm_channel_;
};
class DisplayMode
{
class DisplayMode {
public:
display_mode_t mode;
uint32_t duration_ms;
@ -66,8 +58,7 @@ class DisplayMode
uint32_t duration_ms_start_;
};
class DisplayText
{
class DisplayText {
public:
bool content_changed;
uint max_pos; // max. display position
@ -93,9 +84,7 @@ class DisplayText
void init_text_effect_(void);
};
class Display : public DisplayBrightness,
public DisplayMode
{
class Display : public DisplayBrightness, public DisplayMode {
public:
Display(MAX6921Component *max6921) { max6921_ = max6921; }
void clear(int pos = -1);
@ -106,8 +95,8 @@ class Display : public DisplayBrightness,
void set_demo_mode(demo_mode_t mode, uint32_t interval, uint8_t cycle_num);
void set_demo_mode(const std::string &mode, uint32_t interval, uint8_t cycle_num);
int set_text(const char *text, uint8_t start_pos);
int set_text(const std::string& text, uint8_t start_pos, const std::string& align,
uint32_t duration, const std::string& effect, uint32_t interval, uint8_t cycle_num);
int set_text(const std::string &text, uint8_t start_pos, const std::string &align, uint32_t duration,
const std::string &effect, uint32_t interval, uint8_t cycle_num);
void set_update_interval(uint32_t interval_ms);
void update(void);
@ -130,6 +119,5 @@ class Display : public DisplayBrightness,
void init_font__(void);
};
} // namespace max6921
} // namespace esphome

View file

@ -46,6 +46,8 @@ CONF_POS_12_PIN = "pos_12_pin"
CONF_TEXT = "text"
CONF_ALIGN = "align"
CONF_CYCLE_NUM = "cycle_num"
CONF_OFF = "off"
CONF_SCROLL_FONT = "scroll_font"
max6921_ns = cg.esphome_ns.namespace("max6921")
@ -59,13 +61,11 @@ SetTextAction = max6921_ns.class_("SetTextAction", automation.Action)
# optional "demo_mode" configuration
CONF_DEMO_MODE_OFF = "off"
CONF_DEMO_MODE_SCROLL_FONT = "scroll_font"
DemoMode = max6921_ns.enum("DemoMode")
DEMO_MODES = {
CONF_DEMO_MODE_OFF: DemoMode.DEMO_MODE_OFF,
CONF_DEMO_MODE_SCROLL_FONT: DemoMode.DEMO_MODE_SCROLL_FONT,
}
# DemoMode = max6921_ns.enum("DemoMode")
# DEMO_MODES = {
# CONF_OFF: DemoMode.OFF,
# CONF_SCROLL_FONT: DemoMode.SCROLL_FONT,
# }
def validate_out_pin_mapping(value):

View file

@ -12,7 +12,6 @@ namespace max6921 {
static const char *const TAG = "max6921";
float MAX6921Component::get_setup_priority() const { return setup_priority::HARDWARE; }
void MAX6921Component::setup() {
@ -31,10 +30,10 @@ void MAX6921Component::setup() {
this->display_->setup(this->seg_to_out_map__, this->pos_to_out_map__);
// setup display brightness (PWM for BLANK pin)...
if (this->display_->config_brightness_pwm(this->blank_pin_->get_pin(), 0,
PWM_RESOLUTION, PWM_FREQ_WANTED) == 0) {
if (this->display_->config_brightness_pwm(this->blank_pin_->get_pin(), 0, PWM_RESOLUTION, PWM_FREQ_WANTED) == 0) {
ESP_LOGE(TAG, "Failed to configure PWM -> set to max. brightness");
pinMode(this->blank_pin_->get_pin(), OUTPUT);
this->blank_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->blank_pin_->setup();
this->disable_blank_(); // enable display (max. brightness)
}
@ -87,7 +86,6 @@ void MAX6921Component::update() {
(*this->writer_)(*this);
}
/*
* Evaluates lambda function
* start_pos: 0..n = left..right display position

View file

@ -12,7 +12,6 @@ namespace max6921 {
#define ARRAY_ELEM_COUNT(array) (sizeof(array) / sizeof(array[0]))
class MAX6921Component;
class Display;
@ -41,11 +40,11 @@ class MAX6921Component : public PollingComponent,
protected:
GPIOPin *load_pin_{};
InternalGPIOPin *blank_pin_;
InternalGPIOPin *blank_pin_{};
bool setup_finished{false};
void disable_blank_() { digitalWrite(this->blank_pin_->get_pin(), LOW); } // display on
void disable_blank_() { this->blank_pin_->digital_write(false); } // display on
void IRAM_ATTR HOT disable_load_() { this->load_pin_->digital_write(false); }
void enable_blank_() { digitalWrite(this->blank_pin_->get_pin(), HIGH); } // display off
void enable_blank_() { this->blank_pin_->digital_write(true); } // display off
void IRAM_ATTR HOT enable_load_() { this->load_pin_->digital_write(true); }
void update_demo_mode_scroll_font_(void);
optional<max6921_writer_t> writer_{};
@ -55,6 +54,5 @@ class MAX6921Component : public PollingComponent,
std::vector<uint8_t> pos_to_out_map__; // mapping of display positions to MAX6921 OUT pins
};
} // namespace max6921
} // namespace esphome