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 "LEDWidget.h"
24 #include <platform/CHIPDeviceLayer.h>
26 void LEDWidget::InitGpio(void)
28 // Sets gpio pin mode for ALL board Leds.
32 void LEDWidget::Init(int ledNum)
34 mLastChangeTimeUS = 0;
42 void LEDWidget::Invert(void)
47 void LEDWidget::Set(bool state)
49 mLastChangeTimeUS = mBlinkOnTimeMS = mBlinkOffTimeMS = 0;
53 void LEDWidget::Blink(uint32_t changeRateMS)
55 Blink(changeRateMS, changeRateMS);
58 void LEDWidget::Blink(uint32_t onTimeMS, uint32_t offTimeMS)
60 mBlinkOnTimeMS = onTimeMS;
61 mBlinkOffTimeMS = offTimeMS;
65 void LEDWidget::Animate()
67 if (mBlinkOnTimeMS != 0 && mBlinkOffTimeMS != 0)
69 int64_t nowUS = ::chip::System::Layer::GetClock_MonotonicHiRes();
70 int64_t stateDurUS = ((mState) ? mBlinkOnTimeMS : mBlinkOffTimeMS) * 1000LL;
71 int64_t nextChangeTimeUS = mLastChangeTimeUS + stateDurUS;
73 if (nowUS > nextChangeTimeUS)
76 mLastChangeTimeUS = nowUS;
81 void LEDWidget::DoSet(bool state)
91 BSP_LedClear(mLedNum);