// DS1822.c
// STUB

#include "DS1822.h"

static int index = 0;

UInt8 msb_values [] = {
  0x05, 
  0x01,
  0x00,
  0x00,
  0x00,
  0xFF,
  0xFF,
  0xFE,
  0xFC,
  0xFF
};

UInt8 lsb_values [] = {
  0x50, 
  0x91,
  0xA2,
  0x08,
  0x00,
  0xF8,
  0x5E,
  0x6F,
  0x90,
  0xFF
};

UInt8 GetLsb () { 
  if (index > 9) return 0xFF;
  return lsb_values[index];
}
UInt8 GetMsb () {
  UInt8 value;
  if (index > 9) return 0xFF;
  
  value = msb_values[index];
  index++;
  return value;
}

// Return value :
// 0 : Failed
// 1 : Conversion started
UInt8 DS1822_StartConversion () {
  return 1;
}

UInt8 DS1822_ReadTemperature(UInt8 *lsb, UInt8 *msb) {
  static UInt16 tmp = 0xFE70;

  //*lsb = GetLsb ();
  //*msb = GetMsb ();
  *lsb = tmp & 0xFF;
  *msb = ( tmp >> 8) & 0xFF;
  tmp+=0x0008;
  return 1; // Valid
}

// Return value :
// 0 : Failed
// 1 : Conversion started
UInt8 DS1822_Init (UInt8 mode) {
  index = 0;
  return 1;
}


// End of file
