t2:port_status

port_status


port_status - Status of an I/O port

Description


uint8 port_status(uint8 port, uint8 *protocol, uint8 *device);

Get the current status of a port identified by the first argument. Additional information, related to the port, can be obtained utilizing the arguments protocol and device.

Parameters


  • port: An valid port identifier, accordingly table 1.
  • protocol: Address of an uint8 variable to receive the protocol identifier in use. Refer to table 2 for more details. This argument can be NULL.
  • device: Address of an uint8 variable to receive the device identifier in use. Refer to table 2 for more details. This argument can be NULL.
Table 1
Index Port Designator Port Label
1 PORT_USB_A Input-A
2 PORT_USB_B Input-B
0 PORT_USB_C Output
3 PORT_USB_D Prog
4 PORT_BT_A
5 PORT_BT_B
6 PORT_BT_C
Table 2
Protocol Device
0 1 2 0x40 0x80
PROTOCOL_PS3 Regular Navigation
PROTOCOL_PS4 Regular Third Party V2
PROTOCOL_XB360 Regular
PROTOCOL_XB360_WRC Regular
PROTOCOL_XB1 Regular Third Party Elite
PROTOCOL_XB1_WRC Regular Elite
PROTOCOL_WII
PROTOCOL_SWITCH Pro Controller
PROTOCOL_HID Generic Mouse Keyboard
PROTOCOL_STEAM Regular Wireless

Return Value


The status value of the port, accordingly table 3.

Table 3
Status Value Bitmask
DIR_OUTPUT 0x80 0xC0
DIR_INPUT 0x40 0xC0
PASSTHRU_NONE 0x00 0x03
PASSTHRU_FULL 0x01 0x03
PASSTHRU_PARTIAL 0x02 0x03

Examples


Example #1 port_status() example

// Function to find if there is an Xbox One Elite controller connected
int8 find_xb1_elite() {
    uint8 status, protocol, device;
    uint8 i;
 
    for(i = 0; i <= 3; ++i) {
        status = port_status(i, &protocol, &device);
        if(status & DIR_INPUT) {
            if(protocol == PROTOCOL_XB1) {
                if(device == 2) { // Elite Controller
                    return(i);
                }
            }
        }        
    }
    return(-1);
}
t2/port_status.txt · Last modified: 2018/09/25 04:00 by J2Kbr