Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/can/can/msg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <array>
#include <concepts>
#include <cstdint>
#include <format>
#include <fmt/core.h>

namespace macfe::can {

Expand All @@ -29,20 +29,20 @@ concept TxMessage = requires(const T msg) {

} // namespace macfe::can

// Convert RawMessage to string with `std::format`
// Convert RawMessage to string with `fmt::format`
template <>
struct std::formatter<macfe::can::RawMessage> {
struct fmt::formatter<macfe::can::RawMessage> {
constexpr auto parse(auto& ctx) {
return ctx.begin();
}

template <typename FormatContext>
auto format(const macfe::can::RawMessage& msg, FormatContext& ctx) const {
std::string str = std::format("[{:02X}]", msg.id);
std::string str = fmt::format("[{:02X}]", msg.id);
for (int i = 0; i < msg.data_length; ++i) {
str += std::format(" {:02X}", msg.data[i]);
str += fmt::format(" {:02X}", msg.data[i]);
}

return std::format_to(ctx.out(), "{}", str);
return fmt::format_to(ctx.out(), "{}", str);
}
};
6 changes: 3 additions & 3 deletions lib/mcal/cli/analog_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <format>
#include <fmt/core.h>
#include <iostream>

#include "periph/analog_input.hpp"
Expand All @@ -15,11 +15,11 @@ class AnalogInput : public macfe::periph::AnalogInput {
AnalogInput(std::string name) : name_(name) {}

float ReadVoltage() override {
std::cout << std::format("Reading ADC {} ...", name_) << std::endl;
std::cout << fmt::format("Reading ADC {} ...", name_) << std::endl;
std::cout << " | Enter a voltage level: ";
float voltage;
std::cin >> voltage;
std::cout << std::format(" | Obtained value {:.3f} V", voltage)
std::cout << fmt::format(" | Obtained value {:.3f} V", voltage)
<< std::endl;
return voltage;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/mcal/cli/analog_output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <format>
#include <fmt/core.h>
#include <iostream>
#include <string>

Expand All @@ -16,7 +16,7 @@ class AnalogOutput : public macfe::periph::AnalogOutput {
AnalogOutput(std::string name) : name_(name) {}

void SetVoltage(float voltage) override {
std::cout << std::format("Setting AnalogOutput {} to {:.3f} V", name_,
std::cout << fmt::format("Setting AnalogOutput {} to {:.3f} V", name_,
voltage)
<< std::endl;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/mcal/cli/can.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <chrono>
#include <cstring>
#include <format>
#include <fmt/core.h>
#include <iostream>

#include "can/msg.hpp"
Expand All @@ -20,11 +20,11 @@ class CanBase : public macfe::periph::CanBase {
CanBase(std::string can_iface) : iface_(can_iface) {};

void Setup() {
std::cout << std::format("can interface: {}", iface_) << std::endl;
std::cout << fmt::format("can interface: {}", iface_) << std::endl;
}

void Send(const macfe::can::RawMessage& msg) override {
std::cout << std::format("CanBase {}: Sending\n| {}", iface_, msg)
std::cout << fmt::format("CanBase {}: Sending\n| {}", iface_, msg)
<< std::endl;
}

Expand Down
8 changes: 4 additions & 4 deletions lib/mcal/cli/gpio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <format>
#include <fmt/core.h>
#include <iostream>
#include <string>

Expand All @@ -20,10 +20,10 @@ class DigitalInput : public macfe::periph::DigitalInput {

bool Read() override {
int value;
std::cout << std::format("Reading DigitalInput {}", name_) << std::endl;
std::cout << fmt::format("Reading DigitalInput {}", name_) << std::endl;
std::cout << " | Enter 0 for False, 1 for True: ";
std::cin >> value;
std::cout << std::format(" | Value was {}", value) << std::endl;
std::cout << fmt::format(" | Value was {}", value) << std::endl;
return value;
}
};
Expand All @@ -36,7 +36,7 @@ class DigitalOutput : public macfe::periph::DigitalOutput {
DigitalOutput(std::string name) : name_(name) {}

void Set(bool value) override {
std::cout << std::format("Setting DigitalOutput Channel {} to {}",
std::cout << fmt::format("Setting DigitalOutput Channel {} to {}",
name_, value)
<< std::endl;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/mcal/cli/pwm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <format>
#include <fmt/core.h>
#include <iostream>
#include <string>

Expand All @@ -17,23 +17,23 @@ class PWMOutput : public macfe::periph::PWMOutput {
PWMOutput(std::string name) : name_(name) {}

void Start() override {
std::cout << std::format("Starting PWM {}", name_) << std::endl;
std::cout << fmt::format("Starting PWM {}", name_) << std::endl;
}

void Stop() override {
std::cout << std::format("Stopping PWM {}", name_) << std::endl;
std::cout << fmt::format("Stopping PWM {}", name_) << std::endl;
}

void SetDutyCycle(float duty_cycle) override {
duty_cycle_ = etl::clamp<float>(duty_cycle, 0, 100);

std::cout << std::format("Setting PWM {} duty cycle to {:.3g}%", name_,
std::cout << fmt::format("Setting PWM {} duty cycle to {:.3g}%", name_,
duty_cycle_)
<< std::endl;
}

float GetDutyCycle() override {
std::cout << std::format("PWM {} has duty cycle {:.3g}%", name_,
std::cout << fmt::format("PWM {} has duty cycle {:.3g}%", name_,
duty_cycle_)
<< std::endl;
return duty_cycle_;
Expand All @@ -42,13 +42,13 @@ class PWMOutput : public macfe::periph::PWMOutput {
void SetFrequency(float frequency) override {
frequency_ = std::max((float)0, frequency);

std::cout << std::format("Setting PWM {} frequency to {:.3f} Hz", name_,
std::cout << fmt::format("Setting PWM {} frequency to {:.3f} Hz", name_,
frequency_)
<< std::endl;
}

float GetFrequency() override {
std::cout << std::format("PWM {} has frequency {:.3f} Hz", name_,
std::cout << fmt::format("PWM {} has frequency {:.3f} Hz", name_,
frequency_)
<< std::endl;
return frequency_;
Expand Down
6 changes: 3 additions & 3 deletions lib/mcal/linux/analog_input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

#include "analog_input.hpp"

#include <format>
#include <fmt/core.h>
#include <iostream>

namespace mcal::lnx {

AnalogInput::AnalogInput(std::string name) : name_(name) {}

float AnalogInput::ReadVoltage() {
std::cout << std::format("Reading ADC {} ...", name_) << std::endl;
std::cout << fmt::format("Reading ADC {} ...", name_) << std::endl;
std::cout << " | Enter a voltage level: ";
float voltage;
std::cin >> voltage;
std::cout << std::format(" | Obtained value {:.3f} V", voltage)
std::cout << fmt::format(" | Obtained value {:.3f} V", voltage)
<< std::endl;
return voltage;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/mcal/linux/can.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <chrono>
#include <cstring>
#include <format>
#include <fmt/core.h>
#include <iostream>
#include <thread>

Expand Down Expand Up @@ -33,7 +33,7 @@ void CanBase::Setup() {
}

void CanBase::Send(const macfe::can::RawMessage& can_tx_msg) {
std::cout << std::format("CanBase {}: Sending\n| {}", socket_.GetIface(),
std::cout << fmt::format("CanBase {}: Sending\n| {}", socket_.GetIface(),
can_tx_msg)
<< std::endl;

Expand All @@ -57,7 +57,7 @@ void CanBase::StartReading() {

if (log_rx_) {
// this can get noisy, so set `log_rx=false` to disable it
std::cout << std::format("CanBase {}: Received\n| {}",
std::cout << fmt::format("CanBase {}: Received\n| {}",
socket_.GetIface(), raw_msg)
<< std::endl;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/mcal/linux/digital_input.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "digital_input.hpp"

#include <format>
#include <fmt/core.h>
#include <iostream>
#include <string>

Expand All @@ -11,10 +11,10 @@ DigitalInput::DigitalInput(std::string name) : name_(name) {};
bool DigitalInput::Read() {
int value;

std::cout << std::format("Reading DigitalInput \"{}\"", name_) << std::endl;
std::cout << fmt::format("Reading DigitalInput \"{}\"", name_) << std::endl;
std::cout << "| Enter 0 for False, 1 for True: ";
std::cin >> value;
std::cout << std::format("| Value was {}", value ? "true" : "false")
std::cout << fmt::format("| Value was {}", value ? "true" : "false")
<< std::endl;

return value;
Expand Down
4 changes: 2 additions & 2 deletions lib/mcal/linux/digital_output.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "digital_output.hpp"

#include <format>
#include <fmt/core.h>
#include <iostream>
#include <string>

Expand All @@ -9,7 +9,7 @@ namespace mcal::lnx {
DigitalOutput::DigitalOutput(std::string name) : name_(name) {}

void DigitalOutput::Set(bool value) {
std::cout << std::format("DigitalOutput \"{}\" => {}", name_,
std::cout << fmt::format("DigitalOutput \"{}\" => {}", name_,
value ? "true" : "false")
<< std::endl;
}
Expand Down
14 changes: 7 additions & 7 deletions lib/mcal/linux/pwm_output.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "pwm_output.hpp"

#include <format>
#include <fmt/core.h>
#include <iostream>
#include <string>

Expand All @@ -11,37 +11,37 @@ namespace mcal::lnx {
PWMOutput::PWMOutput(std::string name) {}

void PWMOutput::Start() {
std::cout << std::format("Starting PWM {}", name_) << std::endl;
std::cout << fmt::format("Starting PWM {}", name_) << std::endl;
}

void PWMOutput::Stop() {
std::cout << std::format("Stopping PWM {}", name_) << std::endl;
std::cout << fmt::format("Stopping PWM {}", name_) << std::endl;
}

void PWMOutput::SetDutyCycle(float duty_cycle) {
duty_cycle = etl::clamp<float>(duty_cycle, 0, 100);

std::cout << std::format("Setting PWM {} duty cycle to {:.3g}%", name_,
std::cout << fmt::format("Setting PWM {} duty cycle to {:.3g}%", name_,
duty_cycle)
<< std::endl;
}

float PWMOutput::GetDutyCycle() {
std::cout << std::format("PWM {} has duty cycle {:.3g}%", name_, duty_)
std::cout << fmt::format("PWM {} has duty cycle {:.3g}%", name_, duty_)
<< std::endl;
return duty_;
}

void PWMOutput::SetFrequency(float frequency) {
frequency_ = std::max((float)0, frequency);

std::cout << std::format("Setting PWM {} frequency to {:.3f} Hz", name_,
std::cout << fmt::format("Setting PWM {} frequency to {:.3f} Hz", name_,
frequency_)
<< std::endl;
}

float PWMOutput::GetFrequency() {
std::cout << std::format("PWM {} has frequency {:.3f} Hz", name_,
std::cout << fmt::format("PWM {} has frequency {:.3f} Hz", name_,
frequency_)
<< std::endl;
return frequency_;
Expand Down
4 changes: 2 additions & 2 deletions lib/mcal/linux/vcan/vcan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <cstdio>
#include <cstring>
#include <format>
#include <fmt/core.h>
#include <iostream>
#include <string>

Expand All @@ -35,7 +35,7 @@ int VcanSocket::Open() {
return -1;
}

std::cout << std::format("Opened \"{}\" at index {}.\n", iface_,
std::cout << fmt::format("Opened \"{}\" at index {}.\n", iface_,
addr_.can_ifindex);

return 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/mcal/sil/can.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <chrono>
#include <cstdint>
#include <cstring>
#include <format>
#include <fmt/core.h>
#include <iostream>
#include <queue>
#include <thread>
Expand Down Expand Up @@ -44,7 +44,7 @@ class CanBase : public macfe::periph::CanBase {
// Specify the can interface
strncpy(ifreq_.ifr_name, iface_.c_str(), sizeof(ifreq_.ifr_name) - 1);

std::cout << std::format("can interface: {}", iface_) << std::endl;
std::cout << fmt::format("can interface: {}", iface_) << std::endl;

ioctl(sock_, SIOCGIFINDEX, &ifreq_);

Expand Down
Loading
Loading