#include "tpl5110.hpp"
#include "logger.h"

extern logging::Logger logger;

TPL5110::TPL5110(int donePin) : _donePin(donePin) {
}

void TPL5110::setup() {
    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "TPL5110", "Initializing TPL5110 timer!");
    pinMode(_donePin, OUTPUT);
    digitalWrite(_donePin, LOW);  // DONE pin starts LOW
    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "TPL5110", "TPL5110 initialized!");
}

void TPL5110::signalDone() {
    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "TPL5110", "Signaling DONE to TPL5110!");
    digitalWrite(_donePin, HIGH);
    delay(100);  // Hold HIGH for 100ms
    digitalWrite(_donePin, LOW);
    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "TPL5110", "DONE signal sent - device will sleep now");
}

void TPL5110::setActive() {
    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "TPL5110", "TPL5110 set to ACTIVE");
    digitalWrite(_donePin, LOW);
}

void TPL5110::setInactive() {
    logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "TPL5110", "TPL5110 set to INACTIVE");
    digitalWrite(_donePin, HIGH);
}
