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


//
// Helper functions
//
static void testNVStorage()
{
    // 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 format
    // App::nvStorageFormat();

    // Test read
    eCxx::uint8_t v1;
    eCxx::uint8_t v2;
    uart.write('\n');
    uart.write('\n');
    uart.writeStringln( App::nvStorageRead(&v1, sizeof(v1),  0) ? readOK : readError );
    uart.writeStringln( App::nvStorageRead(&v2, sizeof(v2), 32) ? 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::nvStorageWrite(&v1, sizeof(v1),  0) ? writeOK : writeError );
    uart.writeStringln( App::nvStorageWrite(&v2, sizeof(v2), 32) ? writeOK : writeError );
    uart.write('\n');
    uart.write('\n');
}
