1 //-----------------------------------------------------------------------------
2 //
3 // BasicWindowCovering.cpp
4 //
5 // Implementation of the Z-Wave COMMAND_CLASS_BASIC_WINDOW_COVERING
6 //
7 // Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27
28 #include "command_classes/CommandClasses.h"
29 #include "command_classes/BasicWindowCovering.h"
30 #include "Defs.h"
31 #include "Msg.h"
32 #include "Driver.h"
33 #include "Node.h"
34 #include "platform/Log.h"
35 #include "value_classes/ValueButton.h"
36
37 using namespace OpenZWave;
38
39 enum BasicWindowCoveringCmd
40 {
41 BasicWindowCoveringCmd_StartLevelChange = 0x01,
42 BasicWindowCoveringCmd_StopLevelChange = 0x02
43 };
44
45 enum
46 {
47 BasicWindowCoveringIndex_Open = 0,
48 BasicWindowCoveringIndex_Close
49 };
50
51 //-----------------------------------------------------------------------------
52 // <BasicWindowCovering::SetValue>
53 // Set a value on the Z-Wave device
54 //-----------------------------------------------------------------------------
SetValue(Value const & _value)55 bool BasicWindowCovering::SetValue
56 (
57 Value const& _value
58 )
59 {
60 if( ValueID::ValueType_Button == _value.GetID().GetType() )
61 {
62 ValueButton const* button = static_cast<ValueButton const*>(&_value);
63
64 uint8 action = 0x40;
65 if( button->GetID().GetIndex() ) // Open is index zero, so non-zero is close.
66 {
67 // Close
68 action = 0;
69 }
70
71 if( button && button->IsPressed() )
72 {
73 Log::Write( LogLevel_Info, GetNodeId(), "BasicWindowCovering - Start Level Change (%s)", action ? "Open" : "Close" );
74 Msg* msg = new Msg( "BasicWindowCoveringCmd_StartLevelChange", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true );
75 msg->SetInstance( this, _value.GetID().GetInstance() );
76 msg->Append( GetNodeId() );
77 msg->Append( 3 );
78 msg->Append( GetCommandClassId() );
79 msg->Append( BasicWindowCoveringCmd_StartLevelChange );
80 msg->Append( action );
81 msg->Append( GetDriver()->GetTransmitOptions() );
82 GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
83 return true;
84 }
85 else
86 {
87 Log::Write( LogLevel_Info, GetNodeId(), "BasicWindowCovering - Stop Level Change" );
88 Msg* msg = new Msg( "BasicWindowCoveringCmd_StopLevelChange", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true );
89 msg->SetInstance( this, _value.GetID().GetInstance() );
90 msg->Append( GetNodeId() );
91 msg->Append( 2 );
92 msg->Append( GetCommandClassId() );
93 msg->Append( BasicWindowCoveringCmd_StopLevelChange );
94 msg->Append( GetDriver()->GetTransmitOptions() );
95 GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
96 return true;
97 }
98 }
99
100 return false;
101 }
102
103 //-----------------------------------------------------------------------------
104 // <BasicWindowCovering::CreateVars>
105 // Create the values managed by this command class
106 //-----------------------------------------------------------------------------
CreateVars(uint8 const _instance)107 void BasicWindowCovering::CreateVars
108 (
109 uint8 const _instance
110 )
111 {
112 if( Node* node = GetNodeUnsafe() )
113 {
114 node->CreateValueButton( ValueID::ValueGenre_User, GetCommandClassId(), _instance, BasicWindowCoveringIndex_Open, "Open", 0 );
115 node->CreateValueButton( ValueID::ValueGenre_User, GetCommandClassId(), _instance, BasicWindowCoveringIndex_Close, "Close", 0 );
116 }
117 }
118
119