#include "FreeRTOS.h"
#include "task.h"
#include "alps_config.h"
#include "nrf_log.h"
#include "tiny1616.h"
#include "sensor_register.h"
#include "led.h"

TaskHandle_t touch_task_handle;


static void touch_test_task_function (void * pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    tiny1616_dev_t *tiny1616_dev = tiny1616_init();

    if(tiny1616_check_id(tiny1616_dev))
    {
        NRF_LOG_INFO("yiny1616 id check success\r\n");
    }
    else
    {
        NRF_LOG_INFO("yiny1616 id check failure\r\n");
    }

    while (true)
    {
        tiny1616_get_pressed_status(tiny1616_dev);
        if(tiny1616_dev->pressed != 0x00)
        {
            NRF_LOG_INFO("button pressed result:0x%X\r\n", tiny1616_dev->pressed);
        }
        led_on(1);
        vTaskDelay(10);
        led_off(1);
        vTaskDelay(10);
    }
}


void touch_test_task_init(void)
{
    BaseType_t ret;
 /* Create task for LED0 blinking with priority set to 2 */
    ret = xTaskCreate(touch_test_task_function, 
                     "touch", 
                     64, NULL, 
                     5, &touch_task_handle);
    if(ret == pdPASS)
    {
       NRF_LOG_INFO("touch task is startup");
    }
}

