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"
22 #include <dk_buttons_and_leds.h>
25 void LEDWidget::InitGpio()
30 void LEDWidget::Init(uint32_t gpioNum)
32 mLastChangeTimeMS = 0;
40 void LEDWidget::Invert(void)
45 void LEDWidget::Set(bool state)
47 mLastChangeTimeMS = mBlinkOnTimeMS = mBlinkOffTimeMS = 0;
51 void LEDWidget::Blink(uint32_t changeRateMS)
53 Blink(changeRateMS, changeRateMS);
56 void LEDWidget::Blink(uint32_t onTimeMS, uint32_t offTimeMS)
58 mBlinkOnTimeMS = onTimeMS;
59 mBlinkOffTimeMS = offTimeMS;
63 void LEDWidget::Animate()
65 if (mBlinkOnTimeMS != 0 && mBlinkOffTimeMS != 0)
67 int64_t nowMS = k_uptime_get();
68 int64_t stateDurMS = mState ? mBlinkOnTimeMS : mBlinkOffTimeMS;
70 if (nowMS > mLastChangeTimeMS + stateDurMS)
73 mLastChangeTimeMS = nowMS;
78 void LEDWidget::DoSet(bool state)
81 dk_set_led(mGPIONum, state);