Class TINIDrinkMachine

java.lang.Object
  extended byBasicDrinkMachine
      extended byTINIDrinkMachine
All Implemented Interfaces:
DrinkMachineSpec

public class TINIDrinkMachine
extends BasicDrinkMachine

Implements the DrinkMachineSpec interface for TINI-based hardware.

Version:
$Revision: #34 $
Author:
Marius Grigoriu [marius@csh.rit.edu], Bill Kuker [kukester@csh.rit.edu], Kevin Thompson [antiduh@csh.rit.edu]

Nested Class Summary
private  class TINIDrinkMachine.ButtonLoop
          A class to independantly handle the callbacks for the buttons.
 
Field Summary
private  TINIExternalAdapter bus
          The bus that we use to communicate to the TINI one-wire devices with.
private  ConfigMgr configMgr
          The object we pull our configuration values from.
private  Vector drinkButtonListeners
          The objects that want button events.
private  boolean[] lightStatus
          The status's of the lights.
private  DrinkLoggerSpec log
          The class we send all of our log information to.
static int NUMRETRIES
           
static int POWERDOWNTIME
           
static int SLEEPTIME
          The amount to run the slot motor for.
 
Fields inherited from class BasicDrinkMachine
numSlots, slotArray, slotDataFileName, slotMgr
 
Constructor Summary
TINIDrinkMachine(ConfigMgr _configMgr, DrinkLoggerSpec _log)
          Construct the TINIDrinkMachine by saving the passed in parameters and reading in a few variables.
 
Method Summary
 void addDrinkButtonListener(DrinkButtonListener dbl)
          Add a listener to the list of objects requesting callbacks from the buttons
private  void calcTemp(String addie)
          Tells the one-wire temperature sensor to begin calculating its temperature.
 void delDrinkButtonListener(DrinkButtonListener dbl)
          Remove a listener from the list of objects requesting callbacks from the buttons
 String drop(int slot)
          Drops a drink.
 TINIExternalAdapter getBus()
          Returns the one-wire bus that is used by this TINIDrinkMachine
private  Float getTemp(String addie)
          Retrieves the temperature from the temp sensor.
 Float getTempKey(String key)
          Returns a Float object representing the temperature of the sensor specified by the key.
 void lightOff(int slot)
          Turns the given slots [empty] light off.
 void lightOn(int slot)
          Turns the given slots [empty] light on.
private  int readSwitch(String addie)
          Reads the state of a one-wire switch.
private  boolean setSwitch(String addie, boolean state)
          Toggles the one-wire device on or off.
 void shutdown(boolean reboot)
          Shuts down the drink server, but not the TINI.
 Vector slotTemp(int slot)
          Returns a Vector of Float's, one for each temp sensor associated with the given slot.
 float slotTempAvg(int slot)
          Returns the average temperature of the temp sensors listed for the given slot.
 long uptime()
          Returns the uptime, in milliseconds.
 
Methods inherited from class BasicDrinkMachine
drinksDropped, drinksLeft, formatSlotLine, getDrinkNames, getName, getNumSlots, getPrice, getSlot, getSlotArray, getSlotPrintout, isEnabled, setSlot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bus

private TINIExternalAdapter bus
The bus that we use to communicate to the TINI one-wire devices with.


drinkButtonListeners

private Vector drinkButtonListeners
The objects that want button events.


log

private DrinkLoggerSpec log
The class we send all of our log information to.


lightStatus

private boolean[] lightStatus
The status's of the lights.


configMgr

private ConfigMgr configMgr
The object we pull our configuration values from.


SLEEPTIME

public static final int SLEEPTIME
The amount to run the slot motor for. This value should be just enough to rotate the cam to activate the switch to power the motor until the cam rotates and the switch deactivates.

See Also:
Constant Field Values

POWERDOWNTIME

public static final int POWERDOWNTIME
See Also:
Constant Field Values

NUMRETRIES

public static final int NUMRETRIES
See Also:
Constant Field Values
Constructor Detail

TINIDrinkMachine

public TINIDrinkMachine(ConfigMgr _configMgr,
                        DrinkLoggerSpec _log)
                 throws IOException
Construct the TINIDrinkMachine by saving the passed in parameters and reading in a few variables.

Parameters:
_configMgr - The ConfigMgr to use for config options.
_log - The DrinkLoggerSpec to use for printing log messages.
Method Detail

shutdown

public void shutdown(boolean reboot)
Shuts down the drink server, but not the TINI. If reboot is true, then reboot the TINI

Specified by:
shutdown in interface DrinkMachineSpec
Specified by:
shutdown in class BasicDrinkMachine
Parameters:
reboot - If true, reboot the TINI.

uptime

public long uptime()
Returns the uptime, in milliseconds.

Specified by:
uptime in interface DrinkMachineSpec
Specified by:
uptime in class BasicDrinkMachine
Returns:
The uptime of the TINI, in milliseconds.

getBus

public TINIExternalAdapter getBus()
Returns the one-wire bus that is used by this TINIDrinkMachine

Returns:
The bus.

drop

public String drop(int slot)
Drops a drink. If the drop is successful, drop returns null. Else, an error message is returned.

Specified by:
drop in interface DrinkMachineSpec
Specified by:
drop in class BasicDrinkMachine
Parameters:
slot - The index of the slot to drop. The index is zero based.
Returns:
null if the drop is successful, else an error message.

readSwitch

private int readSwitch(String addie)
Reads the state of a one-wire switch. This is done by toggling it twice, then asking to read it.

Parameters:
addie - The 64-bit address of the switch
Returns:
If the read is successful, the value is returned. If the read is unsuccessful, then -1 is returned.

setSwitch

private boolean setSwitch(String addie,
                          boolean state)
Toggles the one-wire device on or off.

Parameters:
addie - The address of the switch to set.
state - The state to set the switch to.
Returns:
True if the operation was successful, false otherwise.

lightOn

public void lightOn(int slot)
Turns the given slots [empty] light on.

Specified by:
lightOn in interface DrinkMachineSpec
Specified by:
lightOn in class BasicDrinkMachine
Parameters:
slot - The slot index associated with the light to turn on.
See Also:
(int)

lightOff

public void lightOff(int slot)
Turns the given slots [empty] light off.

Specified by:
lightOff in interface DrinkMachineSpec
Specified by:
lightOff in class BasicDrinkMachine
Parameters:
slot - The slot associated with the light to turn off.
See Also:
BasicDrinkMachine.lightOn(int)

slotTemp

public Vector slotTemp(int slot)
Returns a Vector of Float's, one for each temp sensor associated with the given slot. If there is no data, then the Vector returned is empty, but not null.

Specified by:
slotTemp in interface DrinkMachineSpec
Specified by:
slotTemp in class BasicDrinkMachine
Parameters:
slot - The slot to retrieve the temp's of the sensors for.
Returns:
The Vector of Float objects representing the temps of the sensors.

slotTempAvg

public float slotTempAvg(int slot)
Returns the average temperature of the temp sensors listed for the given slot. If there is no data available, then -127 is returned. Note that the return value is a primitive float, not Float.

Specified by:
slotTempAvg in interface DrinkMachineSpec
Specified by:
slotTempAvg in class BasicDrinkMachine
Parameters:
slot - The slot to retrieve the average temperature for.
Returns:
The average temperature.

getTempKey

public Float getTempKey(String key)
Returns a Float object representing the temperature of the sensor specified by the key. The key is the mnemonic given to the temp sensor. Key is not the sensors address. If there is a problem, the returned temperature is -127.

Specified by:
getTempKey in interface DrinkMachineSpec
Specified by:
getTempKey in class BasicDrinkMachine
Parameters:
key - The sensors mnemonic key.
Returns:
A Float object representing the temperature, in celsius.

calcTemp

private void calcTemp(String addie)
Tells the one-wire temperature sensor to begin calculating its temperature.

Parameters:
addie - The address of the sensor to poke.
See Also:
getTemp( String )

getTemp

private Float getTemp(String addie)
               throws Exception
Retrieves the temperature from the temp sensor. If the temperature cannot be retrieved, then the return will be null. Else, the return will be the temperature from the sensor.
Before the method can be called, calcTemp(String) must be called to tell the temp sensor to calculate its temp.

Parameters:
addie - The address of the sensor to retrieve.
Returns:
The sensors temperature, or null if there is a problem.
Throws:
Exception

addDrinkButtonListener

public void addDrinkButtonListener(DrinkButtonListener dbl)
Add a listener to the list of objects requesting callbacks from the buttons

Specified by:
addDrinkButtonListener in interface DrinkMachineSpec
Specified by:
addDrinkButtonListener in class BasicDrinkMachine
Parameters:
dbl - The DrinkButtonListener to add to the list.
See Also:
delDrinkButtonListener( DrinkButtonListener )

delDrinkButtonListener

public void delDrinkButtonListener(DrinkButtonListener dbl)
Remove a listener from the list of objects requesting callbacks from the buttons

Specified by:
delDrinkButtonListener in interface DrinkMachineSpec
Specified by:
delDrinkButtonListener in class BasicDrinkMachine
Parameters:
dbl - The DrinkButtonListener to remove.