Added homeSpan.start() method as alternative to homeSpan.poll()
Rather than call homeSpan.poll() in the main Arduino loop() function, you can instead call homeSpan.start() at the end of the set-up function. This keeps the main Arduino loop() function free for user-defined code that will not block, and does not get blocked by, homeSpan.poll(). If using a dual-core processor, polling now occurs on core 0, instead of the core 1 (where all other Arduino stuff normally runs). HomeSpan will throw a fatal error and halt processing if both homeSpan.poll() and homeSpan.start() are used in the same sketch.
This commit is contained in:
parent
fe6b542ed8
commit
c290c8637e
|
|
@ -159,8 +159,21 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
|||
|
||||
void Span::poll() {
|
||||
|
||||
if(pollTaskHandle){
|
||||
Serial.print("\n** FATAL ERROR: Do not call homeSpan.poll() directly if homeSpan.start() is used!\n** PROGRAM HALTED **\n\n");
|
||||
vTaskDelete(pollTaskHandle);
|
||||
while(1);
|
||||
}
|
||||
|
||||
pollTask();
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
void Span::pollTask() {
|
||||
|
||||
if(!strlen(category)){
|
||||
Serial.print("\n** FATAL ERROR: Cannot run homeSpan.poll() without an initial call to homeSpan.begin()!\n** PROGRAM HALTED **\n\n");
|
||||
Serial.print("\n** FATAL ERROR: Cannot start homeSpan polling without an initial call to homeSpan.begin()!\n** PROGRAM HALTED **\n\n");
|
||||
while(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -192,6 +192,7 @@ struct Span{
|
|||
PushButton controlButton; // controls HomeSpan configuration and resets
|
||||
Network network; // configures WiFi and Setup Code via either serial monitor or temporary Access Point
|
||||
SpanWebLog webLog; // optional web status/log
|
||||
TaskHandle_t pollTaskHandle = NULL; // optional task handle to use for poll() function
|
||||
|
||||
SpanOTA spanOTA; // manages OTA process
|
||||
SpanConfig hapConfig; // track configuration changes to the HAP Accessory database; used to increment the configuration number (c#) when changes found
|
||||
|
|
@ -208,7 +209,8 @@ struct Span{
|
|||
const char *hostNameBase=DEFAULT_HOST_NAME,
|
||||
const char *modelName=DEFAULT_MODEL_NAME);
|
||||
|
||||
void poll(); // poll HAP Clients and process any new HAP requests
|
||||
void poll(); // calls pollTask() with some error checking
|
||||
void pollTask(); // poll HAP Clients and process any new HAP requests
|
||||
int getFreeSlot(); // returns free HAPClient slot number. HAPClients slot keep track of each active HAPClient connection
|
||||
void checkConnect(); // check WiFi connection; connect if needed
|
||||
void commandMode(); // allows user to control and reset HomeSpan settings with the control button
|
||||
|
|
@ -257,6 +259,8 @@ struct Span{
|
|||
webLog.init(maxEntries, serv, tz, url);
|
||||
}
|
||||
|
||||
void start(){xTaskCreateUniversal([](void *parms){for(;;)homeSpan.pollTask();}, "pollTask", getArduinoLoopTaskStackSize(), NULL, 1, &pollTaskHandle, 0);} // start pollTask()
|
||||
|
||||
void setTimeServerTimeout(uint32_t tSec){webLog.waitTime=tSec*1000;} // sets wait time (in seconds) for optional web log time server to connect
|
||||
|
||||
[[deprecated("Please use reserveSocketConnections(n) method instead.")]]
|
||||
|
|
|
|||
Loading…
Reference in New Issue