/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include <eCxx/eCxx.h>

#include "NodeMCU_Common.h"


// Uncomment this to use buffered GPIO in the NodeMCU eCxx development board
// #define USE_BUFFERED_GPIO


//
// Pin numbers
//
#ifdef USE_BUFFERED_GPIO
static constexpr eCxx::uint8_t RECV = eCxx::NodeMCU::D3; // GPIO0
#else
static constexpr eCxx::uint8_t RECV = eCxx::NodeMCU::D1; // GPIO5 (SCL)
#endif


//
// Include common source code for StreamSampler test application
//
#include "../CommonCode/StreamSampler_Common.h"


//
// The init function
//
void eCxx_user_init()
{
    // Initialize application
    initBasicNodeMCUApp();

#ifdef USE_BUFFERED_GPIO
    // Enable the 74LVC541 buffers on the eCxx NodeMCU development board because
    // the RECV pin defined above is buffered
    App::setPinMode  ( eCxx::NodeMCU::D0, eCxx::Application::PinMode::Output ); // GPIO16
    App::digitalWrite( eCxx::NodeMCU::D0, false                              ); // The buffers are active low
#endif

    // Initialize UART
    App::uart().begin(9600);

    // Initialize and run the data-stream sampler
    initAndRunStreamSampler();
}


//
// The task function
//
void eCxx_user_task()
{
    // Process event
    App::processEvent();
}
