| // Copyright 2024 The Pigweed Authors |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| // use this file except in compliance with the License. You may obtain a copy of |
| // the License at |
| // |
| // https://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| // License for the specific language governing permissions and limitations under |
| // the License. |
| #define PW_LOG_MODULE_NAME "BLINKY" |
| |
| #include "modules/blinky/service.h" |
| |
| #include "pw_assert/check.h" |
| |
| namespace demo { |
| |
| void BlinkyService::Init(pw::async2::Dispatcher& dispatcher, |
| pw::async2::TimeProvider<pw::chrono::SystemClock>& time, |
| pw::Allocator& allocator, |
| pw::digital_io::DigitalInOut& monochrome_led) { |
| blinky_.Init(dispatcher, time, allocator, monochrome_led); |
| // Start binking once every 1000ms. |
| PW_CHECK_OK(blinky_.Blink(/*blink_count=*/0, /*interval_ms=*/1000)); |
| } |
| |
| pw::Status BlinkyService::ToggleLed(const pw_protobuf_Empty&, |
| pw_protobuf_Empty&) { |
| blinky_.Toggle(); |
| return pw::OkStatus(); |
| } |
| |
| pw::Status BlinkyService::SetLed(const blinky_SetLedRequest& request, |
| pw_protobuf_Empty&) { |
| blinky_.SetLed(request.on); |
| return pw::OkStatus(); |
| } |
| |
| pw::Status BlinkyService::IsIdle(const pw_protobuf_Empty&, |
| blinky_BlinkIdleResponse& response) { |
| response.is_idle = blinky_.IsIdle(); |
| return pw::OkStatus(); |
| } |
| |
| pw::Status BlinkyService::Blink(const blinky_BlinkRequest& request, |
| pw_protobuf_Empty&) { |
| uint32_t interval_ms = request.interval_ms == 0 ? Blinky::kDefaultIntervalMs |
| : request.interval_ms; |
| uint32_t blink_count = request.has_blink_count ? request.blink_count : 0; |
| return blinky_.Blink(blink_count, interval_ms); |
| } |
| |
| } // namespace demo |