esp8266_web_settings beta
Sht31Sensor.h
1/*
2 * Copyright (c) 2021, 2022 G. R. McDorman
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#pragma once
24
25#include <SHT31.h>
26#include <Ticker.h>
27
28#include "grmcdorman/device/AbstractTemperaturePressureSensor.h"
29
30namespace grmcdorman::device
31{
39 {
40 public:
42
43 void setup() override;
44 void loop() override;
45
57 virtual String get_status() const;
58
59 private:
60 void set_timer();
61
62 SHT31 sht;
63 Ticker ticker;
64 uint32_t current_polling_seconds = 0;
65
66 uint32_t last_read_millis;
67 bool requested = false;
68 bool available = false;
69 uint32_t statusReadPreviousMillis = 0; // The time since the last read.
71 constexpr static uint32_t statusReadInterval = (30 / 5) * 1000;
72 NoteSetting title;
73 ExclusiveOptionSetting dataPin;
74 ExclusiveOptionSetting clockPin;
75 ExclusiveOptionSetting address;
76 FloatSetting temperatureOffset;
77 FloatSetting temperatureScale;
78 FloatSetting humidityOffset;
79 FloatSetting humidityScale;
80 UnsignedIntegerSetting readInterval;
81 InfoSettingHtml device_status;
82 };
83}
This is an abstract base class for temperature/pressor sensors.
Definition: AbstractTemperaturePressureSensor.h:38
This class supports the SHT31-D sensor as a device.
Definition: Sht31Sensor.h:39
void setup() override
Setup the device.
Definition: Sht31Sensor.cpp:149
virtual String get_status() const
Get a status report.
Definition: Sht31Sensor.cpp:195
void loop() override
Main loop.
Definition: Sht31Sensor.cpp:173