| // Copyright 2022 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef FUCHSIA_DRIVERS_MISC_GOOGLE_BACKLIGHT_SRC_BACKLIGHT_DRIVER_H_ |
| #define FUCHSIA_DRIVERS_MISC_GOOGLE_BACKLIGHT_SRC_BACKLIGHT_DRIVER_H_ |
| |
| #include <lib/driver/component/cpp/driver_cpp.h> |
| |
| #include "driver/src/backlight_manager.h" |
| |
| namespace backlight_driver { |
| constexpr uint64_t kMaxBacklight = 100; |
| |
| // Animation starts with the maximum backlight, dims down to the minimum for a bit |
| // then starts increasing brightness again to the max and repeats. |
| constexpr zx::duration kAnimationInterval = zx::msec(50); |
| constexpr std::array kAnimation = {100, 100, 100, 100, 100, 90, 80, 70, 60, 50, 40, 30, 20, 10, |
| 1, 1, 1, 1, 1, 10, 20, 30, 40, 50, 60, 70, 80, 90}; |
| |
| // Animation runs for 20 seconds. |
| const zx::duration kAnimationDuration = zx::sec(20); |
| |
| class BacklightDriver : public driver::DriverBase { |
| public: |
| BacklightDriver(driver::DriverStartArgs start_args, fdf::UnownedDispatcher driver_dispatcher) |
| : driver::DriverBase("chromeos-keyboard-led", std::move(start_args), |
| std::move(driver_dispatcher)) {} |
| |
| ~BacklightDriver() = default; |
| |
| zx::result<> Start() override; |
| |
| private: |
| // Initializes the BacklightManager. |
| zx::result<> Initialize(); |
| |
| void StartBacklightBreathing(); |
| |
| // Implements the breathing backlight. The next_index is used to index the kAnimation array. |
| // Stops after kAnimationDuration. |
| void BreathingBacklightImpl(int next_index); |
| |
| std::optional<BacklightManager> backlight_manager_; |
| zx::time breathing_start; |
| }; |
| |
| } // namespace backlight_driver |
| |
| FUCHSIA_DRIVER_RECORD_CPP_V2(driver::Record<backlight_driver::BacklightDriver>); |
| |
| #endif // FUCHSIA_DRIVERS_MISC_GOOGLE_BACKLIGHT_SRC_BACKLIGHT_DRIVER_H_ |