mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 06:33:51 +00:00
Cleanup dashboard JS (#491)
* Cleanup dashboard JS * Add vscode * Save start_mark/end_mark * Updates * Updates * Remove need for cv.nameable It's a bit hacky but removes so much bloat from integrations * Add enum helper * Document APIs, and Improvements * Fixes * Fixes * Update PULL_REQUEST_TEMPLATE.md * Updates * Updates * Updates
This commit is contained in:
@@ -3,7 +3,7 @@ import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import display, spi
|
||||
from esphome.const import CONF_BUSY_PIN, CONF_DC_PIN, CONF_FULL_UPDATE_EVERY, \
|
||||
CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_PAGES, CONF_RESET_PIN, CONF_UPDATE_INTERVAL
|
||||
CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_PAGES, CONF_RESET_PIN
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
|
||||
@@ -38,27 +38,24 @@ def validate_full_update_every_only_type_a(value):
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.All(display.FULL_DISPLAY_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_variable_id(WaveshareEPaper),
|
||||
cv.GenerateID(): cv.declare_id(WaveshareEPaper),
|
||||
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Required(CONF_MODEL): cv.one_of(*MODELS, lower=True),
|
||||
cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema,
|
||||
cv.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t,
|
||||
cv.Optional(CONF_UPDATE_INTERVAL, default='1s'): cv.update_interval,
|
||||
}).extend(cv.COMPONENT_SCHEMA).extend(spi.SPI_DEVICE_SCHEMA),
|
||||
}).extend(cv.polling_component_schema('1s')).extend(spi.SPI_DEVICE_SCHEMA),
|
||||
validate_full_update_every_only_type_a,
|
||||
cv.has_at_most_one_key(CONF_PAGES, CONF_LAMBDA))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
dc = yield cg.gpio_pin_expression(config[CONF_DC_PIN])
|
||||
|
||||
model_type, model = MODELS[config[CONF_MODEL]]
|
||||
if model_type == 'a':
|
||||
rhs = WaveshareEPaperTypeA.new(dc, model)
|
||||
rhs = WaveshareEPaperTypeA.new(model)
|
||||
var = cg.Pvariable(config[CONF_ID], rhs, type=WaveshareEPaperTypeA)
|
||||
elif model_type == 'b':
|
||||
rhs = model.new(dc)
|
||||
rhs = model.new()
|
||||
var = cg.Pvariable(config[CONF_ID], rhs, type=model)
|
||||
else:
|
||||
raise NotImplementedError()
|
||||
@@ -67,6 +64,9 @@ def to_code(config):
|
||||
yield display.register_display(var, config)
|
||||
yield spi.register_spi_device(var, config)
|
||||
|
||||
dc = yield cg.gpio_pin_expression(config[CONF_DC_PIN])
|
||||
cg.add(var.set_dc_pin(dc))
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')],
|
||||
return_type=cg.void)
|
||||
|
||||
@@ -110,7 +110,6 @@ void HOT WaveshareEPaper::draw_absolute_pixel_internal(int x, int y, int color)
|
||||
this->buffer_[pos] &= ~(0x80 >> subpos);
|
||||
}
|
||||
uint32_t WaveshareEPaper::get_buffer_length_() { return this->get_width_internal() * this->get_height_internal() / 8u; }
|
||||
WaveshareEPaper::WaveshareEPaper(GPIOPin *dc_pin) : PollingComponent(0), dc_pin_(dc_pin) {}
|
||||
bool WaveshareEPaper::is_device_high_speed() { return true; }
|
||||
void WaveshareEPaper::start_command_() {
|
||||
this->dc_pin_->digital_write(false);
|
||||
@@ -246,8 +245,7 @@ void WaveshareEPaperTypeA::write_lut_(const uint8_t *lut) {
|
||||
for (uint8_t i = 0; i < 30; i++)
|
||||
this->data(lut[i]);
|
||||
}
|
||||
WaveshareEPaperTypeA::WaveshareEPaperTypeA(GPIOPin *dc_pin, WaveshareEPaperTypeAModel model)
|
||||
: WaveshareEPaper(dc_pin), model_(model) {}
|
||||
WaveshareEPaperTypeA::WaveshareEPaperTypeA(WaveshareEPaperTypeAModel model) : model_(model) {}
|
||||
void WaveshareEPaperTypeA::set_full_update_every(uint32_t full_update_every) {
|
||||
this->full_update_every_ = full_update_every;
|
||||
}
|
||||
@@ -414,7 +412,6 @@ void HOT WaveshareEPaper2P7In::display() {
|
||||
}
|
||||
int WaveshareEPaper2P7In::get_width_internal() { return 176; }
|
||||
int WaveshareEPaper2P7In::get_height_internal() { return 264; }
|
||||
WaveshareEPaper2P7In::WaveshareEPaper2P7In(GPIOPin *dc_pin) : WaveshareEPaper(dc_pin) {}
|
||||
void WaveshareEPaper2P7In::dump_config() {
|
||||
LOG_DISPLAY("", "Waveshare E-Paper", this);
|
||||
ESP_LOGCONFIG(TAG, " Model: 2.7in");
|
||||
@@ -523,7 +520,6 @@ void HOT WaveshareEPaper4P2In::display() {
|
||||
int WaveshareEPaper4P2In::get_width_internal() { return 400; }
|
||||
int WaveshareEPaper4P2In::get_height_internal() { return 300; }
|
||||
bool WaveshareEPaper4P2In::is_device_high_speed() { return false; }
|
||||
WaveshareEPaper4P2In::WaveshareEPaper4P2In(GPIOPin *dc_pin) : WaveshareEPaper(dc_pin) {}
|
||||
void WaveshareEPaper4P2In::dump_config() {
|
||||
LOG_DISPLAY("", "Waveshare E-Paper", this);
|
||||
ESP_LOGCONFIG(TAG, " Model: 4.2in");
|
||||
@@ -609,7 +605,6 @@ void HOT WaveshareEPaper7P5In::display() {
|
||||
}
|
||||
int WaveshareEPaper7P5In::get_width_internal() { return 640; }
|
||||
int WaveshareEPaper7P5In::get_height_internal() { return 384; }
|
||||
WaveshareEPaper7P5In::WaveshareEPaper7P5In(GPIOPin *dc_pin) : WaveshareEPaper(dc_pin) {}
|
||||
void WaveshareEPaper7P5In::dump_config() {
|
||||
LOG_DISPLAY("", "Waveshare E-Paper", this);
|
||||
ESP_LOGCONFIG(TAG, " Model: 7.5in");
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace waveshare_epaper {
|
||||
|
||||
class WaveshareEPaper : public PollingComponent, public spi::SPIDevice, public display::DisplayBuffer {
|
||||
public:
|
||||
WaveshareEPaper(GPIOPin *dc_pin);
|
||||
void set_dc_pin(GPIOPin *dc_pin) { dc_pin_ = dc_pin; }
|
||||
float get_setup_priority() const override;
|
||||
void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
|
||||
void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
|
||||
@@ -53,7 +53,7 @@ enum WaveshareEPaperTypeAModel {
|
||||
|
||||
class WaveshareEPaperTypeA : public WaveshareEPaper {
|
||||
public:
|
||||
WaveshareEPaperTypeA(GPIOPin *dc_pin, WaveshareEPaperTypeAModel model);
|
||||
WaveshareEPaperTypeA(WaveshareEPaperTypeAModel model);
|
||||
|
||||
void setup() override;
|
||||
|
||||
@@ -83,7 +83,6 @@ enum WaveshareEPaperTypeBModel {
|
||||
|
||||
class WaveshareEPaper2P7In : public WaveshareEPaper {
|
||||
public:
|
||||
WaveshareEPaper2P7In(GPIOPin *dc_pin);
|
||||
void setup() override;
|
||||
|
||||
void display() override;
|
||||
@@ -98,7 +97,6 @@ class WaveshareEPaper2P7In : public WaveshareEPaper {
|
||||
|
||||
class WaveshareEPaper4P2In : public WaveshareEPaper {
|
||||
public:
|
||||
WaveshareEPaper4P2In(GPIOPin *dc_pin);
|
||||
void setup() override;
|
||||
|
||||
void display() override;
|
||||
@@ -115,7 +113,6 @@ class WaveshareEPaper4P2In : public WaveshareEPaper {
|
||||
|
||||
class WaveshareEPaper7P5In : public WaveshareEPaper {
|
||||
public:
|
||||
WaveshareEPaper7P5In(GPIOPin *dc_pin);
|
||||
void setup() override;
|
||||
|
||||
void display() override;
|
||||
|
||||
Reference in New Issue
Block a user