#include "TaskMain.hpp"
#include "SDCard.hpp"

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>

#include "nrf_gpio.h"
#include "nrf_error.h"
#include "nrf_delay.h"



#define NRF_LOG_MODULE_NAME TaskMain
#include "nrf_log.h"
NRF_LOG_MODULE_REGISTER();

APP_TIMER_DEF(m_battery_timer_id);

static void battery_timer_handler(void * p_context);


void TaskMain::init()
{
	// initialize timer for sending according to the frequency
	this->timer_init();

}

//!
//! @brief Initialize the counter in Timer 0 used to count number of
//! TWI transfers from BMX
//!
void TaskMain::timer_init()
{
    ret_code_t err_code;

    err_code = app_timer_create(&m_battery_timer_id,
                                APP_TIMER_MODE_REPEATED,
                                battery_timer_handler);
	app_timer_start(m_battery_timer_id, APP_TIMER_TICKS(1000), this);
    APP_ERROR_CHECK(err_code);
}



#define TEST_STRING "SD card example."

static void battery_timer_handler(void * p_context){
	SDCard* sdcard = SDCard::getInstance();
	sdcard->write((uint8_t* )TEST_STRING, sizeof(TEST_STRING) - 1);
}
