Skip to content

Commit 552a7d4

Browse files
authored
fix: wheel protocol config (#8)
1 parent 1392671 commit 552a7d4

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

include/fffb/joy/protocol.hxx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ namespace fffb
2828

2929
constexpr uti::u32_t Logitech_VendorID { 0x0000046d } ;
3030
constexpr uti::u32_t Logitech_G923_PS_DeviceID { 0xc266046d } ;
31+
constexpr uti::u32_t Logitech_G29_PS4_DeviceID { 0xc24f046d } ;
3132

32-
constexpr uti::array< uti::u32_t, 1 > known_wheel_device_ids
33+
constexpr uti::array< uti::u32_t, 2 > known_wheel_device_ids
3334
{
3435
Logitech_G923_PS_DeviceID,
36+
Logitech_G29_PS4_DeviceID,
3537
} ;
3638

3739
////////////////////////////////////////////////////////////////////////////////
@@ -152,6 +154,8 @@ public:
152154
static constexpr report play_force ( ffb_protocol const protocol, uti::u8_t slots ) noexcept ;
153155
static constexpr report refresh_force ( ffb_protocol const protocol, force const & f ) noexcept ;
154156
static constexpr report stop_force ( ffb_protocol const protocol, uti::u8_t slots ) noexcept ;
157+
158+
static constexpr vector< report > init_sequence ( ffb_protocol const protocol, uti::u32_t device_id ) noexcept ;
155159
private:
156160
static constexpr report _constant_force ( ffb_protocol const protocol, force const & force ) noexcept ;
157161
static constexpr report _spring_force ( ffb_protocol const protocol, force const & force ) noexcept ;
@@ -328,6 +332,27 @@ constexpr report protocol::stop_force ( ffb_protocol const protocol, uti::u8_t s
328332
}
329333
}
330334

335+
constexpr vector< report > protocol::init_sequence ( ffb_protocol const protocol, uti::u32_t device_id ) noexcept
336+
{
337+
vector< report > reports ;
338+
339+
if( protocol == ffb_protocol::logitech_classic )
340+
{
341+
switch( device_id )
342+
{
343+
case Logitech_G923_PS_DeviceID:
344+
reports.push_back( { 0x30, 0xf8, 0x09, 0x05, 0x01 } ) ;
345+
break ;
346+
case Logitech_G29_PS4_DeviceID:
347+
reports.push_back( { 0x30, 0xf8, 0x09, 0x05, 0x01 } ) ;
348+
break ;
349+
default:
350+
FFFB_F_ERR_S( "protocol::init_sequence", "unknown device id" ) ;
351+
}
352+
}
353+
return reports ;
354+
}
355+
331356
constexpr report protocol::_constant_force ( ffb_protocol const protocol, force const & f ) noexcept
332357
{
333358
uti::u8_t command = f.params.slot << 4 ;

include/fffb/joy/wheel.hxx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ private:
8787

8888
constexpr bool _write_report ( report const & report , char const * scope ) const noexcept ;
8989
constexpr bool _write_reports ( vector< report > const & reports, char const * scope ) const noexcept ;
90+
91+
constexpr bool _init_protocol () const noexcept ;
9092
} ;
9193

9294
////////////////////////////////////////////////////////////////////////////////
@@ -113,20 +115,23 @@ constexpr wheel::wheel () noexcept
113115
FFFB_F_INFO_S( "wheel::ctor", "using wheel with device id 0x%.8x", device.device_id() ) ;
114116
device_ = UTI_MOVE( device ) ;
115117
protocol_ = get_supported_protocol( device_ ) ;
116-
117-
return ;
118118
}
119119
}
120120
if( device.vendor_id() == Logitech_VendorID )
121121
{
122122
FFFB_F_WARN_S( "wheel::ctor", "using unknown logitech wheel with device id 0x%.8x", device.device_id() ) ;
123123
device_ = UTI_MOVE( device ) ;
124124
protocol_ = get_supported_protocol( device_ ) ;
125-
126-
return ;
127125
}
128126
}
129-
FFFB_F_ERR_S( "wheel::ctor", "no known wheels found!" ) ;
127+
if( device_ )
128+
{
129+
_init_protocol() ;
130+
}
131+
else
132+
{
133+
FFFB_F_ERR_S( "wheel::ctor", "no known wheels found!" ) ;
134+
}
130135
}
131136

132137
////////////////////////////////////////////////////////////////////////////////
@@ -472,5 +477,16 @@ constexpr bool wheel::_write_reports ( vector< report > const & reports, [[ mayb
472477

473478
////////////////////////////////////////////////////////////////////////////////
474479

480+
constexpr bool wheel::_init_protocol () const noexcept
481+
{
482+
auto init_sequence = protocol::init_sequence( protocol_, device_.device_id() ) ;
483+
484+
if( init_sequence.empty() ) return true ;
485+
486+
return _write_reports( init_sequence, "wheel::init_sequence" ) ;
487+
}
488+
489+
////////////////////////////////////////////////////////////////////////////////
490+
475491

476492
} // namespace fffb

0 commit comments

Comments
 (0)