3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2019 Google LLC.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include "LightingManager.h"
24 LightingManager LightingManager::sLight;
26 int LightingManager::Init()
32 bool LightingManager::IsTurnedOn()
34 return mState == kState_On;
37 void LightingManager::SetCallbacks(LightingCallback_fn aActionInitiated_CB, LightingCallback_fn aActionCompleted_CB)
39 mActionInitiated_CB = aActionInitiated_CB;
40 mActionCompleted_CB = aActionCompleted_CB;
43 bool LightingManager::InitiateAction(Action_t aAction)
45 // TODO: this function is called InitiateAction because we want to implement some features such as ramping up here.
46 bool action_initiated = false;
52 printf("LightingManager::InitiateAction(ON_ACTION)");
55 printf("LightingManager::InitiateAction(OFF_ACTION)");
58 printf("LightingManager::InitiateAction(unknown)");
62 // Initiate On/Off Action only when the previous one is complete.
63 if (mState == kState_Off && aAction == ON_ACTION)
65 action_initiated = true;
66 new_state = kState_On;
68 else if (mState == kState_On && aAction == OFF_ACTION)
70 action_initiated = true;
71 new_state = kState_Off;
76 if (mActionInitiated_CB)
78 mActionInitiated_CB(aAction);
81 Set(new_state == kState_On);
83 if (mActionCompleted_CB)
85 mActionCompleted_CB(aAction);
89 return action_initiated;
92 void LightingManager::Set(bool aOn)