blob: db903cb3ac420a8fe58d9250581b1d6451ae3285 [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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019#include <fstream>
20#include <iostream>
Patrick Venture863b9242018-03-08 08:29:23 -080021
Patrick Venturea0764872020-08-08 07:48:43 -070022namespace pid_control
23{
24
Patrick Venture863b9242018-03-08 08:29:23 -080025void SysFsWritePercent::write(double value)
26{
Patrick Venture5f59c0f2018-11-11 12:55:14 -080027 double minimum = getMin();
28 double maximum = getMax();
Patrick Venture863b9242018-03-08 08:29:23 -080029
Patrick Venture5f59c0f2018-11-11 12:55:14 -080030 double range = maximum - minimum;
31 double offset = range * value;
32 double ovalue = offset + minimum;
Patrick Venture863b9242018-03-08 08:29:23 -080033
34 std::ofstream ofs;
Patrick Venturea1c5d372019-02-11 10:03:35 -080035 ofs.open(_writePath);
Patrick Venture863b9242018-03-08 08:29:23 -080036 ofs << static_cast<int64_t>(ovalue);
37 ofs.close();
38
39 return;
40}
41
42void SysFsWrite::write(double value)
43{
44 std::ofstream ofs;
Patrick Venturea1c5d372019-02-11 10:03:35 -080045 ofs.open(_writePath);
Patrick Venture863b9242018-03-08 08:29:23 -080046 ofs << static_cast<int64_t>(value);
47 ofs.close();
48
49 return;
50}
Patrick Venturea0764872020-08-08 07:48:43 -070051
52} // namespace pid_control