blob: 78ba2d4d5ae6afd3a7aaa32dde30a3c20f719ace [file] [log] [blame]
// 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.
#include "driver/src/backlight_manager.h"
#include <lib/driver/logging/cpp/structured_logger.h>
namespace backlight_driver {
zx::result<> BacklightManager::SetBacklight(uint64_t value) {
fidl::Arena arena;
auto input = fuchsia_hardware_acpi::wire::Object::WithIntegerVal(arena, value);
auto result = acpi_device_client_->EvaluateObject(
fidl::StringView::FromExternal(kLedWrite),
fuchsia_hardware_acpi::EvaluateObjectMode::kPlainObject,
fidl::VectorView<fuchsia_hardware_acpi::wire::Object>::FromExternal(&input, 1));
if (!result.ok()) {
return zx::error(result.status());
}
if (result->is_error()) {
FDF_SLOG(ERROR, "EvaluateObject error.",
KV("acpi_status", fidl::ToUnderlying(result->error_value())));
return zx::error(ZX_ERR_INTERNAL);
}
return zx::ok();
}
zx::result<uint64_t> BacklightManager::GetBacklight() {
auto result =
acpi_device_client_->EvaluateObject(fidl::StringView::FromExternal(kLedRead),
fuchsia_hardware_acpi::EvaluateObjectMode::kPlainObject,
fidl::VectorView<fuchsia_hardware_acpi::wire::Object>());
if (!result.ok()) {
return zx::error(result.status());
}
if (result->is_error()) {
FDF_SLOG(ERROR, "EvaluateObject error.",
KV("acpi_status", fidl::ToUnderlying(result->error_value())));
return zx::error(ZX_ERR_INTERNAL);
}
fuchsia_hardware_acpi::wire::DeviceEvaluateObjectResponse& backlight = *result->value();
if (!backlight.result.has_value()) {
return zx::error(ZX_ERR_INVALID_ARGS);
}
fuchsia_hardware_acpi::wire::EncodedObject& encoded = backlight.result.value();
if (!encoded.is_object()) {
return zx::error(ZX_ERR_INVALID_ARGS);
}
if (!encoded.object().is_integer_val()) {
return zx::error(ZX_ERR_INVALID_ARGS);
}
return zx::ok(encoded.object().integer_val());
}
} // namespace backlight_driver