Skip to content

Commit

Permalink
Wire up FAVHID
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Jan 3, 2024
1 parent 08ec3eb commit e12788f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
17 changes: 14 additions & 3 deletions lib/connections.cpp
Expand Up @@ -5,14 +5,16 @@
* This source code is licensed under the ISC license found in the LICENSE file
* in the root directory of this source tree.
*/
#include <cpp-remapper/connections.h>

#include <cpp-remapper/MappableFAVHIDOutput.h>
#include <cpp-remapper/MappableInput.h>
#include <cpp-remapper/MappableVJoyOutput.h>
#include <cpp-remapper/connections.h>

namespace fredemmott::inputmapping {

void operator>>(MappableInput& s, const MappableVJoyOutput& t) {
namespace detail {
template <class T>
void AssignVJoyLike(MappableInput& s, const T& t) {
s.XAxis >> t.XAxis;
s.YAxis >> t.YAxis;
s.ZAxis >> t.ZAxis;
Expand All @@ -27,5 +29,14 @@ void operator>>(MappableInput& s, const MappableVJoyOutput& t) {
s.hat(i) >> t.hat(i);
}
}
}// namespace detail

void operator>>(MappableInput& s, const MappableFAVHIDOutput& t) {
detail::AssignVJoyLike(s, t);
}

void operator>>(MappableInput& s, const MappableVJoyOutput& t) {
detail::AssignVJoyLike(s, t);
}

}// namespace fredemmott::inputmapping
11 changes: 7 additions & 4 deletions lib/include/cpp-remapper/MappableFAVHIDOutput.h
Expand Up @@ -17,10 +17,17 @@ namespace fredemmott::inputmapping {
class FAVHIDDevice;

class MappableFAVHIDOutput final : public MappableOutput {
private:
struct Impl;
// Must be initialized before the const members
std::shared_ptr<Impl> p;

public:
MappableFAVHIDOutput() = delete;
explicit MappableFAVHIDOutput(uint8_t vjoy_id);
MappableFAVHIDOutput(std::shared_ptr<FAVHIDDevice> dev);
~MappableFAVHIDOutput();

std::shared_ptr<OutputDevice> getDevice() const override;

ButtonSinkPtr button(uint8_t id) const;
Expand Down Expand Up @@ -49,9 +56,5 @@ class MappableFAVHIDOutput final : public MappableOutput {
Button127, Button128;

const HatSinkPtr Hat1, Hat2, Hat3, Hat4;

private:
struct Impl;
std::unique_ptr<Impl> p;
};
}// namespace fredemmott::inputmapping
1 change: 1 addition & 0 deletions lib/include/cpp-remapper/MappableVJoyOutput.h
Expand Up @@ -21,6 +21,7 @@ class MappableVJoyOutput final : public MappableOutput {
std::shared_ptr<VJoyDevice> mDevice;

public:
MappableVJoyOutput() = delete;
explicit MappableVJoyOutput(uint8_t vjoy_id);
MappableVJoyOutput(std::shared_ptr<VJoyDevice> dev);
~MappableVJoyOutput();
Expand Down
11 changes: 11 additions & 0 deletions lib/include/cpp-remapper/Profile.h
Expand Up @@ -134,6 +134,17 @@ auto get_devices(
get_devices(p, c, rest...));
}

template <typename... Ts>
auto get_devices(
Profile* p,
InputDeviceCollection* c,
const FAVHIDID& first,
Ts... rest) {
return std::tuple_cat(
std::make_tuple(MappableFAVHIDOutput(first.value)),
get_devices(p, c, rest...));
}

template <typename... Ts>
auto get_devices(
Profile* p,
Expand Down
2 changes: 2 additions & 0 deletions lib/include/cpp-remapper/connections.h
Expand Up @@ -18,10 +18,12 @@
namespace fredemmott::inputmapping {

class MappableInput;
class MappableFAVHIDOutput;
class MappableVJoyOutput;

/// Convenience: copy an entire input device to vjoy
void operator>>(MappableInput&, const MappableVJoyOutput&);
void operator>>(MappableInput&, const MappableFAVHIDOutput&);

/* Most of the 'how to tie stuff together' stuff works on '_ptr's, which is
* essentially 'kinda looks like a `shared_ptr<>`.
Expand Down
7 changes: 7 additions & 0 deletions tests/Profile_test.cpp
Expand Up @@ -19,6 +19,13 @@ using namespace fredemmott::inputmapping::devicedb;
static void static_test_vjoy() {
auto [p, stick, vj1] = create_profile(VPC_RIGHT_WARBRD, VJOY_1);
stick.Button1 >> vj1.Button1;
stick >> vj1;
}

static void static_test_favhid() {
auto [p, stick, fh1] = create_profile(VPC_RIGHT_WARBRD, FAVHID_1);
stick.Button1 >> fh1.Button1;
stick >> fh1;
}

static void static_test_vigem() {
Expand Down

0 comments on commit e12788f

Please sign in to comment.