/*
 * 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 "../AVR_Common.h"


//
// Check the MCU
//
#ifndef __AVR_ARCH_X__
#error "this test application is meant for AVRX platform only"
#endif


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

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

    // PROGMEM strings
    eCxx::PGMCharPointer readOK     = PGM_STR("Read OK"    );
    eCxx::PGMCharPointer readError  = PGM_STR("Read ERROR" );
    eCxx::PGMCharPointer writeOK    = PGM_STR("Write OK"   );
    eCxx::PGMCharPointer writeError = PGM_STR("Write ERROR");

    // Test read
    eCxx::uint8_t v1;
    eCxx::uint8_t v2;
    uart.write('\n');
    uart.write('\n');
    uart.writeStringln( App::readUserRow( 0, v1) ? readOK : readError );
    uart.writeStringln( App::readUserRow(32, v2) ? readOK : readError );

    // Write to UART
    uart.write('\n');
    uart.write('\n');
    uart.writeDecStringln(v1);
    uart.writeDecStringln(v2);
    uart.write('\n');
    uart.write('\n');

    // Test write
    ++v1;
    ++v2;
    uart.writeStringln( App::writeUserRow( 0, v1) ? writeOK : writeError );
    uart.writeStringln( App::writeUserRow(32, v2) ? writeOK : writeError );
    uart.write('\n');
    uart.write('\n');
}


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