From ed0bbc22681681a16b7d45b05133c38a0b82006f Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Mon, 29 Mar 2021 18:01:20 -0400 Subject: formatting + file renames --- common/rawaccel-io.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 703ea92..0d3ddee 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -6,7 +6,7 @@ #include #include "rawaccel-io-def.h" -#include "rawaccel-settings.h" +#include "rawaccel-base.hpp" #include "rawaccel-version.h" #include "rawaccel-error.hpp" @@ -15,7 +15,8 @@ namespace rawaccel { - void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) { + inline void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) + { HANDLE ra_handle = INVALID_HANDLE_VALUE; ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); @@ -44,19 +45,22 @@ namespace rawaccel { } } - settings read() { + inline settings read() + { settings args; io_control(RA_READ, NULL, 0, &args, sizeof(settings)); return args; } - void write(const settings& args) { + inline void write(const settings& args) + { auto in_ptr = const_cast(&args); io_control(RA_WRITE, in_ptr, sizeof(settings), NULL, 0); } - version_t get_version() { + inline version_t get_version() + { version_t ver; io_control(RA_GET_VERSION, NULL, 0, &ver, sizeof(version_t)); return ver; -- cgit v1.2.3 From fa3ebfb1eb054ba88824a908c996094bb98e85c5 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Tue, 30 Mar 2021 18:27:02 -0400 Subject: refactor lut/motivity --- common/rawaccel-io.hpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index 0d3ddee..da496fa 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -1,14 +1,15 @@ #pragma once -#include +#include "rawaccel-io-def.h" +#include "rawaccel.hpp" +#include "rawaccel-version.h" +#include "rawaccel-error.hpp" #define NOMINMAX +#define WIN32_LEAN_AND_MEAN #include -#include "rawaccel-io-def.h" -#include "rawaccel-base.hpp" -#include "rawaccel-version.h" -#include "rawaccel-error.hpp" +#include #pragma warning(push) #pragma warning(disable:4245) // int -> DWORD conversion while passing CTL_CODE @@ -45,18 +46,14 @@ namespace rawaccel { } } - inline settings read() + inline void read(io_t& args) { - settings args; - io_control(RA_READ, NULL, 0, &args, sizeof(settings)); - return args; + io_control(RA_READ, NULL, 0, &args, sizeof(io_t)); } - - inline void write(const settings& args) + inline void write(const io_t& args) { - auto in_ptr = const_cast(&args); - io_control(RA_WRITE, in_ptr, sizeof(settings), NULL, 0); + io_control(RA_WRITE, const_cast(&args), sizeof(io_t), NULL, 0); } inline version_t get_version() -- cgit v1.2.3 From 14bde56daf188bfc027dc8ead5b45ec0aa1109d6 Mon Sep 17 00:00:00 2001 From: a1xd <68629610+a1xd@users.noreply.github.com> Date: Thu, 1 Apr 2021 01:51:31 -0400 Subject: update rest grapher is still broken refactored io / error handling a bit --- common/rawaccel-io.hpp | 123 ++++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 53 deletions(-) (limited to 'common/rawaccel-io.hpp') diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp index da496fa..a80e254 100644 --- a/common/rawaccel-io.hpp +++ b/common/rawaccel-io.hpp @@ -1,67 +1,84 @@ #pragma once #include "rawaccel-io-def.h" -#include "rawaccel.hpp" #include "rawaccel-version.h" #include "rawaccel-error.hpp" - -#define NOMINMAX -#define WIN32_LEAN_AND_MEAN -#include - -#include +#include "rawaccel.hpp" #pragma warning(push) #pragma warning(disable:4245) // int -> DWORD conversion while passing CTL_CODE namespace rawaccel { - inline void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) - { - HANDLE ra_handle = INVALID_HANDLE_VALUE; - - ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); - - if (ra_handle == INVALID_HANDLE_VALUE) { - throw install_error(); - } - - DWORD dummy; - - BOOL success = DeviceIoControl( - ra_handle, - code, - in, - in_size, - out, - out_size, - &dummy, // bytes returned - NULL // overlapped structure - ); - - CloseHandle(ra_handle); - - if (!success) { - throw std::system_error(GetLastError(), std::system_category(), "DeviceIoControl failed"); - } - } - - inline void read(io_t& args) - { - io_control(RA_READ, NULL, 0, &args, sizeof(io_t)); - } - - inline void write(const io_t& args) - { - io_control(RA_WRITE, const_cast(&args), sizeof(io_t), NULL, 0); - } - - inline version_t get_version() - { - version_t ver; - io_control(RA_GET_VERSION, NULL, 0, &ver, sizeof(version_t)); - return ver; - } + inline void io_control(DWORD code, void* in, DWORD in_size, void* out, DWORD out_size) + { + HANDLE ra_handle = INVALID_HANDLE_VALUE; + + ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0); + + if (ra_handle == INVALID_HANDLE_VALUE) { + throw install_error(); + } + + DWORD dummy; + + BOOL success = DeviceIoControl( + ra_handle, + code, + in, + in_size, + out, + out_size, + &dummy, // bytes returned + NULL // overlapped structure + ); + + CloseHandle(ra_handle); + + if (!success) { + throw sys_error("DeviceIoControl failed"); + } + } + + inline void read(io_t& args) + { + io_control(RA_READ, NULL, 0, &args, sizeof(io_t)); + } + + inline void write(const io_t& args) + { + io_control(RA_WRITE, const_cast(&args), sizeof(io_t), NULL, 0); + } + + inline version_t get_version() + { + version_t v; + + try { + io_control(RA_GET_VERSION, NULL, 0, &v, sizeof(version_t)); + } + catch (const sys_error&) { + // assume request is not implemented (< 1.3) + v = { 0 }; + } + + return v; + } + + inline version_t valid_version_or_throw() + { + auto v = get_version(); + + if (v < min_driver_version) { + throw error("reinstallation required"); + } + + if (version < v) { + throw error("newer driver is installed"); + } + + return v; + } } -- cgit v1.2.3