ch.aplu.nxt
Class PrototypeSensor

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.PrototypeSensor
All Implemented Interfaces:
SharedConstants

public class PrototypeSensor
extends I2CSensor

Class that represents a prototype sensor (HiTechnic NXT Prototyping Board). The following register layout is assumed:
0x00-0x07 Version number
0x08-0x0F Manufacturer
0x10-0x17 Sensor type
0x42 Analog channel 0, pin A0, upper 8bits
0x43 Analog channel 0, pin A0, lower 2bits
0x44 Analog channel 1, pin A1, upper 8bits
0x45 Analog channel 1, pin A1, lower 2bits
0x46 Analog channel 2, pin A2, upper 8bits
0x47 Analog channel 2, pin A2, lower 2bits
0x48 Analog channel 3, pin A3, upper 8bits
0x49 Analog channel 3, pin A3, lower 2bits
0x4A Analog channel 4, pin A4, upper 8bits
0x4B Analog channel 4, pin A4, lower 2bits
0x4C Digital input channels, bits 0..5
0x4D Digitag output channels, bits 0..5
0x4E Digital control, bits 0..5, low: input (default), high: output
0x4F Sampling time 4..100(ms)

Analog inputs in range 0..3.3V, 10 bit (0..1023)
Digital inputs/outputs 0/3.3V, pin B0..B5, max. 12mA per output (high or low)


Field Summary
 
Fields inherited from class ch.aplu.nxt.Part
robot
 
Fields inherited from interface ch.aplu.nxt.SharedConstants
ABOUT, ANGLE, ANGLESTEPSMODE, BOOLEANMODE, BOOT, BRAKE, CELSIUSMODE, CLOSE, CUSTOM, DEBUG_LEVEL_HIGH, DEBUG_LEVEL_LOW, DEBUG_LEVEL_MEDIUM, DEBUG_LEVEL_OFF, DELETE, DELETE_USER_FLASH, DIRECT_COMMAND_NOREPLY, DIRECT_COMMAND_REPLY, FAHRENHEITMODE, FIND_FIRST, FIND_NEXT, GET_BATTERY_LEVEL, GET_CURRENT_PROGRAM_NAME, GET_DEVICE_INFO, GET_FIRMWARE_VERSION, GET_INPUT_VALUES, GET_OUTPUT_STATE, HIGH_SPEED_BUFFER, KEEP_ALIVE, LIGHT_ACTIVE, LIGHT_INACTIVE, LOWSPEED, LOWSPEED_9V, LS_GET_STATUS, LS_READ, LS_WRITE, MESSAGE_READ, MESSAGE_WRITE, MODEMASK, MOTOR_RUN_STATE_IDLE, MOTOR_RUN_STATE_RAMPDOWN, MOTOR_RUN_STATE_RAMPUP, MOTOR_RUN_STATE_RUNNING, MOTORON, NO_OF_SENSOR_TYPES, NO_SENSOR, NXJ_FIND_FIRST, NXJ_FIND_NEXT, 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, RAWMODE, READ, REFLECTION, REGULATED, REGULATION_MODE_IDLE, REGULATION_MODE_MOTOR_SPEED, REGULATION_MODE_MOTOR_SYNC, REPLY_COMMAND, RESET_MOTOR_POSITION, RESET_SCALED_INPUT_VALUE, SET_BRICK_NAME, SET_INPUT_MODE, SET_OUTPUT_STATE, SLOPEMASK, SOUND_DB, SOUND_DBA, START_PROGRAM, STOP_PROGRAM, STOP_SOUND_PLAYBACK, SWITCH, SYSTEM_COMMAND_NOREPLY, SYSTEM_COMMAND_REPLY, TEMPERATURE, TITLE, TITLEMP, TRANSITIONCNTMODE, VERSION, WRITE
 
Constructor Summary
PrototypeSensor()
          Creates a sensor instance connected to port S1.
PrototypeSensor(SensorPort port)
          Creates a sensor instance connected to the given port.
 
Method Summary
 void addPrototypeListener(PrototypeListener prototypeListener)
          Registers the given prototype listener.
protected  void cleanup()
           
protected  void init()
           
 void read(int[] ain, int[] din)
          Reads the sensor.
 void readAnalog(int[] ain)
          Reads the sensor.
 void readDigital(int[] din)
          Reads the sensor.
 void setDIO(int[] ioControl)
          Sets the direction of the 6 digital input/output channels.
 void setSamplingPeriod(int period)
          Sets the sampling period of the ADC (4..100 ms, default 4 ms).
protected  void startPrototypeThread()
           
protected  void stopPrototypeThread()
           
 void write(int[] dout)
          Writes the given bit state (low/high) to the digital output channels.
 
Methods inherited from class ch.aplu.nxt.I2CSensor
fetchString, getData, sendData, sendData
 
Methods inherited from class ch.aplu.nxt.Sensor
getPort, getPortId, getPortLabel, LSRead, LSWrite, readBooleanValue, readNormalizedValue, readRawValue, readScaledValue, setTypeAndMode
 
Methods inherited from class ch.aplu.nxt.Part
setRobot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrototypeSensor

public PrototypeSensor(SensorPort port)
Creates a sensor instance connected to the given port.

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

PrototypeSensor

public PrototypeSensor()
Creates a sensor instance connected to port S1.

Method Detail

init

protected void init()
Overrides:
init in class I2CSensor

cleanup

protected void cleanup()
Overrides:
cleanup in class I2CSensor

setDIO

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

Parameters:
ioControl - the direction of each channel. 0: input, 1: output

readAnalog

public void readAnalog(int[] ain)
Reads the sensor. Analog input data 0..1023 are returned in the given ain.


readDigital

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


setSamplingPeriod

public void setSamplingPeriod(int period)
Sets the sampling period of the ADC (4..100 ms, default 4 ms).

Parameters:
period - the new sampling period

read

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


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 6 that holds the bit state: 0->low, 1->high

addPrototypeListener

public void addPrototypeListener(PrototypeListener prototypeListener)
Registers the given prototype listener. If the touch thread is not yet started, starts it now.

Parameters:
prototypeListener - the PrototypeListener to become registered.

startPrototypeThread

protected void startPrototypeThread()

stopPrototypeThread

protected void stopPrototypeThread()