Repository navigation
Expand file tree
/
Copy pathBasicWindowCovering.cpp
More file actions
114 lines (105 loc) · 4.08 KB
/
Copy pathBasicWindowCovering.cpp
File metadata and controls
114 lines (105 loc) · 4.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//-----------------------------------------------------------------------------
//
// BasicWindowCovering.cpp
//
// Implementation of the Z-Wave COMMAND_CLASS_BASIC_WINDOW_COVERING
//
// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#include "command_classes/CommandClasses.h"
#include "command_classes/BasicWindowCovering.h"
#include "Defs.h"
#include "Msg.h"
#include "Driver.h"
#include "Node.h"
#include "platform/Log.h"
#include "value_classes/ValueButton.h"
namespace OpenZWave
{
namespace Internal
{
namespace CC
{
enum BasicWindowCoveringCmd
{
BasicWindowCoveringCmd_StartLevelChange = 0x01,
BasicWindowCoveringCmd_StopLevelChange = 0x02
};
//-----------------------------------------------------------------------------
// <BasicWindowCovering::SetValue>
// Set a value on the Z-Wave device
//-----------------------------------------------------------------------------
bool BasicWindowCovering::SetValue(Internal::VC::Value const& _value)
{
if (ValueID::ValueType_Button == _value.GetID().GetType())
{
Internal::VC::ValueButton const* button = static_cast<Internal::VC::ValueButton const*>(&_value);
uint8 action = 0x40;
if (button->GetID().GetIndex() == ValueID_Index_BasicWindowCovering::Close) // Open is index zero, so non-zero is close.
{
// Close
action = 0;
}
if (button && button->IsPressed())
{
Log::Write(LogLevel_Info, GetNodeId(), "BasicWindowCovering - Start Level Change (%s)", action ? "Open" : "Close");
Msg* msg = new Msg("BasicWindowCoveringCmd_StartLevelChange", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
msg->SetInstance(this, _value.GetID().GetInstance());
msg->Append(GetNodeId());
msg->Append(3);
msg->Append(GetCommandClassId());
msg->Append(BasicWindowCoveringCmd_StartLevelChange);
msg->Append(action);
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
return true;
}
else
{
Log::Write(LogLevel_Info, GetNodeId(), "BasicWindowCovering - Stop Level Change");
Msg* msg = new Msg("BasicWindowCoveringCmd_StopLevelChange", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true);
msg->SetInstance(this, _value.GetID().GetInstance());
msg->Append(GetNodeId());
msg->Append(2);
msg->Append(GetCommandClassId());
msg->Append(BasicWindowCoveringCmd_StopLevelChange);
msg->Append(GetDriver()->GetTransmitOptions());
GetDriver()->SendMsg(msg, Driver::MsgQueue_Send);
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// <BasicWindowCovering::CreateVars>
// Create the values managed by this command class
//-----------------------------------------------------------------------------
void BasicWindowCovering::CreateVars(uint8 const _instance)
{
if (Node* node = GetNodeUnsafe())
{
node->CreateValueButton(ValueID::ValueGenre_User, GetCommandClassId(), _instance, ValueID_Index_BasicWindowCovering::Open, "Open", 0);
node->CreateValueButton(ValueID::ValueGenre_User, GetCommandClassId(), _instance, ValueID_Index_BasicWindowCovering::Close, "Close", 0);
}
}
} // namespace CC
} // namespace Internal
} // namespace OpenZWave