Register / Login  |  Desktop view  |  Jump to bottom of page

IoAbstraction & TaskManagerIO » Use libary for software-events

Author: chicorelli
05/06/2020 07:44:36
Hello,

I started to work with arduinos for my electronic projects. Currently I try to build a word-clock. To avoid unclean programming I found the library IoAbstraction. I like to work with events (my job is to work with C#) so I tried to find a solution for that. For timing issues or hardware switches it is perfect. I still use it for that.

But now my question:
It is possible to use this library for triggering an event by software.

For example I have a class called DCF. This class is responsible to receive the time by DCF77. If a new time is available it should fire an event. So it is not really a hardware event. It should be triggered by software.

class DCF {
 private:
 ExecuteNewTimeReceived();
...
...
 public:
 DCF();
...
...
}


in my main program I would like to register the class "DCF". If the ExecuteNewTimeReceived() function will be run in class DCF an event should be fired and the main program can do something.

Currently for this issue I use a timing event and ask the DCF if a new time is available. It works for sure but maybe there is a better way to do that.

taskManager.scheduleFixedRate(100, checkNewDataDCF);


void checkNewDataDCF() {
	// check if new data of DCF is available
	if(dcf.CheckForNewTime())
        {
            ....
        }
}


My next step would be to extend the library by myself to have this feature. I think it is similar to the SwitchInput Class...only that I is not triggered by hardware.

Thanks in advance for your help! And thanks for the great library!!

Author: davetcc
06/06/2020 08:50:10
Hi there, at the moment taskManager cannot handle events that are not either interrupt-driven or timed. I have a plan to add timed events that can be replaced so there's only even one of a given ID on the queue, but I've not really considered a more generic eventing framework. I'm not 100% sure how that would work to be honest. I'm open to discussion on it though.

Author: davetcc
30/06/2020 07:54:10
Sometimes, a bit of time is needed to work out how something can be done...

I had an idea, there is a method of creating tasks that are of type Executable, these tasks get the virtual exec() method called when the time is hit. There's a couple of possibilities here:

1. create an Event class extending abstract type Executable that carries the event payload and the exec method would "process" the event.

2. make taskmanager able to either "find" or "replace" an existing entry if a new executable with the same key arrives.

As of 1.5.0 where the task queue grows in size as needed, this is now a possibility because it can handle a much larger pool of events than before. If you take a look at the IoAbstraction documentation you'll see the Executable type documented there, let me know if you also think something could be done around this.

Thanks,
Dave




Register / Login  |  Desktop view  |  Jump to top of page