[Logo] TCC discussion forum
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Top Downloads] Top Downloads   [Groups] Back to home page 
[Register] Register /  [Login] Login 


This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.

TaskManager listing of tasks RSS feed
Forum Index » IoAbstraction & TaskManagerIO
Author Message
jacobez


Joined: Mar 21, 2021
Messages: 10
Offline
Hi Dave,
I've used the tcMenu with i2c LCD & 3 button input on a Mega.
I'm also using a SPI datalogger to log some system temperatures to a SD card.
I use the tcMenu to set the time duration between data saving events like in the code below.

void CALLBACK_FUNCTION onDataSaveInterval(int id) {

    menuDataSaveId = taskManager.scheduleFixedRate(menuDataSave.getCurrentValue()*60, dataLogging, TIME_SECONDS);
    Serial.print("DataSaveInterval from Callback " );  // for debug
    Serial.println(menuDataSave.getCurrentValue());
    Serial.print("menuDataSaveId Callback ");
    Serial.println(menuDataSaveId);
}


What I see from the serial debug is that the data is being saved for every iteration that one increases or reduces the value.
I did check out Serial.println(taskManager.checkAvailableSlots(debugData,sizeof(debugData)));, but that does not help me a lot.

I've also tried the following, but it still seems to be logging for every instance I changed the menu item.
void CALLBACK_FUNCTION onDataSaveInterval(int id) {
   
//    Cancel current scheduling first, then reschedule. menuDataSaveId
    if (appMode != APP_SETUP_MODE) {  // Cannot cancel task in Setup mode as ID's are only allocated at this time
          taskManager.cancelTask(menuDataSaveId);
          Serial.print("Cancel menuDataSaveId = ");
          Serial.println(menuDataSaveId);
    }
    menuDataSaveId = taskManager.scheduleFixedRate(menuDataSave.getCurrentValue()*60, dataLogging, TIME_SECONDS);
    Serial.print("DataSaveInterval from Callback " );
    Serial.println(menuDataSave.getCurrentValue());
    Serial.print("menuDataSaveId Callback ");
    Serial.println(menuDataSaveId);
}



Is there a way that one can see a list of the names of the "functions" scheduled?
jacobez


Joined: Mar 21, 2021
Messages: 10
Offline
Here is a screenshot of the Serial Monitor:

menuDataSaveId Callback 5
DataSaveInterval from Callback 3
menuDataSaveId Callback 6
Save to EEPROM
dataLogging 6 02/04/2021;15:34:43;314;315;298
dataLogging 6 02/04/2021;15:36:29;315;315;297
dataLogging 6 02/04/2021;15:36:32;308;309;293
dataLogging 6 02/04/2021;15:37:00;306;305;289
dataLogging 6 02/04/2021;15:37:04;307;307;291
dataLogging 6 02/04/2021;15:37:32;316;317;298

davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
Is there a way that one can see a list of the names of the "functions" scheduled?


Short answer: You can see the task states (what's scheduled basically) but not the function names.

Longer answer: There is not really an easy way to do that, as RTTI (runtime type information) is not enabled on any embedded framework I've used (to reduce memory footprint). The only other way we could do it is by capturing __LINE__ and __FILE__ but that would be hideously expensive adding very high overhead to every task.

There is a function show what the state of each task slot is, but it only shows if it is running, waiting etc.

char* checkAvailableSlots(char* slotData, size_t slotDataSize) const;


Each slot is output in turn, so a trick you could use is to log each ID you get back from creating tasks, each one is an offset in that list of slots.
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
So BTW if you use the serdebug(..) functions in IoLogging.h you can compile them in / out by defining a variable, you may find it useful.

See https://www.thecoderscorner.com/ref-docs/ioabstraction/html/_io_logging_8h_source.html
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
What I would do in your case is use scheduleOnce as follows, then it will always use the correct time:

void myTimerTask() {

   // other work to be done

   taskManager.scheduleOnce(menuTime.getCurrentValue(), myTimerTask, TIME_SECONDS);

}


myInitialisation() {
   taskManager.scheduleOnce(menuTime.getCurrentValue(), myTimerTask, TIME_SECONDS);
}
jacobez


Joined: Mar 21, 2021
Messages: 10
Offline
Thanks a mill Dave,
I shall have a look at the suggestions.
Is the high level logic in the second code posting, to cancel the previous scheduled task before scheduling the next?
jacobez


Joined: Mar 21, 2021
Messages: 10
Offline
forgot the "Is it correct?" smilie
davetcc


Joined: Jan 19, 2019
Messages: 686
Offline
You can schedule and cancel in any order, but you're better not relying on cancel for regular operation. It's a very heavy operation that has itself to wait for scheduling. There is no guarantee that it will happen before the next execution.

Cancelling a task involves scheduling a task for immediate execution that will go through the running queue and remove the task that is to be scheduled.

It's better when the event timing changes often to use the schedule once as shown in my example. You could also use a polling event as described in the task manager docs.
 
Forum Index » IoAbstraction & TaskManagerIO
Go to:   
Mobile view
Powered by JForum 2.7.0 © 2020 JForum Team • Maintained by Andowson Chang and Ulf Dittmer

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.