 }
 
 // TODO(z2amiller):  Have a maximum allowed elapsed time?
-// TODO(z2amiller):  Can't dump to serial in a library.  #ifdef debug?
 void TI128D818::pollUntilReady() {
   int delay_time = 33;
   while (true) {

#define ADC_INT 14

#define ADC_ADDR 0x37

// TODO(z2amiller):  Cut this out into a separate library.
class TI128D818 {
 public:
  TI128D818();
  TI128D818(const uint8_t add_addr);
  bool init(const uint8_t adc_mode = 0);
  float temp(const uint8_t channel = 0);
 private:
  uint8_t read8(const uint8_t addr);
  uint16_t read16(const uint8_t addr);

}

TI128D818 adc = TI128D818();
PrometheusClient prom = PrometheusClient(SERVER_IP, SERVER_PORT,
                                         "OctoTemp", "WaterHeater");

void setup(void)
{
  Serial.begin(115200);
  adc.Init(0x1);
}

float TempC(const uint8_t channel) {
  const uint16_t t = adc.RawValue(channel);
  const int measured_resistance = 10000.0 * ((4096.0 / t) - 1); 
  const float mr_log = log(measured_resistance / 10000.0);
  // Steinhart-Hart coefficients for the Vishay NTCLG100E2103.
  // (10K @ 25C thermistor)
  const float tempK = 1 / (0.003354016 +
                          (0.0002569850 * mr_log) +
                          (0.000002620131 * pow(mr_log, 2)) +
                          (0.00000006383091 * pow(mr_log, 3)));
  return tempK - 273.15; // tempC
}

float TempF(const uint8_t channel) {
  return TempC(channel) * 1.8 + 32;
}

// TODO(z2amiller):  Do something interesting with this data.
//                   Post to prometheus or MQTT or something.
void loop(void)
{
  for (int ch = 0; ch < NUM_CHANNELS; ch++) {
    prom.AddGauge("octo_sensor_tempF", TempF(ch),
                  "location=\"" + channels[ch] + "\"");
    Serial.println(channels[ch] + "(" + ch + ") = " + TempF(ch));
  }
  prom.Send();
  delay(5000);
} 
