-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleOnOff.hpp
More file actions
89 lines (65 loc) · 2.08 KB
/
Copy pathsimpleOnOff.hpp
File metadata and controls
89 lines (65 loc) · 2.08 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef TMP_SIMPLE_ON_OFF_HPP
#define TMP_SIMPLE_ON_OFF_HPP
// ----------------------------------------------------------------------------------------------------
#include "simplePin.hpp"
#include <stdint.h>
// ----------------------------------------------------------------------------------------------------
namespace SimpleOnOffProperties
{
enum State
{
On,
Off
};
} // namespace SimpleOnOffProperties
// ----------------------------------------------------------------------------------------------------
/**
* @brief SimpleOnOffRead interpretes simplePin values for on-/off-behaviour - readonly.
*/
template <typename SimplePinRead_,
SimplePin::State OnState_>
class SimpleOnOffRead
{
public:
typedef SimplePinRead_ Pin;
// static Pin::State constexpr OnState = OnState_;
static void initialize()
{
SimplePinRead_::initialize();
}
static void deinitialize()
{
SimplePinRead_::deinitialize();
}
static SimpleOnOffProperties::State get()
{
return (OnState_ == SimplePinRead_::get()) ? SimpleOnOffProperties::State::On : SimpleOnOffProperties::State::Off;
}
private:
SimpleOnOffRead() = delete;
};
// ----------------------------------------------------------------------------------------------------
/**
* @brief SimpleOnOff interpretes simplePin values for on-/off-behaviour.
*/
template <typename SimplePin_,
SimplePin::State OnState_>
class SimpleOnOff : public SimpleOnOffRead<SimplePin_, OnState_>
{
public:
typedef SimplePin_ Pin;
// static Pin::State constexpr OnState = OnState_;
typedef SimpleOnOffRead<SimplePin_, OnState_> Base;
static void set(typename SimpleOnOffProperties::State const state)
{
SimplePin_::set( (SimpleOnOffProperties::State::On == state) ? OnState_ : SimplePin::other<OnState_>());
}
static void toggle()
{
SimplePin_::toggle();
}
private:
SimpleOnOff() = delete;
};
// ----------------------------------------------------------------------------------------------------
#endif // TMP_SIMPLE_ON_OFF_HPP