Avionics
Dropship Simulator
Joystick.h
Go to the documentation of this file.
1 #pragma once
2 
3 // have to include these in this order because bass.h refers to something that screws it up
4 #include <WinSock2.h>
5 #include <Windows.h>
6 //#include <WS2tcpip.h>
7 
8 #define DIRECTINPUT_VERSION 0x0800
9 #include <dinput.h>
10 
11 #include "Bus.h"
12 
13 namespace Devices
14 {
16  {
17  bool enable = false;
18  GUID serialno;
19  unsigned int location;
20  bool registerWithFcs = false;
21  bool registerWithFadec = false;
22 
23  struct Axis
24  {
25  int index; // x y z rx ry rz slider0 slider1
26  bool inverse = false;
27  int deadband = 0;
28  int min = -1000;
29  int max = 1000;
30  float scale = 0.001f;
31  };
32 
33  std::vector<Axis> axes;
34 
35  struct Button
36  {
37  UINT index;
38  bool onPress;
39  float durationRequired = 0.0f;
40  float durationElapsed = 0.0f;
41  bool durationTripped = false;
42  std::vector<Command> commands;
43  };
44 
45  std::vector<Button> buttons;
46  };
47 
48  class Joystick
49  {
50  private:
51  Logger* logger = nullptr;
52  JoystickConfig* config = nullptr;
53  Bus* bus = nullptr; // needs a pointer because it is two-way (digital in or sensor can add, commands removed can trigger digital out)
54 
55  DIJOYSTATE jsOld;
56  std::vector<float> axes;
57  bool acquired = false;
58 
59  LPDIRECTINPUTDEVICE8 g_pJoystick = nullptr;
60 
61  static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE* pdidInstance, VOID* pContext);
62  static BOOL CALLBACK EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE* pdidoi, VOID* pContext);
63  std::vector<GUID> guids;
64 
65  public:
66  void FrameMove(float fElapsed);
67  void Destroy();
68  void Initialize(Logger* logger, JoystickConfig* config, Bus* prmBus, LPDIRECTINPUT8 g_pDI);
69  float GetAxis(UINT);
70  bool IsActive() const;
71  bool GetButton(int) const;
72  DWORD GetPOV(int);
73  };
74 }
std::vector< Axis > axes
Definition: Joystick.h:33
JoystickConfig * config
Definition: Joystick.h:52
Definition: Logger.h:5
LPDIRECTINPUT8 g_pDI
Definition: Avionics.cpp:16
unsigned int location
Definition: Joystick.h:19
okay, the portable keyboard numbers don&#39;t work like the outside keypad because the outside keypad is ...
Definition: Analog.cpp:3
std::vector< GUID > guids
Definition: Joystick.h:63
Definition: Bus.h:12
bool GetButton(int) const
Definition: Joystick.cpp:297
DIJOYSTATE jsOld
Definition: Joystick.h:55
std::vector< Command > commands
Definition: Joystick.h:42
std::vector< float > axes
Definition: Joystick.h:56
void FrameMove(float fElapsed)
Definition: Joystick.cpp:181
static BOOL CALLBACK EnumJoysticksCallback(const DIDEVICEINSTANCE *pdidInstance, VOID *pContext)
Definition: Joystick.cpp:10
DWORD GetPOV(int)
Definition: Joystick.cpp:303
LPDIRECTINPUTDEVICE8 g_pJoystick
Definition: Joystick.h:59
void Initialize(Logger *logger, JoystickConfig *config, Bus *prmBus, LPDIRECTINPUT8 g_pDI)
Definition: Joystick.cpp:89
bool IsActive() const
Definition: Joystick.cpp:286
std::vector< Button > buttons
Definition: Joystick.h:45
Logger * logger
Definition: Joystick.h:51
float GetAxis(UINT)
Definition: Joystick.cpp:291
static BOOL CALLBACK EnumObjectsCallback(const DIDEVICEOBJECTINSTANCE *pdidoi, VOID *pContext)
Definition: Joystick.cpp:35