fulf/prei

Make Core board agnostic

Opened this issue · 0 comments

fulf commented

Allow the Core class to be used with any wifi module (ESP8266, ESP32, etc.)

Suggested implementations:

BoardClass implements CoreInterface

Have LazyBoxCore as an interface. All boards implement the interface, having to define their control logic.

Have a factory class that returns the right LazyBoxCore implementation board.

A downside to this would be the fact that all ESP8266 boards have to implement the control logic, meaning a lot of duplicated code.

BoardClass extends ModuleAbstractClass implements CoreInterface

Have LazyBoxCore as an interface. Each WiFi module represents an abstract class properly implementing the control logic. Each board extends the abstract class, specifying their properties (pins, memory, etc.)

Again, a factory class will return the correct BoardClass for the specific WiFi module.

A downside to this would be the need to create factories for all WiFi modules, and have the end user define the LazyBox variable type depending on the WiFi module he uses.


Apparently C++ doesn't support interfaces, but they can be mocked up via Virtual Classes.

The second implementation looks best, and we might go for something like:

class CoreInterface {
  public:
    LazyBoxPin* getPins() {
      // implementation
    }
    virtual void setPins(LazyBoxPin* p) = 0;
    virtual uint8_t connectWiFi(const char*, const char* = "") = 0;
    virtual void setPinMode(LazyBoxPin, const char*) = 0;
    // ...
}

class MyWiFiModule : CoreInterface {
  public:
    virtual uint8_t connectWiFi(const char*, const char* = "") {
      // implementation
    }
   virtual void setPinMode(LazyBoxPin, const char*) {
     // implementation
   };
  // ...
}

class MyBoardClass : public MyWiFiModule {
  public:
    MyBoardClass() {
      // set board pins, memory, etc.
    }
}

class MyWiFiModuleFactory {
  public:
    static MyWiFiModule getBoard(String board) {
      // return MyBoardClass
    }
}

// ---

class MyApp {
  public:
    MyApp() {
      MyWiFiModule module = MyWiFiModuleFactory::getBoard("MyBoard");
    }
}