blob: 0a0ad0ef5214c618cf2ec79a49f045ccf42e5ff7 [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 SensorKind kind,
28 Delegate* delegate);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090029 Configuration(const Configuration&) = delete;
30 Configuration& operator=(const Configuration&) = delete;
Enrico Granata60b1cbc2019-05-20 11:06:46 -070031
32 bool Configure();
33
34 private:
35 bool ConfigGyro();
Enrico Granata7a622342019-05-21 11:10:59 -070036 bool ConfigAccelerometer();
Enrico Granata651d2572019-07-16 15:17:01 -070037 bool ConfigIlluminance();
Enrico Granata60b1cbc2019-05-20 11:06:46 -070038
Enrico Granata651d2572019-07-16 15:17:01 -070039 bool CopyImuCalibationFromVpd(int max_value);
Tom Hughes09483d12020-08-27 15:55:08 -070040 bool CopyImuCalibationFromVpd(int max_value, const std::string& location);
Enrico Granata651d2572019-07-16 15:17:01 -070041
42 bool CopyLightCalibrationFromVpd();
Enrico Granata60b1cbc2019-05-20 11:06:46 -070043
Gwendal Grignou1a663372020-01-24 09:36:49 -080044 bool AddSysfsTrigger(int sysfs_trigger_id);
Enrico Granata10e19de2019-05-21 14:17:36 -070045
Enrico Granata064a25c2019-07-15 15:48:03 -070046 bool EnableAccelScanElements();
47
48 bool EnableBuffer();
49
Enrico Granatafc2e3472019-07-16 11:23:25 -070050 bool EnableKeyboardAngle();
51
Gwendal Grignou7397fe72019-11-18 10:03:59 -080052 bool EnableCalibration(bool enable);
53
Harvey Yang34f464c2020-01-08 17:43:46 +080054 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 Granata60b1cbc2019-05-20 11:06:46 -070059 Delegate* delegate_; // non-owned
60 SensorKind kind_;
Tom Hughes09483d12020-08-27 15:55:08 -070061 libmems::IioDevice* sensor_; // non-owned
Gwendal Grignouba911fe2019-12-08 17:14:53 -080062 libmems::IioContext* context_; // non-owned
Enrico Granata60b1cbc2019-05-20 11:06:46 -070063
Harvey Yang34f464c2020-01-08 17:43:46 +080064 base::Optional<gid_t> iioservice_gid_ = base::nullopt;
Enrico Granata60b1cbc2019-05-20 11:06:46 -070065};
66
67} // namespace mems_setup
68
69#endif // MEMS_SETUP_CONFIGURATION_H_