8 static const char *
const TAG =
"gdk101";
9 static const uint8_t NUMBER_OF_READ_RETRIES = 5;
11 void GDK101Component::update() {
37 ESP_LOGCONFIG(TAG,
"Setting up GDK101...");
59 void GDK101Component::dump_config() {
60 ESP_LOGCONFIG(TAG,
"GDK101:");
63 ESP_LOGE(TAG,
"Communication with GDK101 failed!");
66 LOG_SENSOR(
" ",
"Firmware Version", this->fw_version_sensor_);
67 LOG_SENSOR(
" ",
"Average Radaition Dose per 1 minute", this->rad_1m_sensor_);
68 LOG_SENSOR(
" ",
"Average Radaition Dose per 10 minutes", this->rad_10m_sensor_);
69 LOG_SENSOR(
" ",
"Status", this->status_sensor_);
70 LOG_SENSOR(
" ",
"Measurement Duration", this->measurement_duration_sensor_);
73 #ifdef USE_BINARY_SENSOR 74 LOG_BINARY_SENSOR(
" ",
"Vibration Status", this->vibration_binary_sensor_);
75 #endif // USE_BINARY_SENSOR 81 uint8_t retry = NUMBER_OF_READ_RETRIES;
83 while (!status && retry) {
84 status = this->
read_bytes(a_register, data, len);
96 ESP_LOGE(TAG,
"Updating GDK101 failed!");
105 if (this->rad_1m_sensor_ !=
nullptr) {
106 if (!this->
read_bytes(GDK101_REG_READ_1MIN_AVG, data, 2)) {
107 ESP_LOGE(TAG,
"Updating GDK101 failed!");
111 const float dose = data[0] + (data[1] / 100.0f);
113 this->rad_1m_sensor_->publish_state(dose);
121 if (this->rad_10m_sensor_ !=
nullptr) {
122 if (!this->
read_bytes(GDK101_REG_READ_10MIN_AVG, data, 2)) {
123 ESP_LOGE(TAG,
"Updating GDK101 failed!");
127 const float dose = data[0] + (data[1] / 100.0f);
129 this->rad_10m_sensor_->publish_state(dose);
136 if (!this->
read_bytes(GDK101_REG_READ_STATUS, data, 2)) {
137 ESP_LOGE(TAG,
"Updating GDK101 failed!");
142 if (this->status_sensor_ !=
nullptr) {
143 this->status_sensor_->publish_state(data[0]);
147 #ifdef USE_BINARY_SENSOR 148 if (this->vibration_binary_sensor_ !=
nullptr) {
149 this->vibration_binary_sensor_->publish_state(data[1]);
151 #endif // USE_BINARY_SENSOR 158 if (this->fw_version_sensor_ !=
nullptr) {
159 if (!this->
read_bytes(GDK101_REG_READ_FIRMWARE, data, 2)) {
160 ESP_LOGE(TAG,
"Updating GDK101 failed!");
164 const float fw_version = data[0] + (data[1] / 10.0f);
166 this->fw_version_sensor_->publish_state(fw_version);
174 if (this->measurement_duration_sensor_ !=
nullptr) {
175 if (!this->
read_bytes(GDK101_REG_READ_MEASURING_TIME, data, 2)) {
176 ESP_LOGE(TAG,
"Updating GDK101 failed!");
180 const float meas_time = (data[0] * 60) + data[1];
182 this->measurement_duration_sensor_->publish_state(meas_time);
bool reset_sensor_(uint8_t *data)
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
bool read_fw_version_(uint8_t *data)
void status_set_error(const char *message="unspecified")
virtual void setup()
Where the component's initialization should happen.
void status_clear_warning()
bool read_bytes_with_retry_(uint8_t a_register, uint8_t *data, uint8_t len)
bool read_dose_1m_(uint8_t *data)
virtual void mark_failed()
Mark this component as failed.
bool read_status_(uint8_t *data)
Implementation of SPI Controller mode.
bool read_measurement_duration_(uint8_t *data)
bool read_dose_10m_(uint8_t *data)
void IRAM_ATTR HOT delay(uint32_t ms)