7static const char *
const TAG =
"gdk101";
8static constexpr uint8_t NUMBER_OF_READ_RETRIES = 5;
9static constexpr uint8_t NUMBER_OF_RESET_RETRIES = 30;
10static constexpr uint32_t RESET_INTERVAL_ID = 0;
11static constexpr uint32_t RESET_INTERVAL_MS = 1000;
13void GDK101Component::update() {
44 this->
set_interval(RESET_INTERVAL_ID, RESET_INTERVAL_MS, [
this]() {
53 this->
mark_failed(LOG_STR(
"Reset failed after retries"));
61 uint8_t data[2] = {0};
73 this->
mark_failed(LOG_STR(
"Failed to read firmware version"));
82void GDK101Component::dump_config() {
83 ESP_LOGCONFIG(TAG,
"GDK101:");
86 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
89 LOG_SENSOR(
" ",
"Average Radaition Dose per 1 minute", this->rad_1m_sensor_);
90 LOG_SENSOR(
" ",
"Average Radaition Dose per 10 minutes", this->rad_10m_sensor_);
91 LOG_SENSOR(
" ",
"Status", this->status_sensor_);
92 LOG_SENSOR(
" ",
"Measurement Duration", this->measurement_duration_sensor_);
95#ifdef USE_BINARY_SENSOR
96 LOG_BINARY_SENSOR(
" ",
"Vibration Status", this->vibration_binary_sensor_);
100 LOG_TEXT_SENSOR(
" ",
"Firmware Version", this->fw_version_text_sensor_);
105 uint8_t retry = NUMBER_OF_READ_RETRIES;
107 while (!
status && retry) {
124 if (this->rad_1m_sensor_ !=
nullptr) {
125 if (!this->
read_bytes(GDK101_REG_READ_1MIN_AVG, data, 2)) {
126 ESP_LOGE(TAG,
"Updating GDK101 failed!");
130 const float dose = data[0] + (data[1] / 100.0f);
132 this->rad_1m_sensor_->publish_state(dose);
140 if (this->rad_10m_sensor_ !=
nullptr) {
141 if (!this->
read_bytes(GDK101_REG_READ_10MIN_AVG, data, 2)) {
142 ESP_LOGE(TAG,
"Updating GDK101 failed!");
146 const float dose = data[0] + (data[1] / 100.0f);
148 this->rad_10m_sensor_->publish_state(dose);
155 if (!this->
read_bytes(GDK101_REG_READ_STATUS, data, 2)) {
156 ESP_LOGE(TAG,
"Updating GDK101 failed!");
161 if (this->status_sensor_ !=
nullptr) {
162 this->status_sensor_->publish_state(data[0]);
166#ifdef USE_BINARY_SENSOR
167 if (this->vibration_binary_sensor_ !=
nullptr) {
168 this->vibration_binary_sensor_->publish_state(data[1]);
176#ifdef USE_TEXT_SENSOR
177 if (this->fw_version_text_sensor_ !=
nullptr) {
178 if (!this->
read_bytes(GDK101_REG_READ_FIRMWARE, data, 2)) {
179 ESP_LOGE(TAG,
"Updating GDK101 failed!");
185 snprintf(buf,
sizeof(buf),
"%d.%d", data[0], data[1]);
186 this->fw_version_text_sensor_->publish_state(buf);
194 if (this->measurement_duration_sensor_ !=
nullptr) {
195 if (!this->
read_bytes(GDK101_REG_READ_MEASURING_TIME, data, 2)) {
196 ESP_LOGE(TAG,
"Updating GDK101 failed!");
200 const float meas_time = (data[0] * 60) + data[1];
202 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.
void HOT delay(uint32_t ms)