From f09e4ab5c8421821e80e9db1b3affcbcf5b0476e Mon Sep 17 00:00:00 2001 From: Moritz Martinius Date: Sat, 12 Nov 2022 18:37:24 +0100 Subject: [PATCH] Formatting... --- inc/IUsb.hpp | 2 +- inc/P700Driver.hpp | 7 ++++--- inc/Usb.hpp | 4 ++-- src/P700Driver.cpp | 29 ++++++++++++++++------------- src/Usb.cpp | 23 ++++++++++++----------- src/main.cpp | 8 ++------ 6 files changed, 37 insertions(+), 36 deletions(-) diff --git a/inc/IUsb.hpp b/inc/IUsb.hpp index 1c8ca92..3e0d02e 100644 --- a/inc/IUsb.hpp +++ b/inc/IUsb.hpp @@ -1,7 +1,7 @@ #include "UsbTypes.hpp" -#include #include +#include #pragma once diff --git a/inc/P700Driver.hpp b/inc/P700Driver.hpp index 2c0ed36..8cd975d 100644 --- a/inc/P700Driver.hpp +++ b/inc/P700Driver.hpp @@ -10,8 +10,9 @@ namespace ptprnt::driver { class P700Driver : public IDriver { - public: - P700Driver(std::shared_ptr usbDriver, uint16_t usbDevVendor = 0x04f9, uint16_t usbDevId = 0x2061); + public: + P700Driver(std::shared_ptr usbDriver, uint16_t usbDevVendor = 0x04f9, + uint16_t usbDevId = 0x2061); ~P700Driver() override; driver::info getInfo() override; @@ -19,7 +20,7 @@ class P700Driver : public IDriver { bool close() override; bool command() override; - private: + private: std::shared_ptr mUsbDriver{0}; UsbDevice mUsbDev{0}; diff --git a/inc/Usb.hpp b/inc/Usb.hpp index 8b72f27..4ec3074 100644 --- a/inc/Usb.hpp +++ b/inc/Usb.hpp @@ -8,13 +8,13 @@ namespace ptprnt::driver { class Usb : public IUsb { - public: + public: Usb(); ~Usb() override; std::optional> getDevices() override; - private: + private: std::vector mDevices{}; }; diff --git a/src/P700Driver.cpp b/src/P700Driver.cpp index 4d0da59..cc4046b 100644 --- a/src/P700Driver.cpp +++ b/src/P700Driver.cpp @@ -7,16 +7,16 @@ namespace ptprnt::driver { -P700Driver::P700Driver(std::shared_ptr usbDriver, uint16_t usbDevVendor, uint16_t usbProductId) - : mUsbDriver{std::move(usbDriver)} - , mUsbDev{.vendorId = usbDevVendor, .productId = usbProductId} +P700Driver::P700Driver(std::shared_ptr usbDriver, uint16_t usbDevVendor, + uint16_t usbProductId) + : mUsbDriver{std::move(usbDriver)}, + mUsbDev{.vendorId = usbDevVendor, .productId = usbProductId} { spdlog::debug("P700Driver constructing"); - if(!init()) { + if (!init()) { spdlog::error("Could not find any P700 Printers."); - } - else { + } else { spdlog::info("Found P700 Printer :-)."); } } @@ -44,17 +44,20 @@ bool P700Driver::command() { bool P700Driver::init() { auto devs = mUsbDriver->getDevices(); - if(!devs.has_value()) { + if (!devs.has_value()) { spdlog::error("No USB devices found"); return false; } - - 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); + 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); return false; } diff --git a/src/Usb.cpp b/src/Usb.cpp index 1adc5fb..a262410 100644 --- a/src/Usb.cpp +++ b/src/Usb.cpp @@ -1,9 +1,9 @@ #include "Usb.hpp" -#include -#include -#include #include +#include +#include +#include namespace ptprnt::driver { @@ -11,28 +11,29 @@ Usb::Usb() { spdlog::debug("Usb constructing"); libusb_init(NULL); } + Usb::~Usb() { spdlog::debug("Usb destructing"); } std::optional> Usb::getDevices() { - libusb_device ** devs; - libusb_device *dev; + libusb_device** devs; + libusb_device* dev; struct libusb_device_descriptor desc; - int r,i=0; + int r, i = 0; mDevices.clear(); libusb_get_device_list(NULL, &devs); - while ((dev=devs[i++]) != NULL) { + while ((dev = devs[i++]) != NULL) { UsbDevice newDev; - if ((r=libusb_get_device_descriptor(dev, &desc)) < 0) { - spdlog::error("failed to open device"); - libusb_free_device_list(devs, 1); + if ((r = libusb_get_device_descriptor(dev, &desc)) < 0) { + spdlog::error("failed to open device"); + libusb_free_device_list(devs, 1); return std::nullopt; - } + } newDev.vendorId = desc.idVendor; newDev.productId = desc.idProduct; diff --git a/src/main.cpp b/src/main.cpp index fcd7d9b..ca4dc08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,9 +11,8 @@ using namespace ptprnt; void setupLogger() { - spdlog::set_level(spdlog::level::debug); + spdlog::set_level(spdlog::level::debug); spdlog::info("Starting ptprnt {}", PROJ_VERSION); - } int main(int argc, char** argv) { @@ -21,7 +20,7 @@ int main(int argc, char** argv) { auto usb = std::make_shared(); auto maybeDevs = usb->getDevices(); - if(!maybeDevs.has_value()) { + if (!maybeDevs.has_value()) { spdlog::error("No USB devices found"); return -1; } @@ -32,6 +31,3 @@ int main(int argc, char** argv) { return 0; } - - -