Skip to content
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

Make core board agnostic #9

Open
fulf opened this issue May 14, 2018 · 0 comments
Open

Make core board agnostic #9

fulf opened this issue May 14, 2018 · 0 comments
Labels
core Core functionality that is board agnostic enhancement New feature or request help wanted Extra attention is needed

Comments

@fulf
Copy link
Owner

fulf commented May 14, 2018

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");
    }
}
@fulf fulf added enhancement New feature or request help wanted Extra attention is needed core Core functionality that is board agnostic labels May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality that is board agnostic enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant