commit 76a1593fc3e7a8c063f798a17b9a3ce48bbf5e68
Author: Priya <pdeo@Phlegethon.(none)>
Date:   Wed Nov 30 19:29:15 2011 -0500

    Added buttons to libscout. Compiles!

diff --git a/scout/libscout/src/libbuttons.cpp b/scout/libscout/src/libbuttons.cpp
new file mode 100644
index 0000000..b55e825
--- /dev/null
+++ b/scout/libscout/src/libbuttons.cpp
@@ -0,0 +1,133 @@
+/**
+ * Copyright (c) 2011 Colony Project
+ * 
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ **/
+
+
+/**
+ * @file libbuttons.cpp
+ * @brief Contains buttons declarations and functions
+ * 
+ * Contains functions and definitions for the use of
+ * buttons
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+/* Author: Priyanka Deo
+*/
+
+#include "libbuttons.h"
+
+
+/* ROS node created in libscout.cpp */
+extern ros::NodeHandle libscout_node;
+
+/** ROS publisher and client declaration */
+ros::Publisher button_event_publisher;
+ros::ServiceClient query_buttons_client;
+
+/*!
+ * \brief Initialize the buttons module of libscout.
+ *
+ * Initialize the libscout node as a publisher of button_event and a client of
+ * query_buttons.
+ */
+void libbuttons_init()
+{
+  button_event_publisher = libscout_node.advertise<buttons::button_event>("libbuttons", 10);
+  query_buttons_client = libscout_node.serviceClient<buttons::query_buttons>("libbuttons");
+}
+
+/*!
+ * \brief Respond to button events
+ * Sends out button events if buttons are pressed. Tells which buttons
+ * have been pressed.
+ * \param which_button - Which button is pressed
+ * \param which A bitmask of which motors should be set
+ * \return Function status
+ */
+int event_button(int which_button)
+{
+  if(!ros::ok())
+  {
+    return LIB_ERROR;
+  }
+
+  /* Create message */
+  buttons::button_event msg;
+  switch(which_button)
+  {
+    case BUTTON1:
+      msg.button1_pressed = BUTTON_PRESSED;
+      break;
+    case BUTTON2:
+      msg.button2_pressed = BUTTON_PRESSED;
+      break;
+    default:
+      ROS_ERROR("Button %d does not exist\n", which_button);
+      return LIB_ERROR;
+  }
+
+  /* Publishes message to button_event topic */
+  button_event_publisher.publish(msg);
+  ros::spinOnce();
+
+  return LIB_OK;
+}
+
+/*!
+ * \brief Query the current status of the buttons
+ *
+ * Sends a request to the query_buttons service which will reply with the
+ *  current status of the buttons
+ *
+ * \param which_button - Which button we are querying
+ * \return status of the button queried, or LIB_ERROR on error
+ */
+
+int buttons_query(int which_button)
+{
+  buttons::query_buttons srv;
+  if(query_buttons_client.call(srv))
+  {
+    switch(which_button)
+    {
+      case BUTTON1:
+        return srv.response.button1_pressed;
+      case BUTTON2:
+        return srv.response.button2_pressed;
+      default:
+        ROS_ERROR("Button %d does not exist", which_button);
+        return LIB_ERROR;
+    }
+  }
+  else
+  {
+    ROS_ERROR("Failed to call service query_buttons");
+    return LIB_ERROR;
+  }
+  
+  /* Code never reaches here */
+  return 0;
+}
diff --git a/scout/libscout/src/libbuttons.h b/scout/libscout/src/libbuttons.h
new file mode 100644
index 0000000..c188daf
--- /dev/null
+++ b/scout/libscout/src/libbuttons.h
@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) 2011 Colony Project
+ * 
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ **/
+
+
+/**
+ * @file libbuttons.h
+ * @brief Contains buttons declarations and functions
+ * 
+ * Contains functions and definitions for the use of
+ * buttons
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+/* Author: Priyanka Deo
+*/
+
+#include "ros/ros.h"
+#include "constants.h"
+#include "buttons/query_buttons.h"
+#include "buttons/button_event.h"
+
+#ifndef _LIBBUTTONS_H_
+#define _LIBBUTTONS_H_
+
+/* Defines */
+#define BUTTON1 0
+#define BUTTON2 1
+#define BUTTON_PRESSED 1
+
+void libbuttons_init();
+int event_button(int which_button);
+int buttons_query(int which_button);
+
+#endif
+
