
#define MAX_ADDONS 5

#include "debug_config.h"
#include <xmath.h>


#include "config.h"
#include <osr-base.h>
#include <App.h>
#include <Addon.h>
#include <Component.h>
#include <Bridge.h>
#include "H7TC.h"
#include "PID.h"
#include "SerialMessage.h"
#include "enums.h"
#include <ArduinoLog.h>

class OSR_PID_Test : public App
{
public:
  PIDModel_S1 *pid;
  SerialMessage *com_serial;

  OSR_PID_Test() : App(),
                   pid(new PIDModel_S1(this))
  {
    // setFlag(OBJECT_RUN_FLAGS::E_OF_DEBUG);
    bridge = new Bridge((Component *)this);
    com_serial = new SerialMessage(Serial, bridge);
  }

  short setup()
  {
    Serial.begin(SERIAL_BAUD_RATE);
    while (!Serial && !Serial.available())
    {
    }

    Log.begin(LOG_LEVEL_VERBOSE, &Serial);
    Log.verbose(F(CR "* App:setup   *" CR));

    components.push_back((Component *)pid);
    components.push_back((Component *)com_serial);
    components.push_back((Component *)bridge);

    App::setup();

    onRegisterMethods(bridge);

    return E_OK;
  }

  short foo(lint arg1, lint arg2)
  {
    Log.verbose(F("* App:foo arg1=%d arg2=%d = %d" CR), arg1, arg2, arg1 + arg2);
    return E_FATAL;
  }

  short onRegisterMethods(Bridge *bridge)
  {
    Log.verbose(F("* App:onRegisterMethods *" CR));
    bridge->registerMemberFunction(COMPONENT_KEY::COMPONENT_KEY_APP, this, C_STR("foo"), (ComponentFnPtr)&OSR_PID_Test::foo);
    return E_OK;
  }
};

OSR_PID_Test testApp;

void setup()
{
  // init_osr_base();
  Log.verboseln("Setup");
  testApp.setup();
}

void loop()
{
  testApp.loop();
  // Log.verbose(F("* main hb *" CR));
  delay(100);
}
