blob: 40d5bd84e7e1c9e18fa2c15686820f8c257239e5 [file] [log] [blame]
Alexander Hansen46a755f2025-10-27 16:31:08 +01001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2017 Google Inc
Patrick Venture863b9242018-03-08 08:29:23 -08003
Patrick Venture863b9242018-03-08 08:29:23 -08004#include "sysfswrite.hpp"
5
Ed Tanousf8b6e552025-06-27 13:27:50 -07006#include <cstdint>
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07007#include <fstream>
8#include <iostream>
Patrick Venture863b9242018-03-08 08:29:23 -08009
Patrick Venturea0764872020-08-08 07:48:43 -070010namespace pid_control
11{
12
Patrick Venture863b9242018-03-08 08:29:23 -080013void SysFsWritePercent::write(double value)
14{
Patrick Venture5f59c0f2018-11-11 12:55:14 -080015 double minimum = getMin();
16 double maximum = getMax();
Patrick Venture863b9242018-03-08 08:29:23 -080017
Patrick Venture5f59c0f2018-11-11 12:55:14 -080018 double range = maximum - minimum;
19 double offset = range * value;
20 double ovalue = offset + minimum;
Patrick Venture863b9242018-03-08 08:29:23 -080021
22 std::ofstream ofs;
Patrick Venturea1c5d372019-02-11 10:03:35 -080023 ofs.open(_writePath);
Patrick Venture863b9242018-03-08 08:29:23 -080024 ofs << static_cast<int64_t>(ovalue);
25 ofs.close();
26
27 return;
28}
29
30void SysFsWrite::write(double value)
31{
32 std::ofstream ofs;
Patrick Venturea1c5d372019-02-11 10:03:35 -080033 ofs.open(_writePath);
Patrick Venture863b9242018-03-08 08:29:23 -080034 ofs << static_cast<int64_t>(value);
35 ofs.close();
36
37 return;
38}
Patrick Venturea0764872020-08-08 07:48:43 -070039
40} // namespace pid_control