From 07eeac0c9fc1d48bc0f73dfe2f58ab80f83d8ca0 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Sat, 24 Jun 2023 02:59:40 +0200 Subject: [PATCH] moved measure to separate file --- teng/measure.hpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 teng/measure.hpp diff --git a/teng/measure.hpp b/teng/measure.hpp new file mode 100644 index 0000000..a5948a7 --- /dev/null +++ b/teng/measure.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include "services.hpp" +#include "status.hpp" + +enum MeasurementTask { STOP_MEASURE, START_MEASURE, START_MEASURE_COUNT }; +MeasurementTask measurementTask = STOP_MEASURE; + +void measure(BLEDevice central, bool limitToCount=false) { + uint16_t interval = tengInterval.value(); + uint16_t count = tengCount.value(); + + Serial.print("Starting measurement with interval="); + Serial.print(interval, DEC); + if (limitToCount) { + Serial.print(", count="); + Serial.print(count, DEC); + } + Serial.println(""); + + uint16_t i = 0; + setStatus(DeviceStatus::MEASURING); + while (central.connected() && (!limitToCount || i < count) && measurementTask != STOP_MEASURE) { + uint16_t val = static_cast(analogRead(PIN_TENG)); + Serial.println(val, DEC); + tengReading.writeValue(val); + /* Serial.println(val, DEC); */ + delay(interval); + i++; + central.poll(); + } + measurementTask = STOP_MEASURE; + setStatus(DeviceStatus::CONNECTED); +}