|
@@ -82,9 +82,10 @@ GpioPin::~GpioPin()
|
|
|
MQTTunregisterSubscribeFunction(_mqttTopic);
|
|
MQTTunregisterSubscribeFunction(_mqttTopic);
|
|
|
}
|
|
}
|
|
|
#endif // ENABLE_MQTT
|
|
#endif // ENABLE_MQTT
|
|
|
- if (_interruptType != GPIO_INTR_DISABLE) {
|
|
|
|
|
- // Remove the interrupt before releasing this pin's callback target.
|
|
|
|
|
|
|
+ if (_isrRegistered) {
|
|
|
|
|
+ // Remove only an ISR that was successfully installed for this pin.
|
|
|
gpio_isr_handler_remove(_gpio);
|
|
gpio_isr_handler_remove(_gpio);
|
|
|
|
|
+ _isrRegistered = false;
|
|
|
}
|
|
}
|
|
|
gpio_reset_pin(_gpio);
|
|
gpio_reset_pin(_gpio);
|
|
|
}
|
|
}
|
|
@@ -131,7 +132,7 @@ void GpioPin::gpioInterrupt(int value) {
|
|
|
currentState = value;
|
|
currentState = value;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void GpioPin::init()
|
|
|
|
|
|
|
+bool GpioPin::init()
|
|
|
{
|
|
{
|
|
|
gpio_config_t io_conf = {};
|
|
gpio_config_t io_conf = {};
|
|
|
io_conf.intr_type = _interruptType;
|
|
io_conf.intr_type = _interruptType;
|
|
@@ -143,14 +144,20 @@ void GpioPin::init()
|
|
|
const esp_err_t configResult = gpio_config(&io_conf);
|
|
const esp_err_t configResult = gpio_config(&io_conf);
|
|
|
if (configResult != ESP_OK) {
|
|
if (configResult != ESP_OK) {
|
|
|
ESP_LOGE(TAG, "gpio_config failed for GPIO%d: %s", static_cast<int>(_gpio), esp_err_to_name(configResult));
|
|
ESP_LOGE(TAG, "gpio_config failed for GPIO%d: %s", static_cast<int>(_gpio), esp_err_to_name(configResult));
|
|
|
- return;
|
|
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// if (_interruptType != GPIO_INTR_DISABLE) { // ohne GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X, wenn das genutzt wird, dann soll auch der Handler hier nicht initialisiert werden, da das dann über SmartLED erfolgt.
|
|
// if (_interruptType != GPIO_INTR_DISABLE) { // ohne GPIO_PIN_MODE_EXTERNAL_FLASH_WS281X, wenn das genutzt wird, dann soll auch der Handler hier nicht initialisiert werden, da das dann über SmartLED erfolgt.
|
|
|
if (_interruptType != GPIO_INTR_DISABLE) {
|
|
if (_interruptType != GPIO_INTR_DISABLE) {
|
|
|
//hook isr handler for specific gpio pin
|
|
//hook isr handler for specific gpio pin
|
|
|
ESP_LOGD(TAG, "GpioPin::init add isr handler for GPIO %d", _gpio);
|
|
ESP_LOGD(TAG, "GpioPin::init add isr handler for GPIO %d", _gpio);
|
|
|
- gpio_isr_handler_add(_gpio, gpio_isr_handler, (void*)&_gpio);
|
|
|
|
|
|
|
+ const esp_err_t isrResult = gpio_isr_handler_add(_gpio, gpio_isr_handler, (void*)&_gpio);
|
|
|
|
|
+ if (isrResult != ESP_OK) {
|
|
|
|
|
+ ESP_LOGE(TAG, "gpio_isr_handler_add failed for GPIO%d: %s",
|
|
|
|
|
+ static_cast<int>(_gpio), esp_err_to_name(isrResult));
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ _isrRegistered = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_MQTT
|
|
#ifdef ENABLE_MQTT
|
|
@@ -159,6 +166,7 @@ void GpioPin::init()
|
|
|
MQTTregisterSubscribeFunction(_mqttTopic, f);
|
|
MQTTregisterSubscribeFunction(_mqttTopic, f);
|
|
|
}
|
|
}
|
|
|
#endif //ENABLE_MQTT
|
|
#endif //ENABLE_MQTT
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool GpioPin::getValue(std::string* errorText)
|
|
bool GpioPin::getValue(std::string* errorText)
|
|
@@ -292,7 +300,15 @@ void GpioHandler::init()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for(std::map<gpio_num_t, GpioPin*>::iterator it = gpioMap->begin(); it != gpioMap->end(); ++it) {
|
|
for(std::map<gpio_num_t, GpioPin*>::iterator it = gpioMap->begin(); it != gpioMap->end(); ++it) {
|
|
|
- it->second->init();
|
|
|
|
|
|
|
+ if (!it->second->init()) {
|
|
|
|
|
+ LogFile.WriteToFile(ESP_LOG_ERROR, TAG,
|
|
|
|
|
+ "GPIO initialization failed for GPIO" + std::to_string(static_cast<int>(it->first)));
|
|
|
|
|
+ clear();
|
|
|
|
|
+ vQueueDelete(gpio_queue_handle);
|
|
|
|
|
+ gpio_queue_handle = NULL;
|
|
|
|
|
+ _isEnabled = false;
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifdef ENABLE_MQTT
|
|
#ifdef ENABLE_MQTT
|