 // This reads a magnetic door sensor. At least with this style
 // the sensor is normally open and the circuit closes when the
 // two sensors are next to each other.
+//
+// Connect one wire to digital and other to ground
+//
+// TEMP421 code thanks to http://ka1kjz.com (my bookmark no longer points to the source
+// posting though, should still be on there somewhere
+// TEMP421 pinout (pins are counted if sensor is on right):
+// D - pin3
+// G - pin1
+// + - pin2
+// A - pin4
 
-// Connect one wire to digital and other to ground
 
 #include <JeeLib.h>
 

int batt_loop_count = 99;      // Make high so we get data first time
int has_lowbat = false;        // Start out assuming it's fine

// Basic macro for debugging
// Ideally change this to a function once I figure out how to accept anything
#ifdef DEBUG
  #define DEBUG_PRINT(x) Serial.println(x)
#else
  #define DEBUG_PRINT(x)
#endif


// TEMP421 code thanks to http://ka1kjz.com (my bookmark no longer points to the source
// posting though, should still be on there somewhere
// TEMP421 pinout (pins are counted if sensor is on right):
// D - pin3
// G - pin1
// + - pin2
// A - pin4

// Secong parameter that's commented out is the rate of communication
// Can be KHZMAX (default), KHZ400, or KHZ100
PortI2C temp_port1 (1 /*, PortI2C::KHZ400 */);
DeviceI2C temp_dev1 (temp_port1, 0x2A);  // I2C Address of 0x2A


// Currently just have sensor connected to port 4
//int DIO1 = 1 + DIO_OFFSET;

const int DIO4 = 4 + DIO_OFFSET;


// Print the line to serial if debug is enabled. The delay is important
void debug_print(String x) {
  if (DEBUG) {
    Serial.println(x);
    delay(100);
  }
}


// Convenience function that will take in a float and return a string
String float2str(float val, int length) {
  char strval[length];
  dtostrf(val, 0, 2, strval);
  return strval;
}


// Returns the temperature of tempdev where tempdev is a DeviceI2C object
float get_temperature(DeviceI2C tempdev) {
  int temp_lo = 0;
  int temp_high = 0;
  float tempc = 0;
