#include "PHApp.h"

//#include "components/MotorLoad.h"
//#include "components/POT.h"
//#include "components/Relay.h"
#include "ModbusBridge.h"

/*
short PHApp::loop()
{
    App:loop();
    return E_OK;
}
*/
short PHApp::setup()
{
    Serial.begin(SERIAL_BAUD_RATE);
    while (!Serial && !Serial.available())
    {
    }

    Log.begin(LOG_LEVEL_VERBOSE, &Serial);
    Log.verbose(F(CR "* App:setup   *" CR));

    setFlag(OBJECT_RUN_FLAGS::E_OF_DEBUG);

   // bridge = new Bridge((Component *)this);
   // com_serial = new SerialMessage(Serial, bridge);
    //mLoad = new MotorLoad(MOTOR_LOAD_PIN);
   // pot1 = new POT((Component *)this, 0);
   // relay1 = new Relay((Component *)this, 0);

    //components.push_back((Component *)pid);
    //components.push_back((Component *)com_serial);
    //components.push_back((Component *)bridge);
    //components.push_back((Component *)mLoad);
  //  components.push_back((Component *)pot1);
   // components.push_back((Component *)relay1);
    
    #ifdef MODBUS_BRIDGE
        modbusBridge = new ModbusBridge((Component *)this);
        components.push_back((Component *)modbusBridge);
    #endif

    App::setup();
    onRegisterMethods(bridge);
    return E_OK;
}

short PHApp::onRegisterMethods(Bridge *bridge)
{
    Log.verbose(F("* App:onRegisterMethods *" CR));
    // bridge->registerMemberFunction(COMPONENT_KEY::COMPONENT_KEY_APP, this, C_STR("foo"), (ComponentFnPtr)&PHApp::foo);
   // bridge->registerMemberFunction(COMPONENT_KEY_RELAY_1, relay1, C_STR("_set"), (ComponentFnPtr)&Relay::_set);
    return E_OK;
}
