Set up clang format & tidy and format all the files
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
#include "P700Driver.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
namespace ptprnt::driver {
|
||||
|
||||
P700Driver::P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor,
|
||||
uint16_t usbProductId)
|
||||
P700Driver::P700Driver(std::shared_ptr<Usb> usbDriver, uint16_t usbDevVendor, uint16_t usbProductId)
|
||||
: mUsbDriver{std::move(usbDriver)},
|
||||
mUsbDev{.vendorId = usbDevVendor, .productId = usbProductId}
|
||||
|
||||
@@ -31,7 +30,7 @@ driver::info P700Driver::getInfo() {
|
||||
|
||||
bool P700Driver::open() {
|
||||
auto maybeUsbDev = mUsbDriver->open(mUsbDev);
|
||||
if(!maybeUsbDev.has_value()) {
|
||||
if (!maybeUsbDev.has_value()) {
|
||||
spdlog::error("Can't open P700 printer");
|
||||
return false;
|
||||
}
|
||||
@@ -40,7 +39,7 @@ bool P700Driver::open() {
|
||||
}
|
||||
|
||||
bool P700Driver::close() {
|
||||
if(!mUsbDriver->close(mUsbDev)) {
|
||||
if (!mUsbDriver->close(mUsbDev)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -60,15 +59,12 @@ bool P700Driver::init() {
|
||||
|
||||
// TODO: There is the possibility, that two printers with the same ID are connected
|
||||
// We have to take that into account
|
||||
auto devIt =
|
||||
std::find_if(devs.value().begin(), devs.value().end(), [=](auto dev) {
|
||||
return mUsbDev.vendorId == dev.vendorId &&
|
||||
mUsbDev.productId == dev.productId;
|
||||
});
|
||||
auto devIt = std::find_if(devs.value().begin(), devs.value().end(), [=](auto dev) {
|
||||
return mUsbDev.vendorId == dev.vendorId && mUsbDev.productId == dev.productId;
|
||||
});
|
||||
|
||||
if (devIt == devs.value().end()) {
|
||||
spdlog::error("No device with {0:04X}:{1:04X}", mUsbDev.vendorId,
|
||||
mUsbDev.productId);
|
||||
spdlog::error("No device with {0:04X}:{1:04X}", mUsbDev.vendorId, mUsbDev.productId);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
14
src/Usb.cpp
14
src/Usb.cpp
@@ -1,6 +1,7 @@
|
||||
#include "Usb.hpp"
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
@@ -27,8 +28,7 @@ std::optional<std::vector<UsbDevice>> Usb::getDevices() {
|
||||
mDevices.clear();
|
||||
|
||||
if (0 == (ret = libusb_get_device_list(NULL, &libUsbDevs))) {
|
||||
spdlog::error("Could not find any USB devices: {}",
|
||||
libusb_error_name(ret));
|
||||
spdlog::error("Could not find any USB devices: {}", libusb_error_name(ret));
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@ std::optional<std::vector<UsbDevice>> Usb::getDevices() {
|
||||
newDev.vendorId = libUsbDesc.idVendor;
|
||||
newDev.productId = libUsbDesc.idProduct;
|
||||
newDev.device = libUsbDev;
|
||||
newDev.hndl =
|
||||
nullptr; // handle is only available after we opened the dev
|
||||
newDev.hndl = nullptr; // handle is only available after we opened the dev
|
||||
mDevices.push_back(newDev);
|
||||
}
|
||||
|
||||
@@ -58,8 +57,8 @@ std::optional<UsbDevice> Usb::open(UsbDevice dev) {
|
||||
int ret = 0;
|
||||
|
||||
if ((ret = libusb_open(dev.device, &libUsbHandle) != 0)) {
|
||||
spdlog::error("Could not open device {0:04X}:{1:04X}: {2}",
|
||||
dev.vendorId, dev.productId, libusb_error_name(ret));
|
||||
spdlog::error("Could not open device {0:04X}:{1:04X}: {2}", dev.vendorId, dev.productId,
|
||||
libusb_error_name(ret));
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@@ -89,13 +88,14 @@ std::optional<UsbDevice> Usb::open(UsbDevice dev) {
|
||||
|
||||
bool Usb::close(UsbDevice dev) {
|
||||
int ret = 0;
|
||||
if(0 != (ret = libusb_release_interface(dev.hndl, 0))) {
|
||||
if (0 != (ret = libusb_release_interface(dev.hndl, 0))) {
|
||||
spdlog::error(
|
||||
"Could not close USB device {0:04X}:{1:04X}: "
|
||||
"{2}",
|
||||
dev.vendorId, dev.productId, libusb_error_name(ret));
|
||||
}
|
||||
|
||||
std::cout << "test" << std::endl;
|
||||
libusb_close(dev.hndl);
|
||||
return true;
|
||||
}
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "IPrinter.hpp"
|
||||
#include "P700Printer.hpp"
|
||||
#include "Usb.hpp"
|
||||
|
||||
#include <libusb-1.0/libusb.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
using namespace ptprnt;
|
||||
|
||||
|
Reference in New Issue
Block a user