8static const char *
const TAG =
"sx127x";
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 this->
read_array(packet.data(), packet.size());
53 ESP_LOGCONFIG(TAG,
"Running setup");
87 uint64_t frf = ((uint64_t) this->
frequency_ << 19) / FXOSC;
136 uint32_t fdev = std::min((this->
deviation_ * 4096) / 250000, (uint32_t) 0x3FFF);
176 for (uint32_t i = 0; i < this->
sync_value_.size(); i++) {
257 ESP_LOGE(TAG,
"Packet size does not match config");
260 if (packet.empty() || packet.size() > this->get_max_packet_size()) {
261 ESP_LOGE(TAG,
"Packet size out of range");
285 uint32_t start =
millis();
287 if (
millis() - start > 4000) {
288 ESP_LOGE(TAG,
"Transmit packet failure");
303 listener->on_packet(packet, rssi, snr);
332 if (payload_length == 0) {
335 this->
packet_.resize(payload_length);
351 uint32_t start =
millis();
353 if (
millis() - start > 20) {
354 ESP_LOGE(TAG,
"Image cal failure");
366 uint32_t start =
millis();
376 if (
millis() - start > 20) {
377 ESP_LOGE(TAG,
"Set mode failure");
405 ESP_LOGCONFIG(TAG,
"SX127x:");
406 LOG_PIN(
" CS Pin: ", this->
cs_);
407 LOG_PIN(
" RST Pin: ", this->
rst_pin_);
409 const char *pa_pin =
"RFO";
415 " Frequency: %" PRIu32
" Hz\n"
416 " Bandwidth: %" PRIu32
" Hz\n"
418 " PA Power: %" PRIu8
" dBm\n"
419 " PA Ramp: %" PRIu16
" us",
423 ESP_LOGCONFIG(TAG,
" Deviation: %" PRIu32
" Hz", this->
deviation_);
426 const char *cr =
"4/8";
435 " Modulation: LORA\n"
436 " Preamble Size: %" PRIu16
"\n"
437 " Spreading Factor: %" PRIu8
"\n"
442 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
445 ESP_LOGCONFIG(TAG,
" Sync Value: 0x%02x", this->
sync_value_[0]);
448 const char *shaping =
"NONE";
451 shaping =
"GAUSSIAN_BT_0_3";
453 shaping =
"GAUSSIAN_BT_0_5";
455 shaping =
"GAUSSIAN_BT_1_0";
459 shaping =
"CUTOFF_BR_X_2";
461 shaping =
"CUTOFF_BR_X_1";
467 " Bitrate: %" PRIu32
"b/s\n"
470 " Rx Floor: %.1f dBm\n"
475 ESP_LOGCONFIG(TAG,
" CRC Enable: %s", TRUEFALSE(this->
crc_enable_));
478 ESP_LOGCONFIG(TAG,
" Payload Length: %" PRIu32, this->
payload_length_);
485 " Preamble Polarity: 0x%X\n"
486 " Preamble Size: %" PRIu16
"\n"
487 " Preamble Detect: %" PRIu8
"\n"
488 " Preamble Errors: %" PRIu8,
493 ESP_LOGE(TAG,
"Configuring SX127x failed");
BedjetMode mode
BedJet operating mode.
virtual void mark_failed()
Mark this component as failed.
virtual void digital_write(bool value)=0
virtual bool digital_read()=0
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
void spi_setup() override
void write_byte(uint8_t data)
void write_array(const uint8_t *data, size_t length)
void read_array(uint8_t *data, size_t length)
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 std::vector< uint8_t > &packet)
SX127xError transmit_packet(const std::vector< uint8_t > &packet)
std::vector< uint8_t > sync_value_
void dump_config() override
uint8_t read_register_(uint8_t reg)
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_
void configure_fsk_ook_()
@ PREAMBLE_DETECTOR_TOL_SHIFT
@ PREAMBLE_DETECTOR_SIZE_SHIFT
@ LOW_DATA_RATE_OPTIMIZE_ON
Providing packet encoding functions for exchanging data with a remote host.
std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
uint32_t IRAM_ATTR HOT millis()