blob: ce6786588a5f30fefe5490be7ef6dfe2d91f01da [file] [log] [blame]
Enrico Granata60b1cbc2019-05-20 11:06:46 -07001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef MEMS_SETUP_CONFIGURATION_H_
6#define MEMS_SETUP_CONFIGURATION_H_
7
8#include <memory>
9#include <string>
Harvey Yang34f464c2020-01-08 17:43:46 +080010#include <vector>
Enrico Granata60b1cbc2019-05-20 11:06:46 -070011
Harvey Yang34f464c2020-01-08 17:43:46 +080012#include <base/files/file_path.h>
Enrico Granata60b1cbc2019-05-20 11:06:46 -070013#include <base/macros.h>
14
Enrico Granata51cdb942019-06-18 16:40:17 -070015#include <libmems/iio_device.h>
Enrico Granata60b1cbc2019-05-20 11:06:46 -070016#include "mems_setup/delegate.h"
Enrico Granata60b1cbc2019-05-20 11:06:46 -070017#include "mems_setup/sensor_kind.h"
18
19namespace mems_setup {
20
21class Configuration {
22 public:
Harvey Yang34f464c2020-01-08 17:43:46 +080023 static const char* GetGroupNameForSysfs();
24
Gwendal Grignouba911fe2019-12-08 17:14:53 -080025 Configuration(libmems::IioContext* context,
26 libmems::IioDevice* sensor,
Enrico Granata51cdb942019-06-18 16:40:17 -070027 Delegate* delegate);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090028 Configuration(const Configuration&) = delete;
29 Configuration& operator=(const Configuration&) = delete;
Enrico Granata60b1cbc2019-05-20 11:06:46 -070030
31 bool Configure();
32
33 private:
Harvey Yangee5a26d2021-03-23 17:19:27 +080034 bool ConfigureOnKind();
35
Enrico Granata60b1cbc2019-05-20 11:06:46 -070036 bool ConfigGyro();
Enrico Granata7a622342019-05-21 11:10:59 -070037 bool ConfigAccelerometer();
Enrico Granata651d2572019-07-16 15:17:01 -070038 bool ConfigIlluminance();
Enrico Granata60b1cbc2019-05-20 11:06:46 -070039
Enrico Granata651d2572019-07-16 15:17:01 -070040 bool CopyImuCalibationFromVpd(int max_value);
Tom Hughes09483d12020-08-27 15:55:08 -070041 bool CopyImuCalibationFromVpd(int max_value, const std::string& location);
Enrico Granata651d2572019-07-16 15:17:01 -070042
43 bool CopyLightCalibrationFromVpd();
Enrico Granata60b1cbc2019-05-20 11:06:46 -070044
Gwendal Grignou1a663372020-01-24 09:36:49 -080045 bool AddSysfsTrigger(int sysfs_trigger_id);
Enrico Granata10e19de2019-05-21 14:17:36 -070046
Enrico Granata064a25c2019-07-15 15:48:03 -070047 bool EnableAccelScanElements();
48
49 bool EnableBuffer();
50
Enrico Granatafc2e3472019-07-16 11:23:25 -070051 bool EnableKeyboardAngle();
52
Gwendal Grignou7397fe72019-11-18 10:03:59 -080053 bool EnableCalibration(bool enable);
54
Harvey Yang34f464c2020-01-08 17:43:46 +080055 bool SetupPermissions();
56 std::vector<base::FilePath> EnumerateAllFiles(base::FilePath file_path);
57 bool SetReadPermissionAndOwnership(base::FilePath file_path);
58 bool SetWritePermissionAndOwnership(base::FilePath file_path);
59
Enrico Granata60b1cbc2019-05-20 11:06:46 -070060 Delegate* delegate_; // non-owned
61 SensorKind kind_;
Tom Hughes09483d12020-08-27 15:55:08 -070062 libmems::IioDevice* sensor_; // non-owned
Gwendal Grignouba911fe2019-12-08 17:14:53 -080063 libmems::IioContext* context_; // non-owned
Enrico Granata60b1cbc2019-05-20 11:06:46 -070064
Harvey Yang34f464c2020-01-08 17:43:46 +080065 base::Optional<gid_t> iioservice_gid_ = base::nullopt;
Enrico Granata60b1cbc2019-05-20 11:06:46 -070066};
67
68} // namespace mems_setup
69
70#endif // MEMS_SETUP_CONFIGURATION_H_