Skip to content

Commit

Permalink
fix task recreation and gpio assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
rednblkx committed Nov 18, 2024
1 parent c53931a commit d20b6f3
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ void gpio_task(void* arg) {
}
}
} else if (status.action == 2) {
vTaskDelete(NULL);
return;
}
}
Expand Down Expand Up @@ -298,6 +299,7 @@ void neopixel_task(void* arg) {
}
break;
default:
vTaskDelete(NULL);
return;
break;
}
Expand Down Expand Up @@ -333,6 +335,7 @@ void nfc_gpio_task(void* arg) {
break;
default:
LOG(I, "STOP");
vTaskDelete(NULL);
return;
break;
}
Expand Down Expand Up @@ -1201,15 +1204,15 @@ void setupWeb() {
request->send(200, "text/plain", msg.c_str());
return;
}
if (espConfig::miscConfig.nfcNeopixelPin == 255 && p->value().toInt() != 255) {
if (espConfig::miscConfig.nfcNeopixelPin == 255 && p->value().toInt() != 255 && neopixel_task_handle == nullptr) {
xTaskCreate(neopixel_task, "neopixel_task", 4096, NULL, 2, &neopixel_task_handle);
if (!pixel) {
pixel = std::make_unique<Pixel>(p->value().toInt(), PixelType::GRB);
}
} else if (espConfig::miscConfig.nfcNeopixelPin != 255 && p->value().toInt() == 255 && neopixel_task_handle != nullptr) {
uint8_t status = 2;
xQueueSend(neopixel_handle, &status, 0);
vTaskDelete(neopixel_task_handle);
neopixel_task_handle = nullptr;
}
espConfig::miscConfig.nfcNeopixelPin = p->value().toInt();
} else if (!strcmp(p->name().c_str(), "neopixel-s-time")) {
Expand Down Expand Up @@ -1244,9 +1247,13 @@ void setupWeb() {
pinMode(p->value().toInt(), OUTPUT);
xTaskCreate(nfc_gpio_task, "nfc_gpio_task", 4096, NULL, 2, &gpio_led_task_handle);
} else if (espConfig::miscConfig.nfcSuccessPin != 255 && p->value().toInt() == 255 && gpio_led_task_handle != nullptr) {
uint8_t status = 2;
xQueueSend(gpio_led_handle, &status, 0);
vTaskDelete(gpio_led_task_handle);
if (espConfig::miscConfig.nfcFailPin == 255) {
uint8_t status = 2;
xQueueSend(gpio_led_handle, &status, 0);
gpio_led_task_handle = nullptr;
}
} else if(p->value().toInt() != 255) {
pinMode(p->value().toInt(), OUTPUT);
}
espConfig::miscConfig.nfcSuccessPin = p->value().toInt();
} else if (!strcmp(p->name().c_str(), "nfc-f-pin")) {
Expand All @@ -1260,9 +1267,13 @@ void setupWeb() {
pinMode(p->value().toInt(), OUTPUT);
xTaskCreate(nfc_gpio_task, "nfc_gpio_task", 4096, NULL, 2, &gpio_led_task_handle);
} else if (espConfig::miscConfig.nfcFailPin != 255 && p->value().toInt() == 255 && gpio_led_task_handle != nullptr) {
uint8_t status = 2;
xQueueSend(gpio_led_handle, &status, 0);
vTaskDelete(gpio_led_task_handle);
if (espConfig::miscConfig.nfcSuccessPin == 255) {
uint8_t status = 2;
xQueueSend(gpio_led_handle, &status, 0);
gpio_led_task_handle = nullptr;
}
} else if(p->value().toInt() != 255) {
pinMode(p->value().toInt(), OUTPUT);
}
espConfig::miscConfig.nfcFailPin = p->value().toInt();
} else if (!strcmp(p->name().c_str(), "nfc-s-hl")) {
Expand All @@ -1280,13 +1291,13 @@ void setupWeb() {
request->send(200, "text/plain", msg.c_str());
return;
}
if (espConfig::miscConfig.gpioActionPin == 255 && p->value().toInt() != 255) {
if (espConfig::miscConfig.gpioActionPin == 255 && p->value().toInt() != 255 && gpio_lock_task_handle == nullptr) {
pinMode(p->value().toInt(), OUTPUT);
xTaskCreate(gpio_task, "gpio_task", 4096, NULL, 2, &gpio_lock_task_handle);
} else if (espConfig::miscConfig.gpioActionPin != 255 && p->value().toInt() == 255 && gpio_lock_task_handle != nullptr) {
gpioLockAction status{ .source = gpioLockAction::OTHER, .action = 2 };
xQueueSend(gpio_lock_handle, &status, 0);
vTaskDelete(gpio_lock_task_handle);
gpio_lock_task_handle = nullptr;
}
espConfig::miscConfig.gpioActionPin = p->value().toInt();
} else if (!strcmp(p->name().c_str(), "gpio-a-lock")) {
Expand Down Expand Up @@ -1508,7 +1519,7 @@ void nfc_thread_entry(void* arg) {
} else if(!espConfig::mqttData.nfcTagNoPublish) {
LOG(W, "Invalid Response, probably not Homekey, publishing target's UID");
bool status = false;
if (espConfig::miscConfig.nfcSuccessPin != 255) {
if (espConfig::miscConfig.nfcFailPin != 255) {
xQueueSend(gpio_led_handle, &status, 0);
}
if (espConfig::miscConfig.nfcNeopixelPin != 255) {
Expand Down

0 comments on commit d20b6f3

Please sign in to comment.