-
Notifications
You must be signed in to change notification settings - Fork 20
/
limit_number.h
75 lines (63 loc) · 2.07 KB
/
limit_number.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once
#include "esphome/components/number/number.h"
#include "esphome/core/preferences.h"
#include "esphome/core/component.h"
#include "LD2450.h"
namespace esphome::ld2450
{
/**
* Enum which determines which property this number component affects.
*/
enum LimitType
{
MAX_DISTANCE,
MAX_TILT_ANGLE,
MIN_TILT_ANGLE,
};
/**
* User controlled number component which updates a limitation property on it's parent.
*/
class LimitNumber : public number::Number, public Component, public Parented<LD2450>
{
public:
void setup() override;
/**
* @brief Sets the initial value of this number.
* @param value new value
*/
void set_initial_state(float value)
{
initial_value_ = value;
}
/**
* @brief Sets which property is affected by this number component
* @param type new type
*/
void set_type(LimitType type)
{
type_ = type;
}
/**
* @brief Sets the restore flag. If set to true, this component will attempt to restore the value instead of using the initial value.
* @param restore_value new value
*/
void set_restore(bool restore_value)
{
restore_value_ = restore_value;
}
protected:
/**
* @brief Action performed when a new value is available. Forwards the value to the parent component. Updates preferences if required.
* @param value new limitation value
*/
void control(float value) override;
/// @brief Determines which property is affected by this component
LimitType type_ = MAX_DISTANCE;
/// @brief Initial value of this number component
float initial_value_ = 6.0f;
/// @brief Value restore flag. If set to true, the initial value will be restored from memory.
bool restore_value_ = true;
/// @brief Preference management reference
ESPPreferenceObject pref_;
};
} // namespace esphome::ld2450