9static const uint32_t FXOSC = 32000000u;
10static const uint16_t RAMP[16] = {3400, 2000, 1000, 500, 250, 125, 100, 62, 50, 40, 31, 25, 20, 15, 12, 10};
11static const uint32_t BW_HZ[22] = {2604, 3125, 3906, 5208, 6250, 7812, 10416, 12500, 15625, 20833, 25000,
12 31250, 41666, 50000, 62500, 83333, 100000, 125000, 166666, 200000, 250000, 500000};
20static const int32_t RSSI_OFFSET_HF = 157;
21static const int32_t RSSI_OFFSET_LF = 164;
41 for (
auto &
byte : packet) {
50 for (
size_t i = 0; i <
len; i++) {
84 this->
mark_failed(LOG_STR(
"Unsupported chip version"));
92 uint64_t frf = ((uint64_t) this->
frequency_ << 19) / FXOSC;
254 return SX127X_MAX_PACKET_SIZE;
262 ESP_LOGW(TAG,
"Radio not ready, packet dropped");
266 ESP_LOGE(TAG,
"Packet size does not match config");
270 ESP_LOGE(TAG,
"Packet size out of range");
275 ESP_LOGE(TAG,
"DIO0 pin not configured, cannot wait for transmit completion");
302 if (
millis() - start > 4000) {
303 ESP_LOGE(TAG,
"Transmit packet failure");
318 listener->on_packet(packet, rssi, snr);
348 if (payload_length == 0) {
351 this->
packet_.resize(payload_length);
369 if (
millis() - start > 20) {
391 if (
millis() - start > 20) {
419 ESP_LOGCONFIG(TAG,
"SX127x:");
420 LOG_PIN(
" CS Pin: ", this->
cs_);
421 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
423 const char *pa_pin =
"RFO";
429 " Frequency: %" PRIu32
" Hz\n"
430 " Bandwidth: %" PRIu32
" Hz\n"
432 " PA Power: %" PRIu8
" dBm\n"
433 " PA Ramp: %" PRIu16
" us",
437 ESP_LOGCONFIG(TAG,
" Deviation: %" PRIu32
" Hz", this->
deviation_);
440 const char *cr =
"4/8";
449 " Modulation: LORA\n"
450 " Preamble Size: %" PRIu16
"\n"
451 " Spreading Factor: %" PRIu8
"\n"
456 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
459 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%02x", this->
sync_value_[0]);
462 const char *shaping =
"NONE";
465 shaping =
"GAUSSIAN_BT_0_3";
467 shaping =
"GAUSSIAN_BT_0_5";
469 shaping =
"GAUSSIAN_BT_1_0";
473 shaping =
"CUTOFF_BR_X_2";
475 shaping =
"CUTOFF_BR_X_1";
481 " Bitrate: %" PRIu32
"b/s\n"
484 " Rx Floor: %.1f dBm\n"
486 shaping, this->
modulation_ ==
MOD_FSK ? LOG_STR_LITERAL(
"FSK") : LOG_STR_LITERAL(
"OOK"),
490 ESP_LOGCONFIG(TAG,
" CRC Enable: %s", TRUEFALSE(this->
crc_enable_));
493 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
497 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%s",
502 " Preamble Polarity: 0x%X\n"
503 " Preamble Size: %" PRIu16
"\n"
504 " Preamble Detect: %" PRIu8
"\n"
505 " Preamble Errors: %" PRIu8,
BedjetMode mode
BedJet operating mode.
void feed_wdt()
Feed the task watchdog.
void mark_failed()
Mark this component as failed.
void enable_loop_soon_any_context()
Thread and ISR-safe version of enable_loop() that can be called from any context.
void disable_loop()
Disable this component's loop.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
void attach_interrupt(void(*func)(T *), T *arg, gpio::InterruptType type) const
bool digital_read() override
void digital_write(bool value) override
void spi_setup() override
void write_byte(uint8_t data)
uint8_t transfer_byte(uint8_t data)
InternalGPIOPin * rst_pin_
uint8_t preamble_polarity_
InternalGPIOPin * dio0_pin_
Trigger< std::vector< uint8_t >, float, float > packet_trigger_
std::vector< SX127xListener * > listeners_
void write_fifo_(const uint8_t *data, size_t len)
std::vector< uint8_t > sync_value_
void dump_config() override
uint8_t read_register_(uint8_t reg)
static void gpio_intr(SX127x *arg)
void set_mode_(uint8_t modulation, uint8_t mode)
void read_fifo_(std::vector< uint8_t > &packet)
std::vector< uint8_t > packet_
size_t get_max_packet_size()
void write_register_(uint8_t reg, uint8_t value)
void call_listeners_(const std::vector< uint8_t > &packet, float rssi, float snr)
uint8_t spreading_factor_
SX127xError transmit_packet(const uint8_t *data, size_t len)
void configure_fsk_ook_()
@ PREAMBLE_DETECTOR_TOL_SHIFT
@ PREAMBLE_DETECTOR_SIZE_SHIFT
ESPHOME_LOG_TAG(TAG, "sx127x_transport")
@ LOW_DATA_RATE_OPTIMIZE_ON
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t IRAM_ATTR HOT millis()
char * format_hex_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as lowercase hex to buffer (base implementation).
Application App
Global storage of Application pointer - only one Application can exist.