Skip to content

Commit 2a12c8b

Browse files
committed
Improve error handling at ADC readings
1 parent ba570ac commit 2a12c8b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

doc/Troubleshooting_en.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ Please, open an
194194
- Wrong count of input pins in a coded rotary switch
195195
- LEDStrip: rmt_new_tx_channel() failed
196196
- LEDStrip: rmt_new_bytes_encoder() failed
197+
- getADCreading: adc_oneshot_new_unit() failed
197198

198199
## Non-error messages
199200

src/common/HAL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,7 @@ int internals::hal::gpio::getADCreading(ADC_GPIO pin, int sampleCount)
251251
adc_channel_t channel;
252252
adc_unit_t adc_unit;
253253
if (adc_oneshot_io_to_channel(pin, &adc_unit, &channel) != ESP_OK)
254-
{
255-
log_e("getADCreading: GPIO %u is not ADC", pin);
256-
abort();
257-
}
254+
throw gpio_error(pin, "not ADC-capable");
258255
else if (sampleCount > 0)
259256
{
260257
adc_oneshot_unit_handle_t handle;
@@ -269,7 +266,10 @@ int internals::hal::gpio::getADCreading(ADC_GPIO pin, int sampleCount)
269266
.atten = adc_atten_t::ADC_ATTEN_DB_12,
270267
.bitwidth = ADC_BITWIDTH_12,
271268
};
269+
handle = nullptr;
272270
ESP_ERROR_CHECK(adc_oneshot_new_unit(&unitCfg, &handle));
271+
if (!handle)
272+
throw std::runtime_error("getADCreading: adc_oneshot_new_unit() failed");
273273
ESP_ERROR_CHECK(adc_oneshot_config_channel(handle, channel, &channelCfg));
274274
int result = 0;
275275
for (int i = 0; i < sampleCount; i++)

0 commit comments

Comments
 (0)