github.com/racerxdl/gonx@v0.0.0-20210103083128-c5afc43bcbd2/nx/hid.go (about)

     1  // +build nintendoswitch
     2  
     3  package nx
     4  
     5  type HidControllerId uint64
     6  type HidControllerKeys uint64
     7  
     8  // HidControllerID
     9  const (
    10      ControllerPlayer1  HidControllerId = 0
    11      ControllerPlayer2  HidControllerId = 1
    12      ControllerPlayer3  HidControllerId = 2
    13      ControllerPlayer4  HidControllerId = 3
    14      ControllerPlayer5  HidControllerId = 4
    15      ControllerPlayer6  HidControllerId = 5
    16      ControllerPlayer7  HidControllerId = 6
    17      ControllerPlayer8  HidControllerId = 7
    18      ControllerHandheld HidControllerId = 8
    19      ControllerUnknown  HidControllerId = 9
    20      // Not an actual HID-sysmodule ID. Only for hidKeys*()/hidJoystickRead()/hidSixAxisSensorValuesRead()/hidGetControllerType()/hidGetControllerColors()/hidIsControllerConnected().
    21      // Automatically uses CONTROLLER_PLAYER_1 when connected, otherwise uses CONTROLLER_HANDHELD.
    22      ControllerP1Auto HidControllerId = 10
    23  )
    24  
    25  const (
    26      KeyA           HidControllerKeys = 1 << 0  // A
    27      KeyB           HidControllerKeys = 1 << 1  // B
    28      KeyX           HidControllerKeys = 1 << 2  // X
    29      KeyY           HidControllerKeys = 1 << 3  // Y
    30      KeyLStick      HidControllerKeys = 1 << 4  // Left Stick Button
    31      KeyRStick      HidControllerKeys = 1 << 5  // Right Stick Button
    32      KeyL           HidControllerKeys = 1 << 6  // L
    33      KeyR           HidControllerKeys = 1 << 7  // R
    34      KeyZL          HidControllerKeys = 1 << 8  // ZL
    35      KeyZR          HidControllerKeys = 1 << 9  // ZR
    36      KeyPlus        HidControllerKeys = 1 << 10 // Plus
    37      KeyMinus       HidControllerKeys = 1 << 11 // Minus
    38      KeyDLeft       HidControllerKeys = 1 << 12 // D-Pad Left
    39      KeyDup         HidControllerKeys = 1 << 13 // D-Pad Up
    40      KeyDRight      HidControllerKeys = 1 << 14 // D-Pad Right
    41      KeyDDown       HidControllerKeys = 1 << 15 // D-Pad Down
    42      KeyLStickLeft  HidControllerKeys = 1 << 16 // Left Stick Left
    43      KeyLStickUp    HidControllerKeys = 1 << 17 // Left Stick Up
    44      KeyLStickRight HidControllerKeys = 1 << 18 // Left Stick Right
    45      KeyLStickDown  HidControllerKeys = 1 << 19 // Left Stick Down
    46      KeyRStickLeft  HidControllerKeys = 1 << 20 // Right Stick Left
    47      KeyRStickUp    HidControllerKeys = 1 << 21 // Right Stick Up
    48      KeyRStickRight HidControllerKeys = 1 << 22 // Right Stick Right
    49      KeyRStickDown  HidControllerKeys = 1 << 23 // Right Stick Down
    50      KeySLLeft      HidControllerKeys = 1 << 24 // SL on Left Joy-Con
    51      KeySRLeft      HidControllerKeys = 1 << 25 // SR on Left Joy-Con
    52      KeySLRight     HidControllerKeys = 1 << 26 // SL on Right Joy-Con
    53      KeySRRight     HidControllerKeys = 1 << 27 // SR on Right Joy-Con
    54  
    55      KeyHome    HidControllerKeys = 1 << 18 // HOME button, only available for use with HiddbgHdlsState::buttons.
    56      KeyCapture HidControllerKeys = 1 << 19 // Capture button, only available for use with HiddbgHdlsState::buttons.
    57  
    58      // Pseudo-key for at least one finger on the touch screen
    59      KeyTouch HidControllerKeys = 1 << 28
    60  
    61      // Buttons by orientation (for single Joy-Con), also works with Joy-Con pairs, Pro Controller
    62      KeyJoyconRight HidControllerKeys = 1 << 0
    63      KeyJoyconDown  HidControllerKeys = 1 << 1
    64      KeyJoyconUp    HidControllerKeys = 1 << 2
    65      KeyJoyconLeft  HidControllerKeys = 1 << 3
    66  
    67      // Generic catch-all directions, also works for single Joy-Con
    68      KeyUp    = KeyDup | KeyLStickUp | KeyRStickUp          // D-Pad Up or Sticks Up
    69      KeyDown  = KeyDDown | KeyLStickDown | KeyRStickDown    // D-Pad Down or Sticks Down
    70      KeyLeft  = KeyDLeft | KeyLStickLeft | KeyRStickLeft    // D-Pad Left or Sticks Left
    71      KeyRight = KeyDRight | KeyLStickRight | KeyRStickRight // D-Pad Right or Sticks Right
    72      KeySl    = KeySLLeft | KeySLRight                      // SL on Left or Right Joy-Con
    73      KeySr    = KeySRLeft | KeySRRight                      // SR on Left or Right Joy-Con
    74  )
    75  
    76  func (k HidControllerKeys) IsKeyDown(key HidControllerKeys) bool {
    77      return k & key > 0
    78  }
    79  
    80  func (k HidControllerKeys) IsKeyUp(key HidControllerKeys) bool {
    81      return !k.IsKeyDown(key)
    82  }
    83