Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 17 | #include "sysfswrite.hpp" |
| 18 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame] | 19 | #include <fstream> |
| 20 | #include <iostream> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 21 | |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 22 | namespace pid_control |
| 23 | { |
| 24 | |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 25 | void SysFsWritePercent::write(double value) |
| 26 | { |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 27 | double minimum = getMin(); |
| 28 | double maximum = getMax(); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 29 | |
Patrick Venture | 5f59c0f | 2018-11-11 12:55:14 -0800 | [diff] [blame] | 30 | double range = maximum - minimum; |
| 31 | double offset = range * value; |
| 32 | double ovalue = offset + minimum; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 33 | |
| 34 | std::ofstream ofs; |
Patrick Venture | a1c5d37 | 2019-02-11 10:03:35 -0800 | [diff] [blame] | 35 | ofs.open(_writePath); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 36 | ofs << static_cast<int64_t>(ovalue); |
| 37 | ofs.close(); |
| 38 | |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | void SysFsWrite::write(double value) |
| 43 | { |
| 44 | std::ofstream ofs; |
Patrick Venture | a1c5d37 | 2019-02-11 10:03:35 -0800 | [diff] [blame] | 45 | ofs.open(_writePath); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 46 | ofs << static_cast<int64_t>(value); |
| 47 | ofs.close(); |
| 48 | |
| 49 | return; |
| 50 | } |
Patrick Venture | a076487 | 2020-08-08 07:48:43 -0700 | [diff] [blame] | 51 | |
| 52 | } // namespace pid_control |