This is the os/image_process/image_process.cpp example rewritten as a "module".It inherits better starting up, configuring, and shutting down behavior.
class ImageProcessModule : public RFModule
{
private:
BufferedPort<ImageOf<PixelRgb>> port;
Port cmdPort;
size_t ct;
public:
bool open(Searchable& config)
{
ct = 0;
port.open(getName());
cmdPort.open(getName("cmd"));
attach(cmdPort);
return true;
}
bool interruptModule() override
{
port.interrupt();
return true;
}
bool updateModule() override
{
ImageOf<PixelRgb>* img = port.read();
if (img == nullptr) {
return false;
}
PixelRgb blue{0, 0, 255};
ct = (ct + 5) % img->width();
port.prepare() = *img;
port.write();
return true;
}
};
int main(
int argc,
char* argv[])
{
auto& rf = ResourceFinder::getResourceFinderSingleton();
rf.configure(argc, argv);
}