I like the idea of it. It would greatly simplify how the controller is programmed and you could just load a basic "code template" that would be your framework / shell running. Then you can change the functions on the fly as needed. It would be great for the standard / generic and most people's controllers but would be difficult for those who customized a lot.
Based on what you proposed, I am going to start thinking about this one. I have a trip coming up and will have some downtime on the plane and such. So I'm gonna start working up some ideas for you. I've already got something starting in my head but I need to process it and work it out.
The short of what I'm thinking of doing is this:
Have a generic function added to the library that would take a port...say, ReefAngel.Assign(Port1);
Inside that function Assign, it does the following:
- Read the memory location assigned to the port (this would be a lookup table or something)
- Perform a "switch" on the value and call the appropriate function
Here's an example of the code:
Code: Select all
// uint8_t is the same as byte
void ReefAngel::Assign(uint8_t port) {
// use 95 as the offset since port1 is 1 and 1+95 = 96
uint8_t loc = InternalMemory.read(port + 95);
switch ( loc ) {
default: // default value that is unrecognized is always off
case 0:
Relay.Off(port);
break;
case 1:
Relay.On(port);
break;
case 2:
// use the standard lights simple call
StandardLights(port);
break;
case 3:
ActinicLights(port);
break;
case 4:
Moonlights(port);
break;
case 5:
StandardHeater(port);
break;
case 6:
StandardFan(port);
break;
}
}
Then you would just add in all the functions that we could call. I know some of the stuff I posted are not correct (Moonlights, ActinicLights, etc). Also, the lookup would need to be modified because we would be skipping offsets 9 & 10 between the main relay and 1st expansion box. So there will be 2 offsets that get skipped. That would need to be improved.
This function would expand nicely just by adding on more "cases" and we could even create a DEFINE statement for each case, such as #define 0 ALWAYS_OFF, #define 1 ALWAYS_ON, etc to make it even more readable in the libraries. It would just add 1 more level of the function calls. You could also bypass using the short function calls here and just call the functions that the short functions call. So instead of using StandardLights(port), you would use StandardLights(port, onhr, onmin, offhr, offmin). I'm not sure if this would save anything or not but just a thought.
Anyways, I'll think on this more and see if I can come up with a better solution but this is probably as simple as it can be.
