#include <Arduino.h>
#include <WF100DPZ.h>

// Wire these pins to your sensor module.
static constexpr int PIN_CSB = 10;   // Chip select
static constexpr int PIN_SDA = 11;  // Shared SPI data line
static constexpr int PIN_CLK = 12;  // SPI clock

// Create one sensor object using those pins.
static WF100DPZ sensor(PIN_CSB, PIN_SDA, PIN_CLK);
static WF100DPZ::StatusCode st = WF100DPZ::StatusCode::Ok;

void setup() {
  Serial.begin(115200);
  delay(200);

  // Initialize the sensor once at startup.
  if (!sensor.begin(&st)) {
    Serial.printf("WF100DPZ init failed: %s\n", sensor.statusString(st));
    return;
  }

  const uint8_t part_id = sensor.readPartId(&st);
  Serial.println("=== WF100DPZ QuickStart ===");
  Serial.printf("PART_ID=0x%02X\n", part_id);
}

void loop() {
  // Core usage:
  // 1) Request one combined measurement
  // 2) Print temperature and pressure
  const WF100DPZ::Sample sample = sensor.readCombined(&st);
  if (st == WF100DPZ::StatusCode::Ok) {
    Serial.printf("Temperature: %.2f C | Pressure: %.3f kPa\n", sample.temp_c, sample.pressure_kpa);
  } else {
    Serial.printf("Read failed: %s\n", sensor.statusString(st));
  }

  // Optional: pressure-only measurement snippet.
  // const float pressure_kpa = sensor.readPressure(&st);
  // if (st == WF100DPZ::StatusCode::Ok) {
  //   Serial.printf("Pressure only: %.3f kPa\n", pressure_kpa);
  // }

  // Optional: temperature-only measurement snippet.
  // const float temp_c = sensor.readTemp(&st);
  // if (st == WF100DPZ::StatusCode::Ok) {
  //   Serial.printf("Temperature only: %.2f C\n", temp_c);
  // }

  // Delay controls output/update rate.
  delay(500);
}

