ch.aplu.nxt
Class SuperProSensor

java.lang.Object
  extended by ch.aplu.nxt.Part
      extended by ch.aplu.nxt.Sensor
          extended by ch.aplu.nxt.I2CSensor
              extended by ch.aplu.nxt.SuperProSensor
All Implemented Interfaces:
SharedConstants

public class SuperProSensor
extends I2CSensor

Class that represents a SuperPro prototype sensor (HiTechnic NXT SuperPro Prototype Board).

The following I2C register layout is assumed:
Device address 0x10
0x00-0x07 Version number
0x08-0x0F Manufacturer
0x10-0x17 Sensor type
0x42 Analog input channel 0, pin A0, upper 8bits
0x43 Analog input channel 0, pin A0, lower 2bits
0x44 Analog input channel 1, pin A1, upper 8bits
0x45 Analog input channel 1, pin A1, lower 2bits
0x46 Analog input channel 2, pin A2, upper 8bits
0x47 Analog input channel 2, pin A2, lower 2bits
0x48 Analog input channel 3, pin A3, upper 8bits
0x49 Analog input channel 3, pin A3, lower 2bits
0x4C Digital input channels, bits 0..7
0x4D Digitag output channels, bits 0..7
0x4E Digital control, bits 0..7, low: input (default), high: output
0x50 Strobe output, bits 0..3
0x51 LED control, bits 0..3
0x52 Analog output channel 0 mode
0x53 Analog output channel 0 frequency, upper 5bits
0x54 Analog output channel 0 frequency, lower 8bits
0x55 Analog output channel 0 voltage, upper 8bits (exotic!)
0x56 Analog output channel 0 voltage, lower 2bits (exotic!)
0x57 Analog output channel 1 mode
0x58 Analog output channel 1 frequency, upper 5bits
0x59 Analog output channel 1 frequency, lower 8bits
0x5A Analog output channel 1 voltage, upper 8bits (exotic!)
0x5B Analog output channel 1 voltage, lower 2bits (exotic!)
Analog inputs in range 0..3.3V, 10 bit (0..1023)
Digital inputs/outputs 0/3.3V, pin B0..B7, max. 12mA per output (high or low)
Strobe outputs 0..3 general purpose digital output
Strobe output WR: rectangle pulse of approx. 0.5 us length (3V approx.) at every write action to digital out (B0..B7 ports)
Strobe output RD: rectangle pulse of approx. 0.5 us length (3V approx.) at every read action of digital in (B0..B7 ports)
Analog output frequency 1..8191 Hz, analog output voltage 0..3.3V (0..1023)
Analog output modes:
0: DC
1: sine wave
2: square wave
3: positive sawtooth
4: negative sawtooth
5: triangle wave
6: pulse width modulation


Nested Class Summary
static class SuperProSensor.LED
          Enumeration for the on board LEDs.
 
Field Summary
static SuperProSensor.LED blueLED
          Constant for the blue onboard LED.
static SuperProSensor.LED redLED
          Constant for the red onboard LED.
 
Fields inherited from interface ch.aplu.nxt.SharedConstants
ABOUT, ACCELEROMETERPOLLDELAY, ANGLE, ANGLESTEPSMODE, AXELENGTH, BOOLEANMODE, BOOT, BRAKE, BRAKEDELAY, CELSIUSMODE, CLOSE, COLORPOLLDELAY, COMPASSPOLLDELAY, CRAWLERROTATIONFACTOR, CRAWLERROTATIONSPEED, CRAWLERSPEED, CRAWLERSTEPFACTOR, CUSTOM, DEBUG_LEVEL_HIGH, DEBUG_LEVEL_LOW, DEBUG_LEVEL_MEDIUM, DEBUG_LEVEL_OFF, DEBUGLEVEL, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GEARSPEED, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, GYROPOLLDELAY, HIGH_SPEED_BUFFER, INFRAREDSEEKERPOLLDELAY, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LIGHTPOLLDELAY, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTIONDETECTORPOLLDELAY, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, MOTORSPEED, MOTORSPEEDFACTOR, MOTORSPEEDMULTIPLIER, NO_OF_SENSOR_TYPES, NO_SENSOR, OPEN_APPEND_DATA, OPEN_READ, OPEN_READ_LINEAR, OPEN_WRITE, OPEN_WRITE_DATA, OPEN_WRITE_LINEAR, PCTFULLSCALEMODE, PERIODCOUNTERMODE, PLAY_SOUND_FILE, PLAY_TONE, POLL, POLL_BUFFER, POLL_LENGTH, PROTOTYPEPOLLDELAY, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, RFIDPOLLDELAY, SENSOREVENTDELAY, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, SOUNDPOLLDELAY, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TITLE, TITLEMP, TOUCHPOLLDELAY, TRANSITIONCNTMODE, TURTLEROTATIONFACTOR, TURTLEROTATIONSPEED, TURTLESPEED, TURTLESTEPFACTOR, ULTRASONICPOLLDELAY, VERSION, WRITE
 
Constructor Summary
SuperProSensor()
          Creates a sensor instance connected to port S1.
SuperProSensor(SensorPort port)
          Creates a sensor instance connected to the given port.
 
Method Summary
 void addPrototypeListener(PrototypeListener prototypeListener)
          Registers the given prototype listener.
 void ledOff()
          Turn off both onboard LEDs (red and blue).
 void ledOff(SuperProSensor.LED led)
          Turn the given onboard LED off.
 void ledOn()
          Turn on both onboard LEDs (red and blue).
 void ledOn(SuperProSensor.LED led)
          Turn the given onboard LED on.
 void read(int[] ain, int[] din)
          Reads the sensor.
 void readAnalog(int[] ain)
          Reads the analog input of the sensor.
 void readDigital(int[] din)
          Reads the sensor.
 void setAnalogOut(int port, int mode, int frequency, int voltage)
          Enables the digital output.
 void setDIO(int[] ioControl)
          Sets the direction of the 8 digital input/output channels.
 void write(int value)
          Writes the lower byte of the given value to the digital output channels.
 void write(int[] dout)
          Writes the given bit state (low/high) to the digital output channels.
 void writeStrobe(int value)
          Writes the lower half byte (lower 4 bits) of the given value to the strobe output channels.
 void writeStrobe(int[] sout)
          Writes the given bit state (low/high) to the strobe output channels.
 
Methods inherited from class ch.aplu.nxt.I2CSensor
getData, getLejosI2CSensor, getLejosPort, getProductID, getVersion, sendData, sendData
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

redLED

public static final SuperProSensor.LED redLED
Constant for the red onboard LED.


blueLED

public static final SuperProSensor.LED blueLED
Constant for the blue onboard LED.

Constructor Detail

SuperProSensor

public SuperProSensor(SensorPort port)
Creates a sensor instance connected to the given port. (default: all digital channels as input)

Parameters:
port - the port where the sensor is plugged-in

SuperProSensor

public SuperProSensor()
Creates a sensor instance connected to port S1. (default: all digital channels as input)

Method Detail

setDIO

public void setDIO(int[] ioControl)
Sets the direction of the 8 digital input/output channels.

Parameters:
ioControl - the direction of each channel. 0: input, 1: output (default: all digital channels as input)

readAnalog

public void readAnalog(int[] ain)
Reads the analog input of the sensor. Analog input data 0..1023 (corresponding to 0..3.3 V) are returned in the given ain.

Parameters:
ain - an integer array of length 4 where to get the analog values

readDigital

public void readDigital(int[] din)
Reads the sensor. Digital input data 0 (corresponds to low state, 0 V) or 1 (corresponds to high state, 3.3 V) is returned in the given din. For digital channels defined as outputs -1 is returned.

Parameters:
din - an integer array of length 8 where to get the values

read

public void read(int[] ain,
                 int[] din)
Reads the sensor. Analog input data 0..1023 (corresponding to 0..3.3 V) are returned in the given ain, digital input data (0, 1) in the given din. For digital channels defined as outputs -1 is returned.

Parameters:
ain - an integer array of length 4 where to get the analog values
din - an integer array of length 8 where to get the digital values

write

public void write(int value)
Writes the lower byte of the given value to the digital output channels. Only channels set as output will be affected. Input channel bits are ignored.

Parameters:
value - the lower 8 bits are written to the digital output channel.

write

public void write(int[] dout)
Writes the given bit state (low/high) to the digital output channels. Only channels set as output will be affected. Input channel bits are ignored.

Parameters:
dout - an integer array of length 8 that holds the bit state: 0->low, 1->high

writeStrobe

public void writeStrobe(int value)
Writes the lower half byte (lower 4 bits) of the given value to the strobe output channels.

Parameters:
value - the lower 4 bits are written to the strobe output channel.

writeStrobe

public void writeStrobe(int[] sout)
Writes the given bit state (low/high) to the strobe output channels.

Parameters:
sout - an integer array of length 4 that holds the bit state: 0->low, 1->high

ledOn

public void ledOn()
Turn on both onboard LEDs (red and blue). When the program terminates, the current state of the LEDs is maintained.


ledOn

public void ledOn(SuperProSensor.LED led)
Turn the given onboard LED on. When the program terminates, the current state of the LEDs is maintained.

Parameters:
led - a value of enumeration LED

ledOff

public void ledOff()
Turn off both onboard LEDs (red and blue). When the program terminates, the current state of the LEDs is maintained.


ledOff

public void ledOff(SuperProSensor.LED led)
Turn the given onboard LED off. When the program terminates, the current state of the LEDs is maintained.

Parameters:
led - a value of enumeration LED

setAnalogOut

public void setAnalogOut(int port,
                         int mode,
                         int frequency,
                         int voltage)
Enables the digital output. The following modes are available:
1: DC voltage level 2: Sine wave 3: Square wave 4: Positive going sawtooth 5: Negative going sawtooth 5: Triangle wave 6: PWM voltage Once the output is enabled, it remains active even when the program terminates.

Parameters:
port - 0: for digital output O0, 1: for digital output O1
mode - the mode (1..5)
frequency - the frequency in Hertz (1..8191)
voltage - the peak-to-peak voltage (0..1021 corresponding to 0..3.3V)

addPrototypeListener

public void addPrototypeListener(PrototypeListener prototypeListener)
Registers the given prototype listener.

Parameters:
prototypeListener - the SuperProListener to become registered.