LCOV - code coverage report
Current view: top level - src - DirectInputFFB.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 2 2
Test Date: 2026-03-01 21:30:38 Functions: 100.0 % 2 2
Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : #ifndef DIRECTINPUTFFB_H
       2                 :             : #define DIRECTINPUTFFB_H
       3                 :             : 
       4                 :             : #include <vector>
       5                 :             : #include <string>
       6                 :             : #include <atomic>
       7                 :             : 
       8                 :             : #ifdef _WIN32
       9                 :             : #ifndef DIRECTINPUT_VERSION
      10                 :             : #define DIRECTINPUT_VERSION 0x0800
      11                 :             : #endif
      12                 :             : #include <dinput.h>
      13                 :             : #pragma comment(lib, "dinput8.lib")
      14                 :             : #pragma comment(lib, "dxguid.lib")
      15                 :             : #else
      16                 :             : #include "lmu_sm_interface/LinuxMock.h"
      17                 :             : // Mock types for non-Windows build/test
      18                 :             : typedef void* LPDIRECTINPUT8;
      19                 :             : typedef void* LPDIRECTINPUTDEVICE8;
      20                 :             : typedef void* LPDIRECTINPUTEFFECT;
      21                 :             : #endif
      22                 :             : 
      23                 :             : struct DeviceInfo {
      24                 :             :     GUID guid;
      25                 :             :     std::string name;
      26                 :             : };
      27                 :             : 
      28                 :             : class DirectInputFFB {
      29                 :             : public:
      30                 :             :     static DirectInputFFB& Get();
      31                 :             : 
      32                 :             :     bool Initialize(HWND hwnd);
      33                 :             :     void Shutdown();
      34                 :             : 
      35                 :             :     // Returns a list of FFB-capable devices
      36                 :             :     std::vector<DeviceInfo> EnumerateDevices();
      37                 :             : 
      38                 :             :     // Select and Acquire a device
      39                 :             :     bool SelectDevice(const GUID& guid);
      40                 :             :     
      41                 :             :     // Release the currently acquired device (User unbind)
      42                 :             :     void ReleaseDevice();
      43                 :             : 
      44                 :             :     // Update the Constant Force effect (-1.0 to 1.0)
      45                 :             :     // Returns true if the hardware was actually updated (value changed)
      46                 :             :     bool UpdateForce(double normalizedForce);
      47                 :             : 
      48                 :             :     // NEW: Helpers for Config persistence
      49                 :             :     static std::string GuidToString(const GUID& guid);
      50                 :             :     static GUID StringToGuid(const std::string& str);
      51                 :             :     static std::string GetActiveWindowTitle();
      52                 :             : 
      53                 :         379 :     bool IsActive() const { return m_active; }
      54                 :             :     std::string GetCurrentDeviceName() const { return m_deviceName; }
      55                 :             :     
      56                 :             :     // Check if device was acquired in exclusive mode
      57                 :           1 :     bool IsExclusive() const { return m_isExclusive; }
      58                 :             : 
      59                 :             : private:
      60                 :             :     DirectInputFFB();
      61                 :             :     ~DirectInputFFB();
      62                 :             : 
      63                 :             :     LPDIRECTINPUT8 m_pDI = nullptr;
      64                 :             :     LPDIRECTINPUTDEVICE8 m_pDevice = nullptr;
      65                 :             :     LPDIRECTINPUTEFFECT m_pEffect = nullptr;
      66                 :             :     HWND m_hwnd = nullptr;
      67                 :             :     
      68                 :             :     bool m_active = false;
      69                 :             :     bool m_isExclusive = false; // Track acquisition mode
      70                 :             :     std::string m_deviceName = "None";
      71                 :             :     
      72                 :             :     // Internal helper to create the Constant Force effect
      73                 :             :     bool CreateEffect();
      74                 :             : 
      75                 :             :     long m_last_force = -999999; 
      76                 :             : };
      77                 :             : 
      78                 :             : #endif // DIRECTINPUTFFB_H
        

Generated by: LCOV version 2.0-1