Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 1 | // 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 Yang | 34f464c | 2020-01-08 17:43:46 +0800 | [diff] [blame] | 10 | #include <vector> |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 11 | |
Harvey Yang | 34f464c | 2020-01-08 17:43:46 +0800 | [diff] [blame] | 12 | #include <base/files/file_path.h> |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 13 | #include <base/macros.h> |
| 14 | |
Enrico Granata | 51cdb94 | 2019-06-18 16:40:17 -0700 | [diff] [blame] | 15 | #include <libmems/iio_device.h> |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 16 | #include "mems_setup/delegate.h" |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 17 | #include "mems_setup/sensor_kind.h" |
| 18 | |
| 19 | namespace mems_setup { |
| 20 | |
| 21 | class Configuration { |
| 22 | public: |
Harvey Yang | 34f464c | 2020-01-08 17:43:46 +0800 | [diff] [blame] | 23 | static const char* GetGroupNameForSysfs(); |
| 24 | |
Gwendal Grignou | ba911fe | 2019-12-08 17:14:53 -0800 | [diff] [blame] | 25 | Configuration(libmems::IioContext* context, |
| 26 | libmems::IioDevice* sensor, |
Enrico Granata | 51cdb94 | 2019-06-18 16:40:17 -0700 | [diff] [blame] | 27 | SensorKind kind, |
| 28 | Delegate* delegate); |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame^] | 29 | Configuration(const Configuration&) = delete; |
| 30 | Configuration& operator=(const Configuration&) = delete; |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 31 | |
| 32 | bool Configure(); |
| 33 | |
| 34 | private: |
| 35 | bool ConfigGyro(); |
Enrico Granata | 7a62234 | 2019-05-21 11:10:59 -0700 | [diff] [blame] | 36 | bool ConfigAccelerometer(); |
Enrico Granata | 651d257 | 2019-07-16 15:17:01 -0700 | [diff] [blame] | 37 | bool ConfigIlluminance(); |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 38 | |
Enrico Granata | 651d257 | 2019-07-16 15:17:01 -0700 | [diff] [blame] | 39 | bool CopyImuCalibationFromVpd(int max_value); |
Tom Hughes | 09483d1 | 2020-08-27 15:55:08 -0700 | [diff] [blame] | 40 | bool CopyImuCalibationFromVpd(int max_value, const std::string& location); |
Enrico Granata | 651d257 | 2019-07-16 15:17:01 -0700 | [diff] [blame] | 41 | |
| 42 | bool CopyLightCalibrationFromVpd(); |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 43 | |
Gwendal Grignou | 1a66337 | 2020-01-24 09:36:49 -0800 | [diff] [blame] | 44 | bool AddSysfsTrigger(int sysfs_trigger_id); |
Enrico Granata | 10e19de | 2019-05-21 14:17:36 -0700 | [diff] [blame] | 45 | |
Enrico Granata | 064a25c | 2019-07-15 15:48:03 -0700 | [diff] [blame] | 46 | bool EnableAccelScanElements(); |
| 47 | |
| 48 | bool EnableBuffer(); |
| 49 | |
Enrico Granata | fc2e347 | 2019-07-16 11:23:25 -0700 | [diff] [blame] | 50 | bool EnableKeyboardAngle(); |
| 51 | |
Gwendal Grignou | 7397fe7 | 2019-11-18 10:03:59 -0800 | [diff] [blame] | 52 | bool EnableCalibration(bool enable); |
| 53 | |
Harvey Yang | 34f464c | 2020-01-08 17:43:46 +0800 | [diff] [blame] | 54 | bool SetupPermissions(); |
| 55 | std::vector<base::FilePath> EnumerateAllFiles(base::FilePath file_path); |
| 56 | bool SetReadPermissionAndOwnership(base::FilePath file_path); |
| 57 | bool SetWritePermissionAndOwnership(base::FilePath file_path); |
| 58 | |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 59 | Delegate* delegate_; // non-owned |
| 60 | SensorKind kind_; |
Tom Hughes | 09483d1 | 2020-08-27 15:55:08 -0700 | [diff] [blame] | 61 | libmems::IioDevice* sensor_; // non-owned |
Gwendal Grignou | ba911fe | 2019-12-08 17:14:53 -0800 | [diff] [blame] | 62 | libmems::IioContext* context_; // non-owned |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 63 | |
Harvey Yang | 34f464c | 2020-01-08 17:43:46 +0800 | [diff] [blame] | 64 | base::Optional<gid_t> iioservice_gid_ = base::nullopt; |
Enrico Granata | 60b1cbc | 2019-05-20 11:06:46 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace mems_setup |
| 68 | |
| 69 | #endif // MEMS_SETUP_CONFIGURATION_H_ |