#pragma once

#include "TempSensor.h"

#define TEMP_POSITIVE PIN_B3
#define TEMP_PIN A2

class Tmp36Sensor : public TempSensor {
    int temperature;
public:
    Tmp36Sensor(short id) :
        TempSensor(id) {
    }

    void setup() override {
        analogReference(INTERNAL);
        pinMode(TEMP_POSITIVE, OUTPUT);
        digitalWrite(TEMP_POSITIVE, LOW);
    }

    bool readTemp() override {
        digitalWrite(TEMP_POSITIVE, HIGH);
        delay(10);
        int reading = analogRead(TEMP_PIN);
        digitalWrite(TEMP_POSITIVE, LOW);

        float voltage = reading * (1100 / 1024.0);
        float temperatureC = (voltage - 500) / 10;
        temperature = roundf(temperatureC * 10);
        return true;
    }

    void sendValues(bool voltage) override {
        voltage ? sendTempAndVoltage(temperature) : sendTemp(temperature);
    }
};
