esphome 2024.8.3__py3-none-any.whl → 2024.9.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esphome/__main__.py +6 -2
- esphome/components/api/api_connection.cpp +19 -0
- esphome/components/api/api_connection.h +1 -0
- esphome/components/api/api_pb2.cpp +136 -0
- esphome/components/api/api_pb2.h +43 -0
- esphome/components/api/api_pb2_service.cpp +21 -0
- esphome/components/api/api_pb2_service.h +6 -0
- esphome/components/async_tcp/__init__.py +3 -3
- esphome/components/atm90e26/sensor.py +10 -10
- esphome/components/atm90e32/sensor.py +1 -1
- esphome/components/bl0906/__init__.py +1 -0
- esphome/components/bl0906/bl0906.cpp +238 -0
- esphome/components/bl0906/bl0906.h +96 -0
- esphome/components/bl0906/const.py +4 -0
- esphome/components/bl0906/constants.h +122 -0
- esphome/components/bl0906/sensor.py +184 -0
- esphome/components/bl0942/__init__.py +1 -1
- esphome/components/bl0942/bl0942.cpp +127 -34
- esphome/components/bl0942/bl0942.h +87 -3
- esphome/components/bl0942/sensor.py +46 -8
- esphome/components/ble_client/__init__.py +1 -3
- esphome/components/bluetooth_proxy/bluetooth_proxy.cpp +5 -0
- esphome/components/bmp280/sensor.py +2 -93
- esphome/components/bmp280_base/__init__.py +88 -0
- esphome/components/{bmp280/bmp280.cpp → bmp280_base/bmp280_base.cpp} +11 -4
- esphome/components/{bmp280/bmp280.h → bmp280_base/bmp280_base.h} +9 -5
- esphome/components/bmp280_i2c/__init__.py +0 -0
- esphome/components/bmp280_i2c/bmp280_i2c.cpp +27 -0
- esphome/components/bmp280_i2c/bmp280_i2c.h +22 -0
- esphome/components/bmp280_i2c/sensor.py +22 -0
- esphome/components/bmp280_spi/__init__.py +0 -0
- esphome/components/bmp280_spi/bmp280_spi.cpp +65 -0
- esphome/components/bmp280_spi/bmp280_spi.h +20 -0
- esphome/components/bmp280_spi/sensor.py +22 -0
- esphome/components/captive_portal/captive_portal.cpp +2 -0
- esphome/components/captive_portal/captive_portal.h +3 -1
- esphome/components/ch422g/__init__.py +67 -0
- esphome/components/ch422g/ch422g.cpp +122 -0
- esphome/components/ch422g/ch422g.h +70 -0
- esphome/components/debug/debug_esp32.cpp +3 -1
- esphome/components/display/__init__.py +5 -4
- esphome/components/dsmr/dsmr.cpp +6 -0
- esphome/components/dsmr/dsmr.h +6 -0
- esphome/components/dsmr/text_sensor.py +7 -2
- esphome/components/e131/e131.cpp +2 -0
- esphome/components/e131/e131.h +3 -1
- esphome/components/e131/e131_addressable_light_effect.cpp +2 -0
- esphome/components/e131/e131_addressable_light_effect.h +2 -1
- esphome/components/e131/e131_packet.cpp +2 -0
- esphome/components/esp32_camera/__init__.py +4 -0
- esphome/components/esp32_camera/esp32_camera.cpp +9 -1
- esphome/components/esp32_camera/esp32_camera.h +3 -0
- esphome/components/esp32_can/canbus.py +18 -7
- esphome/components/esp32_can/esp32_can.cpp +8 -0
- esphome/components/esp32_can/esp32_can.h +4 -0
- esphome/components/esp32_rmt_led_strip/led_strip.cpp +14 -2
- esphome/components/esp32_rmt_led_strip/led_strip.h +3 -2
- esphome/components/esp32_rmt_led_strip/light.py +21 -4
- esphome/components/esphome/ota/ota_esphome.cpp +2 -1
- esphome/components/esphome/ota/ota_esphome.h +2 -0
- esphome/components/font/__init__.py +11 -22
- esphome/components/font/font.cpp +3 -2
- esphome/components/font/font.h +12 -3
- esphome/components/gree/climate.py +2 -1
- esphome/components/gree/gree.cpp +54 -3
- esphome/components/gree/gree.h +10 -2
- esphome/components/gt911/touchscreen/__init__.py +6 -4
- esphome/components/gt911/touchscreen/gt911_touchscreen.cpp +17 -0
- esphome/components/gt911/touchscreen/gt911_touchscreen.h +2 -0
- esphome/components/hmac_md5/__init__.py +2 -0
- esphome/components/hmac_md5/hmac_md5.cpp +56 -0
- esphome/components/hmac_md5/hmac_md5.h +48 -0
- esphome/components/homeassistant/__init__.py +13 -0
- esphome/components/homeassistant/switch/__init__.py +15 -2
- esphome/components/homeassistant/switch/homeassistant_switch.cpp +2 -2
- esphome/components/i2s_audio/__init__.py +88 -9
- esphome/components/i2s_audio/i2s_audio.h +20 -2
- esphome/components/i2s_audio/media_player/__init__.py +8 -4
- esphome/components/i2s_audio/media_player/i2s_audio_media_player.h +1 -1
- esphome/components/i2s_audio/microphone/__init__.py +19 -51
- esphome/components/i2s_audio/microphone/i2s_audio_microphone.cpp +18 -15
- esphome/components/i2s_audio/microphone/i2s_audio_microphone.h +0 -12
- esphome/components/i2s_audio/speaker/__init__.py +39 -27
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.cpp +49 -37
- esphome/components/i2s_audio/speaker/i2s_audio_speaker.h +3 -4
- esphome/components/ili9xxx/display.py +16 -17
- esphome/components/ili9xxx/ili9xxx_display.cpp +1 -1
- esphome/components/ili9xxx/ili9xxx_display.h +18 -18
- esphome/components/ili9xxx/ili9xxx_init.h +0 -3
- esphome/components/improv_serial/improv_serial_component.cpp +2 -1
- esphome/components/improv_serial/improv_serial_component.h +2 -1
- esphome/components/ledc/ledc_output.cpp +11 -7
- esphome/components/libretiny/__init__.py +8 -13
- esphome/components/ltr501/__init__.py +1 -0
- esphome/components/ltr501/ltr501.cpp +542 -0
- esphome/components/ltr501/ltr501.h +184 -0
- esphome/components/ltr501/ltr_definitions_501.h +260 -0
- esphome/components/ltr501/sensor.py +274 -0
- esphome/components/ltr_als_ps/sensor.py +2 -2
- esphome/components/lvgl/__init__.py +19 -16
- esphome/components/lvgl/automation.py +90 -9
- esphome/components/lvgl/defines.py +29 -2
- esphome/components/lvgl/gradient.py +61 -0
- esphome/components/lvgl/lv_validation.py +45 -27
- esphome/components/lvgl/lvcode.py +8 -3
- esphome/components/lvgl/lvgl_esphome.cpp +54 -0
- esphome/components/lvgl/lvgl_esphome.h +9 -3
- esphome/components/lvgl/number/__init__.py +1 -0
- esphome/components/lvgl/number/lvgl_number.h +3 -1
- esphome/components/lvgl/schemas.py +16 -11
- esphome/components/lvgl/select/__init__.py +1 -0
- esphome/components/lvgl/select/lvgl_select.h +3 -1
- esphome/components/lvgl/switch/__init__.py +2 -1
- esphome/components/lvgl/switch/lvgl_switch.h +3 -1
- esphome/components/lvgl/text/__init__.py +1 -0
- esphome/components/lvgl/text/lvgl_text.h +3 -1
- esphome/components/lvgl/trigger.py +3 -2
- esphome/components/lvgl/types.py +2 -1
- esphome/components/lvgl/widgets/__init__.py +23 -8
- esphome/components/lvgl/widgets/arc.py +5 -1
- esphome/components/lvgl/widgets/buttonmatrix.py +5 -1
- esphome/components/lvgl/widgets/checkbox.py +8 -3
- esphome/components/lvgl/widgets/meter.py +8 -1
- esphome/components/lvgl/widgets/msgbox.py +26 -15
- esphome/components/lvgl/widgets/page.py +51 -7
- esphome/components/lvgl/widgets/tileview.py +2 -8
- esphome/components/max31856/max31856.cpp +12 -1
- esphome/components/max31856/max31856.h +5 -2
- esphome/components/max31856/sensor.py +20 -0
- esphome/components/mcp9600/sensor.py +2 -2
- esphome/components/mdns/__init__.py +6 -6
- esphome/components/media_player/media_player.h +15 -0
- esphome/components/micro_wake_word/__init__.py +2 -25
- esphome/components/microphone/microphone.h +1 -1
- esphome/components/mics_4514/mics_4514.cpp +26 -36
- esphome/components/modbus_controller/__init__.py +6 -0
- esphome/components/modbus_controller/const.py +2 -0
- esphome/components/modbus_controller/modbus_controller.cpp +30 -27
- esphome/components/modbus_controller/modbus_controller.h +22 -4
- esphome/components/network/__init__.py +11 -8
- esphome/components/pipsolar/pipsolar.cpp +3 -0
- esphome/components/pipsolar/pipsolar.h +1 -0
- esphome/components/pipsolar/switch/__init__.py +2 -0
- esphome/components/prometheus/prometheus_handler.cpp +2 -0
- esphome/components/prometheus/prometheus_handler.h +3 -1
- esphome/components/rp2040/__init__.py +7 -8
- esphome/components/rpi_dpi_rgb/display.py +20 -17
- esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.cpp +36 -6
- esphome/components/rpi_dpi_rgb/rpi_dpi_rgb.h +4 -0
- esphome/components/socket/socket.cpp +2 -0
- esphome/components/socket/socket.h +2 -0
- esphome/components/speaker/speaker.h +1 -1
- esphome/components/st7701s/display.py +35 -37
- esphome/components/st7701s/st7701s.cpp +11 -6
- esphome/components/st7701s/st7701s.h +1 -0
- esphome/components/statsd/__init__.py +65 -0
- esphome/components/statsd/statsd.cpp +156 -0
- esphome/components/statsd/statsd.h +86 -0
- esphome/components/tuya/__init__.py +1 -0
- esphome/components/tuya/number/__init__.py +39 -2
- esphome/components/tuya/number/tuya_number.cpp +58 -2
- esphome/components/tuya/number/tuya_number.h +12 -3
- esphome/components/udp/__init__.py +158 -0
- esphome/components/udp/binary_sensor.py +27 -0
- esphome/components/udp/sensor.py +27 -0
- esphome/components/udp/udp_component.cpp +616 -0
- esphome/components/udp/udp_component.h +158 -0
- esphome/components/uponor_smatrix/uponor_smatrix.cpp +4 -6
- esphome/components/uponor_smatrix/uponor_smatrix.h +0 -1
- esphome/components/veml7700/sensor.py +2 -2
- esphome/components/voice_assistant/__init__.py +6 -0
- esphome/components/voice_assistant/voice_assistant.cpp +23 -1
- esphome/components/voice_assistant/voice_assistant.h +4 -0
- esphome/components/web_server/__init__.py +11 -11
- esphome/components/web_server/list_entities.cpp +2 -0
- esphome/components/web_server/list_entities.h +3 -1
- esphome/components/web_server/web_server.cpp +2 -1
- esphome/components/web_server/web_server.h +2 -0
- esphome/components/web_server_base/web_server_base.cpp +2 -0
- esphome/components/web_server_base/web_server_base.h +3 -1
- esphome/components/wifi/wifi_component_libretiny.cpp +15 -1
- esphome/components/wireguard/__init__.py +9 -6
- esphome/components/wireguard/wireguard.cpp +2 -1
- esphome/components/wireguard/wireguard.h +3 -1
- esphome/config_validation.py +8 -0
- esphome/const.py +8 -1
- esphome/core/bytebuffer.cpp +117 -84
- esphome/core/bytebuffer.h +69 -21
- esphome/core/defines.h +2 -0
- esphome/core/ring_buffer.cpp +13 -2
- esphome/core/ring_buffer.h +56 -0
- esphome/external_files.py +5 -3
- {esphome-2024.8.3.dist-info → esphome-2024.9.0b1.dist-info}/METADATA +1 -1
- {esphome-2024.8.3.dist-info → esphome-2024.9.0b1.dist-info}/RECORD +198 -163
- {esphome-2024.8.3.dist-info → esphome-2024.9.0b1.dist-info}/LICENSE +0 -0
- {esphome-2024.8.3.dist-info → esphome-2024.9.0b1.dist-info}/WHEEL +0 -0
- {esphome-2024.8.3.dist-info → esphome-2024.9.0b1.dist-info}/entry_points.txt +0 -0
- {esphome-2024.8.3.dist-info → esphome-2024.9.0b1.dist-info}/top_level.txt +0 -0
@@ -8,6 +8,57 @@
|
|
8
8
|
namespace esphome {
|
9
9
|
namespace bl0942 {
|
10
10
|
|
11
|
+
// The BL0942 IC is "calibration-free", which means that it doesn't care
|
12
|
+
// at all about calibration, and that's left to software. It measures a
|
13
|
+
// voltage differential on its IP/IN pins which linearly proportional to
|
14
|
+
// the current flow, and another on its VP pin which is proportional to
|
15
|
+
// the line voltage. It never knows the actual calibration; the values
|
16
|
+
// it reports are solely in terms of those inputs.
|
17
|
+
//
|
18
|
+
// The datasheet refers to the input voltages as I(A) and V(V), both
|
19
|
+
// in millivolts. It measures them against a reference voltage Vref,
|
20
|
+
// which is typically 1.218V (but that absolute value is meaningless
|
21
|
+
// without the actual calibration anyway).
|
22
|
+
//
|
23
|
+
// The reported I_RMS value is 305978 I(A)/Vref, and the reported V_RMS
|
24
|
+
// value is 73989 V(V)/Vref. So we can calibrate those by applying a
|
25
|
+
// simple meter with a resistive load.
|
26
|
+
//
|
27
|
+
// The chip also measures the phase difference between voltage and
|
28
|
+
// current, and uses it to calculate the power factor (cos φ). It
|
29
|
+
// reports the WATT value of 3537 * I_RMS * V_RMS * cos φ).
|
30
|
+
//
|
31
|
+
// It also integrates total energy based on the WATT value. The time for
|
32
|
+
// one CF_CNT pulse is 1638.4*256 / WATT.
|
33
|
+
//
|
34
|
+
// So... how do we calibrate that?
|
35
|
+
//
|
36
|
+
// Using a simple resistive load and an external meter, we can measure
|
37
|
+
// the true voltage and current for a given V_RMS and I_RMS reading,
|
38
|
+
// to calculate BL0942_UREF and BL0942_IREF. Those are in units of
|
39
|
+
// "305978 counts per amp" or "73989 counts per volt" respectively.
|
40
|
+
//
|
41
|
+
// We can derive BL0942_PREF from those. Let's eliminate the weird
|
42
|
+
// factors and express the calibration in plain counts per volt/amp:
|
43
|
+
// UREF1 = UREF/73989, IREF1 = IREF/305978.
|
44
|
+
//
|
45
|
+
// Next... the true power in Watts is V * I * cos φ, so that's equal
|
46
|
+
// to WATT/3537 * IREF1 * UREF1. Which means
|
47
|
+
// BL0942_PREF = BL0942_UREF * BL0942_IREF * 3537 / 305978 / 73989.
|
48
|
+
//
|
49
|
+
// Finally the accumulated energy. The period of a CF_CNT count is
|
50
|
+
// 1638.4*256 / WATT seconds, or 419230.4 / WATT seconds. Which means
|
51
|
+
// the energy represented by a CN_CNT pulse is 419230.4 WATT-seconds.
|
52
|
+
// Factoring in the calibration, that's 419230.4 / BL0942_PREF actual
|
53
|
+
// Watt-seconds (or Joules, as the physicists like to call them).
|
54
|
+
//
|
55
|
+
// But we're not being physicists today; we we're being engineers, so
|
56
|
+
// we want to convert to kWh instead. Which we do by dividing by 1000
|
57
|
+
// and then by 3600, so the energy in kWh is
|
58
|
+
// CF_CNT * 419230.4 / BL0942_PREF / 3600000
|
59
|
+
//
|
60
|
+
// Which makes BL0952_EREF = BL0942_PREF * 3600000 / 419430.4
|
61
|
+
|
11
62
|
static const float BL0942_PREF = 596; // taken from tasmota
|
12
63
|
static const float BL0942_UREF = 15873.35944299; // should be 73989/1.218
|
13
64
|
static const float BL0942_IREF = 251213.46469622; // 305978/1.218
|
@@ -28,6 +79,11 @@ struct DataPacket {
|
|
28
79
|
uint8_t checksum;
|
29
80
|
} __attribute__((packed));
|
30
81
|
|
82
|
+
enum LineFrequency : uint8_t {
|
83
|
+
LINE_FREQUENCY_50HZ = 50,
|
84
|
+
LINE_FREQUENCY_60HZ = 60,
|
85
|
+
};
|
86
|
+
|
31
87
|
class BL0942 : public PollingComponent, public uart::UARTDevice {
|
32
88
|
public:
|
33
89
|
void set_voltage_sensor(sensor::Sensor *voltage_sensor) { voltage_sensor_ = voltage_sensor; }
|
@@ -35,9 +91,27 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
|
|
35
91
|
void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
|
36
92
|
void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
|
37
93
|
void set_frequency_sensor(sensor::Sensor *frequency_sensor) { frequency_sensor_ = frequency_sensor; }
|
94
|
+
void set_line_freq(LineFrequency freq) { this->line_freq_ = freq; }
|
95
|
+
void set_address(uint8_t address) { this->address_ = address; }
|
96
|
+
void set_reset(bool reset) { this->reset_ = reset; }
|
97
|
+
void set_current_reference(float current_ref) {
|
98
|
+
this->current_reference_ = current_ref;
|
99
|
+
this->current_reference_set_ = true;
|
100
|
+
}
|
101
|
+
void set_energy_reference(float energy_ref) {
|
102
|
+
this->energy_reference_ = energy_ref;
|
103
|
+
this->energy_reference_set_ = true;
|
104
|
+
}
|
105
|
+
void set_power_reference(float power_ref) {
|
106
|
+
this->power_reference_ = power_ref;
|
107
|
+
this->power_reference_set_ = true;
|
108
|
+
}
|
109
|
+
void set_voltage_reference(float voltage_ref) {
|
110
|
+
this->voltage_reference_ = voltage_ref;
|
111
|
+
this->voltage_reference_set_ = true;
|
112
|
+
}
|
38
113
|
|
39
114
|
void loop() override;
|
40
|
-
|
41
115
|
void update() override;
|
42
116
|
void setup() override;
|
43
117
|
void dump_config() override;
|
@@ -53,15 +127,25 @@ class BL0942 : public PollingComponent, public uart::UARTDevice {
|
|
53
127
|
|
54
128
|
// Divide by this to turn into Watt
|
55
129
|
float power_reference_ = BL0942_PREF;
|
130
|
+
bool power_reference_set_ = false;
|
56
131
|
// Divide by this to turn into Volt
|
57
132
|
float voltage_reference_ = BL0942_UREF;
|
133
|
+
bool voltage_reference_set_ = false;
|
58
134
|
// Divide by this to turn into Ampere
|
59
135
|
float current_reference_ = BL0942_IREF;
|
136
|
+
bool current_reference_set_ = false;
|
60
137
|
// Divide by this to turn into kWh
|
61
138
|
float energy_reference_ = BL0942_EREF;
|
139
|
+
bool energy_reference_set_ = false;
|
140
|
+
uint8_t address_ = 0;
|
141
|
+
bool reset_ = false;
|
142
|
+
LineFrequency line_freq_ = LINE_FREQUENCY_50HZ;
|
143
|
+
uint32_t rx_start_ = 0;
|
144
|
+
uint32_t prev_cf_cnt_ = 0;
|
62
145
|
|
63
|
-
|
64
|
-
|
146
|
+
bool validate_checksum_(DataPacket *data);
|
147
|
+
int read_reg_(uint8_t reg);
|
148
|
+
void write_reg_(uint8_t reg, uint32_t val);
|
65
149
|
void received_package_(DataPacket *data);
|
66
150
|
};
|
67
151
|
} // namespace bl0942
|
@@ -1,32 +1,46 @@
|
|
1
1
|
import esphome.codegen as cg
|
2
|
-
import esphome.config_validation as cv
|
3
2
|
from esphome.components import sensor, uart
|
3
|
+
import esphome.config_validation as cv
|
4
4
|
from esphome.const import (
|
5
|
+
CONF_ADDRESS,
|
5
6
|
CONF_CURRENT,
|
6
7
|
CONF_ENERGY,
|
8
|
+
CONF_FREQUENCY,
|
7
9
|
CONF_ID,
|
10
|
+
CONF_LINE_FREQUENCY,
|
8
11
|
CONF_POWER,
|
9
12
|
CONF_VOLTAGE,
|
10
|
-
CONF_FREQUENCY,
|
11
13
|
DEVICE_CLASS_CURRENT,
|
12
14
|
DEVICE_CLASS_ENERGY,
|
15
|
+
DEVICE_CLASS_FREQUENCY,
|
13
16
|
DEVICE_CLASS_POWER,
|
14
17
|
DEVICE_CLASS_VOLTAGE,
|
15
|
-
DEVICE_CLASS_FREQUENCY,
|
16
18
|
STATE_CLASS_MEASUREMENT,
|
19
|
+
STATE_CLASS_TOTAL_INCREASING,
|
17
20
|
UNIT_AMPERE,
|
21
|
+
UNIT_HERTZ,
|
18
22
|
UNIT_KILOWATT_HOURS,
|
19
23
|
UNIT_VOLT,
|
20
24
|
UNIT_WATT,
|
21
|
-
UNIT_HERTZ,
|
22
|
-
STATE_CLASS_TOTAL_INCREASING,
|
23
25
|
)
|
24
26
|
|
27
|
+
CONF_CURRENT_REFERENCE = "current_reference"
|
28
|
+
CONF_ENERGY_REFERENCE = "energy_reference"
|
29
|
+
CONF_POWER_REFERENCE = "power_reference"
|
30
|
+
CONF_RESET = "reset"
|
31
|
+
CONF_VOLTAGE_REFERENCE = "voltage_reference"
|
32
|
+
|
25
33
|
DEPENDENCIES = ["uart"]
|
26
34
|
|
27
35
|
bl0942_ns = cg.esphome_ns.namespace("bl0942")
|
28
36
|
BL0942 = bl0942_ns.class_("BL0942", cg.PollingComponent, uart.UARTDevice)
|
29
37
|
|
38
|
+
LineFrequency = bl0942_ns.enum("LineFrequency")
|
39
|
+
LINE_FREQS = {
|
40
|
+
50: LineFrequency.LINE_FREQUENCY_50HZ,
|
41
|
+
60: LineFrequency.LINE_FREQUENCY_60HZ,
|
42
|
+
}
|
43
|
+
|
30
44
|
CONFIG_SCHEMA = (
|
31
45
|
cv.Schema(
|
32
46
|
{
|
@@ -45,22 +59,35 @@ CONFIG_SCHEMA = (
|
|
45
59
|
),
|
46
60
|
cv.Optional(CONF_POWER): sensor.sensor_schema(
|
47
61
|
unit_of_measurement=UNIT_WATT,
|
48
|
-
accuracy_decimals=
|
62
|
+
accuracy_decimals=1,
|
49
63
|
device_class=DEVICE_CLASS_POWER,
|
50
64
|
state_class=STATE_CLASS_MEASUREMENT,
|
51
65
|
),
|
52
66
|
cv.Optional(CONF_ENERGY): sensor.sensor_schema(
|
53
67
|
unit_of_measurement=UNIT_KILOWATT_HOURS,
|
54
|
-
accuracy_decimals=
|
68
|
+
accuracy_decimals=3,
|
55
69
|
device_class=DEVICE_CLASS_ENERGY,
|
56
70
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
57
71
|
),
|
58
72
|
cv.Optional(CONF_FREQUENCY): sensor.sensor_schema(
|
59
73
|
unit_of_measurement=UNIT_HERTZ,
|
60
|
-
accuracy_decimals=
|
74
|
+
accuracy_decimals=2,
|
61
75
|
device_class=DEVICE_CLASS_FREQUENCY,
|
62
76
|
state_class=STATE_CLASS_MEASUREMENT,
|
63
77
|
),
|
78
|
+
cv.Optional(CONF_LINE_FREQUENCY, default="50HZ"): cv.All(
|
79
|
+
cv.frequency,
|
80
|
+
cv.enum(
|
81
|
+
LINE_FREQS,
|
82
|
+
int=True,
|
83
|
+
),
|
84
|
+
),
|
85
|
+
cv.Optional(CONF_ADDRESS, default=0): cv.int_range(min=0, max=3),
|
86
|
+
cv.Optional(CONF_RESET, default=True): cv.boolean,
|
87
|
+
cv.Optional(CONF_CURRENT_REFERENCE): cv.float_,
|
88
|
+
cv.Optional(CONF_ENERGY_REFERENCE): cv.float_,
|
89
|
+
cv.Optional(CONF_POWER_REFERENCE): cv.float_,
|
90
|
+
cv.Optional(CONF_VOLTAGE_REFERENCE): cv.float_,
|
64
91
|
}
|
65
92
|
)
|
66
93
|
.extend(cv.polling_component_schema("60s"))
|
@@ -88,3 +115,14 @@ async def to_code(config):
|
|
88
115
|
if frequency_config := config.get(CONF_FREQUENCY):
|
89
116
|
sens = await sensor.new_sensor(frequency_config)
|
90
117
|
cg.add(var.set_frequency_sensor(sens))
|
118
|
+
cg.add(var.set_line_freq(config[CONF_LINE_FREQUENCY]))
|
119
|
+
cg.add(var.set_address(config[CONF_ADDRESS]))
|
120
|
+
cg.add(var.set_reset(config[CONF_RESET]))
|
121
|
+
if (current_reference := config.get(CONF_CURRENT_REFERENCE, None)) is not None:
|
122
|
+
cg.add(var.set_current_reference(current_reference))
|
123
|
+
if (voltage_reference := config.get(CONF_VOLTAGE_REFERENCE, None)) is not None:
|
124
|
+
cg.add(var.set_voltage_reference(voltage_reference))
|
125
|
+
if (power_reference := config.get(CONF_POWER_REFERENCE, None)) is not None:
|
126
|
+
cg.add(var.set_power_reference(power_reference))
|
127
|
+
if (energy_reference := config.get(CONF_ENERGY_REFERENCE, None)) is not None:
|
128
|
+
cg.add(var.set_energy_reference(energy_reference))
|
@@ -65,9 +65,7 @@ CONF_ON_PASSKEY_NOTIFICATION = "on_passkey_notification"
|
|
65
65
|
CONF_ON_NUMERIC_COMPARISON_REQUEST = "on_numeric_comparison_request"
|
66
66
|
CONF_AUTO_CONNECT = "auto_connect"
|
67
67
|
|
68
|
-
|
69
|
-
# enforce this in yaml checks.
|
70
|
-
MULTI_CONF = 3
|
68
|
+
MULTI_CONF = True
|
71
69
|
|
72
70
|
CONFIG_SCHEMA = (
|
73
71
|
cv.Schema(
|
@@ -54,6 +54,9 @@ bool BluetoothProxy::parse_devices(esp_ble_gap_cb_param_t::ble_scan_result_evt_p
|
|
54
54
|
}
|
55
55
|
|
56
56
|
resp.advertisements.push_back(std::move(adv));
|
57
|
+
|
58
|
+
ESP_LOGV(TAG, "Proxying raw packet from %02X:%02X:%02X:%02X:%02X:%02X, length %d. RSSI: %d dB", result.bda[0],
|
59
|
+
result.bda[1], result.bda[2], result.bda[3], result.bda[4], result.bda[5], length, result.rssi);
|
57
60
|
}
|
58
61
|
ESP_LOGV(TAG, "Proxying %d packets", count);
|
59
62
|
this->api_connection_->send_bluetooth_le_raw_advertisements_response(resp);
|
@@ -87,6 +90,8 @@ void BluetoothProxy::send_api_packet_(const esp32_ble_tracker::ESPBTDevice &devi
|
|
87
90
|
void BluetoothProxy::dump_config() {
|
88
91
|
ESP_LOGCONFIG(TAG, "Bluetooth Proxy:");
|
89
92
|
ESP_LOGCONFIG(TAG, " Active: %s", YESNO(this->active_));
|
93
|
+
ESP_LOGCONFIG(TAG, " Connections: %d", this->connections_.size());
|
94
|
+
ESP_LOGCONFIG(TAG, " Raw advertisements: %s", YESNO(this->raw_advertisements_));
|
90
95
|
}
|
91
96
|
|
92
97
|
int BluetoothProxy::get_bluetooth_connections_free() {
|
@@ -1,96 +1,5 @@
|
|
1
|
-
import esphome.codegen as cg
|
2
1
|
import esphome.config_validation as cv
|
3
|
-
from esphome.components import i2c, sensor
|
4
|
-
from esphome.const import (
|
5
|
-
CONF_ID,
|
6
|
-
CONF_PRESSURE,
|
7
|
-
CONF_TEMPERATURE,
|
8
|
-
DEVICE_CLASS_PRESSURE,
|
9
|
-
DEVICE_CLASS_TEMPERATURE,
|
10
|
-
STATE_CLASS_MEASUREMENT,
|
11
|
-
UNIT_CELSIUS,
|
12
|
-
UNIT_HECTOPASCAL,
|
13
|
-
CONF_IIR_FILTER,
|
14
|
-
CONF_OVERSAMPLING,
|
15
|
-
)
|
16
|
-
|
17
|
-
DEPENDENCIES = ["i2c"]
|
18
|
-
|
19
|
-
bmp280_ns = cg.esphome_ns.namespace("bmp280")
|
20
|
-
BMP280Oversampling = bmp280_ns.enum("BMP280Oversampling")
|
21
|
-
OVERSAMPLING_OPTIONS = {
|
22
|
-
"NONE": BMP280Oversampling.BMP280_OVERSAMPLING_NONE,
|
23
|
-
"1X": BMP280Oversampling.BMP280_OVERSAMPLING_1X,
|
24
|
-
"2X": BMP280Oversampling.BMP280_OVERSAMPLING_2X,
|
25
|
-
"4X": BMP280Oversampling.BMP280_OVERSAMPLING_4X,
|
26
|
-
"8X": BMP280Oversampling.BMP280_OVERSAMPLING_8X,
|
27
|
-
"16X": BMP280Oversampling.BMP280_OVERSAMPLING_16X,
|
28
|
-
}
|
29
|
-
|
30
|
-
BMP280IIRFilter = bmp280_ns.enum("BMP280IIRFilter")
|
31
|
-
IIR_FILTER_OPTIONS = {
|
32
|
-
"OFF": BMP280IIRFilter.BMP280_IIR_FILTER_OFF,
|
33
|
-
"2X": BMP280IIRFilter.BMP280_IIR_FILTER_2X,
|
34
|
-
"4X": BMP280IIRFilter.BMP280_IIR_FILTER_4X,
|
35
|
-
"8X": BMP280IIRFilter.BMP280_IIR_FILTER_8X,
|
36
|
-
"16X": BMP280IIRFilter.BMP280_IIR_FILTER_16X,
|
37
|
-
}
|
38
|
-
|
39
|
-
BMP280Component = bmp280_ns.class_(
|
40
|
-
"BMP280Component", cg.PollingComponent, i2c.I2CDevice
|
41
|
-
)
|
42
2
|
|
43
|
-
CONFIG_SCHEMA = (
|
44
|
-
|
45
|
-
{
|
46
|
-
cv.GenerateID(): cv.declare_id(BMP280Component),
|
47
|
-
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
48
|
-
unit_of_measurement=UNIT_CELSIUS,
|
49
|
-
accuracy_decimals=1,
|
50
|
-
device_class=DEVICE_CLASS_TEMPERATURE,
|
51
|
-
state_class=STATE_CLASS_MEASUREMENT,
|
52
|
-
).extend(
|
53
|
-
{
|
54
|
-
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
55
|
-
OVERSAMPLING_OPTIONS, upper=True
|
56
|
-
),
|
57
|
-
}
|
58
|
-
),
|
59
|
-
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
60
|
-
unit_of_measurement=UNIT_HECTOPASCAL,
|
61
|
-
accuracy_decimals=1,
|
62
|
-
device_class=DEVICE_CLASS_PRESSURE,
|
63
|
-
state_class=STATE_CLASS_MEASUREMENT,
|
64
|
-
).extend(
|
65
|
-
{
|
66
|
-
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
67
|
-
OVERSAMPLING_OPTIONS, upper=True
|
68
|
-
),
|
69
|
-
}
|
70
|
-
),
|
71
|
-
cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum(
|
72
|
-
IIR_FILTER_OPTIONS, upper=True
|
73
|
-
),
|
74
|
-
}
|
75
|
-
)
|
76
|
-
.extend(cv.polling_component_schema("60s"))
|
77
|
-
.extend(i2c.i2c_device_schema(0x77))
|
3
|
+
CONFIG_SCHEMA = cv.invalid(
|
4
|
+
"The bmp280 sensor component has been renamed to bmp280_i2c."
|
78
5
|
)
|
79
|
-
|
80
|
-
|
81
|
-
async def to_code(config):
|
82
|
-
var = cg.new_Pvariable(config[CONF_ID])
|
83
|
-
await cg.register_component(var, config)
|
84
|
-
await i2c.register_i2c_device(var, config)
|
85
|
-
|
86
|
-
if temperature_config := config.get(CONF_TEMPERATURE):
|
87
|
-
sens = await sensor.new_sensor(temperature_config)
|
88
|
-
cg.add(var.set_temperature_sensor(sens))
|
89
|
-
cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING]))
|
90
|
-
|
91
|
-
if pressure_config := config.get(CONF_PRESSURE):
|
92
|
-
sens = await sensor.new_sensor(pressure_config)
|
93
|
-
cg.add(var.set_pressure_sensor(sens))
|
94
|
-
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
|
95
|
-
|
96
|
-
cg.add(var.set_iir_filter(config[CONF_IIR_FILTER]))
|
@@ -0,0 +1,88 @@
|
|
1
|
+
import esphome.codegen as cg
|
2
|
+
import esphome.config_validation as cv
|
3
|
+
from esphome.components import sensor
|
4
|
+
from esphome.const import (
|
5
|
+
CONF_ID,
|
6
|
+
CONF_IIR_FILTER,
|
7
|
+
CONF_OVERSAMPLING,
|
8
|
+
CONF_PRESSURE,
|
9
|
+
CONF_TEMPERATURE,
|
10
|
+
DEVICE_CLASS_PRESSURE,
|
11
|
+
DEVICE_CLASS_TEMPERATURE,
|
12
|
+
STATE_CLASS_MEASUREMENT,
|
13
|
+
UNIT_CELSIUS,
|
14
|
+
UNIT_HECTOPASCAL,
|
15
|
+
)
|
16
|
+
|
17
|
+
CODEOWNERS = ["@ademuri"]
|
18
|
+
|
19
|
+
bmp280_ns = cg.esphome_ns.namespace("bmp280_base")
|
20
|
+
BMP280Oversampling = bmp280_ns.enum("BMP280Oversampling")
|
21
|
+
OVERSAMPLING_OPTIONS = {
|
22
|
+
"NONE": BMP280Oversampling.BMP280_OVERSAMPLING_NONE,
|
23
|
+
"1X": BMP280Oversampling.BMP280_OVERSAMPLING_1X,
|
24
|
+
"2X": BMP280Oversampling.BMP280_OVERSAMPLING_2X,
|
25
|
+
"4X": BMP280Oversampling.BMP280_OVERSAMPLING_4X,
|
26
|
+
"8X": BMP280Oversampling.BMP280_OVERSAMPLING_8X,
|
27
|
+
"16X": BMP280Oversampling.BMP280_OVERSAMPLING_16X,
|
28
|
+
}
|
29
|
+
|
30
|
+
BMP280IIRFilter = bmp280_ns.enum("BMP280IIRFilter")
|
31
|
+
IIR_FILTER_OPTIONS = {
|
32
|
+
"OFF": BMP280IIRFilter.BMP280_IIR_FILTER_OFF,
|
33
|
+
"2X": BMP280IIRFilter.BMP280_IIR_FILTER_2X,
|
34
|
+
"4X": BMP280IIRFilter.BMP280_IIR_FILTER_4X,
|
35
|
+
"8X": BMP280IIRFilter.BMP280_IIR_FILTER_8X,
|
36
|
+
"16X": BMP280IIRFilter.BMP280_IIR_FILTER_16X,
|
37
|
+
}
|
38
|
+
|
39
|
+
CONFIG_SCHEMA_BASE = cv.Schema(
|
40
|
+
{
|
41
|
+
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(
|
42
|
+
unit_of_measurement=UNIT_CELSIUS,
|
43
|
+
accuracy_decimals=1,
|
44
|
+
device_class=DEVICE_CLASS_TEMPERATURE,
|
45
|
+
state_class=STATE_CLASS_MEASUREMENT,
|
46
|
+
).extend(
|
47
|
+
{
|
48
|
+
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
49
|
+
OVERSAMPLING_OPTIONS, upper=True
|
50
|
+
),
|
51
|
+
}
|
52
|
+
),
|
53
|
+
cv.Optional(CONF_PRESSURE): sensor.sensor_schema(
|
54
|
+
unit_of_measurement=UNIT_HECTOPASCAL,
|
55
|
+
accuracy_decimals=1,
|
56
|
+
device_class=DEVICE_CLASS_PRESSURE,
|
57
|
+
state_class=STATE_CLASS_MEASUREMENT,
|
58
|
+
).extend(
|
59
|
+
{
|
60
|
+
cv.Optional(CONF_OVERSAMPLING, default="16X"): cv.enum(
|
61
|
+
OVERSAMPLING_OPTIONS, upper=True
|
62
|
+
),
|
63
|
+
}
|
64
|
+
),
|
65
|
+
cv.Optional(CONF_IIR_FILTER, default="OFF"): cv.enum(
|
66
|
+
IIR_FILTER_OPTIONS, upper=True
|
67
|
+
),
|
68
|
+
}
|
69
|
+
).extend(cv.polling_component_schema("60s"))
|
70
|
+
|
71
|
+
|
72
|
+
async def to_code_base(config):
|
73
|
+
var = cg.new_Pvariable(config[CONF_ID])
|
74
|
+
await cg.register_component(var, config)
|
75
|
+
|
76
|
+
if temperature_config := config.get(CONF_TEMPERATURE):
|
77
|
+
sens = await sensor.new_sensor(temperature_config)
|
78
|
+
cg.add(var.set_temperature_sensor(sens))
|
79
|
+
cg.add(var.set_temperature_oversampling(temperature_config[CONF_OVERSAMPLING]))
|
80
|
+
|
81
|
+
if pressure_config := config.get(CONF_PRESSURE):
|
82
|
+
sens = await sensor.new_sensor(pressure_config)
|
83
|
+
cg.add(var.set_pressure_sensor(sens))
|
84
|
+
cg.add(var.set_pressure_oversampling(pressure_config[CONF_OVERSAMPLING]))
|
85
|
+
|
86
|
+
cg.add(var.set_iir_filter(config[CONF_IIR_FILTER]))
|
87
|
+
|
88
|
+
return var
|
@@ -1,9 +1,9 @@
|
|
1
|
-
#include "
|
1
|
+
#include "bmp280_base.h"
|
2
2
|
#include "esphome/core/hal.h"
|
3
3
|
#include "esphome/core/log.h"
|
4
4
|
|
5
5
|
namespace esphome {
|
6
|
-
namespace
|
6
|
+
namespace bmp280_base {
|
7
7
|
|
8
8
|
static const char *const TAG = "bmp280.sensor";
|
9
9
|
|
@@ -59,6 +59,14 @@ static const char *iir_filter_to_str(BMP280IIRFilter filter) {
|
|
59
59
|
void BMP280Component::setup() {
|
60
60
|
ESP_LOGCONFIG(TAG, "Setting up BMP280...");
|
61
61
|
uint8_t chip_id = 0;
|
62
|
+
|
63
|
+
// Read the chip id twice, to work around a bug where the first read is 0.
|
64
|
+
// https://community.st.com/t5/stm32-mcus-products/issue-with-reading-bmp280-chip-id-using-spi/td-p/691855
|
65
|
+
if (!this->read_byte(0xD0, &chip_id)) {
|
66
|
+
this->error_code_ = COMMUNICATION_FAILED;
|
67
|
+
this->mark_failed();
|
68
|
+
return;
|
69
|
+
}
|
62
70
|
if (!this->read_byte(0xD0, &chip_id)) {
|
63
71
|
this->error_code_ = COMMUNICATION_FAILED;
|
64
72
|
this->mark_failed();
|
@@ -122,7 +130,6 @@ void BMP280Component::setup() {
|
|
122
130
|
}
|
123
131
|
void BMP280Component::dump_config() {
|
124
132
|
ESP_LOGCONFIG(TAG, "BMP280:");
|
125
|
-
LOG_I2C_DEVICE(this);
|
126
133
|
switch (this->error_code_) {
|
127
134
|
case COMMUNICATION_FAILED:
|
128
135
|
ESP_LOGE(TAG, "Communication with BMP280 failed!");
|
@@ -262,5 +269,5 @@ uint16_t BMP280Component::read_u16_le_(uint8_t a_register) {
|
|
262
269
|
}
|
263
270
|
int16_t BMP280Component::read_s16_le_(uint8_t a_register) { return this->read_u16_le_(a_register); }
|
264
271
|
|
265
|
-
} // namespace
|
272
|
+
} // namespace bmp280_base
|
266
273
|
} // namespace esphome
|
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
#include "esphome/core/component.h"
|
4
4
|
#include "esphome/components/sensor/sensor.h"
|
5
|
-
#include "esphome/components/i2c/i2c.h"
|
6
5
|
|
7
6
|
namespace esphome {
|
8
|
-
namespace
|
7
|
+
namespace bmp280_base {
|
9
8
|
|
10
9
|
/// Internal struct storing the calibration values of an BMP280.
|
11
10
|
struct BMP280CalibrationData {
|
@@ -50,8 +49,8 @@ enum BMP280IIRFilter {
|
|
50
49
|
BMP280_IIR_FILTER_16X = 0b100,
|
51
50
|
};
|
52
51
|
|
53
|
-
/// This class implements support for the BMP280 Temperature+Pressure
|
54
|
-
class BMP280Component : public PollingComponent
|
52
|
+
/// This class implements support for the BMP280 Temperature+Pressure sensor.
|
53
|
+
class BMP280Component : public PollingComponent {
|
55
54
|
public:
|
56
55
|
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
|
57
56
|
void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
|
@@ -68,6 +67,11 @@ class BMP280Component : public PollingComponent, public i2c::I2CDevice {
|
|
68
67
|
float get_setup_priority() const override;
|
69
68
|
void update() override;
|
70
69
|
|
70
|
+
virtual bool read_byte(uint8_t a_register, uint8_t *data) = 0;
|
71
|
+
virtual bool write_byte(uint8_t a_register, uint8_t data) = 0;
|
72
|
+
virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) = 0;
|
73
|
+
virtual bool read_byte_16(uint8_t a_register, uint16_t *data) = 0;
|
74
|
+
|
71
75
|
protected:
|
72
76
|
/// Read the temperature value and store the calculated ambient temperature in t_fine.
|
73
77
|
float read_temperature_(int32_t *t_fine);
|
@@ -90,5 +94,5 @@ class BMP280Component : public PollingComponent, public i2c::I2CDevice {
|
|
90
94
|
} error_code_{NONE};
|
91
95
|
};
|
92
96
|
|
93
|
-
} // namespace
|
97
|
+
} // namespace bmp280_base
|
94
98
|
} // namespace esphome
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#include "bmp280_i2c.h"
|
2
|
+
#include "esphome/core/hal.h"
|
3
|
+
#include "esphome/core/log.h"
|
4
|
+
|
5
|
+
namespace esphome {
|
6
|
+
namespace bmp280_i2c {
|
7
|
+
|
8
|
+
bool BMP280I2CComponent::read_byte(uint8_t a_register, uint8_t *data) {
|
9
|
+
return I2CDevice::read_byte(a_register, data);
|
10
|
+
};
|
11
|
+
bool BMP280I2CComponent::write_byte(uint8_t a_register, uint8_t data) {
|
12
|
+
return I2CDevice::write_byte(a_register, data);
|
13
|
+
};
|
14
|
+
bool BMP280I2CComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
|
15
|
+
return I2CDevice::read_bytes(a_register, data, len);
|
16
|
+
};
|
17
|
+
bool BMP280I2CComponent::read_byte_16(uint8_t a_register, uint16_t *data) {
|
18
|
+
return I2CDevice::read_byte_16(a_register, data);
|
19
|
+
};
|
20
|
+
|
21
|
+
void BMP280I2CComponent::dump_config() {
|
22
|
+
LOG_I2C_DEVICE(this);
|
23
|
+
BMP280Component::dump_config();
|
24
|
+
}
|
25
|
+
|
26
|
+
} // namespace bmp280_i2c
|
27
|
+
} // namespace esphome
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include "esphome/components/bmp280_base/bmp280_base.h"
|
4
|
+
#include "esphome/components/i2c/i2c.h"
|
5
|
+
|
6
|
+
namespace esphome {
|
7
|
+
namespace bmp280_i2c {
|
8
|
+
|
9
|
+
static const char *const TAG = "bmp280_i2c.sensor";
|
10
|
+
|
11
|
+
/// This class implements support for the BMP280 Temperature+Pressure i2c sensor.
|
12
|
+
class BMP280I2CComponent : public esphome::bmp280_base::BMP280Component, public i2c::I2CDevice {
|
13
|
+
public:
|
14
|
+
bool read_byte(uint8_t a_register, uint8_t *data) override;
|
15
|
+
bool write_byte(uint8_t a_register, uint8_t data) override;
|
16
|
+
bool read_bytes(uint8_t a_register, uint8_t *data, size_t len) override;
|
17
|
+
bool read_byte_16(uint8_t a_register, uint16_t *data) override;
|
18
|
+
void dump_config() override;
|
19
|
+
};
|
20
|
+
|
21
|
+
} // namespace bmp280_i2c
|
22
|
+
} // namespace esphome
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import esphome.codegen as cg
|
2
|
+
import esphome.config_validation as cv
|
3
|
+
from esphome.components import i2c
|
4
|
+
from ..bmp280_base import to_code_base, CONFIG_SCHEMA_BASE
|
5
|
+
|
6
|
+
AUTO_LOAD = ["bmp280_base"]
|
7
|
+
CODEOWNERS = ["@ademuri"]
|
8
|
+
DEPENDENCIES = ["i2c"]
|
9
|
+
|
10
|
+
bmp280_ns = cg.esphome_ns.namespace("bmp280_i2c")
|
11
|
+
BMP280I2CComponent = bmp280_ns.class_(
|
12
|
+
"BMP280I2CComponent", cg.PollingComponent, i2c.I2CDevice
|
13
|
+
)
|
14
|
+
|
15
|
+
CONFIG_SCHEMA = CONFIG_SCHEMA_BASE.extend(
|
16
|
+
i2c.i2c_device_schema(default_address=0x77)
|
17
|
+
).extend({cv.GenerateID(): cv.declare_id(BMP280I2CComponent)})
|
18
|
+
|
19
|
+
|
20
|
+
async def to_code(config):
|
21
|
+
var = await to_code_base(config)
|
22
|
+
await i2c.register_i2c_device(var, config)
|
File without changes
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#include <cstdint>
|
2
|
+
#include <cstddef>
|
3
|
+
|
4
|
+
#include "bmp280_spi.h"
|
5
|
+
#include <esphome/components/bmp280_base/bmp280_base.h>
|
6
|
+
|
7
|
+
namespace esphome {
|
8
|
+
namespace bmp280_spi {
|
9
|
+
|
10
|
+
uint8_t set_bit(uint8_t num, uint8_t position) {
|
11
|
+
uint8_t mask = 1 << position;
|
12
|
+
return num | mask;
|
13
|
+
}
|
14
|
+
|
15
|
+
uint8_t clear_bit(uint8_t num, uint8_t position) {
|
16
|
+
uint8_t mask = 1 << position;
|
17
|
+
return num & ~mask;
|
18
|
+
}
|
19
|
+
|
20
|
+
void BMP280SPIComponent::setup() {
|
21
|
+
this->spi_setup();
|
22
|
+
BMP280Component::setup();
|
23
|
+
};
|
24
|
+
|
25
|
+
// In SPI mode, only 7 bits of the register addresses are used; the MSB of register address is not used
|
26
|
+
// and replaced by a read/write bit (RW = ‘0’ for write and RW = ‘1’ for read).
|
27
|
+
// Example: address 0xF7 is accessed by using SPI register address 0x77. For write access, the byte
|
28
|
+
// 0x77 is transferred, for read access, the byte 0xF7 is transferred.
|
29
|
+
// https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bmp280-ds001.pdf
|
30
|
+
|
31
|
+
bool BMP280SPIComponent::read_byte(uint8_t a_register, uint8_t *data) {
|
32
|
+
this->enable();
|
33
|
+
this->transfer_byte(set_bit(a_register, 7));
|
34
|
+
*data = this->transfer_byte(0);
|
35
|
+
this->disable();
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
|
39
|
+
bool BMP280SPIComponent::write_byte(uint8_t a_register, uint8_t data) {
|
40
|
+
this->enable();
|
41
|
+
this->transfer_byte(clear_bit(a_register, 7));
|
42
|
+
this->transfer_byte(data);
|
43
|
+
this->disable();
|
44
|
+
return true;
|
45
|
+
}
|
46
|
+
|
47
|
+
bool BMP280SPIComponent::read_bytes(uint8_t a_register, uint8_t *data, size_t len) {
|
48
|
+
this->enable();
|
49
|
+
this->transfer_byte(set_bit(a_register, 7));
|
50
|
+
this->read_array(data, len);
|
51
|
+
this->disable();
|
52
|
+
return true;
|
53
|
+
}
|
54
|
+
|
55
|
+
bool BMP280SPIComponent::read_byte_16(uint8_t a_register, uint16_t *data) {
|
56
|
+
this->enable();
|
57
|
+
this->transfer_byte(set_bit(a_register, 7));
|
58
|
+
((uint8_t *) data)[1] = this->transfer_byte(0);
|
59
|
+
((uint8_t *) data)[0] = this->transfer_byte(0);
|
60
|
+
this->disable();
|
61
|
+
return true;
|
62
|
+
}
|
63
|
+
|
64
|
+
} // namespace bmp280_spi
|
65
|
+
} // namespace esphome
|