# Serial Flux Python example: Custom CSV data logger
#
# Demonstrates writing measurements or parsed communication data
# to a CSV file using Python's built-in csv module.

import csv
import datetime
import time

filename = "serial_flux_measurements.csv"

with open(filename, "w", newline="") as f:
    writer = csv.writer(f)
    writer.writerow(["Timestamp", "Sample", "Value"])

    for sample in range(20):
        # Replace this demonstration value with data obtained from
        # your Serial Flux communication/test logic.
        value = sample * 0.125
        timestamp = datetime.datetime.now().isoformat(timespec="milliseconds")
        writer.writerow([timestamp, sample, value])
        print(timestamp, value)
        time.sleep(0.1)

print(f"Saved {filename}")
