This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
7 changed files
with
427 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
src/se/nicklasgavelin/configuration/ProjectProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.