New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For sensors creating multiple child IDs allow invoking their functions just once #198
Comments
If you see this as an issue, I would understand the problem as an architectural issue. The structure clearly started as something simple, node-sensor. But now we must do more complex things.
At some point, you would also want to access and modify base class elements, like settings. Then you will need a differentiation like this:
And then:
And you also can have defaults and/or apply properties to all child or first child. This makes it coherent and expandable.
|
You are 100% right, all of this is due to a mix of sensors and children which is causing all of this confusion. I think the approach you have proposed is the best possible, with an additional contained in between. I'll try to draft something as v1.7 development will start so we can check together if the direction is the right one. |
Maybe it would be a good idea, to have one instance of one specific sensor class with all the variables and parameters wich are global for all the different measurements (childs) of this sensor. And there is an array of pointers/IDs of all the child instances (for each measurement) of this sensor. The setter methods are either looping through this array or are called for only some of the childs. |
Hi guys, thanks for the feedback so far. This issue is number 1 priority for v1.7 and I think must be addressed before adding other sensors or fixing other issues before would have an overall impact. The thing is we need to 1) define a new hierarchy 2) redefine the terminology. Up to v1.6 we have an array of pointers to instances of Sensor and subclasses. When registering a sensor providing more than one measure (e.g. temperature and humidity), registerSensor() creates two instances of the same class and registers two child IDs by adding two pointers to the array.
Let's start from Sergio's idea which I think should cover all those requirements. I struggle a bit to understand the relationship between Child and Sensor. Also, that .first. and .All., is it from a specific C++ object or it is just pseudo-code? Thanks! |
That was some pseudo-C# code, but it could work on cpp. First, I would try if we can use vectors for storage (there's a small library for arduino). They allow add and remove elements, but I dunno if they are feasible on low perf boards. We must also think on allow a function callback for "sensor" action. Then we could make virtual "physical sensors" or electronics that are not directly related to a pin for actuating, like a shift register. |
Hi guys, I spent some time thinking about this architectural thing and get lost pretty quickly :(
However if we want to apply the same setting to all the Child belonging to the sensor we need to replicate ALL the other functions which will cycle through the Child and invoke the methods. This scares me since we are already almost out of storage and this will make the code much longer, complex and resources intensive but providing little value. |
You must think in what elements are properties from the sensor and what are tools from the framework. |
If you want, we can talk through chat on this and perhaps do some work together. Just drop me a line when you will get on to this. |
Ok, let me try to follow your line of thinking. Despite almost all the properties can be child-specific, this is going against the need to 1) make it simple 2) do not use additional storage. So let's assume to keep to the very minimum the child-specific properties. What properties MUST be child-specific? This is the list:
This can be the minimum set of information a Child class can have. So let's assume a Sensor will have a data structure with those properties for each Child. This may somehow solve the problem (and creating a few others which I cannot see right now) because 1) would avoid invoking the same methods on all the child (because those parameters will be attached to Sensor and not to child) 2) would save additional space since for sensors with multiple child a single instance of the Sensor class would be created and not many. |
I spent some time thinking about the idea above and doing some initial tests and I think it could work. Each Sensor will have a data structure to store a list of Child with the information reported above. No more the need then to create multiple instances of the class for each child id. There will be one single instance for the sensor containing its child id. In the Sensor's loop(), for each Child onLoop() will be executed. The challenge will be with received() when loop() of a child only needs to be executed but I think we could find the way to make it working. This approach could also solve a bunch of other problems: since the logic in registerSensor() is no longer needed (Sensor will create any additional objects in its constructor since all the child belonging to it will be within the instance) we could even simplify the main sketch.
Of course there will be no compatibility with previous version but I can live with it. |
Hi, I've done some steps ahead (PR #229) and looking for your feedback. |
Another few improvements in PR #229. Both _sensors and _children have been now migrated into a vector-like structure as @SergioRius recommended.
The sensor will register itself against NodeManager. No more the need to get and cast either as you can see above. Much more intuitive I hope.
The values have been moved into the Child class, however I don't like at all the mess I'm doing declaring a variable for each type (int, float,double,string) and then using only one in Sensor::loop() (same with the previous versions). I'm sure this would help us saving a good amount of storage but fixing this would go way beyond my c++ knowledge. |
Completed architecture review #198 |
Reopening
|
Closing, fixed by #251 |
Issue described here: #176
The text was updated successfully, but these errors were encountered: