Permalink
Browse files

Shutdown hook, Configuration update

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...
1 parent 1f3e315 commit d2a324089bfbd62c649445e70c8cf14565f97733 @nicklasgav committed Mar 5, 2012
@@ -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;
@@ -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;
+ }
+}
@@ -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
@@ -1,46 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- *
- * @author Nicklas Gavelin, nicklas.gavelin@gmail.com, Luleå University of Technology
- */
-package se.nicklasgavelin.log;
-
-import com.intel.bluetooth.DebugLog;
-
-/**
- * Handles configuration such as debug level and debugging
- *
- * @author Nicklas Gavelin
- */
-public class Configuration
-{
- /* Debug settings */
-
- /**
- * Flag for turning on/off debugging
- */
- public static boolean debugEnabled = true;
-
- /**
- * Name of logger
- */
- public static final String loggerName = "se.nicklasgavelin";
-
- /**
- * Value for turning on/off Bluecove library debugging
- */
- public static boolean bluecoveDebugEnabled = false;
-
- /**
- * The logging level during runtime
- */
- public static Logging.Level debugLevel = Logging.Level.ERROR;
-
- static
- {
- // Set bluecove debugging
- DebugLog.setDebugEnabled( Configuration.bluecoveDebugEnabled );
- Logging.info( "Turning " + (Configuration.bluecoveDebugEnabled ? "ON" : "OFF") + " bluecove debugger" );
- }
-}
Oops, something went wrong.

0 comments on commit d2a3240

Please sign in to comment.