8static const char *
const TAG =
"gdk101";
9static constexpr uint8_t NUMBER_OF_READ_RETRIES = 5;
10static constexpr uint8_t NUMBER_OF_RESET_RETRIES = 30;
11static constexpr uint32_t RESET_INTERVAL_ID = 0;
12static constexpr uint32_t RESET_INTERVAL_MS = 1000;
14void GDK101Component::update() {
45 this->
set_interval(RESET_INTERVAL_ID, RESET_INTERVAL_MS, [
this]() {
54 this->
mark_failed(LOG_STR(
"Reset failed after retries"));
62 uint8_t data[2] = {0};
74 this->
mark_failed(LOG_STR(
"Failed to read firmware version"));
83void GDK101Component::dump_config() {
84 ESP_LOGCONFIG(TAG,
"GDK101:");
87 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
90 LOG_SENSOR(
" ",
"Average Radaition Dose per 1 minute", this->rad_1m_sensor_);
91 LOG_SENSOR(
" ",
"Average Radaition Dose per 10 minutes", this->rad_10m_sensor_);
92 LOG_SENSOR(
" ",
"Status", this->status_sensor_);
93 LOG_SENSOR(
" ",
"Measurement Duration", this->measurement_duration_sensor_);
96#ifdef USE_BINARY_SENSOR
97 LOG_BINARY_SENSOR(
" ",
"Vibration Status", this->vibration_binary_sensor_);
100#ifdef USE_TEXT_SENSOR
101 LOG_TEXT_SENSOR(
" ",
"Firmware Version", this->fw_version_text_sensor_);
106 uint8_t retry = NUMBER_OF_READ_RETRIES;
108 while (!
status && retry) {
125 if (this->rad_1m_sensor_ !=
nullptr) {
126 if (!this->
read_bytes(GDK101_REG_READ_1MIN_AVG, data, 2)) {
127 ESP_LOGE(TAG,
"Updating GDK101 failed!");
131 const float dose = data[0] + (data[1] / 100.0f);
133 this->rad_1m_sensor_->publish_state(dose);
141 if (this->rad_10m_sensor_ !=
nullptr) {
142 if (!this->
read_bytes(GDK101_REG_READ_10MIN_AVG, data, 2)) {
143 ESP_LOGE(TAG,
"Updating GDK101 failed!");
147 const float dose = data[0] + (data[1] / 100.0f);
149 this->rad_10m_sensor_->publish_state(dose);
156 if (!this->
read_bytes(GDK101_REG_READ_STATUS, data, 2)) {
157 ESP_LOGE(TAG,
"Updating GDK101 failed!");
162 if (this->status_sensor_ !=
nullptr) {
163 this->status_sensor_->publish_state(data[0]);
167#ifdef USE_BINARY_SENSOR
168 if (this->vibration_binary_sensor_ !=
nullptr) {
169 this->vibration_binary_sensor_->publish_state(data[1]);
177#ifdef USE_TEXT_SENSOR
178 if (this->fw_version_text_sensor_ !=
nullptr) {
179 if (!this->
read_bytes(GDK101_REG_READ_FIRMWARE, data, 2)) {
180 ESP_LOGE(TAG,
"Updating GDK101 failed!");
186 snprintf(buf,
sizeof(buf),
"%d.%d", data[0], data[1]);
187 this->fw_version_text_sensor_->publish_state(buf);
195 if (this->measurement_duration_sensor_ !=
nullptr) {
196 if (!this->
read_bytes(GDK101_REG_READ_MEASURING_TIME, data, 2)) {
197 ESP_LOGE(TAG,
"Updating GDK101 failed!");
201 const float meas_time = (data[0] * 60) + data[1];
203 this->measurement_duration_sensor_->publish_state(meas_time);
void mark_failed()
Mark this component as failed.
virtual void setup()
Where the component's initialization should happen.
void status_set_warning()
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_interval(const std voi set_interval)(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_interval(const std boo cancel_interval)(const char *name)
Cancel an interval function.
void status_clear_warning()
bool try_reset_()
Attempt to reset the sensor and read firmware version. Returns true on success or hard failure.
bool read_status_(uint8_t *data)
bool read_bytes_with_retry_(uint8_t a_register, uint8_t *data, uint8_t len)
bool read_dose_1m_(uint8_t *data)
bool read_dose_10m_(uint8_t *data)
bool read_fw_version_(uint8_t *data)
bool reset_sensor_(uint8_t *data)
uint8_t reset_retries_remaining_
bool read_measurement_duration_(uint8_t *data)
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
Providing packet encoding functions for exchanging data with a remote host.
void HOT delay(uint32_t ms)