| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_LED_LED_SYSFS_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_LED_LED_SYSFS_H_ |
| |
| #include <cstdint> |
| #include <memory> |
| #include <string> |
| |
| #include "absl/base/thread_annotations.h" |
| #include "absl/status/status.h" |
| #include "absl/status/statusor.h" |
| #include "led_config.pb.h" |
| #include "tlbmc/hal/led/led.h" |
| #include "tlbmc/hal/sysfs/led.h" |
| |
| namespace milotic_tlbmc { |
| // LED backed by the Linux LED sysfs subsystem. |
| // |
| // Reuses the LedSysfs HAL to translate high-level LedBehavior into sysfs |
| // attribute writes: |
| // - LED_STATE_OFF: trigger="none", brightness=0. |
| // - LED_STATE_ON: trigger="none", brightness=max_brightness. |
| // - LED_STATE_BLINK: trigger="timer", delay_on/delay_off derived from the |
| // blink period and duty cycle. Blinking is handled by the |
| // kernel timer trigger, so no software timer is required. |
| // |
| // This class is thread-safe. |
| class SysfsLed : public Led { |
| public: |
| static absl::StatusOr<std::unique_ptr<SysfsLed>> Create( |
| const LedConfig& config, const LedSysfs& led_sysfs); |
| |
| protected: |
| absl::Status SetBehaviorImpl(const LedBehavior& behavior) |
| ABSL_EXCLUSIVE_LOCKS_REQUIRED(mutex_) override; |
| absl::StatusOr<LedBehavior> GetBehaviorImpl() const |
| ABSL_SHARED_LOCKS_REQUIRED(mutex_) override; |
| |
| SysfsLed(const LedConfig& config, const LedSysfs& led_sysfs, |
| uint32_t max_brightness = 255) |
| : Led(config), |
| led_sysfs_(led_sysfs), |
| sysfs_name_(config.output().sysfs_name()), |
| max_brightness_(max_brightness) {} |
| |
| private: |
| const LedSysfs& led_sysfs_; |
| const std::string sysfs_name_; |
| const uint32_t max_brightness_; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_HAL_LED_LED_SYSFS_H_ |