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


#include <eCxx/eCxx_SPILEDDriver1DShortcut.h>
#include <eCxx/eCxx_SPILEDDriver2DShortcut.h>

#include "TestUtility.h"


//
// Test application
//
int main()
{
    // For convenience
    static constexpr eCxx::uint8_t  PinData        = 1;
    static constexpr eCxx::uint8_t  PinClock       = 2;
    static constexpr eCxx::uint32_t ClockFrequency = 2000000UL;

    printf("\n");

    // Test 1D without convenience shortcut
    printf("1D color animator without convenience shortcut ...\n");
    do {

        using ColorType       = eCxx::XBGRColor          <eCxx::APA102XPolicy>;
        using ColorFX1DType   = eCxx::ColorFX1D          <ColorType, 8, eCxx::CBP::RawBuffer>;
        using ColorAnim1DType = eCxx::ColorAnimator1D    <1, ColorFX1DType>;
        using APA102CDriver   = eCxx::GenericSPILEDDriver<8, PinData, PinClock, ClockFrequency, ColorFX1DType>;

        APA102CDriver   apa102c;
        ColorFX1DType   colorFX1D;
        ColorAnim1DType colorAnim1D(colorFX1D);

        colorAnim1D.reset();
        apa102c.begin( colorFX1D.colorBufferData() );
        apa102c.update();

        colorAnim1D.update();
        apa102c.update();

    } while(0);

    // Test 2D without convenience shortcut
    printf("2D color animator without convenience shortcut ...\n");
    do {

        using ColorType       = eCxx::XBGRColor          <eCxx::APA102XPolicy>;
        using ColorFX2DType   = eCxx::ColorFX2D          <ColorType, 8, 8, eCxx::CBP::DefaultLayout, eCxx::CBP::RawBuffer>;
        using ColorAnim2DType = eCxx::ColorAnimator2D    <1, ColorFX2DType>;
        using APA102CDriver   = eCxx::GenericSPILEDDriver<8 * 8, PinData, PinClock, ClockFrequency, ColorFX2DType>;

        APA102CDriver   apa102c;
        ColorFX2DType   colorFX2D;
        ColorAnim2DType colorAnim2D(colorFX2D);

        colorAnim2D.reset();
        apa102c.begin( colorFX2D.colorBufferData() );
        apa102c.update();

        colorAnim2D.update();
        apa102c.update();

    } while(0);

    printf("\n");

    // Test 1D with convenience shortcut
    printf("1D color animator with    convenience shortcut ...\n");

    #define TEST_1D_SHORTCUT(ACN, CCN) do {                                                                \
        eCxx::ACN<eCxx::CCN, PinData, PinClock, ClockFrequency, 1, 8, 9, false, eCxx::PGMCharPointer> obj; \
        obj.begin();                                                                                       \
        obj.update();                                                                                      \
    } while(0)

    TEST_1D_SHORTCUT(ColorAnimator1D_SK9822,   XBGRColor);
    TEST_1D_SHORTCUT(ColorAnimator1D_P9813BGR, XBGRColor);
    TEST_1D_SHORTCUT(ColorAnimator1D_LPD8806,   BGRColor);
    TEST_1D_SHORTCUT(ColorAnimator1D_LPD6803,   BGRColor);
    TEST_1D_SHORTCUT(ColorAnimator1D_WS2801,    BGRColor);
    TEST_1D_SHORTCUT(ColorAnimator1D_SM16716,   BGRColor);

    // Test 2D with convenience shortcut
    printf("2D color animator with    convenience shortcut ...\n");

    #define TEST_2D_SHORTCUT(ACN, CCN) do {                                                                                                      \
        eCxx::ACN<eCxx::CCN, PinData, PinClock, ClockFrequency, 1, 8, 8, eCxx::CBP::DefaultLayout, 0, 0, 0, 9, false, eCxx::PGMCharPointer> obj; \
        obj.begin();                                                                                                                             \
        obj.update();                                                                                                                            \
    } while(0)

    TEST_2D_SHORTCUT(ColorAnimator2D_SK9822,   XBGRColor);
    TEST_2D_SHORTCUT(ColorAnimator2D_P9813BGR, XBGRColor);
    TEST_2D_SHORTCUT(ColorAnimator2D_LPD8806,   BGRColor);
    TEST_2D_SHORTCUT(ColorAnimator2D_LPD6803,   BGRColor);
    TEST_2D_SHORTCUT(ColorAnimator2D_WS2801,    BGRColor);
    TEST_2D_SHORTCUT(ColorAnimator2D_SM16716,   BGRColor);

    printf("\n");

    return 0;
}
