| Alexander Hansen | 46a755f | 2025-10-27 16:31:08 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright 2017 Google Inc |
| Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 3 | |
| Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 4 | #include "sysfs/sysfsread.hpp" |
| 5 | |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 6 | #include "interfaces.hpp" |
| 7 | |
| Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 8 | #include <chrono> |
| Ed Tanous | f8b6e55 | 2025-06-27 13:27:50 -0700 | [diff] [blame] | 9 | #include <cstdint> |
| Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 10 | #include <fstream> |
| 11 | #include <iostream> |
| 12 | |
| Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 13 | namespace pid_control |
| 14 | { |
| 15 | |
| Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 16 | ReadReturn SysFsRead::read(void) |
| 17 | { |
| 18 | int64_t value; |
| 19 | std::ifstream ifs; |
| 20 | |
| 21 | ifs.open(_path); |
| 22 | ifs >> value; |
| 23 | ifs.close(); |
| 24 | |
| Patrick Venture | 1df9e87 | 2020-10-08 15:35:01 -0700 | [diff] [blame] | 25 | ReadReturn r = {static_cast<double>(value), |
| 26 | std::chrono::high_resolution_clock::now()}; |
| Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 27 | |
| 28 | return r; |
| 29 | } |
| Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 30 | |
| 31 | } // namespace pid_control |