Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Shutdown hook, Configuration update
Browse files Browse the repository at this point in the history
Added a shutdown hook to Robot to send reset settings on disconnect.
Also added a new Configuration type locateion in sphero.configuration
  • Loading branch information
Nicklas Gavelin committed Mar 5, 2012
1 parent 1f3e315 commit d2a3240
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 183 deletions.
2 changes: 0 additions & 2 deletions experimental/experimental/test/Experimental_Main.java
Expand Up @@ -19,15 +19,13 @@
import se.nicklasgavelin.sphero.Robot;
import se.nicklasgavelin.sphero.RobotListener;
import se.nicklasgavelin.sphero.command.CommandMessage;
import se.nicklasgavelin.sphero.command.RGBLEDCommand;
import se.nicklasgavelin.sphero.command.RawMotorCommand;
import se.nicklasgavelin.sphero.command.SetDataStreamingCommand;
import se.nicklasgavelin.sphero.exception.InvalidRobotAddressException;
import se.nicklasgavelin.sphero.exception.RobotBluetoothException;
import se.nicklasgavelin.sphero.macro.command.Delay;
import se.nicklasgavelin.sphero.macro.MacroObject;
import se.nicklasgavelin.sphero.macro.command.RawMotor;
import experimental.sphero.macro.Rotate;
import se.nicklasgavelin.sphero.macro.command.*;
import se.nicklasgavelin.sphero.response.ResponseMessage;
import se.nicklasgavelin.sphero.response.information.DataResponse;
Expand Down
176 changes: 176 additions & 0 deletions src/se/nicklasgavelin/configuration/ProjectProperties.java
@@ -0,0 +1,176 @@
/*
* Please read the LICENSE file that is included with the source
* code.
*/

package se.nicklasgavelin.configuration;

import java.awt.Color;
import java.util.Properties;
import se.nicklasgavelin.log.Logging;
import se.nicklasgavelin.sphero.Robot;
import se.nicklasgavelin.sphero.RobotSetting;
import se.nicklasgavelin.sphero.command.RawMotorCommand;
import se.nicklasgavelin.util.Value;

/**
* Used for returning current configuration settings
* Settings are stored in project.properties in the same packet as this class.
*
* @author Nicklas Gavelin, nicklas.gavelin@gmail.com, Luleå University of
* Technology
*/
public class ProjectProperties extends Properties
{
private static ProjectProperties instance;


/**
* Create project properties
*/
private ProjectProperties()
{
super();

try
{
// Load the property file
this.load( ProjectProperties.class.getResourceAsStream( "project.properties" ) );
}
catch ( Exception e )
{
// Unable to load property file, sorry :(
}
}


/**
* Returns default robot settings
*
* @return Default robot settings
*/
public RobotSetting getRobotSetting()
{
return new RobotSetting(
new Color(
Integer.parseInt( this.getProperty( "sphero.color.rgb.red", "255" ) ),
Integer.parseInt( this.getProperty( "sphero.color.rgb.green", "255" ) ),
Integer.parseInt( this.getProperty( "sphero.color.rgb.blue", "255" ) )
),
Integer.parseInt( this.getProperty( "sphero.pinginterval", "255" ) ),
Float.parseFloat( this.getProperty( "sphero.color.brightness", "1" ) ),
Integer.parseInt( this.getProperty( "sphero.motor.heading", "0" ) ),
Integer.parseInt( this.getProperty( "sphero.motor.speed", "0" ) ),
Integer.parseInt( this.getProperty( "sphero.macro.size", "0" ) ),
Integer.parseInt( this.getProperty( "sphero.macro.storage", "0" ) ),
Integer.parseInt( this.getProperty( "sphero.macro.minsize", "128" ) ),
Boolean.parseBoolean( this.getProperty( "sphero.motor.stop", "true" ) ),
Float.parseFloat( this.getProperty( "sphero.macro.rotationrate", "0" ) ),
RawMotorCommand.MOTOR_MODE.valueOf( this.getProperty( "sphero.motor.motormode", RawMotorCommand.MOTOR_MODE.FORWARD.toString() ) )
);
}


/**
* Returns size of received buffer
*
* @return The size of the received buffer
*/
public int getBufferSize()
{
return Integer.parseInt( this.getProperty( "sphero.socket.buffersize", "256" ) );
}

/**
* Returns the current debug state
*
* @return True for on, false for off
*/
public boolean getDebugEnabled()
{
return Boolean.parseBoolean( this.getProperty( "debug.enabled", "false" ) );
}


/**
* Set debug status
*
* @param enabled The new debug status (true for on, false otherwise)
*/
public void setDebugEnabled( boolean enabled )
{
this.setProperty( "debug.enabled", Boolean.toString( enabled ) );
}


/**
* Returns the current bluecove debug state
*
* @return The current bluecove debug state
*/
public boolean getBluecoveDebugEnabled()
{
return Boolean.parseBoolean( this.getProperty( "debug.bluecove.enabled", "false" ) );
}


/**
* Set bluecove debug status
*
* @param enabled New debug status
*/
public void setBluecoveDebugEnabled( boolean enabled )
{
this.setProperty( "debug.bluecove.enabled", Boolean.toString( enabled ) );
}


/**
* Returns the logger name
*
* @return The logger name
*/
public String getLoggerName()
{
return this.getProperty( "debug.loggername", "se.nicklasgavelin" );
}


/**
* Set the name of the logger
* WILL NOT WORK AFTER THE LOGGER HAVE BEEN INITIALIZED
*
* @param name The new name for the logger
*/
public void setLoggerName( String name )
{
this.setProperty( "debug.loggername", name );
}


/**
* Returns the current debug level,
* default level is Logging.Level.FATAL
*
* @return The set debug level
*/
public Logging.Level getDebugLevel()
{
return Logging.Level.valueOf( this.getProperty( "debug.level", Logging.Level.FATAL.toString() ) );
}


/**
* Returns the properies instance
*
* @return The property instance
*/
public static ProjectProperties getInstance()
{
// Check if we have a previous instance
if ( ProjectProperties.instance == null )
ProjectProperties.instance = new ProjectProperties();

return ProjectProperties.instance;
}
}
26 changes: 26 additions & 0 deletions src/se/nicklasgavelin/configuration/project.properties
@@ -0,0 +1,26 @@
# Debugging
debug.level = INFO
debug.enabled = true
debug.loggername = se.nicklasgavelin.se

debug.bluecove.enabled = false

# Spero
sphero.macro.size = 200
sphero.macro.storage = 600
sphero.macro.minsize = 150
sphero.pinginterval = 60000

sphero.color.rgb.red = 255
sphero.color.rgb.blue = 255
sphero.color.rgb.green = 255

sphero.color.brightness = 1

sphero.motor.speed = 0
sphero.motor.stop = true
sphero.motor.heading = 0
sphero.motor.rotationrate = 0

# Other
sphero.socket.buffersize = 50
46 changes: 0 additions & 46 deletions src/se/nicklasgavelin/log/Configuration.java

This file was deleted.

0 comments on commit d2a3240

Please sign in to comment.