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


//
// For convenience
//
using App = eCxx::Application;


//
// Basic initialization for all NodeMCU applications
//
static void initBasicNodeMCUApp(bool delayStartup = false)
{
    // NOTE : # In case multiple NodeMCUs will be running at the same time, make sure their
    //          MAC addresses, SSIDs, and channels are set to different values (or they would
    //          fail to initialize).
    //        # Actually, using the same channels is still acceptable (but it will reduce the
    //          WiFi speed); however, using the same MAC addresses is forbidden.

    const App::Config config(
        PGM_STR("NodeMCU Generic OTA"),
        PGM_STR("*GenOTA@NodeMCU!"   ),
        PGM_STR("ota$*"              ),
        PGM_STR("nodemcu"            )
    );

    App::initialize(config);

    // Delay for a while blinking the activity indicator LED
    if(!delayStartup) return;

    App::setActivityIndicatorLED(false);
    App::delayMS(500);

    for(eCxx::uint8_t i = 0; i < 5; ++i) {
        App::setActivityIndicatorLED(true ); App::delayMS( 25);
        App::setActivityIndicatorLED(false); App::delayMS( 25);
        App::setActivityIndicatorLED(true ); App::delayMS( 25);
        App::setActivityIndicatorLED(false); App::delayMS( 25);
        App::setActivityIndicatorLED(true ); App::delayMS( 25);
        App::setActivityIndicatorLED(false); App::delayMS( 25);
                                             App::delayMS(350);
    }

    App::setActivityIndicatorLED(false);
    App::delayMS(500);
}
