#include "str_to_num.h"

uint8_t str_to_num::PH_uint(const char mesure[5])
{
    double reso=0.1;
    double num;
    uint8_t res;
    num=atof(mesure);
    if(fmod((double)num,(double)reso)>=reso*0.5) num=num-fmod(num,reso)+reso;
    else num=num-(fmod(num,reso));
    num=num*10;
    res=(uint8_t)num;
    return res;
}
int16_t str_to_num::Temp_int(const char mesure[8])
{
    double reso=0.1;
    double num;
    int16_t res;
    num=atof(mesure);
    if(fmod(num,reso)>=reso*0.5 && num>0) num=num-fmod(num,reso)+reso;
    else if(fmod(num,reso)>=reso*0.5 && num<0) num=num+fmod(num,reso)-reso;
    else if(num>0) num=num-(fmod(num,reso));
    else if(num<0) num=num+(fmod(num,reso));
    num=num*(1/reso);
    res=(int16_t)num;
    return res;
}
uint16_t str_to_num::Oxy_int(const char mesure[6]){
    double reso=0.1;
    double num;
    uint16_t res;
    num=atof(mesure);
    if(fmod(num,reso)>=reso*0.5) num=num-fmod(num,reso)+reso;
    else num=num-(fmod(num,reso));
    num=num*(1/reso);
    res=(uint16_t)num;
    return res;
}
uint16_t str_to_num::Cond_int(const char mesure[6]){
    double reso=0.1;
    double num;
    uint16_t res;
    num=atof(mesure);
    if(fmod(num,reso)>=reso*0.5) num=num-fmod(num,reso)+reso;
    else num=num-(fmod(num,reso));
    num=num*(1/reso);
    res=(uint16_t)num;
    return res;
}