Compare commits

..

19 Commits

Author SHA1 Message Date
Otto Winter
e4bbb56f6b Apply removed patch 2019-05-29 11:36:31 +02:00
Otto Winter
96d30e28d4 Bump version to v1.13.0b5 2019-05-29 11:22:10 +02:00
Jesse Hills
41b73ff892 Add CT Clamp component (#559)
* Add CT Clamp component

* Update lint

* Some more fixes

* Make updates to work as an analog sensor consumer

* Remove unused imports
Update lint suggestions

* Move setup_priority to header

* Remove unused calibration value

* Remove Unique ID

- Will be auto generated

* Update to use loop and not slow down main loop

Co-authored-by: Otto Winter <otto@otto-winter.com>
2019-05-29 11:22:00 +02:00
Otto Winter
afc4e45fb0 Warn if a component does long-running work in loop thread (#565)
* Warn if a component does long-running work in loop thread

* Update application.cpp
2019-05-29 11:21:15 +02:00
gitolicious
8778ddd5c5 Renamed upload button (#563)
* Renamed upload button

* Renamed upload button in code
2019-05-29 11:17:56 +02:00
Otto Winter
23f1798d20 Bump version to v1.13.0b4 2019-05-28 21:37:31 +02:00
gitolicious
6f3c126805 added download, edit and retry buttons to upload modal (#557)
* added download, edit and retry buttons to upload modal

* changed hide for disabled, resorted buttons

* moved upload action buttons to menu

* button changes

moved edit button from menu in upload modal
swapped validation button for upload in edit modal
2019-05-28 21:37:28 +02:00
Otto Winter
a9ae70cff1 Fix CWWW/RGBWW lights (#562) 2019-05-28 21:37:28 +02:00
Michiel van Turnhout
d7a8c50c98 Binary sensor map implementation (#551)
* add binary_sensor_map c code

* add python file

* fixed python and C++ code for new framework

* renamed add_sensor to add_channel

* travis

* Updates

- Use struct for channels_ array - heap allocation is not really necessary here.
- any_active can also be written as mask != 0
- Update setup priority to DATA
- Use shorter TAG (name is already long; not important)
- Quotes around name
- Add icon to sensor
- Use new cv.typed_schema
- Change CONF_CHANNEL to CONF_BINARY_SENSOR - makes it clearer that this option accepts a binary sensor (and not for example an int)
- Add test


Co-authored-by: Otto Winter <otto@otto-winter.com>
2019-05-28 21:37:27 +02:00
Michiel van Turnhout
9e56318498 Mpr121 added debounce and thresholds config (#558)
* fixed code issues from previous PR

* travis line to long

* travis

* more travis

* Update esphome/components/mpr121/mpr121.h

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* fixed issues

* fixed issues

* fixes remove duplicate line
remove threshold settings

* fixed touch release thresholds mixup
2019-05-28 21:37:27 +02:00
Otto Winter
2570f2d6f2 Waveshare enter deep sleep mode on shutdown (#561)
Fixes https://github.com/esphome/issues/issues/307

Only enters deep sleep mode when node turns off - not between updates because entering+exiting deep sleep takes some time (could be added later)
2019-05-28 21:37:27 +02:00
Otto Winter
359f54d3c1 Bump version to v1.13.0b3 2019-05-28 16:35:55 +02:00
Otto Winter
68ce1b18c4 Add NTC and resistance sensor (#560)
* Add NTC and resistance sensor

Fixes https://github.com/esphome/feature-requests/issues/248

* Fix

* Fix platformio4 moved get_project_dir
2019-05-28 16:35:50 +02:00
Otto Winter
76d7802650 Do not recompile on version change 2019-05-28 12:11:46 +02:00
Otto Winter
9be16916b7 Fix gitlab 2019-05-28 12:01:32 +02:00
Otto Winter
0ced5509fc Bump version to v1.13.0b2 2019-05-28 10:48:48 +02:00
gitolicious
bd6b9ff1da added link from dashboard to web server, if configured (#556)
* added link from dashboard to web server, if configured

* linter fixes

* simplified integration lookup

* included loaded_integration in storage json

* included loaded_integration in storage json

* fixed loaded_integrations

plus linter changes

* fixed comment: List

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* return empty list

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* convert to list

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* default to empty list on missing loaded_integrations

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* None check no longer needed

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* None check no longer needed

Co-Authored-By: Otto Winter <otto@otto-winter.com>

* removed newline
2019-05-28 10:48:45 +02:00
Otto Winter
edee28acf0 Use lint image for tests 2019-05-28 10:41:19 +02:00
Otto Winter
53e8b3ed3e Update gitlab CI script, add cpp lint 2019-05-28 10:24:13 +02:00
39 changed files with 1132 additions and 297 deletions

View File

@@ -3,6 +3,8 @@
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375/
BASE_VERSION: '1.5.1'
TZ: UTC
stages:
- lint
@@ -10,7 +12,7 @@ stages:
- deploy
.lint: &lint
image: esphome/esphome-base-amd64
image: esphome/esphome-lint:latest
stage: lint
before_script:
- script/setup
@@ -18,14 +20,12 @@ stages:
- docker
.test: &test
image: esphome/esphome-base-amd64
image: esphome/esphome-lint:latest
stage: test
before_script:
- script/setup
tags:
- docker
variables:
TZ: UTC
.docker-base: &docker-base
image: esphome/esphome-base-builder
@@ -40,11 +40,11 @@ stages:
- |
if [[ "${IS_HASSIO}" == "YES" ]]; then
BUILD_FROM=esphome/esphome-hassio-base-${BUILD_ARCH}:1.5.1
BUILD_FROM=esphome/esphome-hassio-base-${BUILD_ARCH}:${BASE_VERSION}
BUILD_TO=esphome/esphome-hassio-${BUILD_ARCH}
DOCKERFILE=docker/Dockerfile.hassio
else
BUILD_FROM=esphome/esphome-base-${BUILD_ARCH}:1.5.1
BUILD_FROM=esphome/esphome-base-${BUILD_ARCH}:${BASE_VERSION}
if [[ "${BUILD_ARCH}" == "amd64" ]]; then
BUILD_TO=esphome/esphome
else
@@ -93,12 +93,33 @@ stages:
- docker
stage: deploy
lint-python:
lint-custom:
<<: *lint
script:
- script/ci-custom.py
lint-python:
<<: *lint
script:
- script/lint-python
lint-tidy:
<<: *lint
script:
- pio init --ide atom
- |
if ! patch -R -p0 -s -f --dry-run <script/.neopixelbus.patch; then
patch -p0 < script/.neopixelbus.patch
fi
- script/clang-tidy --all-headers --fix
- script/ci-suggest-changes
lint-format:
<<: *lint
script:
- script/clang-format -i
- script/ci-suggest-changes
test1:
<<: *test
script:
@@ -115,16 +136,12 @@ test3:
- esphome tests/test3.yaml compile
.deploy-pypi: &deploy-pypi
<<: *lint
stage: deploy
image: python:2.7
before_script:
- pip install -e .
- pip install twine
script:
- python setup.py sdist bdist_wheel
- twine upload dist/*
tags:
- docker
- pip install twine wheel
- python setup.py sdist bdist_wheel
- twine upload dist/*
deploy-release:pypi:
<<: *deploy-pypi
@@ -143,77 +160,64 @@ deploy-beta:pypi:
.latest: &latest
<<: *docker-base
only:
- /^v([0-9\.]+)$/
- /^v([0-9\.]+)$/
except:
- branches
.latest-vars: &latest-vars
RELEASE: YES
LATEST: YES
# Also push to beta tag
BETA: YES
- branches
.beta: &beta
<<: *docker-base
only:
- /^v([0-9\.]+b\d+)$/
- /^v([0-9\.]+b\d+)$/
except:
- branches
.beta-vars: &beta-vars
RELEASE: YES
BETA: YES
- branches
.dev: &dev
<<: *docker-base
only:
- dev
- dev
.dev-vars: &dev-vars
DEV: YES
#aarch64-beta-docker:
# <<: *beta
# variables:
# BETA: "YES"
# BUILD_ARCH: aarch64
# IS_HASSIO: "NO"
# RELEASE: "YES"
#aarch64-beta-hassio:
# <<: *beta
# variables:
# BETA: "YES"
# BUILD_ARCH: aarch64
# IS_HASSIO: "YES"
# RELEASE: "YES"
#aarch64-dev-docker:
# <<: *dev
# variables:
# BUILD_ARCH: aarch64
# DEV: "YES"
# IS_HASSIO: "NO"
#aarch64-dev-hassio:
# <<: *dev
# variables:
# BUILD_ARCH: aarch64
# DEV: "YES"
# IS_HASSIO: "YES"
#aarch64-latest-docker:
# <<: *latest
# variables:
# BETA: "YES"
# BUILD_ARCH: aarch64
# IS_HASSIO: "NO"
# LATEST: "YES"
# RELEASE: "YES"
#aarch64-latest-hassio:
# <<: *latest
# variables:
# BETA: "YES"
# BUILD_ARCH: aarch64
# IS_HASSIO: "YES"
# LATEST: "YES"
# RELEASE: "YES"
aarch64-beta-docker:
<<: *beta
variables:
BETA: "YES"
BUILD_ARCH: aarch64
IS_HASSIO: "NO"
RELEASE: "YES"
aarch64-beta-hassio:
<<: *beta
variables:
BETA: "YES"
BUILD_ARCH: aarch64
IS_HASSIO: "YES"
RELEASE: "YES"
aarch64-dev-docker:
<<: *dev
variables:
BUILD_ARCH: aarch64
DEV: "YES"
IS_HASSIO: "NO"
aarch64-dev-hassio:
<<: *dev
variables:
BUILD_ARCH: aarch64
DEV: "YES"
IS_HASSIO: "YES"
aarch64-latest-docker:
<<: *latest
variables:
BETA: "YES"
BUILD_ARCH: aarch64
IS_HASSIO: "NO"
LATEST: "YES"
RELEASE: "YES"
aarch64-latest-hassio:
<<: *latest
variables:
BETA: "YES"
BUILD_ARCH: aarch64
IS_HASSIO: "YES"
LATEST: "YES"
RELEASE: "YES"
amd64-beta-docker:
<<: *beta
variables:
@@ -256,45 +260,45 @@ amd64-latest-hassio:
IS_HASSIO: "YES"
LATEST: "YES"
RELEASE: "YES"
armhf-beta-docker:
armv7-beta-docker:
<<: *beta
variables:
BETA: "YES"
BUILD_ARCH: armhf
BUILD_ARCH: armv7
IS_HASSIO: "NO"
RELEASE: "YES"
armhf-beta-hassio:
armv7-beta-hassio:
<<: *beta
variables:
BETA: "YES"
BUILD_ARCH: armhf
BUILD_ARCH: armv7
IS_HASSIO: "YES"
RELEASE: "YES"
armhf-dev-docker:
armv7-dev-docker:
<<: *dev
variables:
BUILD_ARCH: armhf
BUILD_ARCH: armv7
DEV: "YES"
IS_HASSIO: "NO"
armhf-dev-hassio:
armv7-dev-hassio:
<<: *dev
variables:
BUILD_ARCH: armhf
BUILD_ARCH: armv7
DEV: "YES"
IS_HASSIO: "YES"
armhf-latest-docker:
armv7-latest-docker:
<<: *latest
variables:
BETA: "YES"
BUILD_ARCH: armhf
BUILD_ARCH: armv7
IS_HASSIO: "NO"
LATEST: "YES"
RELEASE: "YES"
armhf-latest-hassio:
armv7-latest-hassio:
<<: *latest
variables:
BETA: "YES"
BUILD_ARCH: armhf
BUILD_ARCH: armv7
IS_HASSIO: "YES"
LATEST: "YES"
RELEASE: "YES"

View File

@@ -1,6 +1,18 @@
FROM python:2.7
FROM esphome/esphome-base-amd64:1.5.1
COPY requirements.txt /requirements.txt
RUN \
apt-get update \
&& apt-get install -y --no-install-recommends \
clang-format-7 \
clang-tidy-7 \
patch \
&& rm -rf \
/tmp/* \
/var/{cache,log}/* \
/var/lib/apt/lists/*
RUN pip install -r /requirements.txt && \
pip install flake8==3.6.0 pylint==1.9.4 pillow
COPY requirements_test.txt /requirements_test.txt
RUN pip2 install -r /requirements_test.txt
VOLUME ["/esphome"]
WORKDIR /esphome

View File

@@ -127,7 +127,10 @@ def wrap_to_code(name, comp):
def wrapped(conf):
cg.add(cg.LineComment(u"{}:".format(name)))
if comp.config_schema is not None:
cg.add(cg.LineComment(indent(yaml_util.dump(conf).decode('utf-8'))))
conf_str = yaml_util.dump(conf)
if IS_PY2:
conf_str = conf_str.decode('utf-8')
cg.add(cg.LineComment(indent(conf_str)))
yield coro(conf)
return wrapped

View File

@@ -0,0 +1,60 @@
#include "binary_sensor_map.h"
#include "esphome/core/log.h"
namespace esphome {
namespace binary_sensor_map {
static const char *TAG = "binary_sensor_map";
void BinarySensorMap::dump_config() { LOG_SENSOR(" ", "binary_sensor_map", this); }
void BinarySensorMap::loop() {
switch (this->sensor_type_) {
case BINARY_SENSOR_MAP_TYPE_GROUP:
this->process_group_();
break;
}
}
void BinarySensorMap::process_group_() {
float total_current_value = 0.0;
uint8_t num_active_sensors = 0;
uint64_t mask = 0x00;
// check all binary_sensors for its state. when active add its value to total_current_value.
// create a bitmask for the binary_sensor status on all channels
for (size_t i = 0; i < this->channels_.size(); i++) {
auto bs = this->channels_[i];
if (bs.binary_sensor->state) {
num_active_sensors++;
total_current_value += bs.sensor_value;
mask |= 1 << i;
}
}
// check if the sensor map was touched
if (mask != 0ULL) {
// did the bit_mask change or is it a new sensor touch
if (this->last_mask_ != mask) {
float publish_value = total_current_value / num_active_sensors;
ESP_LOGD(TAG, "'%s' - Publishing %.2f", this->name_.c_str(), publish_value);
this->publish_state(publish_value);
}
} else if (this->last_mask_ != 0ULL) {
// is this a new sensor release
ESP_LOGD(TAG, "'%s' - No binary sensor active, publishing NAN", this->name_.c_str());
this->publish_state(NAN);
}
this->last_mask_ = mask;
}
void BinarySensorMap::add_channel(binary_sensor::BinarySensor *sensor, float value) {
BinarySensorMapChannel sensor_channel{
.binary_sensor = sensor,
.sensor_value = value,
};
this->channels_.push_back(sensor_channel);
}
void BinarySensorMap::set_sensor_type(BinarySensorMapType sensor_type) { this->sensor_type_ = sensor_type; }
} // namespace binary_sensor_map
} // namespace esphome

View File

@@ -0,0 +1,58 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace binary_sensor_map {
enum BinarySensorMapType {
BINARY_SENSOR_MAP_TYPE_GROUP,
};
struct BinarySensorMapChannel {
binary_sensor::BinarySensor *binary_sensor;
float sensor_value;
};
/** Class to group binary_sensors to one Sensor.
*
* Each binary sensor represents a float value in the group.
*/
class BinarySensorMap : public sensor::Sensor, public Component {
public:
void dump_config() override;
/**
* The loop checks all binary_sensor states
* When the binary_sensor reports a true value for its state, then the float value it represents is added to the
* total_current_value
*
* Only when the total_current_value changed and at least one sensor reports an active state we publish the sensors
* average value. When the value changed and no sensors ar active we publish NAN.
* */
void loop() override;
float get_setup_priority() const override { return setup_priority::DATA; }
/** Add binary_sensors to the group.
* Each binary_sensor represents a float value when its state is true
*
* @param *sensor The binary sensor.
* @param value The value this binary_sensor represents
*/
void add_channel(binary_sensor::BinarySensor *sensor, float value);
void set_sensor_type(BinarySensorMapType sensor_type);
protected:
std::vector<BinarySensorMapChannel> channels_{};
BinarySensorMapType sensor_type_{BINARY_SENSOR_MAP_TYPE_GROUP};
// this gives max 64 channels per binary_sensor_map
uint64_t last_mask_{0x00};
/**
* methods to process the types of binary_sensor_maps
* GROUP: process_group_() just map to a value
* */
void process_group_();
};
} // namespace binary_sensor_map
} // namespace esphome

View File

@@ -0,0 +1,42 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, binary_sensor
from esphome.const import CONF_ID, CONF_CHANNELS, CONF_VALUE, CONF_TYPE, UNIT_EMPTY, \
ICON_CHECK_CIRCLE_OUTLINE, CONF_BINARY_SENSOR
DEPENDENCIES = ['binary_sensor']
binary_sensor_map_ns = cg.esphome_ns.namespace('binary_sensor_map')
BinarySensorMap = binary_sensor_map_ns.class_('BinarySensorMap', cg.Component, sensor.Sensor)
SensorMapType = binary_sensor_map_ns.enum('SensorMapType')
CONF_GROUP = 'group'
SENSOR_MAP_TYPES = {
CONF_GROUP: SensorMapType.BINARY_SENSOR_MAP_TYPE_GROUP,
}
entry = {
cv.Required(CONF_BINARY_SENSOR): cv.use_id(binary_sensor.BinarySensor),
cv.Required(CONF_VALUE): cv.float_,
}
CONFIG_SCHEMA = cv.typed_schema({
CONF_GROUP: sensor.sensor_schema(UNIT_EMPTY, ICON_CHECK_CIRCLE_OUTLINE, 0).extend({
cv.GenerateID(): cv.declare_id(BinarySensorMap),
cv.Required(CONF_CHANNELS): cv.All(cv.ensure_list(entry), cv.Length(min=1)),
}),
}, lower=True)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield sensor.register_sensor(var, config)
constant = SENSOR_MAP_TYPES[config[CONF_TYPE]]
cg.add(var.set_sensor_type(constant))
for ch in config[CONF_CHANNELS]:
input_var = yield cg.get_variable(ch[CONF_BINARY_SENSOR])
cg.add(var.add_channel(input_var, ch[CONF_VALUE]))

View File

View File

@@ -0,0 +1,67 @@
#include "ct_clamp_sensor.h"
#include "esphome/core/log.h"
#include <cmath>
namespace esphome {
namespace ct_clamp {
static const char *TAG = "ct_clamp";
void CTClampSensor::dump_config() {
LOG_SENSOR("", "CT Clamp Sensor", this);
ESP_LOGCONFIG(TAG, " Sample Duration: %.2fs", this->sample_duration_ / 1e3f);
LOG_UPDATE_INTERVAL(this);
}
void CTClampSensor::update() {
// Update only starts the sampling phase, in loop() the actual sampling is happening.
// Request a high loop() execution interval during sampling phase.
this->high_freq_.start();
// Set timeout for ending sampling phase
this->set_timeout("read", this->sample_duration_, [this]() {
this->is_sampling_ = false;
this->high_freq_.stop();
if (this->num_samples_ == 0) {
// Shouldn't happen, but let's not crash if it does.
this->publish_state(NAN);
return;
}
float raw = this->sample_sum_ / this->num_samples_;
float irms = std::sqrt(raw);
ESP_LOGD(TAG, "'%s' - Raw Value: %.2fA", this->name_.c_str(), irms);
this->publish_state(irms);
});
// Set sampling values
this->is_sampling_ = true;
this->num_samples_ = 0;
this->sample_sum_ = 0.0f;
}
void CTClampSensor::loop() {
if (!this->is_sampling_)
return;
// Perform a single sample
float value = this->source_->sample();
// Adjust DC offset via low pass filter (exponential moving average)
const float alpha = 0.001f;
this->offset_ = this->offset_ * (1 - alpha) + value * alpha;
// Filtered value centered around the mid-point (0V)
float filtered = value - this->offset_;
// IRMS is sqrt(∑v_i²)
float sq = filtered * filtered;
this->sample_sum_ += sq;
this->num_samples_++;
}
} // namespace ct_clamp
} // namespace esphome

View File

@@ -0,0 +1,46 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/esphal.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/voltage_sampler/voltage_sampler.h"
namespace esphome {
namespace ct_clamp {
class CTClampSensor : public sensor::Sensor, public PollingComponent {
public:
void update() override;
void loop() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
void set_sample_duration(uint32_t sample_duration) { sample_duration_ = sample_duration; }
void set_source(voltage_sampler::VoltageSampler *source) { source_ = source; }
protected:
/// High Frequency loop() requester used during sampling phase.
HighFrequencyLoopRequester high_freq_;
/// Duration in ms of the sampling phase.
uint32_t sample_duration_;
/// The sampling source to read values from.
voltage_sampler::VoltageSampler *source_;
/** The DC offset of the circuit.
*
* Diagram: https://learn.openenergymonitor.org/electricity-monitoring/ct-sensors/interface-with-arduino
*
* This is automatically calculated with an exponential moving average/digital low pass filter.
*
* 0.5 is a good initial approximation to start with for most ESP8266 setups.
*/
float offset_ = 0.5f;
float sample_sum_ = 0.0f;
uint32_t num_samples_ = 0;
bool is_sampling_ = false;
};
} // namespace ct_clamp
} // namespace esphome

View File

@@ -0,0 +1,27 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, voltage_sampler
from esphome.const import CONF_SENSOR, CONF_ID, ICON_FLASH, UNIT_AMPERE
AUTO_LOAD = ['voltage_sampler']
CONF_SAMPLE_DURATION = 'sample_duration'
ct_clamp_ns = cg.esphome_ns.namespace('ct_clamp')
CTClampSensor = ct_clamp_ns.class_('CTClampSensor', sensor.Sensor, cg.PollingComponent)
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_AMPERE, ICON_FLASH, 2).extend({
cv.GenerateID(): cv.declare_id(CTClampSensor),
cv.Required(CONF_SENSOR): cv.use_id(voltage_sampler.VoltageSampler),
cv.Optional(CONF_SAMPLE_DURATION, default='200ms'): cv.positive_time_period_milliseconds,
}).extend(cv.polling_component_schema('60s'))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield sensor.register_sensor(var, config)
sens = yield cg.get_variable(config[CONF_SENSOR])
cg.add(var.set_source(sens))
cg.add(var.set_sample_duration(config[CONF_SAMPLE_DURATION]))

View File

@@ -19,6 +19,8 @@ class CWWWLightOutput : public light::LightOutput {
traits.set_supports_rgb(false);
traits.set_supports_rgb_white_value(false);
traits.set_supports_color_temperature(true);
traits.set_min_mireds(this->cold_white_temperature_);
traits.set_min_mireds(this->warm_white_temperature_);
return traits;
}
void write_state(light::LightState *state) override {

View File

@@ -3,6 +3,11 @@ import esphome.config_validation as cv
from esphome.components import i2c
from esphome.const import CONF_ID
CONF_TOUCH_THRESHOLD = "touch_threshold"
CONF_RELEASE_THRESHOLD = "release_threshold"
CONF_TOUCH_DEBOUNCE = "touch_debounce"
CONF_RELEASE_DEBOUNCE = "release_debounce"
DEPENDENCIES = ['i2c']
AUTO_LOAD = ['binary_sensor']
@@ -13,10 +18,18 @@ MPR121Component = mpr121_ns.class_('MPR121Component', cg.Component, i2c.I2CDevic
MULTI_CONF = True
CONFIG_SCHEMA = cv.Schema({
cv.GenerateID(): cv.declare_id(MPR121Component),
cv.Optional(CONF_RELEASE_DEBOUNCE, default=0): cv.int_range(min=0, max=7),
cv.Optional(CONF_TOUCH_DEBOUNCE, default=0): cv.int_range(min=0, max=7),
cv.Optional(CONF_TOUCH_THRESHOLD, default=0x0b): cv.int_range(min=0x05, max=0x30),
cv.Optional(CONF_RELEASE_THRESHOLD, default=0x06): cv.int_range(min=0x05, max=0x30),
}).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x5A))
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
cg.add(var.set_touch_debounce(config[CONF_TOUCH_DEBOUNCE]))
cg.add(var.set_release_debounce(config[CONF_RELEASE_DEBOUNCE]))
cg.add(var.set_touch_threshold(config[CONF_TOUCH_THRESHOLD]))
cg.add(var.set_release_threshold(config[CONF_RELEASE_THRESHOLD]))
yield cg.register_component(var, config)
yield i2c.register_i2c_device(var, config)

View File

@@ -2,7 +2,8 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor
from esphome.const import CONF_CHANNEL, CONF_ID
from . import mpr121_ns, MPR121Component, CONF_MPR121_ID
from . import mpr121_ns, MPR121Component, CONF_MPR121_ID, CONF_TOUCH_THRESHOLD, \
CONF_RELEASE_THRESHOLD
DEPENDENCIES = ['mpr121']
MPR121Channel = mpr121_ns.class_('MPR121Channel', binary_sensor.BinarySensor)
@@ -11,14 +12,20 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(MPR121Channel),
cv.GenerateID(CONF_MPR121_ID): cv.use_id(MPR121Component),
cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=11),
cv.Optional(CONF_TOUCH_THRESHOLD): cv.int_range(min=0x05, max=0x30),
cv.Optional(CONF_RELEASE_THRESHOLD): cv.int_range(min=0x05, max=0x30),
})
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield binary_sensor.register_binary_sensor(var, config)
hub = yield cg.get_variable(config[CONF_MPR121_ID])
cg.add(var.set_channel(config[CONF_CHANNEL]))
hub = yield cg.get_variable(config[CONF_MPR121_ID])
if CONF_TOUCH_THRESHOLD in config:
cg.add(var.set_touch_threshold(config[CONF_TOUCH_THRESHOLD]))
if CONF_RELEASE_THRESHOLD in config:
cg.add(var.set_release_threshold(config[CONF_RELEASE_THRESHOLD]))
cg.add(hub.register_channel(var))

View File

@@ -18,9 +18,11 @@ void MPR121Component::setup() {
}
// set touch sensitivity for all 12 channels
for (uint8_t i = 0; i < 12; i++) {
this->write_byte(MPR121_TOUCHTH_0 + 2 * i, 12);
this->write_byte(MPR121_RELEASETH_0 + 2 * i, 6);
for (auto *channel : this->channels_) {
this->write_byte(MPR121_TOUCHTH_0 + 2 * channel->channel_,
channel->touch_threshold_.value_or(this->touch_threshold_));
this->write_byte(MPR121_RELEASETH_0 + 2 * channel->channel_,
channel->release_threshold_.value_or(this->release_threshold_));
}
this->write_byte(MPR121_MHDR, 0x01);
this->write_byte(MPR121_NHDR, 0x01);
@@ -44,6 +46,19 @@ void MPR121Component::setup() {
// start with first 5 bits of baseline tracking
this->write_byte(MPR121_ECR, 0x8F);
}
void MPR121Component::set_touch_debounce(uint8_t debounce) {
uint8_t mask = debounce << 4;
this->debounce_ &= 0x0f;
this->debounce_ |= mask;
}
void MPR121Component::set_release_debounce(uint8_t debounce) {
uint8_t mask = debounce & 0x0f;
this->debounce_ &= 0xf0;
this->debounce_ |= mask;
};
void MPR121Component::dump_config() {
ESP_LOGCONFIG(TAG, "MPR121:");
LOG_I2C_DEVICE(this);

View File

@@ -46,17 +46,29 @@ enum {
};
class MPR121Channel : public binary_sensor::BinarySensor {
friend class MPR121Component;
public:
void set_channel(uint8_t channel) { channel_ = channel; }
void process(uint16_t data) { this->publish_state(static_cast<bool>(data & (1 << this->channel_))); }
void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
void set_release_threshold(uint8_t release_threshold) { this->release_threshold_ = release_threshold; };
protected:
uint8_t channel_{0};
optional<uint8_t> touch_threshold_{};
optional<uint8_t> release_threshold_{};
};
class MPR121Component : public Component, public i2c::I2CDevice {
public:
void register_channel(MPR121Channel *channel) { this->channels_.push_back(channel); }
void set_touch_debounce(uint8_t debounce);
void set_release_debounce(uint8_t debounce);
void set_touch_threshold(uint8_t touch_threshold) { this->touch_threshold_ = touch_threshold; };
void set_release_threshold(uint8_t release_threshold) { this->release_threshold_ = release_threshold; };
uint8_t get_touch_threshold() { return this->touch_threshold_; };
uint8_t get_release_threshold() { return this->release_threshold_; };
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
@@ -64,6 +76,9 @@ class MPR121Component : public Component, public i2c::I2CDevice {
protected:
std::vector<MPR121Channel *> channels_{};
uint8_t debounce_{0};
uint8_t touch_threshold_{};
uint8_t release_threshold_{};
enum ErrorCode {
NONE = 0,
COMMUNICATION_FAILED,

View File

View File

@@ -0,0 +1,31 @@
#include "ntc.h"
#include "esphome/core/log.h"
namespace esphome {
namespace ntc {
static const char *TAG = "ntc";
void NTC::setup() {
this->sensor_->add_on_state_callback([this](float value) { this->process_(value); });
if (this->sensor_->has_state())
this->process_(this->sensor_->state);
}
void NTC::dump_config() { LOG_SENSOR("", "NTC Sensor", this) }
float NTC::get_setup_priority() const { return setup_priority::DATA; }
void NTC::process_(float value) {
if (isnan(value)) {
this->publish_state(NAN);
return;
}
float lr = logf(value);
float v = this->a_ + this->b_ * lr + this->c_ * lr * lr * lr;
float temp = 1 / v - 273.15f;
ESP_LOGD(TAG, "'%s' - Temperature: %.1f°C", this->name_.c_str(), temp);
this->publish_state(temp);
}
} // namespace ntc
} // namespace esphome

View File

@@ -0,0 +1,29 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace ntc {
class NTC : public Component, public sensor::Sensor {
public:
void set_sensor(Sensor *sensor) { sensor_ = sensor; }
void set_a(float a) { a_ = a; }
void set_b(float b) { b_ = b; }
void set_c(float c) { c_ = c; }
void setup() override;
void dump_config() override;
float get_setup_priority() const override;
protected:
void process_(float value);
sensor::Sensor *sensor_;
float a_;
float b_;
float c_;
};
} // namespace ntc
} // namespace esphome

View File

@@ -0,0 +1,120 @@
# coding=utf-8
from math import log
import esphome.config_validation as cv
import esphome.codegen as cg
from esphome.components import sensor
from esphome.const import UNIT_CELSIUS, ICON_THERMOMETER, CONF_SENSOR, CONF_TEMPERATURE, \
CONF_VALUE, CONF_CALIBRATION, CONF_ID
ntc_ns = cg.esphome_ns.namespace('ntc')
NTC = ntc_ns.class_('NTC', cg.Component, sensor.Sensor)
CONF_B_CONSTANT = 'b_constant'
CONF_REFERENCE_TEMPERATURE = 'reference_temperature'
CONF_REFERENCE_RESISTANCE = 'reference_resistance'
CONF_A = 'a'
CONF_B = 'b'
CONF_C = 'c'
ZERO_POINT = 273.15
def validate_calibration_parameter(value):
if isinstance(value, dict):
return cv.Schema({
cv.Required(CONF_TEMPERATURE): cv.float_,
cv.Required(CONF_VALUE): cv.float_,
})(value)
value = cv.string(value)
parts = value.split('->')
if len(parts) != 2:
raise cv.Invalid(u"Calibration parameter must be of form 3000 -> 23°C")
voltage = cv.resistance(parts[0].strip())
temperature = cv.temperature(parts[1].strip())
return validate_calibration_parameter({
CONF_TEMPERATURE: temperature,
CONF_VALUE: voltage,
})
def calc_steinhart_hart(value):
r1 = value[0][CONF_VALUE]
r2 = value[1][CONF_VALUE]
r3 = value[2][CONF_VALUE]
t1 = value[0][CONF_TEMPERATURE] + ZERO_POINT
t2 = value[1][CONF_TEMPERATURE] + ZERO_POINT
t3 = value[2][CONF_TEMPERATURE] + ZERO_POINT
l1 = log(r1)
l2 = log(r2)
l3 = log(r3)
y1 = 1/t1
y2 = 1/t2
y3 = 1/t3
g2 = (y2-y1)/(l2-l1)
g3 = (y3-y1)/(l3-l1)
c = (g3-g2)/(l3-l2) * 1/(l1+l2+l3)
b = g2 - c*(l1*l1 + l1*l2 + l2*l2)
a = y1 - (b + l1*l1*c) * l1
return a, b, c
def calc_b(value):
beta = value[CONF_B_CONSTANT]
t0 = value[CONF_REFERENCE_TEMPERATURE] + ZERO_POINT
r0 = value[CONF_REFERENCE_RESISTANCE]
a = (1/t0) - (1/beta) * log(r0)
b = 1/beta
c = 0
return a, b, c
def process_calibration(value):
if isinstance(value, dict):
value = cv.Schema({
cv.Required(CONF_B_CONSTANT): cv.float_,
cv.Required(CONF_REFERENCE_TEMPERATURE): cv.temperature,
cv.Required(CONF_REFERENCE_RESISTANCE): cv.resistance,
})(value)
a, b, c = calc_b(value)
elif isinstance(value, list):
if len(value) != 3:
raise cv.Invalid("SteinhartHart Calibration must consist of exactly three values")
value = cv.Schema([validate_calibration_parameter])(value)
a, b, c = calc_steinhart_hart(value)
else:
raise cv.Invalid("Calibration parameter accepts either a list for steinhart-hart "
"calibration, or mapping for b-constant calibration, "
"not {}".format(type(value)))
return {
CONF_A: a,
CONF_B: b,
CONF_C: c,
}
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_CELSIUS, ICON_THERMOMETER, 1).extend({
cv.GenerateID(): cv.declare_id(NTC),
cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
cv.Required(CONF_CALIBRATION): process_calibration,
}).extend(cv.COMPONENT_SCHEMA)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield sensor.register_sensor(var, config)
sens = yield cg.get_variable(config[CONF_SENSOR])
cg.add(var.set_sensor(sens))
calib = config[CONF_CALIBRATION]
cg.add(var.set_a(calib[CONF_A]))
cg.add(var.set_b(calib[CONF_B]))
cg.add(var.set_c(calib[CONF_C]))

View File

@@ -0,0 +1,42 @@
#include "resistance_sensor.h"
#include "esphome/core/log.h"
namespace esphome {
namespace resistance {
static const char *TAG = "resistance";
void ResistanceSensor::dump_config() {
LOG_SENSOR("", "Resistance Sensor", this);
ESP_LOGCONFIG(TAG, " Configuration: %s", this->configuration_ == UPSTREAM ? "UPSTREAM" : "DOWNSTREAM");
ESP_LOGCONFIG(TAG, " Resistor: %.2fΩ", this->resistor_);
ESP_LOGCONFIG(TAG, " Reference Voltage: %.1fV", this->reference_voltage_);
}
void ResistanceSensor::process_(float value) {
if (isnan(value)) {
this->publish_state(NAN);
return;
}
float res = 0;
switch (this->configuration_) {
case UPSTREAM:
if (value == 0.0f)
res = NAN;
else
res = (this->reference_voltage_ - value) / value;
break;
case DOWNSTREAM:
if (value == this->reference_voltage_)
res = NAN;
else
res = value / (this->reference_voltage_ - value);
break;
}
res *= this->resistor_;
ESP_LOGD(TAG, "'%s' - Resistance %.1fΩ", this->name_.c_str(), res);
this->publish_state(res);
}
} // namespace resistance
} // namespace esphome

View File

@@ -0,0 +1,38 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
namespace esphome {
namespace resistance {
enum ResistanceConfiguration {
UPSTREAM,
DOWNSTREAM,
};
class ResistanceSensor : public Component, public sensor::Sensor {
public:
void set_sensor(Sensor *sensor) { sensor_ = sensor; }
void set_configuration(ResistanceConfiguration configuration) { configuration_ = configuration; }
void set_resistor(float resistor) { resistor_ = resistor; }
void set_reference_voltage(float reference_voltage) { reference_voltage_ = reference_voltage; }
void setup() override {
this->sensor_->add_on_state_callback([this](float value) { this->process_(value); });
if (this->sensor_->has_state())
this->process_(this->sensor_->state);
}
void dump_config() override;
float get_setup_priority() const override { return setup_priority::DATA; }
protected:
void process_(float value);
sensor::Sensor *sensor_;
ResistanceConfiguration configuration_;
float resistor_;
float reference_voltage_;
};
} // namespace resistance
} // namespace esphome

View File

@@ -0,0 +1,37 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import CONF_SENSOR, UNIT_OHM, ICON_FLASH, CONF_ID
resistance_ns = cg.esphome_ns.namespace('resistance')
ResistanceSensor = resistance_ns.class_('ResistanceSensor', cg.Component, sensor.Sensor)
CONF_REFERENCE_VOLTAGE = 'reference_voltage'
CONF_CONFIGURATION = 'configuration'
CONF_RESISTOR = 'resistor'
ResistanceConfiguration = resistance_ns.enum('ResistanceConfiguration')
CONFIGURATIONS = {
'DOWNSTREAM': ResistanceConfiguration.DOWNSTREAM,
'UPSTREAM': ResistanceConfiguration.UPSTREAM,
}
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_OHM, ICON_FLASH, 1).extend({
cv.GenerateID(): cv.declare_id(ResistanceSensor),
cv.Required(CONF_SENSOR): cv.use_id(sensor.Sensor),
cv.Required(CONF_CONFIGURATION): cv.enum(CONFIGURATIONS, upper=True),
cv.Required(CONF_RESISTOR): cv.resistance,
cv.Optional(CONF_REFERENCE_VOLTAGE, default='3.3V'): cv.voltage,
}).extend(cv.COMPONENT_SCHEMA)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield sensor.register_sensor(var, config)
sens = yield cg.get_variable(config[CONF_SENSOR])
cg.add(var.set_sensor(sens))
cg.add(var.set_configuration(config[CONF_CONFIGURATION]))
cg.add(var.set_resistor(config[CONF_RESISTOR]))
cg.add(var.set_reference_voltage(config[CONF_REFERENCE_VOLTAGE]))

View File

@@ -22,6 +22,8 @@ class RGBWWLightOutput : public light::LightOutput {
traits.set_supports_rgb(true);
traits.set_supports_rgb_white_value(true);
traits.set_supports_color_temperature(true);
traits.set_min_mireds(this->cold_white_temperature_);
traits.set_min_mireds(this->warm_white_temperature_);
return traits;
}
void write_state(light::LightState *state) override {

View File

@@ -8,29 +8,6 @@ namespace waveshare_epaper {
static const char *TAG = "waveshare_epaper";
static const uint8_t WAVESHARE_EPAPER_COMMAND_DRIVER_OUTPUT_CONTROL = 0x01;
static const uint8_t WAVESHARE_EPAPER_COMMAND_BOOSTER_SOFT_START_CONTROL = 0x0C;
// static const uint8_t WAVESHARE_EPAPER_COMMAND_GATE_SCAN_START_POSITION = 0x0F;
// static const uint8_t WAVESHARE_EPAPER_COMMAND_DEEP_SLEEP_MODE = 0x10;
static const uint8_t WAVESHARE_EPAPER_COMMAND_DATA_ENTRY_MODE_SETTING = 0x11;
// static const uint8_t WAVESHARE_EPAPER_COMMAND_SW_RESET = 0x12;
// static const uint8_t WAVESHARE_EPAPER_COMMAND_TEMPERATURE_SENSOR_CONTROL = 0x1A;
static const uint8_t WAVESHARE_EPAPER_COMMAND_MASTER_ACTIVATION = 0x20;
// static const uint8_t WAVESHARE_EPAPER_COMMAND_DISPLAY_UPDATE_CONTROL_1 = 0x21;
static const uint8_t WAVESHARE_EPAPER_COMMAND_DISPLAY_UPDATE_CONTROL_2 = 0x22;
static const uint8_t WAVESHARE_EPAPER_COMMAND_WRITE_RAM = 0x24;
static const uint8_t WAVESHARE_EPAPER_COMMAND_WRITE_VCOM_REGISTER = 0x2C;
static const uint8_t WAVESHARE_EPAPER_COMMAND_WRITE_LUT_REGISTER = 0x32;
static const uint8_t WAVESHARE_EPAPER_COMMAND_SET_DUMMY_LINE_PERIOD = 0x3A;
static const uint8_t WAVESHARE_EPAPER_COMMAND_SET_GATE_TIME = 0x3B;
static const uint8_t WAVESHARE_EPAPER_COMMAND_BORDER_WAVEFORM_CONTROL = 0x3C;
static const uint8_t WAVESHARE_EPAPER_COMMAND_SET_RAM_X_ADDRESS_START_END_POSITION = 0x44;
static const uint8_t WAVESHARE_EPAPER_COMMAND_SET_RAM_Y_ADDRESS_START_END_POSITION = 0x45;
static const uint8_t WAVESHARE_EPAPER_COMMAND_SET_RAM_X_ADDRESS_COUNTER = 0x4E;
static const uint8_t WAVESHARE_EPAPER_COMMAND_SET_RAM_Y_ADDRESS_COUNTER = 0x4F;
static const uint8_t WAVESHARE_EPAPER_COMMAND_TERMINATE_FRAME_READ_WRITE = 0xFF;
// not in .text section since only 30 bytes
static const uint8_t FULL_UPDATE_LUT[30] = {0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22, 0x66, 0x69,
0x69, 0x59, 0x58, 0x99, 0x99, 0x88, 0x00, 0x00, 0x00, 0x00,
0xF8, 0xB4, 0x13, 0x51, 0x35, 0x51, 0x51, 0x19, 0x01, 0x00};
@@ -52,13 +29,7 @@ void WaveshareEPaper::setup_pins_() {
}
this->spi_setup();
// Reset
if (this->reset_pin_ != nullptr) {
this->reset_pin_->digital_write(false);
delay(200);
this->reset_pin_->digital_write(true);
delay(200);
}
this->reset_();
}
float WaveshareEPaper::get_setup_priority() const { return setup_priority::PROCESSOR; }
void WaveshareEPaper::command(uint8_t value) {
@@ -121,34 +92,39 @@ void WaveshareEPaper::start_data_() {
this->enable();
}
void WaveshareEPaper::end_data_() { this->disable(); }
void WaveshareEPaper::on_safe_shutdown() { this->deep_sleep(); }
// ========================================================
// Type A
// ========================================================
void WaveshareEPaperTypeA::setup() {
this->setup_pins_();
this->command(WAVESHARE_EPAPER_COMMAND_DRIVER_OUTPUT_CONTROL);
void WaveshareEPaperTypeA::initialize() {
// COMMAND DRIVER OUTPUT CONTROL
this->command(0x01);
this->data(this->get_height_internal() - 1);
this->data((this->get_height_internal() - 1) >> 8);
this->data(0x00); // ? GD = 0, SM = 0, TB = 0
this->command(WAVESHARE_EPAPER_COMMAND_BOOSTER_SOFT_START_CONTROL); // ?
// COMMAND BOOSTER SOFT START CONTROL
this->command(0x0C);
this->data(0xD7);
this->data(0xD6);
this->data(0x9D);
this->command(WAVESHARE_EPAPER_COMMAND_WRITE_VCOM_REGISTER); // ?
// COMMAND WRITE VCOM REGISTER
this->command(0x2C);
this->data(0xA8);
this->command(WAVESHARE_EPAPER_COMMAND_SET_DUMMY_LINE_PERIOD); // ?
// COMMAND SET DUMMY LINE PERIOD
this->command(0x3A);
this->data(0x1A);
this->command(WAVESHARE_EPAPER_COMMAND_SET_GATE_TIME); // 2µs per row
this->data(0x08);
// COMMAND SET GATE TIME
this->command(0x3B);
this->data(0x08); // 2µs per row
this->command(WAVESHARE_EPAPER_COMMAND_DATA_ENTRY_MODE_SETTING);
// COMMAND DATA ENTRY MODE SETTING
this->command(0x11);
this->data(0x03); // from top left to bottom right
}
void WaveshareEPaperTypeA::dump_config() {
@@ -186,18 +162,22 @@ void HOT WaveshareEPaperTypeA::display() {
}
// Set x & y regions we want to write to (full)
this->command(WAVESHARE_EPAPER_COMMAND_SET_RAM_X_ADDRESS_START_END_POSITION);
// COMMAND SET RAM X ADDRESS START END POSITION
this->command(0x44);
this->data(0x00);
this->data((this->get_width_internal() - 1) >> 3);
this->command(WAVESHARE_EPAPER_COMMAND_SET_RAM_Y_ADDRESS_START_END_POSITION);
// COMMAND SET RAM Y ADDRESS START END POSITION
this->command(0x45);
this->data(0x00);
this->data(0x00);
this->data(this->get_height_internal() - 1);
this->data((this->get_height_internal() - 1) >> 8);
this->command(WAVESHARE_EPAPER_COMMAND_SET_RAM_X_ADDRESS_COUNTER);
// COMMAND SET RAM X ADDRESS COUNTER
this->command(0x4E);
this->data(0x00);
this->command(WAVESHARE_EPAPER_COMMAND_SET_RAM_Y_ADDRESS_COUNTER);
// COMMAND SET RAM Y ADDRESS COUNTER
this->command(0x4F);
this->data(0x00);
this->data(0x00);
@@ -206,15 +186,19 @@ void HOT WaveshareEPaperTypeA::display() {
return;
}
this->command(WAVESHARE_EPAPER_COMMAND_WRITE_RAM);
// COMMAND WRITE RAM
this->command(0x24);
this->start_data_();
this->write_array(this->buffer_, this->get_buffer_length_());
this->end_data_();
this->command(WAVESHARE_EPAPER_COMMAND_DISPLAY_UPDATE_CONTROL_2);
// COMMAND DISPLAY UPDATE CONTROL 2
this->command(0x22);
this->data(0xC4);
this->command(WAVESHARE_EPAPER_COMMAND_MASTER_ACTIVATION);
this->command(WAVESHARE_EPAPER_COMMAND_TERMINATE_FRAME_READ_WRITE);
// COMMAND MASTER ACTIVATION
this->command(0x20);
// COMMAND TERMINATE FRAME READ WRITE
this->command(0xFF);
this->status_clear_warning();
}
@@ -241,7 +225,8 @@ int WaveshareEPaperTypeA::get_height_internal() {
return 0;
}
void WaveshareEPaperTypeA::write_lut_(const uint8_t *lut) {
this->command(WAVESHARE_EPAPER_COMMAND_WRITE_LUT_REGISTER);
// COMMAND WRITE LUT REGISTER
this->command(0x32);
for (uint8_t i = 0; i < 30; i++)
this->data(lut[i]);
}
@@ -253,47 +238,9 @@ void WaveshareEPaperTypeA::set_full_update_every(uint32_t full_update_every) {
// ========================================================
// Type B
// ========================================================
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PANEL_SETTING = 0x00;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_POWER_SETTING = 0x01;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_POWER_OFF = 0x02;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_POWER_OFF_SEQUENCE_SETTING = 0x03;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_POWER_ON = 0x04;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_POWER_MEASURE = 0x05;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_BOOSTER_SOFT_START = 0x06;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_DEEP_SLEEP = 0x07;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_DATA_START_TRANSMISSION_1 = 0x10;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_DATA_STOP = 0x11;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_DISPLAY_REFRESH = 0x12;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_DATA_START_TRANSMISSION_2 = 0x13;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PARTIAL_DATA_START_TRANSMISSION_1 = 0x14;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PARTIAL_DATA_START_TRANSMISSION_2 = 0x15;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PARTIAL_DISPLAY_REFRESH = 0x16;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_LUT_FOR_VCOM = 0x20;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_LUT_WHITE_TO_WHITE = 0x21;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_LUT_BLACK_TO_WHITE = 0x22;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_LUT_WHITE_TO_BLACK = 0x23;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_LUT_BLACK_TO_BLACK = 0x24;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PLL_CONTROL = 0x30;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_TEMPERATURE_SENSOR_COMMAND = 0x40;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_TEMPERATURE_SENSOR_CALIBRATION = 0x41;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_TEMPERATURE_SENSOR_WRITE = 0x42;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_TEMPERATURE_SENSOR_READ = 0x43;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_VCOM_AND_DATA_INTERVAL_SETTING = 0x50;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_LOW_POWER_DETECTION = 0x51;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_TCON_SETTING = 0x60;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_RESOLUTION_SETTING = 0x61;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_GET_STATUS = 0x71;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_AUTO_MEASURE_VCOM = 0x80;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_VCOM_VALUE = 0x81;
static const uint8_t WAVESHARE_EPAPER_B_COMMAND_VCM_DC_SETTING_REGISTER = 0x82;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PARTIAL_WINDOW = 0x90;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PARTIAL_IN = 0x91;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PARTIAL_OUT = 0x92;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_PROGRAM_MODE = 0xA0;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_ACTIVE_PROGRAM = 0xA1;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_READ_OTP_DATA = 0xA2;
// static const uint8_t WAVESHARE_EPAPER_B_COMMAND_POWER_SAVING = 0xE3;
// Datasheet:
// - https://www.waveshare.com/w/upload/7/7f/4.2inch-e-paper-b-specification.pdf
// - https://github.com/soonuse/epd-library-arduino/blob/master/4.2inch_e-paper/epd4in2/
static const uint8_t LUT_VCOM_DC_2_7[44] = {
0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x05, 0x00, 0x32, 0x32, 0x00, 0x00, 0x02, 0x00,
@@ -325,18 +272,17 @@ static const uint8_t LUT_BLACK_TO_BLACK_2_7[42] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
void WaveshareEPaper2P7In::setup() {
this->setup_pins_();
// this->buffer_.init(this->get_width_(), this->get_height_());
this->command(WAVESHARE_EPAPER_B_COMMAND_POWER_SETTING);
void WaveshareEPaper2P7In::initialize() {
// command power setting
this->command(0x01);
this->data(0x03); // VDS_EN, VDG_EN
this->data(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
this->data(0x2B); // VDH
this->data(0x2B); // VDL
this->data(0x09); // VDHR
this->command(WAVESHARE_EPAPER_B_COMMAND_BOOSTER_SOFT_START);
// command booster soft start
this->command(0x06);
this->data(0x07);
this->data(0x07);
this->data(0x17);
@@ -364,51 +310,66 @@ void WaveshareEPaper2P7In::setup() {
this->data(0x73);
this->data(0x41);
this->command(WAVESHARE_EPAPER_B_COMMAND_PARTIAL_DISPLAY_REFRESH);
// command partial display refresh
this->command(0x16);
this->data(0x00);
this->command(WAVESHARE_EPAPER_B_COMMAND_POWER_ON);
// command power on
this->command(0x04);
this->wait_until_idle_();
delay(10);
this->command(WAVESHARE_EPAPER_B_COMMAND_PANEL_SETTING);
// Command panel setting
this->command(0x00);
this->data(0xAF); // KW-BF KWR-AF BWROTP 0f
this->command(WAVESHARE_EPAPER_B_COMMAND_PLL_CONTROL);
// command pll control
this->command(0x30);
this->data(0x3A); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
this->command(WAVESHARE_EPAPER_B_COMMAND_VCM_DC_SETTING_REGISTER);
// COMMAND VCM DC SETTING
this->command(0x82);
this->data(0x12);
delay(2);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_FOR_VCOM);
// COMMAND LUT FOR VCOM
this->command(0x20);
for (uint8_t i : LUT_VCOM_DC_2_7)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_WHITE_TO_WHITE);
// COMMAND LUT WHITE TO WHITE
this->command(0x21);
for (uint8_t i : LUT_WHITE_TO_WHITE_2_7)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_BLACK_TO_WHITE);
// COMMAND LUT BLACK TO WHITE
this->command(0x22);
for (uint8_t i : LUT_BLACK_TO_WHITE_2_7)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_WHITE_TO_BLACK);
// COMMAND LUT WHITE TO BLACK
this->command(0x23);
for (uint8_t i : LUT_WHITE_TO_BLACK_2_7)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_BLACK_TO_BLACK);
// COMMAND LUT BLACK TO BLACK
this->command(0x24);
for (uint8_t i : LUT_BLACK_TO_BLACK_2_7)
this->data(i);
}
void HOT WaveshareEPaper2P7In::display() {
// TODO check active frame buffer to only transmit once / use partial transmits
this->command(WAVESHARE_EPAPER_B_COMMAND_DATA_START_TRANSMISSION_1);
// COMMAND DATA START TRANSMISSION 1
this->command(0x10);
delay(2);
this->start_data_();
this->write_array(this->buffer_, this->get_buffer_length_());
this->end_data_();
delay(2);
this->command(WAVESHARE_EPAPER_B_COMMAND_DATA_START_TRANSMISSION_2);
// COMMAND DATA START TRANSMISSION 2
this->command(0x13);
delay(2);
this->start_data_();
this->write_array(this->buffer_, this->get_buffer_length_());
this->end_data_();
this->command(WAVESHARE_EPAPER_B_COMMAND_DISPLAY_REFRESH);
// COMMAND DISPLAY REFRESH
this->command(0x12);
}
int WaveshareEPaper2P7In::get_width_internal() { return 176; }
int WaveshareEPaper2P7In::get_height_internal() { return 264; }
@@ -449,73 +410,88 @@ static const uint8_t LUT_WHITE_TO_BLACK_4_2[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
void WaveshareEPaper4P2In::setup() {
this->setup_pins_();
void WaveshareEPaper4P2In::initialize() {
// https://www.waveshare.com/w/upload/7/7f/4.2inch-e-paper-b-specification.pdf - page 8
this->command(WAVESHARE_EPAPER_B_COMMAND_POWER_SETTING);
// COMMAND POWER SETTING
this->command(0x01);
this->data(0x03); // VDS_EN, VDG_EN
this->data(0x00); // VCOM_HV, VGHL_LV[1], VGHL_LV[0]
this->data(0x2B); // VDH
this->data(0x2B); // VDL
this->data(0xFF); // VDHR
this->command(WAVESHARE_EPAPER_B_COMMAND_BOOSTER_SOFT_START);
this->data(0x17);
this->data(0x17);
this->data(0x17);
// COMMAND BOOSTER SOFT START
this->command(0x06);
this->data(0x17); // PHA
this->data(0x17); // PHB
this->data(0x17); // PHC
this->command(WAVESHARE_EPAPER_B_COMMAND_POWER_ON);
// COMMAND POWER ON
this->command(0x04);
this->wait_until_idle_();
delay(10);
this->command(WAVESHARE_EPAPER_B_COMMAND_PANEL_SETTING);
// COMMAND PANEL SETTING
this->command(0x00);
this->data(0xBF); // KW-BF KWR-AF BWROTP 0f
this->data(0x0B);
this->command(WAVESHARE_EPAPER_B_COMMAND_PLL_CONTROL);
// COMMAND PLL CONTROL
this->command(0x30);
this->data(0x3C); // 3A 100HZ 29 150Hz 39 200HZ 31 171HZ
delay(2);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_FOR_VCOM);
// COMMAND LUT FOR VCOM
this->command(0x20);
for (uint8_t i : LUT_VCOM_DC_4_2)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_WHITE_TO_WHITE);
// COMMAND LUT WHITE TO WHITE
this->command(0x21);
for (uint8_t i : LUT_WHITE_TO_WHITE_4_2)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_BLACK_TO_WHITE);
// COMMAND LUT BLACK TO WHITE
this->command(0x22);
for (uint8_t i : LUT_BLACK_TO_WHITE_4_2)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_WHITE_TO_BLACK);
// COMMAND LUT WHITE TO BLACK
this->command(0x23);
for (uint8_t i : LUT_WHITE_TO_BLACK_4_2)
this->data(i);
this->command(WAVESHARE_EPAPER_B_COMMAND_LUT_BLACK_TO_BLACK);
// COMMAND LUT BLACK TO BLACK
this->command(0x24);
for (uint8_t i : LUT_BLACK_TO_BLACK_4_2)
this->data(i);
}
void HOT WaveshareEPaper4P2In::display() {
this->command(WAVESHARE_EPAPER_B_COMMAND_RESOLUTION_SETTING);
// COMMAND RESOLUTION SETTING
this->command(0x61);
this->data(0x01);
this->data(0x90);
this->data(0x01);
this->data(0x2C);
this->command(WAVESHARE_EPAPER_B_COMMAND_VCM_DC_SETTING_REGISTER);
// COMMAND VCM DC SETTING REGISTER
this->command(0x82);
this->data(0x12);
this->command(WAVESHARE_EPAPER_B_COMMAND_VCOM_AND_DATA_INTERVAL_SETTING);
// COMMAND VCOM AND DATA INTERVAL SETTING
this->command(0x50);
this->data(0x97);
// TODO check active frame buffer to only transmit once / use partial transmits
this->command(WAVESHARE_EPAPER_B_COMMAND_DATA_START_TRANSMISSION_1);
// COMMAND DATA START TRANSMISSION 1
this->command(0x10);
delay(2);
this->start_data_();
this->write_array(this->buffer_, this->get_buffer_length_());
this->end_data_();
delay(2);
this->command(WAVESHARE_EPAPER_B_COMMAND_DATA_START_TRANSMISSION_2);
// COMMAND DATA START TRANSMISSION 2
this->command(0x13);
delay(2);
this->start_data_();
this->write_array(this->buffer_, this->get_buffer_length_());
this->end_data_();
this->command(WAVESHARE_EPAPER_B_COMMAND_DISPLAY_REFRESH);
// COMMAND DISPLAY REFRESH
this->command(0x12);
}
int WaveshareEPaper4P2In::get_width_internal() { return 400; }
int WaveshareEPaper4P2In::get_height_internal() { return 300; }
@@ -529,52 +505,61 @@ void WaveshareEPaper4P2In::dump_config() {
LOG_UPDATE_INTERVAL(this);
}
void WaveshareEPaper7P5In::setup() {
this->setup_pins_();
this->command(WAVESHARE_EPAPER_B_COMMAND_POWER_SETTING);
void WaveshareEPaper7P5In::initialize() {
// COMMAND POWER SETTING
this->command(0x01);
this->data(0x37);
this->data(0x00);
this->command(WAVESHARE_EPAPER_B_COMMAND_PANEL_SETTING);
// COMMAND PANEL SETTING
this->command(0x00);
this->data(0xCF);
this->data(0x0B);
this->command(WAVESHARE_EPAPER_B_COMMAND_BOOSTER_SOFT_START);
// COMMAND BOOSTER SOFT START
this->command(0x06);
this->data(0xC7);
this->data(0xCC);
this->data(0x28);
this->command(WAVESHARE_EPAPER_B_COMMAND_POWER_ON);
// COMMAND POWER ON
this->command(0x04);
this->wait_until_idle_();
delay(10);
this->command(WAVESHARE_EPAPER_B_COMMAND_PLL_CONTROL);
// COMMAND PLL CONTROL
this->command(0x30);
this->data(0x3C);
this->command(WAVESHARE_EPAPER_B_COMMAND_TEMPERATURE_SENSOR_CALIBRATION);
// COMMAND TEMPERATURE SENSOR CALIBRATION
this->command(0x41);
this->data(0x00);
this->command(WAVESHARE_EPAPER_B_COMMAND_VCOM_AND_DATA_INTERVAL_SETTING);
// COMMAND VCOM AND DATA INTERVAL SETTING
this->command(0x50);
this->data(0x77);
this->command(WAVESHARE_EPAPER_B_COMMAND_TCON_SETTING);
// COMMAND TCON SETTING
this->command(0x60);
this->data(0x22);
this->command(WAVESHARE_EPAPER_B_COMMAND_RESOLUTION_SETTING);
// COMMAND RESOLUTION SETTING
this->command(0x61);
this->data(0x02);
this->data(0x80);
this->data(0x01);
this->data(0x80);
this->command(WAVESHARE_EPAPER_B_COMMAND_VCM_DC_SETTING_REGISTER);
// COMMAND VCM DC SETTING REGISTER
this->command(0x82);
this->data(0x1E);
this->command(0xE5);
this->data(0x03);
}
void HOT WaveshareEPaper7P5In::display() {
this->command(WAVESHARE_EPAPER_B_COMMAND_DATA_START_TRANSMISSION_1);
// COMMAND DATA START TRANSMISSION 1
this->command(0x10);
this->start_data_();
for (size_t i = 0; i < this->get_buffer_length_(); i++) {
@@ -601,7 +586,8 @@ void HOT WaveshareEPaper7P5In::display() {
}
this->end_data_();
this->command(WAVESHARE_EPAPER_B_COMMAND_DISPLAY_REFRESH);
// COMMAND DISPLAY REFRESH
this->command(0x12);
}
int WaveshareEPaper7P5In::get_width_internal() { return 640; }
int WaveshareEPaper7P5In::get_height_internal() { return 384; }

View File

@@ -19,11 +19,20 @@ class WaveshareEPaper : public PollingComponent, public spi::SPIDevice, public d
void data(uint8_t value);
virtual void display() = 0;
virtual void initialize() = 0;
virtual void deep_sleep() = 0;
void update() override;
void fill(int color) override;
void setup() override {
this->setup_pins_();
this->initialize();
}
void on_safe_shutdown() override;
protected:
void draw_absolute_pixel_internal(int x, int y, int color) override;
@@ -31,6 +40,15 @@ class WaveshareEPaper : public PollingComponent, public spi::SPIDevice, public d
void setup_pins_();
void reset_() {
if (this->reset_pin_ != nullptr) {
this->reset_pin_->digital_write(false);
delay(200);
this->reset_pin_->digital_write(true);
delay(200);
}
}
uint32_t get_buffer_length_();
bool is_device_high_speed() override;
@@ -55,12 +73,18 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
public:
WaveshareEPaperTypeA(WaveshareEPaperTypeAModel model);
void setup() override;
void initialize() override;
void dump_config() override;
void display() override;
void deep_sleep() override {
// COMMAND DEEP SLEEP MODE
this->command(0x10);
this->wait_until_idle_();
}
void set_full_update_every(uint32_t full_update_every);
protected:
@@ -83,12 +107,18 @@ enum WaveshareEPaperTypeBModel {
class WaveshareEPaper2P7In : public WaveshareEPaper {
public:
void setup() override;
void initialize() override;
void display() override;
void dump_config() override;
void deep_sleep() override {
// COMMAND DEEP SLEEP
this->command(0x07);
this->data(0xA5); // check byte
}
protected:
int get_width_internal() override;
@@ -97,12 +127,41 @@ class WaveshareEPaper2P7In : public WaveshareEPaper {
class WaveshareEPaper4P2In : public WaveshareEPaper {
public:
void setup() override;
void initialize() override;
void display() override;
void dump_config() override;
void deep_sleep() override {
// COMMAND VCOM AND DATA INTERVAL SETTING
this->command(0x50);
this->data(0x17); // border floating
// COMMAND VCM DC SETTING
this->command(0x82);
// COMMAND PANEL SETTING
this->command(0x00);
delay(100);
// COMMAND POWER SETTING
this->command(0x01);
this->data(0x00);
this->data(0x00);
this->data(0x00);
this->data(0x00);
this->data(0x00);
delay(100);
// COMMAND POWER OFF
this->command(0x02);
this->wait_until_idle_();
// COMMAND DEEP SLEEP
this->command(0x07);
this->data(0xA5); // check byte
}
protected:
int get_width_internal() override;
@@ -113,12 +172,21 @@ class WaveshareEPaper4P2In : public WaveshareEPaper {
class WaveshareEPaper7P5In : public WaveshareEPaper {
public:
void setup() override;
void initialize() override;
void display() override;
void dump_config() override;
void deep_sleep() override {
// COMMAND POWER OFF
this->command(0x02);
this->wait_until_idle_();
// COMMAND DEEP SLEEP
this->command(0x07);
this->data(0xA5); // check byte
}
protected:
int get_width_internal() override;

View File

@@ -61,6 +61,7 @@ RESERVED_IDS = [
'App', 'pinMode', 'delay', 'delayMicroseconds', 'digitalRead', 'digitalWrite', 'INPUT',
'OUTPUT',
'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
'close', 'pause', 'sleep', 'open',
]

View File

@@ -3,7 +3,7 @@
MAJOR_VERSION = 1
MINOR_VERSION = 13
PATCH_VERSION = '0b1'
PATCH_VERSION = '0b5'
__short_version__ = '{}.{}'.format(MAJOR_VERSION, MINOR_VERSION)
__version__ = '{}.{}'.format(__short_version__, PATCH_VERSION)
@@ -62,6 +62,7 @@ CONF_BUILD_PATH = 'build_path'
CONF_BUSY_PIN = 'busy_pin'
CONF_BUS_VOLTAGE = 'bus_voltage'
CONF_CALIBRATE_LINEAR = 'calibrate_linear'
CONF_CALIBRATION = 'calibration'
CONF_CARRIER_DUTY_PERCENT = 'carrier_duty_percent'
CONF_CARRIER_FREQUENCY = 'carrier_frequency'
CONF_CHANGE_MODE_EVERY = 'change_mode_every'
@@ -201,6 +202,7 @@ CONF_LEVEL = 'level'
CONF_LG = 'lg'
CONF_LIBRARIES = 'libraries'
CONF_LIGHT = 'light'
CONF_LOADED_INTEGRATIONS = 'loaded_integrations'
CONF_LOCAL = 'local'
CONF_LOGGER = 'logger'
CONF_LOGS = 'logs'
@@ -456,6 +458,7 @@ ICON_BATTERY = 'mdi:battery'
ICON_BRIEFCASE_DOWNLOAD = 'mdi:briefcase-download'
ICON_BRIGHTNESS_5 = 'mdi:brightness-5'
ICON_CHEMICAL_WEAPON = 'mdi:chemical-weapon'
ICON_CHECK_CIRCLE_OUTLINE = 'mdi:check-circle-outline'
ICON_EMPTY = ''
ICON_FLASH = 'mdi:flash'
ICON_FLOWER = 'mdi:flower'

View File

@@ -66,6 +66,42 @@ void Application::dump_config() {
component->dump_config();
}
}
void Application::loop() {
uint32_t new_app_state = 0;
const uint32_t start = millis();
for (Component *component : this->components_) {
if (!component->is_failed()) {
component->call_loop();
}
new_app_state |= component->get_component_state();
this->app_state_ |= new_app_state;
this->feed_wdt();
}
this->app_state_ = new_app_state;
const uint32_t end = millis();
if (end - start > 200) {
ESP_LOGV(TAG, "A component took a long time in a loop() cycle (%.1f s).", (end - start) / 1e3f);
ESP_LOGV(TAG, "Components should block for at most 20-30ms in loop().");
ESP_LOGV(TAG, "This will become a warning soon.");
}
const uint32_t now = millis();
if (HighFrequencyLoopRequester::is_high_frequency()) {
yield();
} else {
uint32_t delay_time = this->loop_interval_;
if (now - this->last_loop_ < this->loop_interval_)
delay_time = this->loop_interval_ - (now - this->last_loop_);
delay(delay_time);
}
this->last_loop_ = now;
if (this->dump_config_scheduled_) {
this->dump_config();
this->dump_config_scheduled_ = false;
}
}
void ICACHE_RAM_ATTR HOT Application::feed_wdt() {
static uint32_t LAST_FEED = 0;

View File

@@ -87,34 +87,7 @@ class Application {
void setup();
/// Make a loop iteration. Call this in your loop() function.
void loop() {
uint32_t new_app_state = 0;
for (Component *component : this->components_) {
if (!component->is_failed()) {
component->call_loop();
}
new_app_state |= component->get_component_state();
this->app_state_ |= new_app_state;
this->feed_wdt();
}
this->app_state_ = new_app_state;
const uint32_t now = millis();
if (HighFrequencyLoopRequester::is_high_frequency()) {
yield();
} else {
uint32_t delay_time = this->loop_interval_;
if (now - this->last_loop_ < this->loop_interval_)
delay_time = this->loop_interval_ - (now - this->last_loop_);
delay(delay_time);
}
this->last_loop_ = now;
if (this->dump_config_scheduled_) {
this->dump_config();
this->dump_config_scheduled_ = false;
}
}
void loop();
/// Get the name of this Application set by set_name().
const std::string &get_name() const { return this->name_; }

View File

@@ -430,6 +430,12 @@ class DashboardEntry(object):
def update_new(self):
return const.__version__
@property
def loaded_integrations(self):
if self.storage is None:
return []
return self.storage.loaded_integrations
class MainRequestHandler(BaseHandler):
@authenticated

View File

@@ -406,16 +406,27 @@ const logsModal = new LogModalElem({
});
logsModal.setup();
const retryUploadButton = document.querySelector('.retry-upload');
const editAfterUploadButton = document.querySelector('.edit-after-upload');
const downloadAfterUploadButton = document.querySelector('.download-after-upload');
const uploadModal = new LogModalElem({
name: 'upload',
onPrepare: (modalElem, config) => {
downloadAfterUploadButton.classList.add('disabled');
retryUploadButton.setAttribute('data-node', uploadModal.activeConfig);
retryUploadButton.classList.add('disabled');
editAfterUploadButton.setAttribute('data-node', uploadModal.activeConfig);
modalElem.querySelector(".stop-logs").innerHTML = "Stop";
},
onProcessExit: (modalElem, code) => {
if (code === 0) {
M.toast({html: "Program exited successfully."});
// if compilation succeeds but OTA fails, you can still download the binary and upload manually
downloadAfterUploadButton.classList.remove('disabled');
} else {
M.toast({html: `Program failed with code ${code}`});
downloadAfterUploadButton.classList.add('disabled');
retryUploadButton.classList.remove('disabled');
}
modalElem.querySelector(".stop-logs").innerHTML = "Close";
},
@@ -425,6 +436,14 @@ const uploadModal = new LogModalElem({
dismissible: false,
});
uploadModal.setup();
downloadAfterUploadButton.addEventListener('click', () => {
const link = document.createElement("a");
link.download = name;
link.href = `./download.bin?configuration=${encodeURIComponent(uploadModal.activeConfig)}`;
document.body.appendChild(link);
link.click();
link.remove();
});
const validateModal = new LogModalElem({
name: 'validate',
@@ -587,6 +606,12 @@ const startAceWebsocket = () => {
editor.session.setAnnotations(arr);
if(arr.length) {
editorUploadButton.classList.add('disabled');
} else {
editorUploadButton.classList.remove('disabled');
}
aceValidationRunning = false;
} else if (msg.type === "read_file") {
sendAceStdin({
@@ -621,7 +646,7 @@ editor.session.setOption('tabSize', 2);
editor.session.setOption('useWorker', false);
const saveButton = editModalElem.querySelector(".save-button");
const saveValidateButton = editModalElem.querySelector(".save-validate-button");
const editorUploadButton = editModalElem.querySelector(".editor-upload-button");
const saveEditor = () => {
fetch(`./edit?configuration=${activeEditorConfig}`, {
credentials: "same-origin",
@@ -673,14 +698,14 @@ setInterval(() => {
}, 100);
saveButton.addEventListener('click', saveEditor);
saveValidateButton.addEventListener('click', saveEditor);
editorUploadButton.addEventListener('click', saveEditor);
document.querySelectorAll(".action-edit").forEach((btn) => {
btn.addEventListener('click', (e) => {
activeEditorConfig = e.target.getAttribute('data-node');
const modalInstance = M.Modal.getInstance(editModalElem);
const filenameField = editModalElem.querySelector('.filename');
editModalElem.querySelector(".save-validate-button").setAttribute('data-node', activeEditorConfig);
editorUploadButton.setAttribute('data-node', activeEditorConfig);
filenameField.innerHTML = activeEditorConfig;
fetch(`./edit?configuration=${activeEditorConfig}`, {credentials: "same-origin"})

View File

@@ -67,6 +67,9 @@
<div class="card-content">
<span class="card-title">
{{ escape(entry.name) }}
{% if 'web_server' in entry.loaded_integrations %}
<a href="http://{{ escape(entry.address) }}" target="_blank"><i class="material-icons icon-grey">launch</i></a>
{% end %}
<i class="material-icons right dropdown-trigger" data-target="dropdown-{{ i }}">more_vert</i>
</span>
<p>
@@ -121,8 +124,14 @@
class="tooltipped" data-position="left" data-tooltip="Flash using esphomeflasher" rel="noreferrer">
<i class="material-icons flash-using-esphomeflasher">help_outline</i>
</a>
<a class="modal-close waves-effect waves-green btn-flat action-edit edit-after-upload">Edit</a>
<a class="modal-close waves-effect waves-green btn-flat stop-logs">Stop</a>
<div class="btn-flat"><i class="material-icons dropdown-trigger" data-target="dropdown-upload-actions">more_vert</i></div>
</div>
<ul id="dropdown-upload-actions" class="select-action dropdown-content card-dropdown-action">
<li><a class="modal-close waves-effect waves-green btn-flat disabled download-after-upload">Download Binary</a></li>
<li><a class="waves-effect waves-green btn-flat disabled action-upload retry-upload">Retry</a></li>
</ul>
</div>
<div id="modal-compile" class="modal modal-fixed-footer">
@@ -431,7 +440,7 @@
</div>
<div class="modal-footer">
<a class="waves-effect waves-green btn-flat save-button">Save</a>
<a class="modal-close waves-effect waves-green btn-flat action-validate save-validate-button">Save &amp; Validate</a>
<a class="modal-close waves-effect waves-green btn-flat action-upload editor-upload-button">Upload</a>
<a class="modal-close waves-effect waves-green btn-flat">Close</a>
</div>
</div>

View File

@@ -19,12 +19,16 @@ def patch_structhash():
# all issues
from platformio.commands import run
from platformio import util
try:
from platformio.util import get_project_dir
except ImportError:
from platformio.project.helpers import get_project_dir
from os.path import join, isdir, getmtime, isfile
from os import makedirs
def patched_clean_build_dir(build_dir):
structhash_file = join(build_dir, "structure.hash")
platformio_ini = join(util.get_project_dir(), "platformio.ini")
platformio_ini = join(get_project_dir(), "platformio.ini")
# if project's config is modified
if isdir(build_dir) and getmtime(platformio_ini) > getmtime(build_dir):

View File

@@ -37,7 +37,7 @@ def trash_storage_path(base_path): # type: (str) -> str
class StorageJSON(object):
def __init__(self, storage_version, name, esphome_version,
src_version, arduino_version, address, esp_platform, board, build_path,
firmware_bin_path):
firmware_bin_path, loaded_integrations):
# Version of the storage JSON schema
assert storage_version is None or isinstance(storage_version, int)
self.storage_version = storage_version # type: int
@@ -61,6 +61,9 @@ class StorageJSON(object):
self.build_path = build_path # type: str
# The absolute path to the firmware binary
self.firmware_bin_path = firmware_bin_path # type: str
# A list of strings of names of loaded integrations
self.loaded_integrations = loaded_integrations # type: List[str]
self.loaded_integrations.sort()
def as_dict(self):
return {
@@ -74,6 +77,7 @@ class StorageJSON(object):
'board': self.board,
'build_path': self.build_path,
'firmware_bin_path': self.firmware_bin_path,
'loaded_integrations': self.loaded_integrations,
}
def to_json(self):
@@ -97,6 +101,7 @@ class StorageJSON(object):
board=esph.board,
build_path=esph.build_path,
firmware_bin_path=esph.firmware_bin,
loaded_integrations=list(esph.loaded_integrations),
)
@staticmethod
@@ -113,6 +118,7 @@ class StorageJSON(object):
board=board,
build_path=None,
firmware_bin_path=None,
loaded_integrations=[],
)
@staticmethod
@@ -130,9 +136,10 @@ class StorageJSON(object):
board = storage.get('board')
build_path = storage.get('build_path')
firmware_bin_path = storage.get('firmware_bin_path')
loaded_integrations = storage.get('loaded_integrations', [])
return StorageJSON(storage_version, name, esphome_version,
src_version, arduino_version, address, esp_platform, board, build_path,
firmware_bin_path)
firmware_bin_path, loaded_integrations)
@staticmethod
def load(path): # type: (str) -> Optional[StorageJSON]

View File

@@ -130,8 +130,6 @@ def storage_should_clean(old, new): # type: (StorageJSON, StorageJSON) -> bool
if old is None:
return True
if old.esphome_version != new.esphome_version:
return True
if old.src_version != new.src_version:
return True
if old.arduino_version != new.arduino_version:

View File

@@ -11,6 +11,19 @@ import sys
sys.path.append(os.path.dirname(__file__))
from helpers import get_output, git_ls_files, filter_changed
curfile = None
def print_error(file, lineno, msg):
global curfile
if curfile != file:
print()
print("\033[0;32m************* File \033[1;32m{}\033[0m".format(file))
curfile = file
print(u'{}:{} - {}'.format(file, lineno, msg))
def main():
parser = argparse.ArgumentParser()
@@ -38,7 +51,7 @@ def main():
if not files:
sys.exit(0)
errors = collections.defaultdict(list)
errors = 0
cmd = ['flake8'] + files
print("Running flake8...")
log = get_output(*cmd)
@@ -49,7 +62,8 @@ def main():
file_ = line[0]
linno = line[1]
msg = (u':'.join(line[3:])).strip()
errors[file_].append(u'{}:{} - {}'.format(file_, linno, msg))
print_error(file_, linno, msg)
errors += 1
cmd = ['pylint', '-f', 'parseable', '--persistent=n'] + files
print("Running pylint...")
@@ -61,15 +75,10 @@ def main():
file_ = line[0]
linno = line[1]
msg = (u':'.join(line[3:])).strip()
errors[file_].append(u'{}:{} - {}'.format(file_, linno, msg))
print_error(file_, linno, msg)
errors += 1
for f, errs in sorted(errors.items()):
print("\033[0;32m************* File \033[1;32m{}\033[0m".format(f))
for err in errs:
print(err)
print()
sys.exit(len(errors))
sys.exit(errors)
if __name__ == '__main__':

View File

@@ -115,6 +115,33 @@ sensor:
- calibrate_linear:
- 0 -> 0
- 100 -> 100
- platform: resistance
sensor: my_sensor
configuration: DOWNSTREAM
resistor: 10kΩ
reference_voltage: 3.3V
name: Resistance
id: resist
- platform: ntc
sensor: resist
name: NTC Sensor
calibration:
b_constant: 3950
reference_resistance: 10k
reference_temperature: 25°C
- platform: ntc
sensor: resist
name: NTC Sensor2
calibration:
- 10.0kOhm -> 25°C
- 27.219kOhm -> 0°C
- 14.674kOhm -> 15°C
- platform: ct_clamp
sensor: my_sensor
name: CT Clamp
sample_duration: 500ms
update_interval: 5s
- platform: tcs34725
red_channel:
name: Red Channel
@@ -138,6 +165,16 @@ sensor:
sensors:
- id: custom_sensor
name: Custom Sensor
- platform: binary_sensor_map
name: Binary Sensor Map
type: group
channels:
- binary_sensor: bin1
value: 10.0
- binary_sensor: bin2
value: 15.0
- binary_sensor: bin3
value: 100.0
time:
- platform: homeassistant
@@ -182,12 +219,15 @@ binary_sensor:
- platform: mpr121
channel: 1
name: "touchkey1"
id: bin1
- platform: mpr121
channel: 2
name: "touchkey2"
id: bin2
- platform: mpr121
channel: 3
name: "touchkey3"
id: bin3
on_press:
then:
- switch.toggle: mpr121_toggle