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); +}