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 
17 #include "sysfswrite.hpp"
18 
19 #include <fstream>
20 #include <iostream>
21 
22 namespace pid_control
23 {
24 
25 void SysFsWritePercent::write(double value)
26 {
27     double minimum = getMin();
28     double maximum = getMax();
29 
30     double range = maximum - minimum;
31     double offset = range * value;
32     double ovalue = offset + minimum;
33 
34     std::ofstream ofs;
35     ofs.open(_writePath);
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;
45     ofs.open(_writePath);
46     ofs << static_cast<int64_t>(value);
47     ofs.close();
48 
49     return;
50 }
51 
52 } // namespace pid_control
53