#include "MAX6675.h"

Thermo::Thermo(SPI* dev=0, PinName p=D0){
    device = dev;
    cs = new DigitalOut(p); 
    cs->write(OFF);
}

Thermo::~Thermo(){
    cs->write(OFF);
    device->unlock();
}

char Thermo::readTemp(float* temp){
    uint16_t data,t,s;
    readRaw(&data);
    t=(data & 0x7FF8)>>3;
    s=(data & 0x0004)>>2;
    *temp=t*0.25;
    return s;
}

void Thermo::readRaw(uint16_t* data){
    uint16_t d;
    cs->write(ON);
    device->lock();
    d=device->write(0x0000);
    device->unlock();
    cs->write(OFF);
    *data = d;
}
