8 static const char *
const TAG =
"as7341";
11 ESP_LOGCONFIG(TAG,
"Setting up AS7341...");
17 ESP_LOGCONFIG(TAG,
" Read ID: 0x%X",
id);
18 if ((
id & 0xFC) != (AS7341_CHIP_ID << 2)) {
25 ESP_LOGE(TAG,
" Power on failed!");
38 ESP_LOGCONFIG(TAG,
"AS7341:");
41 ESP_LOGE(TAG,
"Communication with AS7341 failed!");
43 LOG_UPDATE_INTERVAL(
this);
44 ESP_LOGCONFIG(TAG,
" Gain: %u",
get_gain());
45 ESP_LOGCONFIG(TAG,
" ATIME: %u",
get_atime());
46 ESP_LOGCONFIG(TAG,
" ASTEP: %u",
get_astep());
48 LOG_SENSOR(
" ",
"F1", this->
f1_);
49 LOG_SENSOR(
" ",
"F2", this->
f2_);
50 LOG_SENSOR(
" ",
"F3", this->
f3_);
51 LOG_SENSOR(
" ",
"F4", this->
f4_);
52 LOG_SENSOR(
" ",
"F5", this->
f5_);
53 LOG_SENSOR(
" ",
"F6", this->
f6_);
54 LOG_SENSOR(
" ",
"F7", this->
f7_);
55 LOG_SENSOR(
" ",
"F8", this->
f8_);
56 LOG_SENSOR(
" ",
"Clear", this->
clear_);
57 LOG_SENSOR(
" ",
"NIR", this->
nir_);
65 if (this->
f1_ !=
nullptr) {
68 if (this->
f2_ !=
nullptr) {
71 if (this->
f3_ !=
nullptr) {
74 if (this->
f4_ !=
nullptr) {
77 if (this->
f5_ !=
nullptr) {
80 if (this->
f6_ !=
nullptr) {
83 if (this->
f7_ !=
nullptr) {
86 if (this->
f8_ !=
nullptr) {
89 if (this->
clear_ !=
nullptr) {
92 if (this->
nir_ !=
nullptr) {
125 bool low_success = this->
read_bytes_16(AS7341_CH0_DATA_L, data, 6);
130 bool high_sucess = this->
read_bytes_16(AS7341_CH0_DATA_L, &data[6], 6);
132 return low_success && high_sucess;
149 uint8_t data = command << 3;
204 uint16_t timeout = 1000;
205 for (uint16_t time = 0; time < timeout; time++) {
219 uint16_t timeout = 1000;
220 for (uint16_t time = 0; time < timeout; time++) {
242 bool bit = (data & (1 << bit_position)) > 0;
257 data |= (1 << bit_position);
264 data &= ~(1 << bit_position);
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
bool read_byte_16(uint8_t a_register, uint16_t *data)
const float DATA
For components that import data from directly connected sensors like DHT.
bool setup_gain(AS7341Gain gain)
bool read_channels(uint16_t *data)
void configure_smux_low_channels()
bool enable_power(bool enable)
Write SMUX configuration from RAM to SMUX chain.
bool read_register_bit(uint8_t address, uint8_t bit_position)
uint16_t channel_readings_[12]
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
bool enable_spectral_measurement(bool enable)
bool setup_atime(uint8_t atime)
bool write_register_bit(uint8_t address, bool value, uint8_t bit_position)
bool setup_astep(uint16_t astep)
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
bool set_register_bit(uint8_t address, uint8_t bit_position)
bool clear_register_bit(uint8_t address, uint8_t bit_position)
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
void configure_smux_high_channels()
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
float get_setup_priority() const override
void set_smux_low_channels(bool enable)
bool write_byte_16(uint8_t a_register, uint16_t data)
uint16_t swap_bytes(uint16_t data)
bool read_bytes_16(uint8_t a_register, uint16_t *data, uint8_t len)
void IRAM_ATTR HOT delay(uint32_t ms)
bool set_smux_command(AS7341SmuxCommand command)