File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
plant-care-better/sensors/include/sensors Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 55#ifndef SOLID_MOISTURESENSOR_H
66#define SOLID_MOISTURESENSOR_H
77
8+ #include < chrono>
9+ #include < mutex>
10+ #include < set>
11+
12+ #include " caretaker/WaterDevice.h"
13+
14+ namespace sensors
15+ {
16+ class MoistureSensor
17+ {
18+ const std::chrono::seconds sleepTime;
19+ std::mutex mtx;
20+ std::set<interfaces::WaterDevice *> devices;
21+
22+ const int min = 0 ;
23+ const int max = 10 ;
24+ const int threshold = 3 ;
25+
26+ public:
27+ MoistureSensor (const std::chrono::seconds, std::mutex);
28+ void subscribe (interfaces::WaterDevice &);
29+ void operator ()();
30+
31+ private:
32+ bool isAirTooDry ();
33+ bool isSoilTooDry ();
34+ int getAirMoisture ();
35+ int getSoilMoisture ();
36+ };
37+
38+ }
39+
840#endif // SOLID_MOISTURESENSOR_H
Original file line number Diff line number Diff line change 55#ifndef SOLID_SUNLIGHTSENSOR_H
66#define SOLID_SUNLIGHTSENSOR_H
77
8+ #include < chrono>
9+ #include < mutex>
10+ #include < optional>
11+ #include < set>
12+
13+ #include " caretaker/WindowDevice.h"
14+
15+ namespace sensors
16+ {
17+ class SunlightSensor
18+ {
19+ using TimePoint = decltype (std::chrono::system_clock::now());
20+
21+ const std::chrono::seconds sleepTime;
22+ std::mutex mtx;
23+ std::set<interfaces::WindowDevice *> device;
24+
25+ std::optional<TimePoint> sunlightOnFrom;
26+ std::optional<TimePoint> sunlightOffFrom;
27+
28+ const int threshold = 2 ;
29+ bool sensorOn = true ;
30+
31+ public:
32+ SunlightSensor (const std::chrono::seconds, std::mutex &);
33+ void subscribe (interfaces::WindowDevice &);
34+ void operator ()();
35+
36+ private:
37+ void updateState (const bool );
38+ bool isTooMuchSunlight (const bool );
39+ bool isTooLittleSunlight (const bool );
40+ bool isSunlight () const ;
41+ };
42+ }
43+
844#endif // SOLID_SUNLIGHTSENSOR_H
You can’t perform that action at this time.
0 commit comments