#include "PHApp.h"

//#include "components/MotorLoad.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);
    components.push_back((Component *)com_serial);
    components.push_back((Component *)bridge);
    
    #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);
    return E_OK;
}
