Function Pointers, meet Serial protocol.

A project log for ECUality1

A light, open-source Engine Control Unit (ECU) using Arduino

Mike ThielvoldtMike Thielvoldt 04/10/2015 at 01:410 Comments

I was already doing this with function pointers:

task[0] = readAirFlow;			ms_freq_of_task[0] = 50;
task[1] = readO2Sensor;			ms_freq_of_task[1] = 50;

But now I'm also doing this:

ESerial.addCommand(F("Winj"), Map::write, &inj_map);
ESerial.addCommand(F("rinj"), Map::read, &inj_map);	
ESerial.addCommand(F("Sinj"), Map::save, &inj_map);	
ESerial.addCommand(F("linj"), Map::load, &inj_map);

It adds a serial command that gets executed on a specific object (in the above example the object is "inj_map" ).

So after calling the above, when I type: rinj into the serial monitor window, the Arduino runs the "Map::read" function on the "inj_map" object. In this case, that prints the injector map out on the serial port, so you can see what's there.

So far I have almost 50 commands, which is why I needed to get it down to a 1-liner.