Mindstorms 3rd Party ROBOTC Drivers RobotC
[Home] [Download] [Submit a bug/suggestion] [ROBOTC Forums] [Blog] [Support this project]
Files | Defines | Typedefs | Enumerations | Functions | Variables

Sensor MUX
[HiTechnic]

Files

file  hitechnic-sensormux.h
 

Commonly used functions used by drivers.


Defines

#define __HTSMUX_SUPPORT__
#define SPORT(X)   (X / 4)
#define MPORT(X)   (X % 4)
#define HTSMUX_I2C_ADDR   0x10
#define HTSMUX_COMMAND   0x20
#define HTSMUX_STATUS   0x21
#define HTSMUX_MODE   0x00
#define HTSMUX_TYPE   0x01
#define HTSMUX_I2C_COUNT   0x02
#define HTSMUX_I2C_DADDR   0x03
#define HTSMUX_I2C_MADDR   0x04
#define HTSMUX_CH_OFFSET   0x22
#define HTSMUX_CH_ENTRY_SIZE   0x05
#define HTSMUX_ANALOG   0x36
#define HTSMUX_AN_ENTRY_SIZE   0x02
#define HTSMUX_I2C_BUF   0x40
#define HTSMUX_BF_ENTRY_SIZE   0x10
#define HTSMUX_CMD_HALT   0x00
#define HTSMUX_CMD_AUTODETECT   0x01
#define HTSMUX_CMD_RUN   0x02
#define HTSMUX_STAT_NORMAL   0x00
#define HTSMUX_STAT_BATT   0x01
#define HTSMUX_STAT_BUSY   0x02
#define HTSMUX_STAT_HALT   0x04
#define HTSMUX_STAT_ERROR   0x08
#define HTSMUX_STAT_NOTHING   0xFF
#define HTSMUX_CHAN_NONE   0x00
#define HTSMUX_CHAN_I2C   0x01
#define HTSMUX_CHAN_9V   0x02
#define HTSMUX_CHAN_DIG0_HIGH   0x04
#define HTSMUX_CHAN_DIG1_HIGH   0x08
#define HTSMUX_CHAN_I2C_SLOW   0x10

Typedefs

typedef ubyte tConfigParams [4]

Enumerations

enum  HTSMUXSensorType {
  HTSMUXAnalogue = 0x00, HTSMUXLegoUS = 0x01, HTSMUXCompass = 0x02, HTSMUXColor = 0x03,
  HTSMUXAccel = 0x04, HTSMUXIRSeeker = 0x05, HTSMUXProto = 0x06, HTSMUXColorNew = 0x07,
  HTSMUXAngle = 0x08, HTSMUXIRSeekerNew = 0x09, HTSMUXSensorCustom = 0x0E, HTSMUXSensorNone = 0x0F
}
enum  tMUXSensor {
  msensor_S1_1 = 0, msensor_S1_2 = 1, msensor_S1_3 = 2, msensor_S1_4 = 3,
  msensor_S2_1 = 4, msensor_S2_2 = 5, msensor_S2_3 = 6, msensor_S2_4 = 7,
  msensor_S3_1 = 8, msensor_S3_2 = 9, msensor_S3_3 = 10, msensor_S3_4 = 11,
  msensor_S4_1 = 12, msensor_S4_2 = 13, msensor_S4_3 = 14, msensor_S4_4 = 15
}

Functions

byte HTSMUXreadStatus (tSensors link)
HTSMUXSensorType HTSMUXreadSensorType (tMUXSensor muxsensor)
bool HTSMUXsendCommand (tSensors link, byte command)
bool HTSMUXreadPort (tMUXSensor muxsensor, tByteArray &result, int numbytes, int offset=0)
bool HTSMUXsetMode (tMUXSensor muxsensor, byte mode)
bool HTSMUXsetAnalogueActive (tMUXSensor muxsensor)
bool HTSMUXsetAnalogueInactive (tMUXSensor muxsensor)
int HTSMUXreadAnalogue (tMUXSensor muxsensor)
bool HTSMUXreadPowerStatus (tSensors link)
bool HTSMUXconfigChannel (tMUXSensor muxsensor, tConfigParams &configparams)
void HTSMUXsensorTypeToString (HTSMUXSensorType muxsensor, string &sensorName)

Variables

ubyte HTSMUXstatus [4] = {HTSMUX_STAT_NOTHING, HTSMUX_STAT_NOTHING, HTSMUX_STAT_NOTHING, HTSMUX_STAT_NOTHING}
HTSMUXSensorType HTSMUXSensorTypes [16]
tByteArray HTSMUX_I2CRequest
tByteArray HTSMUX_I2CReply
tConfigParams Analogue_config = {HTSMUX_CHAN_NONE, 0, 0, 0}

Detailed Description

HiTechnic Sensor MUX Sensor


Define Documentation

#define __HTSMUX_SUPPORT__

Definition at line 38 of file hitechnic-sensormux.h.

#define HTSMUX_AN_ENTRY_SIZE   0x02

Number of registers per analogue channel

Definition at line 71 of file hitechnic-sensormux.h.

#define HTSMUX_ANALOG   0x36

Analogue upper 8 bits register

Definition at line 70 of file hitechnic-sensormux.h.

#define HTSMUX_BF_ENTRY_SIZE   0x10

Number of registers per buffer

Definition at line 74 of file hitechnic-sensormux.h.

#define HTSMUX_CH_ENTRY_SIZE   0x05

Number of registers per sensor channel

Definition at line 68 of file hitechnic-sensormux.h.

#define HTSMUX_CH_OFFSET   0x22

Channel register offset

Definition at line 67 of file hitechnic-sensormux.h.

#define HTSMUX_CHAN_9V   0x02

Enable 9v supply on analogue pin channel mode

Definition at line 93 of file hitechnic-sensormux.h.

#define HTSMUX_CHAN_DIG0_HIGH   0x04

Drive pin 0 high channel mode

Definition at line 94 of file hitechnic-sensormux.h.

#define HTSMUX_CHAN_DIG1_HIGH   0x08

Drive pin 1 high channel mode

Definition at line 95 of file hitechnic-sensormux.h.

#define HTSMUX_CHAN_I2C   0x01

I2C channel present channel mode

Definition at line 92 of file hitechnic-sensormux.h.

#define HTSMUX_CHAN_I2C_SLOW   0x10

Set slow I2C rate channel mode Sensor types as detected by SMUX

Definition at line 96 of file hitechnic-sensormux.h.

#define HTSMUX_CHAN_NONE   0x00

Nothing configured - analogue sensor

Definition at line 91 of file hitechnic-sensormux.h.

#define HTSMUX_CMD_AUTODETECT   0x01

Start auto-detect function command

Definition at line 79 of file hitechnic-sensormux.h.

#define HTSMUX_CMD_HALT   0x00

Halt multiplexer command

Definition at line 78 of file hitechnic-sensormux.h.

#define HTSMUX_CMD_RUN   0x02

Start normal multiplexer operation command

Definition at line 80 of file hitechnic-sensormux.h.

#define HTSMUX_COMMAND   0x20

Command register

Definition at line 58 of file hitechnic-sensormux.h.

#define HTSMUX_I2C_ADDR   0x10

HTSMUX I2C device address

Definition at line 57 of file hitechnic-sensormux.h.

#define HTSMUX_I2C_BUF   0x40

I2C buffer register offset

Definition at line 73 of file hitechnic-sensormux.h.

#define HTSMUX_I2C_COUNT   0x02

I2C byte count register

Definition at line 64 of file hitechnic-sensormux.h.

#define HTSMUX_I2C_DADDR   0x03

I2C device address register

Definition at line 65 of file hitechnic-sensormux.h.

#define HTSMUX_I2C_MADDR   0x04

I2C memory address register

Definition at line 66 of file hitechnic-sensormux.h.

#define HTSMUX_MODE   0x00

Sensor mode register

Definition at line 62 of file hitechnic-sensormux.h.

#define HTSMUX_STAT_BATT   0x01

No battery voltage detected status

Definition at line 84 of file hitechnic-sensormux.h.

#define HTSMUX_STAT_BUSY   0x02

Auto-dected in progress status

Definition at line 85 of file hitechnic-sensormux.h.

#define HTSMUX_STAT_ERROR   0x08

Command error detected status

Definition at line 87 of file hitechnic-sensormux.h.

#define HTSMUX_STAT_HALT   0x04

Multiplexer is halted status

Definition at line 86 of file hitechnic-sensormux.h.

#define HTSMUX_STAT_NORMAL   0x00

Nothing going on, everything's fine

Definition at line 83 of file hitechnic-sensormux.h.

#define HTSMUX_STAT_NOTHING   0xFF

Status hasn't really been set yet

Definition at line 88 of file hitechnic-sensormux.h.

#define HTSMUX_STATUS   0x21

Status register

Definition at line 59 of file hitechnic-sensormux.h.

#define HTSMUX_TYPE   0x01

Sensor type register

Definition at line 63 of file hitechnic-sensormux.h.

#define MPORT (   X )    (X % 4)

Convert tMUXSensor to MUX port number

Definition at line 45 of file hitechnic-sensormux.h.

#define SPORT (   X )    (X / 4)

Convert tMUXSensor to sensor port number

Definition at line 41 of file hitechnic-sensormux.h.


Typedef Documentation

typedef ubyte tConfigParams[4]

Array to hold SMUX channel info

Definition at line 148 of file hitechnic-sensormux.h.


Enumeration Type Documentation

Enumerator:
HTSMUXAnalogue 
HTSMUXLegoUS 
HTSMUXCompass 
HTSMUXColor 
HTSMUXAccel 
HTSMUXIRSeeker 
HTSMUXProto 
HTSMUXColorNew 
HTSMUXAngle 
HTSMUXIRSeekerNew 
HTSMUXSensorCustom 
HTSMUXSensorNone 

Definition at line 100 of file hitechnic-sensormux.h.

enum tMUXSensor
Enumerator:
msensor_S1_1 
msensor_S1_2 
msensor_S1_3 
msensor_S1_4 
msensor_S2_1 
msensor_S2_2 
msensor_S2_3 
msensor_S2_4 
msensor_S3_1 
msensor_S3_2 
msensor_S3_3 
msensor_S3_4 
msensor_S4_1 
msensor_S4_2 
msensor_S4_3 
msensor_S4_4 

Definition at line 116 of file hitechnic-sensormux.h.


Function Documentation

bool HTSMUXconfigChannel ( tMUXSensor  muxsensor,
tConfigParams configparams 
)

Configure the SMUX for a specific sensor.
The parameters are as follows:

  • Channel mode
  • Number of bytes to request from attached sensor
  • I2C address
  • I2C register to request
Parameters:
muxsensorthe SMUX sensor port number
configparamsparameters for the channel's configuration
Returns:
true if there is a power source problem

Definition at line 414 of file hitechnic-sensormux.h.

int HTSMUXreadAnalogue ( tMUXSensor  muxsensor )

Read the value returned by the sensor attached the SMUX. This function is for analogue sensors.

Parameters:
muxsensorthe SMUX sensor port number
Returns:
the value of the sensor or -1 if an error occurred.

Definition at line 344 of file hitechnic-sensormux.h.

bool HTSMUXreadPort ( tMUXSensor  muxsensor,
tByteArray result,
int  numbytes,
int  offset 
)

Read the value returned by the sensor attached the SMUX. This function is for I2C sensors.

Parameters:
muxsensorthe SMUX sensor port number
resultarray to hold values returned from SMUX
numbytesthe size of the I2C reply
offsetthe offset used to start reading from
Returns:
true if no error occured, false if it did

Definition at line 317 of file hitechnic-sensormux.h.

bool HTSMUXreadPowerStatus ( tSensors  link )

Check if the battery is low

Parameters:
linkthe SMUX port number
Returns:
true if there is a power source problem
Examples:
hitechnic-irseeker-v2-enhanced-SMUX-test1.c, and hitechnic-irseeker-v2-SMUX-test1.c.

Definition at line 394 of file hitechnic-sensormux.h.

HTSMUXSensorType HTSMUXreadSensorType ( tMUXSensor  muxsensor )

Get the sensor type attached to specified SMUX port

Parameters:
muxsensorthe SMUX sensor port number
Returns:
the status byte

Definition at line 196 of file hitechnic-sensormux.h.

byte HTSMUXreadStatus ( tSensors  link )

Read the status of the SMUX

The status byte is made up of the following bits:

| D7 | D6 | D4 | D3 | D2 | D1 | D1 |

  • D1 - HTSMUX_STAT_BATT: No battery voltage detected
  • D2 - HTSMUX_STAT_BUSY: Auto-dected in progress status
  • D3 - HTSMUX_STAT_HALT: Multiplexer is halted
  • D4 - HTSMUX_STAT_ERROR: Command error detected
    Parameters:
    linkthe SMUX port number
    Returns:
    the status byte

Definition at line 177 of file hitechnic-sensormux.h.

bool HTSMUXsendCommand ( tSensors  link,
byte  command 
)

Send a command to the SMUX.

command can be one of the following:

  • HTSMUX_CMD_HALT
  • HTSMUX_CMD_AUTODETECT
  • HTSMUX_CMD_RUN

in progress.

Parameters:
linkthe SMUX port number
commandthe command to be sent to the SMUX
Returns:
true if no error occured, false if it did

Definition at line 284 of file hitechnic-sensormux.h.

void HTSMUXsensorTypeToString ( HTSMUXSensorType  muxsensor,
string &  sensorName 
)

Return a string for the sensor type.

Parameters:
muxsensorthe SMUX sensor port number
sensorNamethe string to hold the name of the sensor.

Definition at line 372 of file hitechnic-sensormux.h.

bool HTSMUXsetAnalogueActive ( tMUXSensor  muxsensor )

Set the mode of an analogue channel to Active (turn the light on)

Parameters:
muxsensorthe SMUX sensor port number
Returns:
true if no error occured, false if it did

Definition at line 244 of file hitechnic-sensormux.h.

bool HTSMUXsetAnalogueInactive ( tMUXSensor  muxsensor )

Set the mode of an analogue channel to Inactive (turn the light off)

Parameters:
muxsensorthe SMUX sensor port number
Returns:
true if no error occured, false if it did

Definition at line 260 of file hitechnic-sensormux.h.

bool HTSMUXsetMode ( tMUXSensor  muxsensor,
byte  mode 
)

Set the mode of a SMUX channel.

Mode can be one or more of the following:

  • HTSMUX_CHAN_I2C
  • HTSMUX_CHAN_9V
  • HTSMUX_CHAN_DIG0_HIGH
  • HTSMUX_CHAN_DIG1_HIGH
  • HTSMUX_CHAN_I2C_SLOW
    Parameters:
    muxsensorthe SMUX sensor port number
    modethe mode to set the channel to
    Returns:
    true if no error occured, false if it did

Definition at line 214 of file hitechnic-sensormux.h.


Variable Documentation

tConfigParams Analogue_config = {HTSMUX_CHAN_NONE, 0, 0, 0}

Array to hold SMUX config data for sensor

Definition at line 150 of file hitechnic-sensormux.h.

Array to hold I2C reply data

Definition at line 146 of file hitechnic-sensormux.h.

Array to hold I2C command data

Definition at line 145 of file hitechnic-sensormux.h.

ubyte HTSMUXstatus[4] = {HTSMUX_STAT_NOTHING, HTSMUX_STAT_NOTHING, HTSMUX_STAT_NOTHING, HTSMUX_STAT_NOTHING}

Array for holding sensor types

Definition at line 137 of file hitechnic-sensormux.h.