Browse Source

device: change ControlAxis enum to an Axis enum class

rdb 7 years ago
parent
commit
7cc100c38c

+ 32 - 32
panda/src/device/evdevInputDevice.cxx

@@ -419,89 +419,89 @@ init_device() {
 
     for (int i = 0; i < num_bits; ++i) {
       if (test_bit(i, axes)) {
-        ControlAxis axis = C_none;
+        Axis axis = Axis::none;
         switch (i) {
         case ABS_X:
           if (_device_class == DC_gamepad) {
-            axis = InputDevice::C_left_x;
+            axis = InputDevice::Axis::left_x;
           } else if (_device_class == DC_flight_stick) {
-            axis = InputDevice::C_roll;
+            axis = InputDevice::Axis::roll;
           } else {
-            axis = InputDevice::C_x;
+            axis = InputDevice::Axis::x;
           }
           break;
         case ABS_Y:
           if (_device_class == DC_gamepad) {
-            axis = InputDevice::C_left_y;
+            axis = InputDevice::Axis::left_y;
           } else if (_device_class == DC_flight_stick) {
-            axis = InputDevice::C_pitch;
+            axis = InputDevice::Axis::pitch;
           } else {
-            axis = InputDevice::C_y;
+            axis = InputDevice::Axis::y;
           }
           break;
         case ABS_Z:
           if (quirks & QB_rstick_from_z) {
-            axis = InputDevice::C_right_x;
+            axis = InputDevice::Axis::right_x;
           } else if (_device_class == DC_gamepad) {
-            axis = InputDevice::C_left_trigger;
+            axis = InputDevice::Axis::left_trigger;
             have_analog_triggers = true;
           } else if (_device_class == DC_3d_mouse) {
-            axis = InputDevice::C_z;
+            axis = InputDevice::Axis::z;
           } else {
-            axis = InputDevice::C_throttle;
+            axis = InputDevice::Axis::throttle;
           }
           break;
         case ABS_RX:
           if (_device_class == DC_3d_mouse) {
-            axis = InputDevice::C_pitch;
+            axis = InputDevice::Axis::pitch;
           } else if ((quirks & QB_rstick_from_z) == 0) {
-            axis = InputDevice::C_right_x;
+            axis = InputDevice::Axis::right_x;
           }
           break;
         case ABS_RY:
           if (_device_class == DC_3d_mouse) {
-            axis = InputDevice::C_roll;
+            axis = InputDevice::Axis::roll;
           } else if ((quirks & QB_rstick_from_z) == 0) {
-            axis = InputDevice::C_right_y;
+            axis = InputDevice::Axis::right_y;
           }
           break;
         case ABS_RZ:
           if (quirks & QB_rstick_from_z) {
-            axis = InputDevice::C_right_y;
+            axis = InputDevice::Axis::right_y;
           } else if (_device_class == DC_gamepad) {
-            axis = InputDevice::C_right_trigger;
+            axis = InputDevice::Axis::right_trigger;
             have_analog_triggers = true;
           } else {
-            axis = InputDevice::C_yaw;
+            axis = InputDevice::Axis::yaw;
           }
           break;
         case ABS_THROTTLE:
           if (quirks & QB_rudder_from_throttle) {
-            axis = InputDevice::C_rudder;
+            axis = InputDevice::Axis::rudder;
           } else {
-            axis = InputDevice::C_throttle;
+            axis = InputDevice::Axis::throttle;
           }
           break;
         case ABS_RUDDER:
-          axis = InputDevice::C_rudder;
+          axis = InputDevice::Axis::rudder;
           break;
         case ABS_WHEEL:
-          axis = InputDevice::C_wheel;
+          axis = InputDevice::Axis::wheel;
           break;
         case ABS_GAS:
           if (_device_class == DC_gamepad) {
-            axis = InputDevice::C_right_trigger;
+            axis = InputDevice::Axis::right_trigger;
             have_analog_triggers = true;
           } else {
-            axis = InputDevice::C_accelerator;
+            axis = InputDevice::Axis::accelerator;
           }
           break;
         case ABS_BRAKE:
           if (_device_class == DC_gamepad) {
-            axis = InputDevice::C_left_trigger;
+            axis = InputDevice::Axis::left_trigger;
             have_analog_triggers = true;
           } else {
-            axis = InputDevice::C_brake;
+            axis = InputDevice::Axis::brake;
           }
           break;
         case ABS_HAT0X:
@@ -539,12 +539,12 @@ init_device() {
           // We'd like to reverse the Y axis to match the XInput behavior.
           // Also reverse the yaw axis to match right-hand coordinate system.
           // Also T.Flight Hotas X throttle is reversed and can go backwards.
-          if (axis == C_yaw || axis == C_rudder || axis == C_left_y || axis == C_right_y ||
-              (axis == C_throttle && (quirks & QB_reversed_throttle) != 0) ||
-              (_device_class == DC_3d_mouse && (axis == C_y || axis == C_z || axis == C_roll))) {
+          if (axis == Axis::yaw || axis == Axis::rudder || axis == Axis::left_y || axis == Axis::right_y ||
+              (axis == Axis::throttle && (quirks & QB_reversed_throttle) != 0) ||
+              (_device_class == DC_3d_mouse && (axis == Axis::y || axis == Axis::z || axis == Axis::roll))) {
             std::swap(absinfo.maximum, absinfo.minimum);
           }
-          if (axis == C_throttle && (quirks & QB_centered_throttle) != 0) {
+          if (axis == Axis::throttle && (quirks & QB_centered_throttle) != 0) {
             index = add_control(axis, absinfo.maximum, absinfo.minimum, true);
           } else {
             index = add_control(axis, absinfo.minimum, absinfo.maximum);
@@ -584,8 +584,8 @@ init_device() {
   if (_ltrigger_code >= 0 && _rtrigger_code >= 0 && !have_analog_triggers) {
     // Emulate analog triggers.
     _ltrigger_control = (int)_controls.size();
-    add_control(C_left_trigger, 0, 1, false);
-    add_control(C_right_trigger, 0, 1, false);
+    add_control(Axis::left_trigger, 0, 1, false);
+    add_control(Axis::right_trigger, 0, 1, false);
   } else {
     _ltrigger_code = -1;
     _rtrigger_code = -1;

+ 8 - 31
panda/src/device/inputDevice.I

@@ -292,14 +292,14 @@ get_num_controls() const {
 }
 
 /**
- * Associates the indicated ControlAxis with the control of the indicated index
- * number.  Pass C_none to turn off any association.
+ * Associates the indicated Axis with the control of the indicated index
+ * number.  Pass Axis::none to turn off any association.
  *
  * It is not necessary to call this if you simply want to query the state of
  * the various controls by index number.
  */
 INLINE void InputDevice::
-set_control_map(size_t index, InputDevice::ControlAxis axis) {
+set_control_map(size_t index, InputDevice::Axis axis) {
   LightMutexHolder holder(_lock);
   if (index >= _controls.size()) {
     _controls.resize(index + 1, AnalogState());
@@ -309,16 +309,16 @@ set_control_map(size_t index, InputDevice::ControlAxis axis) {
 }
 
 /**
- * Returns the ControlAxis that was previously associated with the given index
- * number by a call to set_control_map(), or C_none if no control was
+ * Returns the Axis that was previously associated with the given index
+ * number by a call to set_control_map(), or Axis::none if no control was
  * associated.
  */
-INLINE InputDevice::ControlAxis InputDevice::
+INLINE InputDevice::Axis InputDevice::
 get_control_map(size_t index) const {
   if (index < _controls.size()) {
     return _controls[index].axis;
   } else {
-    return C_none;
+    return Axis::none;
   }
 }
 
@@ -356,7 +356,7 @@ get_control(size_t index) const {
  * if the axis was not found in the list.
  */
 INLINE InputDevice::AnalogState InputDevice::
-find_control(InputDevice::ControlAxis axis) const {
+find_control(InputDevice::Axis axis) const {
   for (size_t i = 0; i < _controls.size(); ++i) {
     if (_controls[i].axis == axis) {
       return _controls[i];
@@ -444,16 +444,6 @@ operator < (const InputDevice &) const {
   return false;
 }
 
-/**
- *
- */
-INLINE InputDevice::ButtonState::
-ButtonState() :
-  handle(ButtonHandle::none()),
-  state(S_unknown)
-{
-}
-
 /**
  *
  */
@@ -463,16 +453,3 @@ ButtonState(ButtonHandle handle) :
   state(S_unknown)
 {
 }
-
-/**
- *
- */
-INLINE InputDevice::AnalogState::
-AnalogState() :
-  axis(C_none),
-  state(0.0),
-  known(false),
-  _scale(1.0),
-  _bias(0.0)
-{
-}

+ 37 - 37
panda/src/device/inputDevice.cxx

@@ -124,7 +124,7 @@ get_pointer_events() {
  * Called by the implementation to add a new known control.
  */
 int InputDevice::
-add_control(ControlAxis axis, int minimum, int maximum, bool centered) {
+add_control(Axis axis, int minimum, int maximum, bool centered) {
   AnalogState state;
   state.axis = axis;
   if (centered) {
@@ -146,20 +146,20 @@ add_control(ControlAxis axis, int minimum, int maximum, bool centered) {
  * tries to guess whether the control is centered or not.
  */
 int InputDevice::
-add_control(ControlAxis axis, int minimum, int maximum) {
+add_control(Axis axis, int minimum, int maximum) {
   bool centered = (minimum < 0)
-    || axis == C_x
-    || axis == C_y
-    || axis == C_z
-    || axis == C_yaw
-    || axis == C_pitch
-    || axis == C_roll
-    || axis == C_left_x
-    || axis == C_left_y
-    || axis == C_right_x
-    || axis == C_right_y
-    || axis == C_wheel
-    || axis == C_rudder;
+    || axis == Axis::x
+    || axis == Axis::y
+    || axis == Axis::z
+    || axis == Axis::yaw
+    || axis == Axis::pitch
+    || axis == Axis::roll
+    || axis == Axis::left_x
+    || axis == Axis::left_y
+    || axis == Axis::right_x
+    || axis == Axis::right_y
+    || axis == Axis::wheel
+    || axis == Axis::rudder;
   return add_control(axis, minimum, maximum, centered);
 }
 
@@ -287,7 +287,7 @@ set_control_state(int index, double state) {
     device_cat.spam()
       << "Changed control " << index;
 
-    if (_controls[index].axis != C_none) {
+    if (_controls[index].axis != Axis::none) {
       device_cat.spam(false) << " (" << _controls[index].axis << ")";
     }
 
@@ -315,7 +315,7 @@ control_changed(int index, int state) {
     device_cat.spam()
       << "Changed control " << index;
 
-    if (_controls[index].axis != C_none) {
+    if (_controls[index].axis != Axis::none) {
       device_cat.spam(false) << " (" << _controls[index].axis << ")";
     }
 
@@ -556,63 +556,63 @@ format_device_class(DeviceClass dc) {
  * Returns a string describing the given axis enumerant.
  */
 std::string InputDevice::
-format_axis(ControlAxis axis) {
+format_axis(Axis axis) {
   switch (axis) {
-  case InputDevice::C_none:
+  case InputDevice::Axis::none:
     return "none";
 
-  case InputDevice::C_x:
+  case InputDevice::Axis::x:
     return "x";
 
-  case InputDevice::C_y:
+  case InputDevice::Axis::y:
     return "y";
 
-  case InputDevice::C_z:
+  case InputDevice::Axis::z:
     return "z";
 
-  case InputDevice::C_yaw:
+  case InputDevice::Axis::yaw:
     return "yaw";
 
-  case InputDevice::C_pitch:
+  case InputDevice::Axis::pitch:
     return "pitch";
 
-  case InputDevice::C_roll:
+  case InputDevice::Axis::roll:
     return "roll";
 
-  case InputDevice::C_left_x:
+  case InputDevice::Axis::left_x:
     return "left_x";
 
-  case InputDevice::C_left_y:
+  case InputDevice::Axis::left_y:
     return "left_y";
 
-  case InputDevice::C_left_trigger:
+  case InputDevice::Axis::left_trigger:
     return "left_trigger";
 
-  case InputDevice::C_right_x:
+  case InputDevice::Axis::right_x:
     return "right_x";
 
-  case InputDevice::C_right_y:
+  case InputDevice::Axis::right_y:
     return "right_y";
 
-  case InputDevice::C_right_trigger:
+  case InputDevice::Axis::right_trigger:
     return "right_trigger";
 
-  //case InputDevice::C_trigger:
+  //case InputDevice::Axis::trigger:
   //  return "trigger";
 
-  case InputDevice::C_throttle:
+  case InputDevice::Axis::throttle:
     return "throttle";
 
-  case InputDevice::C_rudder:
+  case InputDevice::Axis::rudder:
     return "rudder";
 
-  case InputDevice::C_wheel:
+  case InputDevice::Axis::wheel:
     return "wheel";
 
-  case InputDevice::C_accelerator:
+  case InputDevice::Axis::accelerator:
     return "accelerator";
 
-  case InputDevice::C_brake:
+  case InputDevice::Axis::brake:
     return "brake";
   }
   return "**invalid**";
@@ -625,7 +625,7 @@ operator << (std::ostream &out, InputDevice::DeviceClass dc) {
 }
 
 std::ostream &
-operator << (std::ostream &out, InputDevice::ControlAxis axis) {
+operator << (std::ostream &out, InputDevice::Axis axis) {
   out << InputDevice::format_axis(axis);
   return out;
 }

+ 35 - 35
panda/src/device/inputDevice.h

@@ -95,35 +95,35 @@ public:
   ~InputDevice();
 
 PUBLISHED:
-  enum ControlAxis {
-    C_none,
+  enum class Axis {
+    none,
 
     // Generic translational axes
-    C_x,
-    C_y,
-    C_z,
+    x,
+    y,
+    z,
 
     // Generic rotational axes, used by joysticks and 3D mice
-    C_yaw,
-    C_pitch,
-    C_roll,
+    yaw,
+    pitch,
+    roll,
 
     // Gamepad
-    C_left_x,
-    C_left_y,
-    C_left_trigger,
-    C_right_x,
-    C_right_y,
-    C_right_trigger,
+    left_x,
+    left_y,
+    left_trigger,
+    right_x,
+    right_y,
+    right_trigger,
 
     // Flight stick specific
-    C_throttle,
-    C_rudder, // When available separately from yaw
+    throttle,
+    rudder, // When available separately from yaw
 
     // Steering wheel / pedals
-    C_wheel,
-    C_accelerator,
-    C_brake,
+    wheel,
+    accelerator,
+    brake,
   };
 
   INLINE std::string get_name() const;
@@ -172,8 +172,8 @@ PUBLISHED:
   INLINE bool is_button_known(size_t index) const;
 
   INLINE size_t get_num_controls() const;
-  INLINE void set_control_map(size_t index, ControlAxis axis);
-  INLINE ControlAxis get_control_map(size_t index) const;
+  INLINE void set_control_map(size_t index, Axis axis);
+  INLINE Axis get_control_map(size_t index) const;
   INLINE double get_control_state(size_t index) const;
   INLINE bool is_control_known(size_t index) const;
 
@@ -191,12 +191,12 @@ PUBLISHED:
 
   virtual void output(std::ostream &out) const;
   static std::string format_device_class(DeviceClass dc);
-  static std::string format_axis(ControlAxis axis);
+  static std::string format_axis(Axis axis);
 
 protected:
   // Called during the constructor to add new controls or buttons
-  int add_control(ControlAxis axis, int minimum, int maximum, bool centered);
-  int add_control(ControlAxis axis, int minimum, int maximum);
+  int add_control(Axis axis, int minimum, int maximum, bool centered);
+  int add_control(Axis axis, int minimum, int maximum);
 
   void set_pointer(bool inwin, double x, double y, double time);
   void set_pointer_out_of_window(double time);
@@ -271,28 +271,28 @@ PUBLISHED:
 
   class ButtonState {
   public:
-    INLINE ButtonState();
+    constexpr ButtonState() = default;
     INLINE ButtonState(ButtonHandle handle);
 
   PUBLISHED:
-    ButtonHandle handle;
-    State state;
+    ButtonHandle handle = ButtonHandle::none();
+    State state = S_unknown;
   };
   typedef pvector<ButtonState> Buttons;
   Buttons _buttons;
 
   class AnalogState {
   public:
-    INLINE AnalogState();
+    constexpr AnalogState() = default;
 
   PUBLISHED:
-    ControlAxis axis;
-    double state;
-    bool known;
+    Axis axis = Axis::none;
+    double state = 0.0;
+    bool known = false;
 
   public:
-    double _scale;
-    double _bias;
+    double _scale = 1.0;
+    double _bias = 0.0;
   };
   typedef pvector<AnalogState> Controls;
   Controls _controls;
@@ -307,7 +307,7 @@ PUBLISHED:
   INLINE ButtonState find_button(ButtonHandle handle) const;
 
   INLINE AnalogState get_control(size_t index) const;
-  INLINE AnalogState find_control(ControlAxis axis) const;
+  INLINE AnalogState find_control(Axis axis) const;
 
   // Make device buttons and controls iterable
   MAKE_SEQ_PROPERTY(buttons, get_num_buttons, get_button);
@@ -337,7 +337,7 @@ INLINE std::ostream &operator << (std::ostream &out, const InputDevice &device)
 }
 
 EXPCL_PANDA_DEVICE std::ostream &operator << (std::ostream &out, InputDevice::DeviceClass dc);
-EXPCL_PANDA_DEVICE std::ostream &operator << (std::ostream &out, InputDevice::ControlAxis axis);
+EXPCL_PANDA_DEVICE std::ostream &operator << (std::ostream &out, InputDevice::Axis axis);
 
 #include "inputDevice.I"
 

+ 25 - 25
panda/src/device/ioKitInputDevice.cxx

@@ -172,7 +172,7 @@ on_remove() {
 void IOKitInputDevice::
 parse_element(IOHIDElementRef element) {
   ButtonHandle handle = ButtonHandle::none();
-  ControlAxis axis = C_none;
+  Axis axis = Axis::none;
   uint32_t page = IOHIDElementGetUsagePage(element);
   uint32_t usage = IOHIDElementGetUsage(element);
 
@@ -183,60 +183,60 @@ parse_element(IOHIDElementRef element) {
       switch (usage) {
       case kHIDUsage_GD_X:
         if (_device_class == DC_gamepad) {
-          axis = C_left_x;
+          axis = Axis::left_x;
         } else if (_device_class == DC_flight_stick) {
-          axis = C_roll;
+          axis = Axis::roll;
         } else if (_device_class == DC_mouse) {
           _pointer_x = element;
           return;
         } else {
-          axis = C_x;
+          axis = Axis::x;
         }
         break;
       case kHIDUsage_GD_Y:
         if (_device_class == DC_gamepad) {
-          axis = C_left_y;
+          axis = Axis::left_y;
         } else if (_device_class == DC_flight_stick) {
-          axis = C_pitch;
+          axis = Axis::pitch;
         } else if (_device_class == DC_mouse) {
           _pointer_y = element;
           return;
         } else {
-          axis = C_y;
+          axis = Axis::y;
         }
         break;
       case kHIDUsage_GD_Z:
         if (_device_class == DC_gamepad) {
-          axis = C_left_trigger;
+          axis = Axis::left_trigger;
         } else if (_device_class == DC_flight_stick) {
-          axis = C_throttle;
+          axis = Axis::throttle;
         } else {
-          axis = C_z;
+          axis = Axis::z;
         }
         break;
       case kHIDUsage_GD_Rx:
         if (_device_class == DC_gamepad) {
-          axis = C_right_x;
+          axis = Axis::right_x;
         } else {
-          axis = C_pitch;
+          axis = Axis::pitch;
         }
         break;
       case kHIDUsage_GD_Ry:
         if (_device_class == DC_gamepad) {
-          axis = C_right_y;
+          axis = Axis::right_y;
         } else {
-          axis = C_roll;
+          axis = Axis::roll;
         }
         break;
       case kHIDUsage_GD_Rz:
         if (_device_class == DC_gamepad) {
-          axis = C_right_trigger;
+          axis = Axis::right_trigger;
         } else {
-          axis = C_yaw;
+          axis = Axis::yaw;
         }
         break;
       case kHIDUsage_GD_Slider:
-        axis = C_rudder;
+        axis = Axis::rudder;
         break;
       case kHIDUsage_GD_Dial:
         break;
@@ -268,28 +268,28 @@ parse_element(IOHIDElementRef element) {
     case kHIDPage_Simulation:
       switch (usage) {
       case kHIDUsage_Sim_Rudder:
-        axis = C_rudder;
+        axis = Axis::rudder;
         break;
       case kHIDUsage_Sim_Throttle:
-        axis = C_throttle;
+        axis = Axis::throttle;
         break;
       case kHIDUsage_Sim_Accelerator:
-        axis = C_accelerator;
+        axis = Axis::accelerator;
         break;
       case kHIDUsage_Sim_Brake:
-        axis = C_brake;
+        axis = Axis::brake;
         break;
       }
       break;
     }
-    if (axis != C_none) {
+    if (axis != Axis::none) {
       int min = IOHIDElementGetLogicalMin(element);
       int max = IOHIDElementGetLogicalMax(element);
-      if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == C_throttle) {
+      if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == Axis::throttle) {
         // T.Flight Hotas X throttle is reversed and can go backwards.
         add_control(axis, max, min, true);
-      } else if (axis == C_yaw || axis == C_rudder || axis == C_left_y || axis == C_right_y ||
-                 (_device_class == DC_3d_mouse && (axis == C_y || axis == C_z || axis == C_roll))) {
+      } else if (axis == Axis::yaw || axis == Axis::rudder || axis == Axis::left_y || axis == Axis::right_y ||
+                 (_device_class == DC_3d_mouse && (axis == Axis::y || axis == Axis::z || axis == Axis::roll))) {
         // We'd like to reverse the Y axis to match the XInput behavior.
         // We also reverse yaw to obey the right-hand rule.
         add_control(axis, max, min);

+ 4 - 4
panda/src/device/linuxInputDeviceManager.cxx

@@ -118,10 +118,10 @@ consider_add_evdev_device(size_t ev_index) {
     _evdev_devices[ev_index] = device;
 
     if (device->is_connected()) {
-      _connected_devices.add_device(MOVE(device));
+      _connected_devices.add_device(std::move(device));
     } else {
       // Wait for activity on the device before it is considered connected.
-      _inactive_devices.add_device(MOVE(device));
+      _inactive_devices.add_device(std::move(device));
     }
     return _evdev_devices[ev_index];
   }
@@ -189,10 +189,10 @@ consider_add_js_device(size_t js_index) {
     InputDevice *device_p = device.p();
 
     if (device->is_connected()) {
-      _connected_devices.add_device(MOVE(device));
+      _connected_devices.add_device(std::move(device));
     } else {
       // Wait for activity on the device before it is considered connected.
-      _inactive_devices.add_device(MOVE(device));
+      _inactive_devices.add_device(std::move(device));
     }
     return device_p;
   }

+ 25 - 25
panda/src/device/linuxJoystickDevice.cxx

@@ -152,71 +152,71 @@ open_device() {
     ioctl(_fd, JSIOCGAXMAP, axmap);
 
     for (uint8_t i = 0; i < num_axes; ++i) {
-      ControlAxis axis = C_none;
+      Axis axis = Axis::none;
 
       switch (axmap[i]) {
       case ABS_X:
         if (_device_class == DC_gamepad) {
-          axis = InputDevice::C_left_x;
+          axis = InputDevice::Axis::left_x;
         } else if (_device_class == DC_flight_stick) {
-          axis = InputDevice::C_roll;
+          axis = InputDevice::Axis::roll;
         } else {
-          axis = InputDevice::C_x;
+          axis = InputDevice::Axis::x;
         }
         break;
 
       case ABS_Y:
         if (_device_class == DC_gamepad) {
-          axis = InputDevice::C_left_y;
+          axis = InputDevice::Axis::left_y;
         } else if (_device_class == DC_flight_stick) {
-          axis = InputDevice::C_pitch;
+          axis = InputDevice::Axis::pitch;
         } else {
-          axis = InputDevice::C_y;
+          axis = InputDevice::Axis::y;
         }
         break;
 
       case ABS_Z:
         if (_device_class == DC_gamepad) {
-          axis = C_left_trigger;
+          axis = Axis::left_trigger;
         } else {
-          //axis = C_trigger;
+          //axis = Axis::trigger;
         }
         break;
 
       case ABS_RX:
-        axis = C_right_x;
+        axis = Axis::right_x;
         break;
 
       case ABS_RY:
-        axis = C_right_y;
+        axis = Axis::right_y;
         break;
 
       case ABS_RZ:
         if (_device_class == DC_gamepad) {
-          axis = InputDevice::C_right_trigger;
+          axis = InputDevice::Axis::right_trigger;
         } else {
-          axis = InputDevice::C_yaw;
+          axis = InputDevice::Axis::yaw;
         }
         break;
 
       case ABS_THROTTLE:
-        axis = InputDevice::C_throttle;
+        axis = InputDevice::Axis::throttle;
         break;
 
       case ABS_RUDDER:
-        axis = InputDevice::C_rudder;
+        axis = InputDevice::Axis::rudder;
         break;
 
       case ABS_WHEEL:
-        axis = InputDevice::C_wheel;
+        axis = InputDevice::Axis::wheel;
         break;
 
       case ABS_GAS:
-        axis = InputDevice::C_accelerator;
+        axis = InputDevice::Axis::accelerator;
         break;
 
       case ABS_BRAKE:
-        axis = InputDevice::C_brake;
+        axis = InputDevice::Axis::brake;
         break;
 
       case ABS_HAT0X:
@@ -231,7 +231,7 @@ open_device() {
             _buttons.push_back(ButtonState(GamepadButton::hat_left()));
             _buttons.push_back(ButtonState(GamepadButton::hat_right()));
           }
-          axis = C_none;
+          axis = Axis::none;
         }
         break;
 
@@ -247,7 +247,7 @@ open_device() {
             _buttons.push_back(ButtonState(GamepadButton::hat_up()));
             _buttons.push_back(ButtonState(GamepadButton::hat_down()));
           }
-          axis = C_none;
+          axis = Axis::none;
         }
         break;
 
@@ -256,17 +256,17 @@ open_device() {
           device_cat.debug() << "Unmapped /dev/input/js" << _index
             << " axis " << (int)i << ": 0x" << std::hex << (int)axmap[i] << "\n";
         }
-        axis = C_none;
+        axis = Axis::none;
         break;
       }
       _controls[i].axis = axis;
 
-      if (axis == C_left_trigger || axis == C_right_trigger) {
+      if (axis == Axis::left_trigger || axis == Axis::right_trigger) {
         // We'd like to use 0.0 to indicate the resting position.
         _controls[i]._scale = 1.0 / 65534.0;
         _controls[i]._bias = 0.5;
         have_analog_triggers = true;
-      } else if (axis == C_left_y || axis == C_right_y || axis == C_y) {
+      } else if (axis == Axis::left_y || axis == Axis::right_y || axis == Axis::y) {
         _controls[i]._scale = 1.0 / -32767.0;
         _controls[i]._bias = 0.0;
       } else {
@@ -279,8 +279,8 @@ open_device() {
   if (_ltrigger_button >= 0 && _rtrigger_button >= 0 && !have_analog_triggers) {
     // Emulate analog triggers.
     _ltrigger_control = (int)_controls.size();
-    add_control(C_left_trigger, 0, 1, false);
-    add_control(C_right_trigger, 0, 1, false);
+    add_control(Axis::left_trigger, 0, 1, false);
+    add_control(Axis::right_trigger, 0, 1, false);
   } else {
     _ltrigger_button = -1;
     _rtrigger_button = -1;

+ 19 - 19
panda/src/device/winRawInputDevice.cxx

@@ -478,71 +478,71 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
         is_signed = false;
       }
 
-      ControlAxis axis = C_none;
+      Axis axis = Axis::none;
       switch (cap.UsagePage) {
       case HID_USAGE_PAGE_GENERIC:
         switch (usage) {
           case HID_USAGE_GENERIC_X:
           if (_device_class == DC_gamepad) {
-            axis = C_left_x;
+            axis = Axis::left_x;
           } else if (_device_class == DC_flight_stick) {
-            axis = C_roll;
+            axis = Axis::roll;
           } else {
-            axis = C_x;
+            axis = Axis::x;
           }
           break;
         case HID_USAGE_GENERIC_Y:
           if (_device_class == DC_gamepad) {
-            axis = C_left_y;
+            axis = Axis::left_y;
             swap(cap.LogicalMin, cap.LogicalMax);
           } else if (_device_class == DC_flight_stick) {
-            axis = C_pitch;
+            axis = Axis::pitch;
           } else {
-            axis = C_y;
+            axis = Axis::y;
             swap(cap.LogicalMin, cap.LogicalMax);
           }
           break;
         case HID_USAGE_GENERIC_Z:
           if (_device_class == DC_gamepad) {
-            axis = C_left_trigger;
+            axis = Axis::left_trigger;
           } else if (_device_class == DC_flight_stick) {
-            axis = C_throttle;
+            axis = Axis::throttle;
           } else {
-            axis = C_z;
+            axis = Axis::z;
             swap(cap.LogicalMin, cap.LogicalMax);
           }
           break;
         case HID_USAGE_GENERIC_RX:
           if (_device_class == DC_gamepad) {
-            axis = C_right_x;
+            axis = Axis::right_x;
           } else {
-            axis = C_pitch;
+            axis = Axis::pitch;
           }
           break;
         case HID_USAGE_GENERIC_RY:
           if (_device_class == DC_gamepad) {
-            axis = C_right_y;
+            axis = Axis::right_y;
           } else {
-            axis = C_roll;
+            axis = Axis::roll;
           }
           swap(cap.LogicalMin, cap.LogicalMax);
           break;
         case HID_USAGE_GENERIC_RZ:
           if (_device_class == DC_gamepad) {
-            axis = C_right_trigger;
+            axis = Axis::right_trigger;
           } else {
             // Flip to match Panda's convention for heading.
-            axis = C_yaw;
+            axis = Axis::yaw;
             swap(cap.LogicalMin, cap.LogicalMax);
           }
           break;
         case HID_USAGE_GENERIC_SLIDER:
           // Flip to match Panda's convention for heading.
-          axis = C_rudder;
+          axis = Axis::rudder;
           swap(cap.LogicalMin, cap.LogicalMax);
           break;
         case HID_USAGE_GENERIC_WHEEL:
-          axis = C_wheel;
+          axis = Axis::wheel;
           break;
         case HID_USAGE_GENERIC_HATSWITCH:
           // This is handled specially.
@@ -554,7 +554,7 @@ on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name) {
       }
 
       int control_index;
-      if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == C_throttle) {
+      if (_vendor_id == 0x044f && _product_id == 0xb108 && axis == Axis::throttle) {
         // T.Flight Hotas X throttle is reversed and can go backwards.
         control_index = add_control(axis, cap.LogicalMax, cap.LogicalMin, true);
       } else if (!is_signed) {

+ 24 - 24
panda/src/device/xInputDevice.cxx

@@ -315,42 +315,42 @@ init_device(const XINPUT_CAPABILITIES_EX &caps, const XINPUT_STATE &state) {
   default:
   case XINPUT_DEVSUBTYPE_GAMEPAD:
     _device_class = DC_gamepad;
-    set_control_map(0, C_left_trigger);
-    set_control_map(1, C_right_trigger);
-    set_control_map(2, C_left_x);
-    set_control_map(3, C_left_y);
-    set_control_map(4, C_right_x);
-    set_control_map(5, C_right_y);
+    set_control_map(0, Axis::left_trigger);
+    set_control_map(1, Axis::right_trigger);
+    set_control_map(2, Axis::left_x);
+    set_control_map(3, Axis::left_y);
+    set_control_map(4, Axis::right_x);
+    set_control_map(5, Axis::right_y);
     break;
 
   case XINPUT_DEVSUBTYPE_WHEEL:
     _device_class = DC_steering_wheel;
-    set_control_map(0, C_brake);
-    set_control_map(1, C_accelerator);
-    set_control_map(2, C_wheel);
-    set_control_map(3, C_none);
-    set_control_map(4, C_none);
-    set_control_map(5, C_none);
+    set_control_map(0, Axis::brake);
+    set_control_map(1, Axis::accelerator);
+    set_control_map(2, Axis::wheel);
+    set_control_map(3, Axis::none);
+    set_control_map(4, Axis::none);
+    set_control_map(5, Axis::none);
     break;
 
   case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
     _device_class = DC_flight_stick;
-    set_control_map(0, C_yaw);
-    set_control_map(1, C_throttle);
-    set_control_map(2, C_roll);
-    set_control_map(3, C_pitch);
-    set_control_map(4, C_none);
-    set_control_map(5, C_none);
+    set_control_map(0, Axis::yaw);
+    set_control_map(1, Axis::throttle);
+    set_control_map(2, Axis::roll);
+    set_control_map(3, Axis::pitch);
+    set_control_map(4, Axis::none);
+    set_control_map(5, Axis::none);
     break;
 
   case XINPUT_DEVSUBTYPE_DANCE_PAD:
     _device_class = DC_dance_pad;
-    set_control_map(0, C_none);
-    set_control_map(1, C_none);
-    set_control_map(2, C_none);
-    set_control_map(3, C_none);
-    set_control_map(4, C_none);
-    set_control_map(5, C_none);
+    set_control_map(0, Axis::none);
+    set_control_map(1, Axis::none);
+    set_control_map(2, Axis::none);
+    set_control_map(3, Axis::none);
+    set_control_map(4, Axis::none);
+    set_control_map(5, Axis::none);
     break;
   }