refactor: streamline task creation in checkVendor and checkFilament functions
This commit is contained in:
		
							
								
								
									
										60
									
								
								src/api.cpp
									
									
									
									
									
								
							
							
						
						
									
										60
									
								
								src/api.cpp
									
									
									
									
									
								
							| @@ -701,27 +701,15 @@ uint16_t checkVendor(String vendor) { | |||||||
|         vTaskDelay(100 / portTICK_PERIOD_MS); |         vTaskDelay(100 / portTICK_PERIOD_MS); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|  |     // Erstelle die Task | ||||||
|     if(spoolmanApiState == API_IDLE) { |     BaseType_t result = xTaskCreate( | ||||||
|         // Erstelle die Task |         sendToApi,                // Task-Funktion | ||||||
|         BaseType_t result = xTaskCreate( |         "SendToApiTask",          // Task-Name | ||||||
|             sendToApi,                // Task-Funktion |         6144,                     // Stackgröße in Bytes | ||||||
|             "SendToApiTask",          // Task-Name |         (void*)params,            // Parameter | ||||||
|             6144,                     // Stackgröße in Bytes |         0,                        // Priorität | ||||||
|             (void*)params,            // Parameter |         NULL                      // Task-Handle (nicht benötigt) | ||||||
|             0,                        // Priorität |     ); | ||||||
|             NULL                      // Task-Handle (nicht benötigt) |  | ||||||
|         ); |  | ||||||
|     } else { |  | ||||||
|         Serial.println("Not spawning new task, API still active!"); |  | ||||||
|         delete params; |  | ||||||
|         return 0; |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     // Wait for task completion |  | ||||||
|     while(spoolmanApiState != API_IDLE) { |  | ||||||
|         vTaskDelay(100 / portTICK_PERIOD_MS); |  | ||||||
|     } |  | ||||||
|      |      | ||||||
|     // Additional delay to ensure foundVendorId is properly set after API state becomes IDLE |     // Additional delay to ensure foundVendorId is properly set after API state becomes IDLE | ||||||
|     while (foundVendorId == NULL) |     while (foundVendorId == NULL) | ||||||
| @@ -852,27 +840,15 @@ uint16_t checkFilament(uint16_t vendorId, const JsonDocument& payload) { | |||||||
|     params->spoolsUrl = spoolsUrl; |     params->spoolsUrl = spoolsUrl; | ||||||
|     params->updatePayload = ""; // Empty for GET request |     params->updatePayload = ""; // Empty for GET request | ||||||
|  |  | ||||||
|     // Check if API is idle before creating task |      // Erstelle die Task | ||||||
|     //if(spoolmanApiState == API_IDLE){ |     BaseType_t result = xTaskCreate( | ||||||
|         // Erstelle die Task |         sendToApi,                // Task-Funktion | ||||||
|         BaseType_t result = xTaskCreate( |         "SendToApiTask",          // Task-Name | ||||||
|             sendToApi,                // Task-Funktion |         6144,                     // Stackgröße in Bytes | ||||||
|             "SendToApiTask",          // Task-Name |         (void*)params,            // Parameter | ||||||
|             6144,                     // Stackgröße in Bytes |         0,                        // Priorität | ||||||
|             (void*)params,            // Parameter |         NULL                      // Task-Handle (nicht benötigt) | ||||||
|             0,                        // Priorität |     ); | ||||||
|             NULL                      // Task-Handle (nicht benötigt) |  | ||||||
|         ); |  | ||||||
|     //} else { |  | ||||||
|     //    Serial.println("Not spawning new task, API still active!"); |  | ||||||
|     //    delete params; |  | ||||||
|     //    return 0; |  | ||||||
|     //} |  | ||||||
|      |  | ||||||
|     // Wait for task completion |  | ||||||
|     while(spoolmanApiState != API_IDLE) { |  | ||||||
|         vTaskDelay(100 / portTICK_PERIOD_MS); |  | ||||||
|     } |  | ||||||
|      |      | ||||||
|     // Additional delay to ensure foundFilamentId is properly set after API state becomes IDLE |     // Additional delay to ensure foundFilamentId is properly set after API state becomes IDLE | ||||||
|     while (foundFilamentId == NULL) { |     while (foundFilamentId == NULL) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user