blob: 69ad8152c7f6d58dda5adfd14c455aeefe2dde7f [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001/**
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 Venture863b9242018-03-08 08:29:23 -080017#include "sysfswrite.hpp"
18
Ed Tanousf8b6e552025-06-27 13:27:50 -070019#include <cstdint>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070020#include <fstream>
21#include <iostream>
Patrick Venture863b9242018-03-08 08:29:23 -080022
Patrick Venturea0764872020-08-08 07:48:43 -070023namespace pid_control
24{
25
Patrick Venture863b9242018-03-08 08:29:23 -080026void SysFsWritePercent::write(double value)
27{
Patrick Venture5f59c0f2018-11-11 12:55:14 -080028 double minimum = getMin();
29 double maximum = getMax();
Patrick Venture863b9242018-03-08 08:29:23 -080030
Patrick Venture5f59c0f2018-11-11 12:55:14 -080031 double range = maximum - minimum;
32 double offset = range * value;
33 double ovalue = offset + minimum;
Patrick Venture863b9242018-03-08 08:29:23 -080034
35 std::ofstream ofs;
Patrick Venturea1c5d372019-02-11 10:03:35 -080036 ofs.open(_writePath);
Patrick Venture863b9242018-03-08 08:29:23 -080037 ofs << static_cast<int64_t>(ovalue);
38 ofs.close();
39
40 return;
41}
42
43void SysFsWrite::write(double value)
44{
45 std::ofstream ofs;
Patrick Venturea1c5d372019-02-11 10:03:35 -080046 ofs.open(_writePath);
Patrick Venture863b9242018-03-08 08:29:23 -080047 ofs << static_cast<int64_t>(value);
48 ofs.close();
49
50 return;
51}
Patrick Venturea0764872020-08-08 07:48:43 -070052
53} // namespace pid_control