#pragma once
#include <Arduino.h>

struct ActualPwm {
  uint32_t requestedHz;
  uint32_t actualHz;
  uint32_t requestedPulseNs;
  uint32_t actualPulseNs;
  float actualDutyPct;
  uint8_t bits;
};

class PwmGenerator {
 public:
  void begin();
  void configureActiveLight(bool lightOn) { activeLightOn_ = lightOn; }
  bool start(uint32_t frequencyHz, uint32_t pulseNs, ActualPwm &actual);
  // Hold the optical level selected as the active TX pulse.
  void active();
  // Hold actual optical light ON, independently of HH/HL/LH/LL.
  void lightOn();
  void stop();
  bool running() const { return running_; }
 private:
  bool running_ = false;
  bool activeLightOn_ = true;
};
