#include "Thermistor.h"

Thermistor::Thermistor(AnalogIn inputChanel, double a, double b, double c):input(inputChanel), error(0){
    this->a = a;    
    this->b = b;
    this->c = c;
}

double Thermistor::getTemperature(){
    double temp;
    double realV;
    double resistance;
        //3.3 - ADC maximum
    realV = input.read()*3.3;
    resistance = (10000 * 5.0) / realV - 10000;
        //Considering the error
    resistance -= error;
        //Calculations using Steinhart–Hart equation
    temp = log(resistance);
    temp = 1/(a+b*temp+c*temp*temp*temp);
        //Convert from Fahrenheit to Celsius
    temp -= 273.15;
    return temp;
}
    
    void Thermistor::setError(double error){
        this->error = error;
    }
    
    double Thermistor::getError(){
        return error;
    }
    
    void Thermistor::setCoefficientA(double a){
        this->a = a;
    }
    
    void Thermistor::setCoefficientB(double b){
        this->b = b;
    }

    void Thermistor::setCoefficientC(double c){
        this->c = c;
    }
    
    double Thermistor::getCoefficientA(){
        return a;
    }
    
    double Thermistor::getCoefficientB(){
        return b;
    }
    
    double Thermistor::getCoefficientC(){
        return c;
    }