mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 04:33:27 +02:00
68e7e5a51c
* added tx20 wind speed sensor * added test * fixed lint errors * fixed more lint errors * updated tx20 * updated tx20 sensor * updated to new structure and removed static variables * removed content from __init__.py * fixing lint errors * resolved issues from review * added as3935 sensor * updated as3935 with more settings * update * support for i2c + spi updated * added tests and various fixes * added tx20 wind speed sensor * fixed lint errors * fixed more lint errors * updated tx20 * updated tx20 sensor * updated to new structure and removed static variables * removed content from __init__.py * fixing lint errors * resolved issues from review * added as3935 sensor * updated as3935 with more settings * update * support for i2c + spi updated * added tests and various fixes * updated tests * fixed style issues * Remove debug line * Update log levels * Reformat * Auto-convert to int Co-authored-by: Thomas <thomas.eckerstorfer@mic-cust.com> Co-authored-by: Otto Winter <otto@otto-winter.com>
50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
#include "as3935_spi.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace as3935_spi {
|
|
|
|
static const char *TAG = "as3935_spi";
|
|
|
|
void SPIAS3935Component::setup() {
|
|
ESP_LOGI(TAG, "SPIAS3935Component setup started!");
|
|
this->spi_setup();
|
|
ESP_LOGI(TAG, "SPI setup finished!");
|
|
AS3935Component::setup();
|
|
|
|
}
|
|
|
|
void SPIAS3935Component::dump_config() {
|
|
AS3935Component::dump_config();
|
|
LOG_PIN(" CS Pin: ", this->cs_);
|
|
}
|
|
|
|
void SPIAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_pos) {
|
|
uint8_t write_reg = this->read_register(reg);
|
|
|
|
write_reg &= (~mask);
|
|
write_reg |= (bits << start_pos);
|
|
|
|
this->enable();
|
|
this->write_byte(reg);
|
|
this->write_byte(write_reg);
|
|
this->disable();
|
|
}
|
|
|
|
uint8_t SPIAS3935Component::read_register(uint8_t reg) {
|
|
uint8_t value = 0;
|
|
this->enable();
|
|
this->write_byte(reg |= SPI_READ_M);
|
|
value = this->read_byte();
|
|
// According to datsheet, the chip select must be written HIGH, LOW, HIGH
|
|
// to correctly end the READ command.
|
|
this->cs_->digital_write(true);
|
|
this->cs_->digital_write(false);
|
|
this->disable();
|
|
ESP_LOGV(TAG, "read_register_: %d", value);
|
|
return value;
|
|
}
|
|
|
|
} // namespace as3935_spi
|
|
} // namespace esphome
|