some more options!

This commit is contained in:
Daniël Koek 2024-04-25 16:01:11 +01:00
parent b7b93d44db
commit fe8725deac
3 changed files with 118 additions and 0 deletions

View file

@ -19,11 +19,58 @@ ebyte_lora_ns = cg.esphome_ns.namespace("ebyte_lora")
EbyteLoraComponent = ebyte_lora_ns.class_(
"EbyteLoraComponent", cg.PollingComponent, uart.UARTDevice
)
UartBpsSpeed = ebyte_lora_ns.enum("UartBpsSpeed")
UART_BPS_OPTIONS = {
"UART_1200": UartBpsSpeed.UART_1200,
"UART_2400": UartBpsSpeed.UART_2400,
"UART_4800": UartBpsSpeed.UART_4800,
"UART_9600": UartBpsSpeed.UART_9600,
"UART_19200": UartBpsSpeed.UART_19200,
"UART_38400": UartBpsSpeed.UART_38400,
"UART_57600": UartBpsSpeed.UART_57600,
"UART_115200": UartBpsSpeed.UART_115200,
}
TransmissionMode = ebyte_lora_ns.enum("TransmissionMode")
TRANSMISSION_MODE_OPTIONS = {
"TRANSPARENT": TransmissionMode.TRANSPARENT,
"FIXED": TransmissionMode.FIXED,
}
TransmissionPower = ebyte_lora_ns.enum("TransmissionPower")
TRANSMISSION_POWER_OPTIONS = {
"TX_DEFAULT_MAX": TransmissionPower.TX_DEFAULT_MAX,
"TX_LOWER": TransmissionPower.TX_LOWER,
"TX_EVEN_LOWER": TransmissionPower.TX_EVEN_LOWER,
"TX_LOWEST": TransmissionPower.TX_LOWEST,
}
AirDataRate = ebyte_lora_ns.enum("AirDataRate")
AIR_DATA_RATE_OPTIONS = {
"AIR_2_4KB": AirDataRate.AIR_2_4KB,
"AIR_4_8KB": AirDataRate.AIR_4_8KB,
"AIR_9_6KB": AirDataRate.AIR_9_6KB,
"AIR_19_2KB": AirDataRate.AIR_19_2KB,
"AIR_38_4KB": AirDataRate.AIR_38_4KB,
"AIR_62_5KB": AirDataRate.AIR_62_5KB,
}
EnableByte = ebyte_lora_ns.enum("EnableByte")
ENABLE_OPTIONS = {
"EBYTE_ENABLED": EnableByte.EBYTE_ENABLED,
"EBYTE_DISABLED": EnableByte.EBYTE_DISABLED,
}
CONF_EBYTE_LORA = "ebyte_lora"
CONF_PIN_AUX = "pin_aux"
CONF_PIN_M0 = "pin_m0"
CONF_PIN_M1 = "pin_m1"
CONF_LORA_RSSI = "lora_rssi"
CONF_UART_BPS = "uart_bps"
CONF_TRANSMISSION_MODE = "transmission_mode"
CONF_TRANSMISSION_POWER = "transmission_power"
CONF_AIR_DATA_RATE = "air_data_rate"
CONF_ENABLE_RSSI = "enable_rssi"
CONF_ENABLE_LBT = "enable_lbt"
CONF_RSSI_NOISE = "rssi_noise"
CONFIG_SCHEMA = (
cv.Schema(
{
@ -41,6 +88,27 @@ CONFIG_SCHEMA = (
accuracy_decimals=1,
state_class=STATE_CLASS_MEASUREMENT,
),
cv.Optional(CONF_UART_BPS, default="UART_9600"): cv.enum(
UART_BPS_OPTIONS, upper=True
),
cv.Optional(CONF_TRANSMISSION_MODE, default="TRANSPARENT"): cv.enum(
TRANSMISSION_MODE_OPTIONS, upper=True
),
cv.Optional(CONF_TRANSMISSION_POWER, default="TX_DEFAULT_MAX"): cv.enum(
TRANSMISSION_POWER_OPTIONS, upper=True
),
cv.Optional(CONF_AIR_DATA_RATE, default="AIR_2_4KB"): cv.enum(
AIR_DATA_RATE_OPTIONS, upper=True
),
cv.Optional(CONF_ENABLE_RSSI, default="EBYTE_DISABLED"): cv.enum(
ENABLE_OPTIONS, upper=True
),
cv.Optional(CONF_ENABLE_LBT, default="EBYTE_DISABLED"): cv.enum(
ENABLE_OPTIONS, upper=True
),
cv.Optional(CONF_RSSI_NOISE, default="EBYTE_DISABLED"): cv.enum(
ENABLE_OPTIONS, upper=True
),
}
)
.extend(cv.polling_component_schema("20s"))
@ -60,6 +128,13 @@ async def to_code(config):
cg.add(var.set_pin_m0(pin_m0))
pin_m1 = await cg.gpio_pin_expression(config[CONF_PIN_M1])
cg.add(var.set_pin_m1(pin_m1))
cg.add(var.set_uart_bps(config[CONF_UART_BPS]))
cg.add(var.set_transmission_mode(config[CONF_TRANSMISSION_MODE]))
cg.add(var.set_transmission_power(config[CONF_TRANSMISSION_POWER]))
cg.add(var.set_air_data_rate(config[CONF_AIR_DATA_RATE]))
cg.add(var.set_enable_rssi(config[CONF_ENABLE_RSSI]))
cg.add(var.set_enable_lbt(config[CONF_ENABLE_LBT]))
cg.add(var.set_rssi_noise(config[CONF_RSSI_NOISE]))
if CONF_LORA_RSSI in config:
sens = await sensor.new_sensor(config[CONF_LORA_RSSI])
cg.add(var.set_rssi_sensor(sens))

View file

@ -11,6 +11,42 @@ void EbyteLoraComponent::update() {
return;
} else {
ESP_LOGD(TAG, "Checking config");
if (this->current_config_.addh != this->expected_config_.addh) {
ESP_LOGD(TAG, "addh was not set right");
}
if (this->current_config_.addl != this->expected_config_.addl) {
ESP_LOGD(TAG, "addl was not set right");
}
if (this->current_config_.air_data_rate != this->expected_config_.air_data_rate) {
ESP_LOGD(TAG, "air_data_rate was not set right");
}
if (this->current_config_.parity != this->expected_config_.parity) {
ESP_LOGD(TAG, "parity was not set right");
}
if (this->current_config_.uart_baud != this->expected_config_.uart_baud) {
ESP_LOGD(TAG, "uart_baud was not set right");
}
if (this->current_config_.transmission_power != this->expected_config_.transmission_power) {
ESP_LOGD(TAG, "transmission_power was not set right");
}
if (this->current_config_.rssi_noise != this->expected_config_.rssi_noise) {
ESP_LOGD(TAG, "rssi_noise was not set right");
}
if (this->current_config_.sub_packet != this->expected_config_.sub_packet) {
ESP_LOGD(TAG, "sub_packet was not set right");
}
if (this->current_config_.channel != this->expected_config_.channel) {
ESP_LOGD(TAG, "channel was not set right");
}
if (this->current_config_.wor_period != this->expected_config_.wor_period) {
ESP_LOGD(TAG, "wor_period was not set right");
}
if (this->current_config_.enable_lbt != this->expected_config_.enable_lbt) {
ESP_LOGD(TAG, "enable_lbt was not set right");
}
if (this->current_config_.enable_rssi != this->expected_config_.enable_rssi) {
ESP_LOGD(TAG, "enable_rssi was not set right");
}
}
if (this->get_mode_() != NORMAL) {
ESP_LOGD(TAG, "Mode was not set right");

View file

@ -35,6 +35,13 @@ class EbyteLoraComponent : public PollingComponent, public uart::UARTDevice {
void register_sensor(EbyteLoraSwitch *obj) { this->sensors_.push_back(obj); }
void set_pin_m0(GPIOPin *pin_m0) { pin_m0_ = pin_m0; }
void set_pin_m1(GPIOPin *pin_m1) { pin_m1_ = pin_m1; }
void set_uart_bps(UartBpsSpeed bps_speed) { expected_config_.uart_baud = bps_speed; }
void set_transmission_mode(TransmissionMode mode) { expected_config_.transmission_mode = mode; }
void set_transmission_power(TransmissionPower power) { expected_config_.transmission_power = power; }
void set_air_data_rate(AirDataRate air_data_rate) { expected_config_.air_data_rate = air_data_rate; }
void set_enable_lbt(EnableByte enable) { expected_config_.enable_lbt = enable; }
void set_enable_rssi(EnableByte enable) { expected_config_.enable_rssi = enable; }
void set_rssi_noise(EnableByte enable) { expected_config_.rssi_noise = enable; }
private:
std::vector<EbyteLoraSwitch *> sensors_;