 #include "OneWire.h"
 #include "DallasTemperature.h"
 #include "TimerOne.h"
+#include "typedefs.h"
 
-// Data wire is plugged into port 2 on the Arduino
+// Data wire is plugged into port ONE_WIRE_BUS on the Arduino
 #define ONE_WIRE_BUS A0
 #define TEMPERATURE_PRECISION 12
 

float         heatTemp,        pipeTemp,        boilTemp;


void setup(void)
{
  // start serial port
  Serial.begin(57600);


  // Start up the library
  sensors.begin();

void timerIsr()
{ 
  interruptTemperature(); // get temperature data and request measure
  
  loop_water_flow(&input_heat);
  loop_water_flow(&input_pipe);
}

void loop_water_flow(flow_sensor_t* sensor_t)
{ 
   if((millis() - sensor_t->oldTime) > 1000)    // Only process counters once per second
  { 
    // Disable the interrupt while calculating flow rate and sending the value to
    // the host
    detachInterrupt(sensor_t->sensorInterrupt);
        
    // Because this loop may not complete in exactly 1 second intervals we calculate
    // the number of milliseconds that have passed since the last execution and use
    // that to scale the output. We also apply the calibrationFactor to scale the output
    // based on the number of pulses per second per units of measure (litres/minute in
    // this case) coming from the sensor.
    sensor_t->flowRate = ((1000.0 / (millis() - sensor_t->oldTime)) * sensor_t->pulseCount) / calibrationFactor;
    
    // Note the time this processing pass was executed. Note that because we've
    // disabled interrupts the millis() function won't actually be incrementing right
    // at this point, but it will still return the value it was set to just before
    // interrupts went away.
    sensor_t->oldTime = millis();
    
    // Divide the flow rate in litres/minute by 60 to determine how many litres have
    // passed through the sensor in this 1 second interval, then multiply by 1000 to
    // convert to millilitres.
    sensor_t->flowMilliLitres = (sensor_t->flowRate / 60) * 1000;
    
    // Add the millilitres passed in this second to the cumulative total
    sensor_t->totalMilliLitres += sensor_t->flowMilliLitres;
      
    unsigned int frac;
    
    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate: ");
    Serial.print(int(sensor_t->flowRate));  // Print the integer part of the variable
    Serial.print(".");             // Print the decimal point
    // Determine the fractional part. The 10 multiplier gives us 1 decimal place.
    frac = (sensor_t->flowRate - int(sensor_t->flowRate)) * 10;
    Serial.print(frac, DEC) ;      // Print the fractional part of the variable
    Serial.print("L/min");
    // Print the number of litres flowed in this second
    Serial.print("  Current Liquid Flowing: ");             // Output separator
    Serial.print(sensor_t->flowMilliLitres);
    Serial.print("mL/Sec");

    // Print the cumulative total of litres flowed since starting
    Serial.print("  Output Liquid Quantity: ");             // Output separator
    Serial.print(sensor_t->totalMilliLitres);
    Serial.println("mL"); 

    // Reset the pulse counter so we can start incrementing again
    sensor_t->pulseCount = 0;
    
    // Enable the interrupt again now that we've finished sending output
    attachInterrupt( sensor_t->sensorInterrupt, sensor_t->pulseCounter, FALLING);
  }
}

void loop(void){
  

}

/*
Interrupt Service Routine
 */
void pulseCounter_heat()
{
  // Increment the pulse counter
  input_heat.pulseCount++;
}

void pulseCounter_pipe()
{
  // Increment the pulse counter
  input_pipe.pulseCount++;
}
