Data Structures | Macros | Enumerations | Functions
EV3 ports and extended ports

Access to EV3 ports and extended ports. More...

Data Structures

struct  EV3_PORT
 Structure of a EV3 port descriptor. More...
 

Macros

#define PORT_DIR   "/sys/class/lego-port"
 
#define PORT_DESC__LIMIT_   DESC_LIMIT
 
#define PORT__NONE_   PORT_DESC__LIMIT_
 
#define EV3_PORT__NONE_   0 /* XXX: 0 is used */
 Identifiers of EV3 ports and extended ports.
 
#define EXT_PORT__NONE_   EV3_PORT__NONE_
 
#define INPUT_1   49
 
#define INPUT_2   50
 
#define INPUT_3   51
 
#define INPUT_4   52
 
#define OUTPUT_A   65
 
#define OUTPUT_B   66
 
#define OUTPUT_C   67
 
#define OUTPUT_D   68
 
#define MUX_1   49
 
#define MUX_2   50
 
#define MUX_3   51
 
#define MUX_4   52
 
#define SERVO__OFFSET_   16
 
#define SERVO_1   65
 
#define SERVO_2   66
 
#define SERVO_3   67
 
#define SERVO_4   68
 
#define SERVO_5   69
 
#define SERVO_6   70
 
#define SERVO_7   71
 
#define SERVO_8   72
 
#define NXTMMX__OFFSET_   28
 
#define NXTMMX_1   77
 
#define NXTMMX_2   78
 
#define WEDO__OFFSET_   48
 
#define WEDO_1   97
 
#define WEDO_2   98
 
#define WEDO_3   99
 
#define WEDO_4   100
 

Enumerations

enum  {
  PORT_TYPE__NONE_ = 0, HT_NXT_SMUX_PORT, LEGOEV3_INPUT_PORT, LEGOEV3_OUTPUT_PORT,
  MS_EV3_SMUX_PORT, MS_NXTMMX_OUT_PORT, WEDO_PORT, PORT_TYPE__COUNT_,
  PORT_TYPE__UNKNOWN_ = PORT_TYPE__COUNT_
}
 Identifiers of EV3 port types. More...
 
enum  {
  PORT_MODE__NONE_ = 0, HT_NXT_SMUX_PORT_ANALOG, HT_NXT_SMUX_ANALOG = HT_NXT_SMUX_PORT_ANALOG, HT_NXT_SMUX_PORT_I2C,
  HT_NXT_SMUX_I2C = HT_NXT_SMUX_PORT_I2C, LEGOEV3_INPUT_PORT_AUTO, INPUT_AUTO = LEGOEV3_INPUT_PORT_AUTO, LEGOEV3_INPUT_PORT_NXT_ANALOG,
  INPUT_NXT_ANALOG = LEGOEV3_INPUT_PORT_NXT_ANALOG, LEGOEV3_INPUT_PORT_NXT_COLOR, INPUT_NXT_COLOR = LEGOEV3_INPUT_PORT_NXT_COLOR, LEGOEV3_INPUT_PORT_NXT_I2C,
  INPUT_NXT_I2C = LEGOEV3_INPUT_PORT_NXT_I2C, LEGOEV3_INPUT_PORT_OTHER_I2C, INPUT_OTHER_I2C = LEGOEV3_INPUT_PORT_OTHER_I2C, LEGOEV3_INPUT_PORT_EV3_ANALOG,
  INPUT_EV3_ANALOG = LEGOEV3_INPUT_PORT_EV3_ANALOG, LEGOEV3_INPUT_PORT_EV3_UART, INPUT_EV3_UART = LEGOEV3_INPUT_PORT_EV3_UART, LEGOEV3_INPUT_PORT_OTHER_UART,
  INPUT_OTHER_UART = LEGOEV3_INPUT_PORT_OTHER_UART, LEGOEV3_INPUT_PORT_RAW, INPUT_RAW = LEGOEV3_INPUT_PORT_RAW, LEGOEV3_OUTPUT_PORT_AUTO,
  OUTPUT_AUTO = LEGOEV3_OUTPUT_PORT_AUTO, LEGOEV3_OUTPUT_PORT_TACHO_MOTOR, OUTPUT_TACHO_MOTOR = LEGOEV3_OUTPUT_PORT_TACHO_MOTOR, LEGOEV3_OUTPUT_PORT_DC_MOTOR,
  OUTPUT_DC_MOTOR = LEGOEV3_OUTPUT_PORT_DC_MOTOR, LEGOEV3_OUTPUT_PORT_LED, OUTPUT_LED = LEGOEV3_OUTPUT_PORT_LED, LEGOEV3_OUTPUT_PORT_RAW,
  OUTPUT_RAW = LEGOEV3_OUTPUT_PORT_RAW, MS_EV3_SMUX_PORT_UART, MS_EV3_SMUX_UART = MS_EV3_SMUX_PORT_UART, MS_EV3_SMUX_PORT_ANALOG,
  MS_EV3_SMUX_ANALOG = MS_EV3_SMUX_PORT_ANALOG, MS_NXTMMX_OUT_PORT_TACHO_MOTOR, MS_NXTMMX_TACHO_MOTOR = MS_NXTMMX_OUT_PORT_TACHO_MOTOR, WEDO_PORT_AUTO,
  WEDO_AUTO = WEDO_PORT_AUTO, PORT_MODE__COUNT_, PORT_MODE__UNKNOWN_ = PORT_MODE__COUNT_
}
 Identifiers of EV3 port "mode" attribute. More...
 

Functions

 EV3_PORT_VAR (EV3_PORT ev3_port[PORT_DESC__LIMIT_])
 Vector of EV3 port descriptors (filled by ev3_port_init).
 
size_t get_port_address (uint8_t sn, char *buf, size_t sz)
 Read "address" attribute of the EV3 port. More...
 
size_t get_port_driver_name (uint8_t sn, char *buf, size_t sz)
 Read "driver_name" attribute of the EV3 port. More...
 
size_t get_port_mode (uint8_t sn, char *buf, size_t sz)
 Read "mode" attribute of the EV3 port. More...
 
size_t set_port_mode (uint8_t sn, char *value)
 Write "mode" attribute of the EV3 port. More...
 
size_t multi_set_port_mode (uint8_t *sn, char *value)
 Write "mode" attribute of several EV3 ports. More...
 
size_t get_port_modes (uint8_t sn, char *buf, size_t sz)
 Read "modes" attribute of the EV3 port. More...
 
size_t set_port_set_device (uint8_t sn, char *value)
 Write "set_device" attribute of the EV3 port. More...
 
size_t multi_set_port_set_device (uint8_t *sn, char *value)
 Write "set_device" attribute of several EV3 ports. More...
 
size_t get_port_status (uint8_t sn, char *buf, size_t sz)
 Read "status" attribute of the EV3 port. More...
 
const char * ev3_port_type (INX_T type_inx)
 Get name of the specified EV3 port type. More...
 
INX_T get_port_type_inx (uint8_t sn)
 Read "driver_name" attribute and get index of the EV3 port type. More...
 
size_t get_port_desc (uint8_t sn, EV3_PORT *desc)
 Read EV3 port attributes that are required for filling the descriptor. More...
 
EV3_PORTev3_port_desc (uint8_t sn)
 Get descriptor of the EV3 port. More...
 
INX_T ev3_port_desc_type_inx (uint8_t sn)
 Get type from the EV3 port descriptor. More...
 
uint8_t ev3_port_desc_port (uint8_t sn)
 Get EV3 port from the EV3 port descriptor. More...
 
uint8_t ev3_port_desc_extport (uint8_t sn)
 Get extended port from the EV3 port descriptor. More...
 
uint8_t ev3_port_desc_addr (uint8_t sn)
 Get I2C address from the EV3 port descriptor. More...
 
char * ev3_port_port_name (uint8_t sn, char *buf)
 Assemble EV3 port name from the EV3 port descriptor. More...
 
bool ev3_search_port_type (INX_T type_inx, uint8_t *sn, uint8_t from)
 Search of a sequence number of the specified EV3 port type. More...
 
bool ev3_search_port_plugged_in (uint8_t port, uint8_t extport, uint8_t *sn, uint8_t from)
 Search of a sequence number the EV3 port by plug-in attributes. More...
 
const char * ev3_port_mode (INX_T mode_inx)
 Get name of the specified EV3 port mode. More...
 
INX_T get_port_mode_inx_of_type (uint8_t sn, INX_T type_inx)
 Read "mode" attribute of the specified EV3 port type and get the index. More...
 
INX_T get_port_mode_inx (uint8_t sn)
 Read "mode" attribute of the EV3 port and get the index. More...
 
size_t set_port_mode_inx (uint8_t sn, INX_T mode_inx)
 Write "mode" attribute of the EV3 port by the index. More...
 
size_t multi_set_port_mode_inx (uint8_t *sn, INX_T mode_inx)
 Write "mode" attribute of several EV3 ports by the index. More...
 
int ev3_port_init (void)
 Detect connected EV3 ports. More...
 
uint8_t ev3_search_port (uint8_t port, uint8_t extport)
 Search of a port sequence number by the EV3 port and the extended port. More...
 
void ev3_parse_port_name (char *name, uint8_t *port, uint8_t *extport, uint8_t *addr)
 Parse name of the EV3 port. More...
 
char * ev3_port_name (uint8_t port, uint8_t extport, uint8_t addr, char *buf)
 Assemble name of the EV3 port. More...
 

Detailed Description

Access to EV3 ports and extended ports.

See also
http://www.ev3dev.org/docs/ports/
http://www.ev3dev.org/docs/drivers/lego-port-class/

Macro Definition Documentation

#define PORT__NONE_   PORT_DESC__LIMIT_

EV3 port is not found.

#define PORT_DESC__LIMIT_   DESC_LIMIT

Limit of EV3 port descriptors.

#define PORT_DIR   "/sys/class/lego-port"

Directory of EV3 ports.

Enumeration Type Documentation

anonymous enum

Identifiers of EV3 port types.

Enumerator
PORT_TYPE__COUNT_ 

Count of EV3 port types.

anonymous enum

Identifiers of EV3 port "mode" attribute.

Enumerator
PORT_MODE__COUNT_ 

Count of EV3 port "mode" attribute.

Function Documentation

void ev3_parse_port_name ( char *  name,
uint8_t *  port,
uint8_t *  extport,
uint8_t *  addr 
)

Parse name of the EV3 port.

Parameters
namePort name.
portBuffer for the EV3 port index.
extportBuffer for the extended port index.
addrBuffer for the address.
EV3_PORT* ev3_port_desc ( uint8_t  sn)

Get descriptor of the EV3 port.

Parameters
snSequence number.
Returns
Pointer to the EV3 port descriptor.
uint8_t ev3_port_desc_addr ( uint8_t  sn)

Get I2C address from the EV3 port descriptor.

Parameters
snSequence number.
Returns
Requested value.
uint8_t ev3_port_desc_extport ( uint8_t  sn)

Get extended port from the EV3 port descriptor.

Parameters
snSequence number.
Returns
Requested value.
uint8_t ev3_port_desc_port ( uint8_t  sn)

Get EV3 port from the EV3 port descriptor.

Parameters
snSequence number.
Returns
Requested value.
INX_T ev3_port_desc_type_inx ( uint8_t  sn)

Get type from the EV3 port descriptor.

Parameters
snSequence number.
Returns
Requested value.
int ev3_port_init ( void  )

Detect connected EV3 ports.

Returns
Number of found EV3 ports or -1 in case of an error.
const char* ev3_port_mode ( INX_T  mode_inx)

Get name of the specified EV3 port mode.

Parameters
mode_inxIndex of the EV3 port mode.
Returns
Requested value.
char* ev3_port_name ( uint8_t  port,
uint8_t  extport,
uint8_t  addr,
char *  buf 
)

Assemble name of the EV3 port.

Parameters
portEV3 port index.
extportExtended port index.
addrAddress.
[out]bufBuffer for result.
Returns
Requested value.
char* ev3_port_port_name ( uint8_t  sn,
char *  buf 
)

Assemble EV3 port name from the EV3 port descriptor.

Parameters
snSequence number.
[out]bufBuffer for result.
Returns
Requested value.
const char* ev3_port_type ( INX_T  type_inx)

Get name of the specified EV3 port type.

Parameters
type_inxIndex of the EV3 port type.
Returns
Requested value.
uint8_t ev3_search_port ( uint8_t  port,
uint8_t  extport 
)

Search of a port sequence number by the EV3 port and the extended port.

Parameters
portEV3 port index.
extportExtended port index.
Returns
Port sequence number.
bool ev3_search_port_plugged_in ( uint8_t  port,
uint8_t  extport,
uint8_t *  sn,
uint8_t  from 
)

Search of a sequence number the EV3 port by plug-in attributes.

Parameters
portEV3 port.
extportExtended port.
[out]snBuffer for the sequence number.
fromSearch initial value.
Returns
Flag - the EV3 port is found.
bool ev3_search_port_type ( INX_T  type_inx,
uint8_t *  sn,
uint8_t  from 
)

Search of a sequence number of the specified EV3 port type.

Parameters
type_inxEV3 port type.
[out]snBuffer for the sequence number.
fromSearch initial value.
Returns
Flag - the EV3 port is found.
size_t get_port_address ( uint8_t  sn,
char *  buf,
size_t  sz 
)

Read "address" attribute of the EV3 port.

Parameters
snSequence number.
[out]bufBuffer for result.
szBuffer size.
Returns
Count of read bytes.
size_t get_port_desc ( uint8_t  sn,
EV3_PORT desc 
)

Read EV3 port attributes that are required for filling the descriptor.

Parameters
snSequence number.
descBuffer for the descriptor.
Returns
Count of read bytes.
size_t get_port_driver_name ( uint8_t  sn,
char *  buf,
size_t  sz 
)

Read "driver_name" attribute of the EV3 port.

Parameters
snSequence number.
[out]bufBuffer for result.
szBuffer size.
Returns
Count of read bytes.
size_t get_port_mode ( uint8_t  sn,
char *  buf,
size_t  sz 
)

Read "mode" attribute of the EV3 port.

Parameters
snSequence number.
[out]bufBuffer for result.
szBuffer size.
Returns
Count of read bytes.
INX_T get_port_mode_inx ( uint8_t  sn)

Read "mode" attribute of the EV3 port and get the index.

Parameters
snSequence number.
Returns
Requested value.

This function gets type of the EV3 port from the descriptor.

INX_T get_port_mode_inx_of_type ( uint8_t  sn,
INX_T  type_inx 
)

Read "mode" attribute of the specified EV3 port type and get the index.

Parameters
snSequence number.
type_inxIndex of the EV3 port type.
Returns
Requested value.
size_t get_port_modes ( uint8_t  sn,
char *  buf,
size_t  sz 
)

Read "modes" attribute of the EV3 port.

Parameters
snSequence number.
[out]bufBuffer for result.
szBuffer size.
Returns
Count of read bytes.
size_t get_port_status ( uint8_t  sn,
char *  buf,
size_t  sz 
)

Read "status" attribute of the EV3 port.

Parameters
snSequence number.
[out]bufBuffer for result.
szBuffer size.
Returns
Count of read bytes.
INX_T get_port_type_inx ( uint8_t  sn)

Read "driver_name" attribute and get index of the EV3 port type.

Parameters
snSequence number.
Returns
Requested value.
size_t multi_set_port_mode ( uint8_t *  sn,
char *  value 
)

Write "mode" attribute of several EV3 ports.

Parameters
snVector of sequence numbers ending with DESC_LIMIT.
valueAttribute value.
Returns
Count of written bytes.
size_t multi_set_port_mode_inx ( uint8_t *  sn,
INX_T  mode_inx 
)

Write "mode" attribute of several EV3 ports by the index.

Parameters
snVector of sequence numbers ending with DESC_LIMIT.
mode_inxIndex of the EV3 port mode.
Returns
Count of written bytes.
size_t multi_set_port_set_device ( uint8_t *  sn,
char *  value 
)

Write "set_device" attribute of several EV3 ports.

Parameters
snVector of sequence numbers ending with DESC_LIMIT.
valueAttribute value.
Returns
Count of written bytes.
size_t set_port_mode ( uint8_t  sn,
char *  value 
)

Write "mode" attribute of the EV3 port.

Parameters
snSequence number.
valueAttribute value.
Returns
Count of written bytes.
size_t set_port_mode_inx ( uint8_t  sn,
INX_T  mode_inx 
)

Write "mode" attribute of the EV3 port by the index.

Parameters
snSequence number.
mode_inxIndex of the EV3 port mode.
Returns
Count of written bytes.
size_t set_port_set_device ( uint8_t  sn,
char *  value 
)

Write "set_device" attribute of the EV3 port.

Parameters
snSequence number.
valueAttribute value.
Returns
Count of written bytes.