#include "mcp3021.h"

int bsp_mcp3021_init(mcp_3021_t* dev, const char* name)
{
    if (dev)
    {
        uint8_t buff[128];
        dev->name = name;
        sprintf(buff, "%/in0_input", name);
        dev->fp_input = fopen(buff, "r");
        return 0;
    }
    return -1;
}

void bsp_mcp3021_exit(mcp_3021_t* dev)
{
    if (dev)
    {
        if (dev->fp_input) fclose(dev->fp_input);
    }
}

float bsp_mcp3021_getInput(mcp_3021_t* dev)
{
    float value=0.0f;
    if (dev)
    {
        
        fseek(dev->fp_input, 0, SEEK_SET); fscanf(dev->fp_input, "%f", &value);
    }
    return value;
}