#pragma once
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

class Display {
 public:
  Display();
  bool begin();
  void show(const char *line1, const char *line2,
            uint32_t progress = 0, uint32_t progressTotal = 0,
            const char *topRight = nullptr);
  void setPower(bool enabled);
  bool available() const { return ok_; }
  bool powered() const { return powered_; }
  static void formatFrequency(float hz, char *out, size_t size);
  static void formatTestFrequency(uint32_t hz, char *out, size_t size);
  static void formatPwmFrequency(uint32_t hz, char *out, size_t size);
  static void formatPulse(uint32_t pulseNs, char *out, size_t size, bool measured = false);
  static void formatDuration(uint64_t us, char *out, size_t size);
 private:
  void drawTextLine(const char *text, int16_t y, int16_t startX = 0);
  Adafruit_SSD1306 oled_;
  bool ok_ = false;
  bool powered_ = false;
};
