Index: include/libwireless/sensor_matrix.h
===================================================================
--- include/libwireless/sensor_matrix.h	(nonexistent)
+++ include/libwireless/sensor_matrix.h	(revision 1554)
@@ -0,0 +1,101 @@
+/**
+ * Copyright (c) 2007 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 sensor_matrix.h
+ * @brief Definitions for sensor matrices
+ *
+ * Contains functions and declarations for using sensor matrices.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+#ifndef SENSOR_MATRIX_H
+#define SENSOR_MATRIX_H
+
+
+/**
+ * @defgroup sensormatrix Sensor Matrix
+ * @brief the robot sensor matrix
+ *
+ * These functions and structures are used for localization
+ * to determine the relative directions of robots.
+ *
+ * @{
+ **/
+
+#define MAXIMUM_XBEE_ID		0x10
+#define READING_UNKNOWN		0xFF
+
+/**
+ * @struct SensorMatrix
+ *
+ * A sensor matrix.
+ **/
+//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
+// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
+// Thus, pointers should be first, followed by int, followed by char.
+typedef struct
+{
+	/**
+	 * The number of robots in the token ring.
+	 **/
+	int numJoined;
+	/**
+	 * The element representing a robot is true if that robot
+	 * is in the token ring and false otherwise.
+	 **/
+	unsigned char joined[MAXIMUM_XBEE_ID];
+
+	// on the bayboard, we don't include the matrix to save memory.
+#ifndef BAYBOARD
+	/**
+	 * The matrix. Each row represents the readings of one
+	 * robot.
+	 **/
+	unsigned char matrix[MAXIMUM_XBEE_ID][MAXIMUM_XBEE_ID];
+#endif
+} SensorMatrix;
+
+/**@brief Create a sensor matrix **/
+void sensor_matrix_create(void);
+/**@brief Set a reading in a sensor matrix **/
+void sensor_matrix_set_reading(int observer, int robot, int reading);
+/**@brief Get a reading in a sensor matrix **/
+int sensor_matrix_get_reading(int observer, int robot);
+/**@brief Set whether the robot is in the token ring **/
+void sensor_matrix_set_in_ring(int robot, int in);
+/**@brief Get whether the robot is in the sensor ring **/
+int sensor_matrix_get_in_ring(int robot);
+/**@brief Get the number of robots which have joined the token ring **/
+int sensor_matrix_get_joined(void);
+/**@brief Get the maximum size of the sensor matrix **/
+int sensor_matrix_get_size(void);
+
+/** @} **/ //end defgroup
+
+
+#endif
+
Index: include/libwireless/wireless.h
===================================================================
--- include/libwireless/wireless.h	(nonexistent)
+++ include/libwireless/wireless.h	(revision 1554)
@@ -0,0 +1,164 @@
+/**
+ * Copyright (c) 2007 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 wireless.h
+ * @brief Contains definitions for the wireless library.
+ *
+ * Contains functions for the wireless library.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+#ifndef WIRELESS_H
+#define WIRELESS_H
+
+//Note: If this is raised above 16, we will need to do
+//something about frame numbers for TX Status packets.
+/**
+ * The maximum number of packet groups.
+ **/
+//TODO: a PacketGroupHandler is at least 10 bytes (I don't know if function pointers are 2 bytes
+// or 4 bytes).  That means that in the c file, your array of packet groups is at least 160 bytes.
+// Normally that might be fine (the robot's avr chips have 4k SRAM), but austin's chip only has
+// 1k SRAM, so if this number can be reduced or if the size of the struct could be reduced, that would be a plus.
+#define WL_MAX_PACKET_GROUPS 16
+
+/**
+ * @defgroup wireless Wireless
+ * @brief Wireless definitions.
+ *
+ * Contains functions and definitions for dealing with wireless functionality.<br><br>
+ *
+ * The wireless library provides a modular method for dealing with
+ * wireless packets, by allowing packet groups to be registered.
+ * A packet group is a collection of packets which share a packet
+ * group code. Each packet in the group also has a type. A packet
+ * group code and type are sent with each packet. When a packet
+ * with a group code registered in the wireless library is
+ * received, the corresponding event handler is called. The
+ * event handler uses the packet type and other information
+ * stored in the packet to respond.<br><br>
+ *
+ * This architecture allows different wireless functionality to be
+ * defined and handled separately, making it simpler and more
+ * efficient to take advantage of the XBee's wireless functionality.
+ *
+ * @{
+ **/
+
+/**
+ * @struct PacketGroupHandler
+ * A PacketGroupHandler represents a packet group, and is used to
+ * register a packet group with the wireless library. It contains
+ * handlers for various events which can occur related to a packet
+ * group.
+ **/
+//TODO: the order of member variables in this struct should be changed in case the compile packs the struct
+// In order to achieve the best packing, the variables should be listed in order of decreasing memory size.
+// Thus, pointers should be first, followed by int, followed by char.
+typedef struct
+{
+	/**
+	 * The group code for this packet group. This number
+	 * must be unique. The maximum number of packet groups
+	 * is defined by WL_MAX_PACKET_GROUPS.
+	 **/
+  //TODO: if this number must be less than or equal to WL_MAX_PACKET_GROUPS, don't you only need
+  // one byte for it and it can be made an unsigned char?
+	unsigned int groupCode;
+
+	/**
+	 * Called every half second (not in interrupt,
+	 * but in wl_do).
+	 **/
+	void (*timeout_handler) (void);
+
+	/**
+	 * Called when a transmit status packet is received
+	 * from the XBee where the first four bits of the frame
+	 * are  the group code.
+	 *
+	 * @param frame the last four bits of the frame
+	 * @param received is true if we received an ack, 0 if
+	 * we did not.
+	 **/
+	void (*handle_response) (int frame, int received);
+
+	/**
+	 * Called when we receive a packet from this group.
+	 *
+	 * @param type the packet type
+	 * @param source the 16-bit address of the XBee this
+	 * packet was sent from
+	 * @param packet the packet received
+	 * @param length the length of the packet
+	 **/
+	void (*handle_receive) (char type, int source, unsigned char* packet, int length);
+
+	/**
+	 * Called for any cleanup when the network is turned off.
+	 **/
+	void (*unregister) (void);
+
+} PacketGroupHandler;
+
+/**@brief Initialize the wireless library **/
+int wl_init(void);
+/**@brief Uninitialize the wireless library **/
+void wl_terminate(void);
+/**@brief Perform wireless library functionality **/
+void wl_do(void);
+/**@brief Register a packet group with the wireless library **/
+void wl_register_packet_group(PacketGroupHandler* h);
+/**@brief Unregister a packet group with the wireless library **/
+void wl_unregister_packet_group(PacketGroupHandler* h);
+
+/**@brief Send a packet to a specific robot in any PAN **/
+int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame);
+/**@brief Send a packet to a specific robot in our PAN **/
+int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame);
+/**@brief Send a packet to all robots **/
+int wl_send_global_packet(char group, char type, char* data, int len, char frame);
+/**@brief Send a packet to all robots in our PAN **/
+void wl_send_pan_packet(char group, char type, char* data, int len, char frame);
+
+/**@brief Set the PAN we are using **/
+int wl_set_pan(int pan);
+/**@brief Get the PAN we are using **/
+int wl_get_pan(void);
+/**@brief Set the channel we are using **/
+int wl_set_channel(int channel);
+/**@brief Get the channel we are using **/
+int wl_get_channel(void);
+/**@brief Get the 16-bit address of the XBee module **/
+int wl_get_xbee_id(void);
+/**@brief Set the com port on a computer, undefined on the robot.**/
+void wl_set_com_port(char* port);
+
+/** @} **/ // end defgroup
+
+#endif
+
Index: include/libwireless/wl_token_ring.h
===================================================================
--- include/libwireless/wl_token_ring.h	(nonexistent)
+++ include/libwireless/wl_token_ring.h	(revision 1554)
@@ -0,0 +1,85 @@
+/**
+ * Copyright (c) 2007 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 wl_token_ring.h
+ * @brief Declarations for the token ring packet group
+ * 
+ * Contains declarations for the token ring packet group.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+#ifndef WL_TOKEN_RING_H
+#define WL_TOKEN_RING_H
+
+/**
+ * @defgroup tokenring Token Ring
+ * @brief Wireless library token ring implementation
+ *
+ * This packet group is used to form a token ring, which
+ * keeps track of the relative directions of the robots
+ * from one another.
+ *
+ * @{
+ **/
+
+/**@brief Register the token ring group with the wireless library.**/
+int wl_token_ring_register(void);
+/**@brief Unregister the token ring group with the wirelss library.**/
+void wl_token_ring_unregister(void);
+/**@brief Set the functions called to turn the bom on and off.**/
+void wl_token_ring_set_bom_functions(void (*on_function) (void), void (*off_function) (void),
+  int (*max_bom_function) (void));
+
+/**@brief Join the token ring **/
+int wl_token_ring_join(void);
+/**@brief Leave the token ring **/
+void wl_token_ring_leave(void);
+
+/**@brief Return the number of robots in the token ring **/
+int wl_token_get_robots_in_ring(void);
+/**@brief Return whether a given robot is in the token ring **/
+int wl_token_is_robot_in_ring(int robot);
+
+/**@brief Begin iterating through robots in the token ring **/
+void wl_token_iterator_begin(void);
+/**@brief Returns whether there are more robots to iterate through **/
+int wl_token_iterator_has_next(void);
+/**@brief Returns the ID of the next robot in the token ring **/
+int wl_token_iterator_next(void);
+
+/**@brief Return the latest BOM reading between two robots **/
+int wl_token_get_sensor_reading(int source, int dest);
+/**@brief Return the latest BOM reading between us and another robot **/
+int wl_token_get_my_sensor_reading(int dest);
+/**@brief Return the number of robots in the sensor matrix.*/
+int wl_token_get_num_robots(void);
+/**@brief Return the number of non-null elements in the sensor matrix*/
+int wl_token_get_matrix_size(void);
+
+/** @} **/ //end token ring group
+
+#endif
Index: include/libwireless/xbee.h
===================================================================
--- include/libwireless/xbee.h	(nonexistent)
+++ include/libwireless/xbee.h	(revision 1554)
@@ -0,0 +1,99 @@
+/**
+ * Copyright (c) 2007 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 xbee.h
+ * @brief Contains definitions for using the XBee
+ *
+ * Contains definitions for interfacing with the 
+ * XBee module, from either a robot or a computer.
+ * To use a robot, define ROBOT in wl_defs.h, and
+ * to use a computer, don't define ROBOT.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+#ifndef XBEE_H
+#define XBEE_H
+
+/**
+ * The port to use the XBee from on the computer.
+ * Also, a backup port if the other is used.
+ **/
+#ifndef ROBOT
+#define XBEE_PORT_DEFAULT "/dev/ttyUSB1"
+#endif
+
+/**
+ * @defgroup xbee XBee
+ * @brief Interface with the XBee module
+ *
+ * Interface with the XBee module.
+ *
+ * @{
+ **/
+
+/*Definitions*/
+/**@brief Unset PAN, uses XBee default **/
+#define XBEE_PAN_DEFAULT 0xFFFF
+/**@brief Unset channel, uses XBee default **/
+#define XBEE_CHANNEL_DEFAULT 0
+/**@brief Broadcast to all robots in the PAN **/
+#define XBEE_BROADCAST 0xFFFF
+/**@brief No special options **/
+#define XBEE_OPTIONS_NONE 0x00
+/**@brief Do not receive a TX_STATUS message from this packet **/
+#define XBEE_OPTIONS_DISABLE_RESPONSE 0x01
+/**@brief Send the packet to all PANS **/
+#define XBEE_OPTIONS_BROADCAST_ALL_PANS 0x04
+/**@brief A transmit status packet **/
+#define XBEE_TX_STATUS 0x89
+/**@brief A packet received from another XBee **/
+#define XBEE_RX 0x81
+
+/**@brief Initialize the XBee library **/
+int xbee_lib_init(void);
+/**@brief Uninitialize the XBee library **/
+void xbee_terminate(void);
+/**@brief Get a packet from the XBee **/
+int xbee_get_packet(unsigned char* packet);
+/**@brief Send a packet to the XBee **/
+int xbee_send_packet(char* packet, int len, int dest, char options, char frame);
+/**@brief Set the PAN ID for the XBee **/
+int xbee_set_pan_id(int id);
+/**@brief Get the XBee's PAN ID **/
+unsigned int xbee_get_pan_id(void);
+/**@brief Set the channel the XBee is currently using **/
+int xbee_set_channel(int channel);
+/**@brief Get the channel the XBee is currently using **/
+int xbee_get_channel(void);
+/**@brief Get the XBee's 16-bit address **/
+unsigned int xbee_get_address(void);
+/**@brief Set the com port on a computer, undefined on the robot**/
+void xbee_set_com_port(char* port);
+
+/**@}**/ //end defgroup
+
+#endif
Index: include/libwireless/wl_basic.h
===================================================================
--- include/libwireless/wl_basic.h	(nonexistent)
+++ include/libwireless/wl_basic.h	(revision 1554)
@@ -0,0 +1,65 @@
+/**
+ * @file wl_basic.h
+ * @brief High Level Wireless Packet Sending-Receiving Functions
+ *
+ * Abstracted wireless functionality for sending and receiving packets
+ *
+ * @author Christopher Mar, Colony Project, CMU Robotics Club
+ **/
+
+/**
+ * @defgroup wl_basic Wireless Basic
+ * @brief Wireless abstraction for easily sending and receing packets.
+ *
+ * A high level abstraction of the wireless library.
+ *
+ * This will allow you to easily send and receive packets.
+ *
+ * @{
+ **/
+
+#ifndef WL_BASIC_H
+#define WL_BASIC_H
+
+#include <wireless.h>
+
+/** @brief default wireless group for basic sending and receiving packets **/
+#define WL_BASIC_GROUP 8
+
+/** @brief PacketGroupHandler struct for Basic Group **/
+PacketGroupHandler wl_basic_group_handler;
+
+/**
+ * @brief struct that contains relevant packet information
+ **/
+struct PacketInfo {
+    char new_flag;
+    char type;
+    int source;
+    unsigned char* data;
+    int length;
+};
+
+/**
+ * @brief current packet information, correct after wl_basic_do()
+ **/
+struct PacketInfo current_packet;
+
+/** @brief init wireless for Basic Group **/
+int wl_basic_init( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
+/** @brief init wireless for Basic Group with default packet handling **/
+int wl_basic_init_default( void );
+/** @brief internal function to register a packet handler function **/
+void wl_basic_register_handler( void (*handle_receive) (char type, int source, unsigned char* packet, int length) );
+/** @brief send a packet to a single robot in Basic Group **/
+void wl_basic_send_robot_packet( char type, char* data, int len, int dest );
+/** @brief send a packet to all robots in Basic Group **/
+void wl_basic_send_global_packet( char type, char* data, int len );
+/** @brief internal default packet handler if none is specified on init **/
+void wl_basic_packet_receive_handler( char type, int source, unsigned char* packet, int length );
+/** @brief wrapper for wl_do() to return packet data buffer **/
+unsigned char* wl_basic_do_default( int *length );
+/** @} **/ // end defgroup
+
+#endif
+
Index: include/libwireless/wl_defs.h
===================================================================
--- include/libwireless/wl_defs.h	(nonexistent)
+++ include/libwireless/wl_defs.h	(revision 1554)
@@ -0,0 +1,97 @@
+/**
+ * Copyright (c) 2007 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 wl_defs.h
+ * @brief Definitions for Wireless
+ *
+ * Contains definitions for wireless packet groups, packet types,
+ * debugging information, etc.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+#ifndef WL_DEFS_H
+#define WL_DEFS_H
+
+//comment out this line if using a computer hooked up to an xbee
+//#define ROBOT
+
+//uncomment this line for debug information
+//#define WL_DEBUG
+
+// Packet Groups and Types
+
+// Error group
+#define WL_ERROR_GROUP 1
+
+#define WL_ERROR_STRING_TYPE 1
+
+// Token Ring group
+#define WL_TOKEN_RING_GROUP 2
+
+#define WL_TOKEN_PASS 1
+#define WL_TOKEN_SENSOR_MATRIX 2
+#define WL_TOKEN_BOM_ON 3
+#define WL_TOKEN_JOIN 4
+#define WL_TOKEN_JOIN_ACCEPT 5
+
+// timing constants
+#ifndef FIREFLY
+#define BOM_DELAY 100
+#else
+#define BOM_DELAY 200
+#endif
+
+#define DEATH_DELAY 4
+#define JOIN_DELAY 8
+
+#ifdef WL_DEBUG
+
+#ifdef ROBOT
+#include <serial.h>
+#endif
+
+#ifdef ROBOT
+#define WL_DEBUG_PRINT( s ) usb_puts( s )
+#else
+#define WL_DEBUG_PRINT( s ) printf( s )
+#endif
+
+#ifdef ROBOT
+#define WL_DEBUG_PRINT_INT( i ) usb_puti(i)
+#else
+#define WL_DEBUG_PRINT_INT( i ) printf("%i", i)
+#endif
+
+#else
+
+#define WL_DEBUG_PRINT( s )
+#define WL_DEBUG_PRINT_INT( i )
+
+#endif
+
+#endif
+
Index: include/libwireless/queue.h
===================================================================
--- include/libwireless/queue.h	(nonexistent)
+++ include/libwireless/queue.h	(revision 1554)
@@ -0,0 +1,95 @@
+/**
+ * Copyright (c) 2007 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 queue.h
+ * @brief A queue implementation
+ * 
+ * Implements a queue, a first in, first out data structure.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+#ifndef WIRELESS_QUEUE_H
+#define WIRELESS_QUEUE_H
+
+#ifndef ROBOT
+#include <pthread.h>
+#endif
+
+struct node_def;
+
+/**
+ * @defgroup queue Queue
+ * @brief A queue implementation
+ * 
+ * A queue implementation.
+ *
+ * @{
+ **/
+
+/**
+ * @struct Queue
+ * Represents a queue, a first in, first out data structure.
+ **/
+typedef struct
+{
+	/**
+	 * The head of the queue, the next item to be removed.
+	 **/
+	struct node_def* head;
+	/**
+	 * The tail of the queue, the last item added.
+	 **/
+	struct node_def* tail;
+	/**
+	 * The number of elements in the queue.
+	 **/
+	int size;
+	
+#ifndef ROBOT
+	pthread_mutex_t lock;
+#endif
+} Queue;
+
+/** @brief Create a new queue **/
+Queue* queue_create(void);
+/** @brief Destroy a queue **/
+void queue_destroy(Queue* q);
+/** @brief Add an element to a queue **/
+int queue_add(Queue* q, void* item);
+/** @brief Remove an element from a queue **/
+void* queue_remove(Queue* q);
+/** @brief Remove all instances of a given element from a queue **/
+void queue_remove_all(Queue* q, void* item);
+/** @brief Get the size of a queue **/
+int queue_size(Queue* q);
+/** @brief Check if the queue is empty **/
+int queue_is_empty(Queue* q);
+
+/** @} **/
+
+
+#endif
Index: include/libwireless/wl_error_group.h
===================================================================
--- include/libwireless/wl_error_group.h	(nonexistent)
+++ include/libwireless/wl_error_group.h	(revision 1554)
@@ -0,0 +1,66 @@
+/**
+ * Copyright (c) 2007 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 wl_error_group.h
+ * @brief Error Packets
+ *
+ * A packet group for sending error packets.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+#ifndef WL_ERROR_GROUP_H
+#define WL_ERROR_GROUP_H
+
+/**
+ * @file wl_error_group.h
+ * @brief A packet group for error messages.
+ *
+ * A packet group for sending and receiving error
+ * messages.
+ *
+ * @author Brian Coltin, Colony Project, CMU Robotics Club
+ **/
+
+/**
+ * @defgroup wlerror Error Packets
+ * @brief Functions for sending and receiving error packets
+ * 
+ * Functions for sending and receiving error packets.
+ * 
+ * @{
+ **/
+
+/**@brief Register this packet group with the wireless library **/
+void wl_error_register(void);
+/**@brief Unregister this packet group with the wireless library **/
+void wl_error_unregister(void);
+/**@brief Send a string in an error packet **/
+void wl_error_send_string(char* str);
+
+/** @} **/ // end defgroup
+
+#endif
Index: include/libdragonfly/lights.h
===================================================================
--- include/libdragonfly/lights.h	(nonexistent)
+++ include/libdragonfly/lights.h	(revision 1554)
@@ -0,0 +1,224 @@
+// FIXME remove
+typedef unsigned char uint8_t;
+
+
+/**
+ * Copyright (c) 2007 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 lights.h
+ * @brief Contains declarations for managing the orbs.
+ *
+ * Contains declarations for using the orbs and PWM.
+ *
+ * @author Colony Project, CMU Robotics Club
+ * Based on Firefly Library, by Tom Lauwers and Steven Shamlian
+ **/
+
+#ifndef _LIGHTS_H_
+#define _LIGHTS_H_
+
+/**
+ * @addtogroup orbs
+ * @{
+ **/
+
+/**
+ * Quick start: call orb_init_pwm or orb_init_binary, depending on which mode you want to use. Call orb*set or
+ * orb*set_color to set the orbs.
+ * 
+ * The orbs have two modes of operation: PWM mode and binary mode. In PWM mode, a pwm signal is generated by a hardware
+ * timer and the orbs can be set to a value of 0 through 255. In binary mode, the orbs can only be turned on or off and
+ * a value of 0 means "off" and any other value means "on". The mode can be chosen on initialization and can be changed
+ * at runtime using the orb_set_mode function.
+ *
+ * Operation (PWM mode): On timer overflow, all LEDs with a value>0 are turned on and the output compare value for the
+ * first LED is loaded. On compare match, the corresponding LED is turned off and the next output compare value is
+ * loaded. All masks are precomputed and sorted by time when setting the values.
+ *
+ * The data structure (pwm_t) containing the PWM times and masks is triple buffered. This is because the buffer the ISR
+ * is reading from may only be modified on timer overflow before the next PWM sequence is started, because otherwise the
+ * next OCR value might be sed to a value smaller than the current timer value, resulting in the remaining channels not
+ * being turned off in that PWM period (flash to on). When using two buffers, the page flip can only occur on a timer
+ * overflow for the same reason. So after writing a buffer and marking it for page flip, neither of the buffers could be
+ * modified because the front buffer is read by the ISR and the back buffer could be switched at any time. So the
+ * calling thread would have to be delayed by up to one full PWM period (8ms in the current implementation, but
+ * 20ms-50ms would be a reasonable value to expect here). To avoid this, triple buffering is used.
+ *
+ * The code for applying the orbs is fairly optimized. See the apply_orbs function for some time measurements and
+ * further nodes.
+ *
+ * The PWM frequency is 120Hz (8ms period time). The next lower frequency (determined by the prescaler) is 30 Hz which
+ * is too slow (orbs flicker).
+ *
+ * The orbs code is thread safe, which means that the functions may be called from another interrupt handler. If there
+ * are multiple concurrent calls to the orb*set* functions, one of them is ignored and the orbs are never left in an
+ * inconsistent state. For example, if the orbs are set to green by the main thread and to red by an interrupt handler,
+ * the resulting color will be either red or green, but never yellow.
+ * Thread safety is achieved by grabbing a lock at the beginning of all functions that modify the orb code and releasing
+ * the lock at the end. If the lock is already taken, the function just returns doing nothing.
+ *
+ * Some performance measurements:
+ *   - Time for setting new orb values (PWM mode):       35us-72us (depending on the degree to which the array is
+ *                                                                  already in the correct order)
+ *   - Time for setting new orb values (binary mode):        5.5us
+ *
+ *   - Interrupt time (PWM mode only):                         8us (overflow)
+ *                                                            10us (output compare)
+ *                                                             6us (last output compare)
+ *                                                            30us (output compare, all value equal)
+ *
+ *   - Maximum total interrupt time per period:               64us
+ *   - Maximum CPU usage for interrupts (PWM mode only):     <0.8%
+ *
+ *   - Maximum contiguous synchronized block:                 30us (output compare interrupt, all values equal)
+ *
+ * There are some potential optimizations left. See the source code for more information.
+ *
+ * A note on robustness: if the output compare interrupt is disabled for too long, either due to a long ISR or a long
+ * synchronized code block, the orbs will flicker to brighter values for being turned off too late. With software PWM,
+ * there's nothing at all to be done about that. The problem can be alleviated by using a lower PWM frequency, but then
+ * the orbs will start flickering all the time due to the low update frequency.
+ * Some measurements: with 100us synchronized blocks, the flickering is accepptably low. Longer synchronized blocks
+ * mean more flickering. At 1ms synchronized blocks, the flickering is quite bad, especially for low orb values. Note
+ * that orb value 0 never flickers at all because the corresponding channels are not turned on at all.
+ * Test code (note the _delay_us restrictions!)
+ *   orb_set (1,1,1); while (1) { SYNC { for (uint8_t m=0; m<10; ++m) { _delay_us(10); } } }
+ **/
+
+/** @} **/ //end addtogroup
+
+/**
+ * @addtogroup orbs
+ * @{
+ **/
+
+// ***** Predefined colors *****
+/** @brief Red **/
+#define RED       0xE0
+/** @brief Orange **/
+#define ORANGE    0xE4
+/** @brief Yellow **/
+#define YELLOW    0xE8
+/** @brief Lime **/
+#define LIME      0x68
+/** @brief Green **/
+#define GREEN     0x1C
+/** @brief Cyan **/
+#define CYAN      0x1F
+/** @brief Blue **/
+#define BLUE      0x03
+/** @brief Pink **/
+#define PINK      0xA6 
+/** @brief Purple **/
+#define PURPLE    0x41
+/** @brief Magenta **/
+#define MAGENTA   0xE3
+/** @brief White **/
+#define WHITE     0xFE
+/** @brief Turn the orb off **/
+#define ORB_OFF   0x00
+
+
+
+// ***** Initialization *****
+
+/** @brief Enables the orbs in default mode **/
+void orb_init(void);
+
+/** @brief Enables the orbs in binary mode **/
+void orb_init_binary (void);
+
+/** @brief Enables the orbs in PWM mode **/
+void orb_init_pwm (void);
+
+
+
+// ***** Mode setting *****
+
+/** Specification of the orb mode **/
+typedef uint8_t orb_mode_t;
+
+/** @brief PWM mode **/
+#define orb_mode_pwm 0
+
+/** @brief Binary mode **/
+#define orb_mode_binary 1
+
+
+/** @brief Switches the orbs to the specified mode **/
+void orb_set_mode (orb_mode_t mode);
+
+/** @brief Disables the orb timer, but does not change the mode **/
+void orb_disable_timer (void);
+
+/** @brief Enables the orb timer, but does not change the mode **/
+void orb_enable_timer (void);
+
+
+
+// ***** Setting RGB colors *****
+
+/** @brief set the specified orb to a specified color
+* 	@deprecated This function indexes from 0 instead of 1 **/
+void orb_n_set (uint8_t num, uint8_t red, uint8_t green, uint8_t blue);
+
+/** @brief Set both orbs to a specified color **/
+void orb_set(uint8_t red, uint8_t green, uint8_t blue);
+
+/** @brief Set orb1 to a specified color **/
+void orb1_set(uint8_t red_led, uint8_t green_led, uint8_t blue_led); 
+
+/** @brief Set orb2 to a specified color **/
+void orb2_set(uint8_t red_led, uint8_t green_led, uint8_t blue_led);
+
+void orbs_set (uint8_t red1, uint8_t green1, uint8_t blue1, uint8_t red2, uint8_t green2, uint8_t blue2);
+
+
+
+// ***** Settings predefined colors *****
+
+/** @brief set the specified orb to the specified color
+* 	@deprecated This function indexes from 0 instead of 1 **/
+void orb_n_set_color(uint8_t num, uint8_t col);
+
+/** @brief Set orb1 to a specified color **/
+void orb1_set_color(uint8_t col);
+
+/** @brief Set orb2 to a specified color **/
+void orb2_set_color(uint8_t col);
+
+/** @brief set the orbs to specified colors **/
+void orbs_set_color(uint8_t col1, uint8_t col2);
+
+/** @brief Set both orbs to a specified color **/
+void orb_set_color(uint8_t col);
+
+
+
+/** @} **/ //end addtogroup
+
+#endif
Index: include/libdragonfly/spi.h
===================================================================
--- include/libdragonfly/spi.h	(nonexistent)
+++ include/libdragonfly/spi.h	(revision 1554)
@@ -0,0 +1,46 @@
+/**
+ * @file spi.h
+ * @brief Definitions for SPI
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+/**
+ * @addtogroup spi
+ * @{
+ **/
+
+#ifndef __SPI_H__
+#define __SPI_H__
+
+#define DOUBLE_SCK 1
+#define SPR0_BIT 1
+
+#define MASTER 1
+#define SLAVE 0
+
+#define MOSI _BV(PB2)
+#define MISO _BV(PB3)
+#define SS   _BV(PB0)
+#define SCLK _BV(PB1)
+
+typedef void (*spi_fun_recv_t)(char);
+typedef void (*spi_fun_recv_complete_t)(void);
+
+/** 
+* @brief Initialize SPI
+* 
+* @param spi_fun_recv_t The function that handles SPI data, byte for byte.
+* @param spi_fun_recv_complete_t  Called on a completed transmission - typically for cleaning up.
+*/
+void spi_init (spi_fun_recv_t, spi_fun_recv_complete_t);
+
+/** 
+* @brief Initialize SPI transfer.
+* 
+* @param char The number of bytes to transfer.
+*/
+void spi_transfer (char);
+
+/**@}**/ //end group
+
+#endif
Index: include/libdragonfly/time.h
===================================================================
--- include/libdragonfly/time.h	(nonexistent)
+++ include/libdragonfly/time.h	(revision 1554)
@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) 2007 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 time.h
+ * @brief Contains time-related functions and definitions
+ *
+ * Contains functions and definitions for dealing with time,
+ * namely delay_ms and the realtime clock.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef _TIME_H_
+#define _TIME_H_
+
+/*	Predefined times for prescale_opt in time.c.
+	To make you own, know that a pulse is 1/16th of a second. You cannot get less than this. To get more, you need
+	to know how many 16ths of a second are in the time you want. (Time_desired * 16 = prescaler_opt)
+*/
+/**
+ * @addtogroup time
+ * @{
+ **/
+/** @brief A sixteenth of a second **/
+#define SIXTEENTH_SECOND 1
+/** @brief An eighth of a second **/
+#define EIGTH_SECOND 2
+/** @brief A quarter of a second **/
+#define QUARTER_SECOND 4
+/** @brief Half of a second **/
+#define HALF_SECOND	8
+/** @brief One second **/
+#define SECOND 16
+/** @brief Two seconds **/
+#define TWO_SECOND 32
+/** @brief Four seconds **/
+#define FOUR_SECOND 64
+
+/** @brief Delay execution for the specified time **/
+void delay_ms(int ms) ;
+/** @brief Enable the realtime clock **/
+void rtc_init(int prescale_opt, void (*rtc_func)(void));
+/** @brief Reset the counter of the realtime clock **/
+void rtc_reset(void);
+/** @brief Get the value of the realtime clock. **/
+int rtc_get(void);
+
+/** @} **/
+
+#endif
+
Index: include/libdragonfly/motor.h
===================================================================
--- include/libdragonfly/motor.h	(nonexistent)
+++ include/libdragonfly/motor.h	(revision 1554)
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2007 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 motor.h
+ * @brief Contains definitions for controlling the motors
+ *
+ * Contains definitions and functions for controlling
+ * the motors.
+ *
+ * @author Colony Project, CMU Robotics Club
+ * Based on Tom Lauwer's Firefly Library
+ **/
+
+#ifndef _MOTOR_H
+#define _MOTOR_H
+
+#include <avr/io.h>
+/**
+ * @addtogroup motors
+ * @{
+ **/
+
+/** @brief make the motors go forwards **/
+#define FORWARD 1
+/** @brief make the motors go backwards **/
+#define BACKWARD 0
+
+/** @brief Initialize the motors **/
+void motors_init(void);
+/** @brief Set speed and direction of motor1 
+ *  @deprecated use the left motor function instead. it's more intuitive and easier to read.**/
+void motor1_set(int direction, int speed);
+/** @brief Set speed and direction of motor2 
+ *  @deprecated use the right motor function instead. it's more intuitive and easier to read.**/
+void motor2_set(int direction, int speed);
+/** @brief Set speed and direction of left motor **/
+void motor_l_set(int direction, int speed);
+/** @brief Set speed and direction of right motor **/
+void motor_r_set(int direction, int speed);
+/** @brief Turn the motors off **/
+void motors_off(void);
+
+/**@}**/ // end addtogroup
+
+#endif
+
Index: include/libdragonfly/analog.h
===================================================================
--- include/libdragonfly/analog.h	(nonexistent)
+++ include/libdragonfly/analog.h	(revision 1554)
@@ -0,0 +1,138 @@
+/**
+ * Copyright (c) 2007 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 analog.h
+ * @brief Contains functions and definitions for using the ADC
+ * 
+ * Contains definitions and function prototypes for using the
+ * ADC to detect analog signals on pins AN0 - AN7.
+ * AN6 and AN7 are used for the wheel and battery.
+	
+ * The pins labeled E6 and E7 are external interrupt pins and are not related 
+ * to analog.
+	
+ * @author Colony Project, CMU Robotics Club, based on firefly
+ * originally taken from fwr analog file (author: Tom Lauwers)
+ * loop code written by Kevin Woo and James Kong
+ */
+
+#ifndef _ANALOG_H
+#define _ANALOG_H
+
+#include <inttypes.h>
+
+/**
+ * @addtogroup analog
+ * @{
+ **/
+
+/** @brief Analog port 0 **/
+#define AN0 0x00
+/** @brief Analog port 1 **/
+#define AN1 0x01
+/** @brief Analog port 2 **/
+#define AN2 0x02
+/** @brief Analog port 3 **/
+#define AN3 0x03
+/** @brief Analog port 4 **/
+#define AN4 0x04
+/** @brief Analog port 5 **/
+#define AN5 0x05
+/** @brief Analog port 6 **/
+#define AN6 0x06
+/** @brief Analog port 7 **/
+#define AN7 0x07
+/** @brief Analog port 8 **/
+#define AN8 0x08
+/** @brief Analog port 9 **/
+#define AN9 0x09
+/** @brief Analog port 10 **/
+#define AN10 0x0A
+/** @brief Analog port 11 **/
+#define AN11 0x0B
+/** @brief Analog port 12 **/
+#define AN12 0x0C
+/** @brief Analog port 13 **/
+#define AN13 0x0D
+/** @brief Analog port 14 **/
+#define AN14 0x0E
+/** @brief Analog port 15 **/
+#define AN15 0x0F
+
+/** @brief BOM_PORT analog port for BOM **/
+#define BOM_PORT AN0
+/** @brief EXT_MUX analog port **/
+#define EXT_MUX AN7
+/** @brief Analog port for the wheel **/
+#define WHEEL_PORT AN10
+/** @brief Analog port for the battery voltage detector **/
+#define BATT_PORT  AN11
+
+/** @brief Analog loop status. ADC conversion running. **/
+#define ADC_LOOP_RUNNING 1
+/** @brief Analog loop status.  No ADC conversion running.**/
+#define ADC_LOOP_STOPPED 0
+
+/** @brief Analog init parameter. Start the analog loop. **/
+#define ADC_START 1
+/** @brief Analog init parameter. Don't start the analog loop. **/
+#define ADC_STOP  0
+
+#define ADMUX_OPT 0x60
+
+/** @brief Struct to hold the value of a particular analog port **/
+typedef struct {
+  uint8_t adc8;
+  uint16_t adc10;
+} adc_t;
+
+
+/** @brief Initialize analog ports. Will start running a loop
+    if start_conversion is ADC_START.**/
+void analog_init(int start_conversion);
+/** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/
+void analog_start_loop(void);
+/** @brief Stops the analog loop. Doesn't do anything if the loop is already stopped. **/
+void analog_stop_loop(void);
+/** @brief Returns the status of the analog loop. **/
+int analog_loop_status(void);
+/** @brief Returns an 8-bit analog value from the look up table. Use this instead of analog_get8. **/
+unsigned int analog8(int which);
+/** @brief Returns an 10-bit analog value from the look up table. Use this instead of analog_get10. **/
+unsigned int analog10(int which);
+/** @brief Read the position of the wheel. **/
+int wheel(void);
+/** @brief Read an 8-bit number from an analog port. Loop must be stopped for this to work. **/
+unsigned int analog_get8(int which);
+/** @brief Read a 10-bit number from an analog port. Loop must be stopped for this to work. **/
+unsigned int analog_get10(int which);
+
+
+/**@}**/ //end group
+
+#endif
+
Index: include/libdragonfly/lcd.h
===================================================================
--- include/libdragonfly/lcd.h	(nonexistent)
+++ include/libdragonfly/lcd.h	(revision 1554)
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) 2007 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 lcd.h
+ * @brief Contains definitions for dealing with the LCD screen.
+ * 
+ * Contains definitions and functions for dealing with the 
+ * LCD screen.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef _LCD_H_
+#define _LCD_H_
+
+/**
+ * @addtogroup lcd
+ * @{
+ **/
+
+/** @brief Initialize the LCD screen **/
+void lcd_init(void);
+/** @brief Clear the LCD screen **/
+void lcd_clear_screen( void );
+/** @brief Print a char to the LCD screen **/
+void lcd_putc(char c);
+/** @brief Print a string to the LCD screen **/
+void lcd_puts(char *s);
+/** @brief Print an int to the LCD screen **/
+void lcd_puti(int value);
+/** @brief Set the current cursor position **/
+void lcd_gotoxy(int x, int y);
+
+/** @} **/
+
+#endif
+
Index: include/libdragonfly/odometry.h
===================================================================
--- include/libdragonfly/odometry.h	(nonexistent)
+++ include/libdragonfly/odometry.h	(revision 1554)
@@ -0,0 +1,56 @@
+
+/**
+ * @file odometry.h
+ * @brief Code for estimating the robots pose.
+ * 
+ * Offers simple position and orientation information.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef __ODOMETRY_C__
+#define __ODOMETRY_C__
+
+/**
+ * @addtogroup odometry 
+ * @{
+ **/
+
+//Odometry resolution, *64 microseconds.
+#define ODOMETRY_CLK 255u 
+#define TIME_SCALE 64
+
+//Wheel = 2.613 in.  
+//Circumference = 208.508133 mm
+//Distance per encoder click (circumference / 1024)  = 203.621224 um.
+//Robot width = 5.3745 in. = 136.5123 mm
+
+#define ROBOT_WIDTH_UM 137000  //um
+#define CLICK_DISTANCE_UM 204 //um
+
+#define DISTANCE_SCALE 2.10526316 //Magic constant.
+#define ANGLE_SCALE 1.12823207 //Magic constant.
+
+/** @brief Retrieve the robots estimated x position*/
+long odometry_dx(void);
+
+/** @brief Retrieve the robots estimated y position*/
+long odometry_dy(void);
+
+/** @brief Retrieve the robots estimated orientation*/
+double odometry_angle(void);
+
+/** @brief Initialize odometry. MUST be called before 
+ * the other functions work.**/
+void odometry_init(void);
+
+/** @brief Reset position and orientation to the origin facing
+ * the x axis.*/
+void odometry_reset(void);
+
+/** @brief Report estimated velocity [mm/s].*/
+long odometry_velocity(void);
+
+/**@}**/ //end group
+
+#endif
Index: include/libdragonfly/encoders.h
===================================================================
--- include/libdragonfly/encoders.h	(nonexistent)
+++ include/libdragonfly/encoders.h	(revision 1554)
@@ -0,0 +1,86 @@
+/**
+ * 
+ * @file encoders.h
+ * @brief Contains functions for reading encoder values.
+ *
+ * Contains high and low level functions for reading encoders
+ * including reading out total distance covered, and 
+ * eventually velocity.
+ *	
+ * @author Colony Project, CMU Robotics Club
+*/
+
+/**
+ * @addtogroup encoders
+ * @{
+ **/
+
+#ifndef __ENCODERS_H__
+#define __ENCODERS_H__
+
+
+#ifndef LEFT
+	/** @brief Left wheel **/
+	#define LEFT 0
+#endif
+#ifndef RIGHT
+	/** @brief Right wheel **/
+	#define RIGHT 1
+#endif
+
+/** @brief Max value of valid encoder reading. **/
+#define ENCODER_MAX 1024
+
+/** @brief Magnet misaligned - likely distance from encoder problem. **/
+#define ENCODER_MAGNET_FAILURE 1025
+/** @brief Encoder misaligned - likely on XY plane. **/
+#define ENCODER_MISALIGNED 1027
+/** @brief Not enough time has passed - encoders not initialized in hardware. **/
+#define ENCODER_DATA_NOT_READY 1026
+
+/** @brief delay_ms argument after a full read is complete **/
+#define ENCODER_DELAY 20
+
+//Data invalid flags (hardware failure):
+#define OCF _BV(4)
+#define COF _BV(3)
+
+//Data invalid alarm (May be invalid):
+#define LIN _BV(2)
+
+#define MagINCn _BV(1)
+#define MagDECn _BV(0)
+
+/** @brief Buffer size **/
+#define BUFFER_SIZE 46
+
+#define ERR_VEL 1024
+
+/** @brief Initialize encoders. **/
+void encoders_init(void);
+/** @brief Read instantaneous encoder value. **/
+int encoder_read(char encoder);
+
+/** @brief Get total distance traveled.
+ *  @note  Simply calls encoder_get_dx.
+ **/
+int encoder_get_x(char encoder);
+
+/** @brief Get instantaneous velocity. **/
+int encoder_get_v(char encoder);
+
+/** @brief Get total distance traveled. **/
+int encoder_get_dx(char encoder);
+/** @brief Reset distance counter. **/
+void encoder_rst_dx(char encoder);
+/** @brief Get time count: The number of encoder reads that have occurred. **/
+int encoder_get_tc(void);
+/** @brief Reset the time count. **/
+void encoder_rst_tc(void);
+
+/** @brief Waits for the next n encoder reading, then returns. **/
+void encoder_wait( int nReadings );
+
+/**@}**/ //end group
+
+#endif
Index: include/libdragonfly/move.h
===================================================================
--- include/libdragonfly/move.h	(nonexistent)
+++ include/libdragonfly/move.h	(revision 1554)
@@ -0,0 +1,75 @@
+/**
+ * Copyright (c) 2007 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 move.h
+ * @brief Contains definitions for controlling robot motion
+ * 
+ * This file offers higher-level functions for robot motion.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef _MOVE_H_
+#define _MOVE_H_
+
+/**
+ * @addtogroup move
+ * @{
+ **/
+
+/** @brief Move forwards **/
+#define FWD 0
+/** @brief Move backwards **/
+#define BCK 1
+
+/** @brief A slow speed **/
+#define SLOW_SPD 96
+/** @brief Half of the full speed **/
+#define HALF_SPD 128
+/** @brief A normal speed **/
+#define NRML_SPD 160
+/** @brief A fast speed **/
+#define FAST_SPD 192
+/** @brief The maximum speed **/
+#define FULL_SPD 255
+
+/** @brief A slow turning speed **/
+#define SLOW_TURN 64
+/** @brief A medium turning speed **/
+#define NRML_TURN 96
+/** @brief A high turning speed **/
+#define FAST_TURN 128
+
+/** @brief Move the robot at the specified velocity **/
+void move(int velocity, int omega);
+/** @brief Move the robot while avoiding obstacles **/
+void move_avoid(int velocity, int omega, int strength);
+
+/** @} **/
+
+#endif
+
Index: include/libdragonfly/battery.h
===================================================================
--- include/libdragonfly/battery.h	(nonexistent)
+++ include/libdragonfly/battery.h	(revision 1554)
@@ -0,0 +1,64 @@
+/**
+ * Copyright (c) 2007 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 battery.h
+ * @brief Definitions for checking battery voltage.
+ * 
+ * Contains definitions for checking the voltage of the 
+ * battery.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef _BATTERY_H_
+#define _BATTERY_H_
+
+/**
+ * @addtogroup battery
+ * @{
+ **/
+
+/** @brief Normal battery voltage. (6 V) **/
+#define BATTERY_NORMALV 154
+/** @brief Charging battery voltage. (7 V) **/
+#define BATTERY_CHARINGV 179
+/** @brief Low battery voltage. ( < 6 V) **/
+#define BATTERY_LOWV 152
+
+/** @brief Read the battery voltage. **/
+int battery8(void);
+/** @brief Read the battery voltage in deciVolts. **/
+int battery(void);
+/** @brief Check if the battery is low. **/
+char battery_low(void);
+/** @brief Get an average battery voltage reading. **/
+int battery8_avg(int n_samples);
+
+/** @} **/ //end addtogroup
+
+#endif
+
Index: include/libdragonfly/dragonfly_lib.h
===================================================================
--- include/libdragonfly/dragonfly_lib.h	(nonexistent)
+++ include/libdragonfly/dragonfly_lib.h	(revision 1554)
@@ -0,0 +1,115 @@
+/**
+ * Copyright (c) 2007 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 dragonfly_lib.h
+ * @brief Contains other include files
+ * 
+ * Include this file for all the functionality of libdragonfly.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef _DRAGONFLY_LIB_H_
+#define _DRAGONFLY_LIB_H_
+
+/**
+ * @addtogroup dragonfly
+ * @{
+ **/
+
+// Configuration definitions
+/** @brief Initialize analog **/
+#define ANALOG 0x01
+/** @brief Initialize serial communications **/
+#define SERIAL 0x02
+/** @brief Initialize USB communications **/
+#define USB    0x02
+/** @brief Initialize communications **/
+#define COMM   0x02
+/** @brief Initialize the orb **/
+#define ORB    0x04
+/** @brief Initialize the motors **/
+#define MOTORS 0x08
+/** @brief Initialize I2C **/
+#define I2C    0x20
+/** @brief Initialize the buzzer **/
+#define BUZZER 0x40
+/** @brief Initialize the LCD screen **/
+#define LCD    0x80
+/** @brief Initialize the rangefinders **/
+#define RANGE  0x0100
+/** @brief Initialize the BOM **/
+#define BOM  0x0200
+/** @brief Initialize everything  **/
+#define ALL_ON 0x03FF
+
+/** @brief Initialize the board **/
+void dragonfly_init(int config);
+
+/** @} **/ //end addtogroup
+
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <util/twi.h>
+
+// This file is included from the libdragonfly directory because it seems to be
+// missing from the AVR libc distribution.
+#include "atomic.h"
+
+#include <analog.h>
+#include <dio.h>
+#include <time.h>
+#include <lcd.h>
+#include <lights.h>
+#include <motor.h>
+#include <serial.h>
+#include <buzzer.h>
+#include <rangefinder.h>
+#include <bom.h>
+#include <move.h>
+#include <reset.h>
+#include <math.h>
+#include <eeprom.h>
+#include <stdbool.h>
+
+/** @brief shortcut for ATOMIC_BLOCK(ATOMIC_RESTORESTATE) **/
+#define SYNC ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+
+/** @brief atomically grab a lock if it is free, return otherwise **/
+#define REQUIRE_LOCK_OR_RETURN(LOCK) do { SYNC { if (LOCK) return; LOCK=1; } } while (0)
+
+/** @brief atomically release a lock **/
+#define RELEASE_LOCK(LOCK) do { LOCK=0; } while (0)
+
+
+
+#endif
+
Index: include/libdragonfly/dio.h
===================================================================
--- include/libdragonfly/dio.h	(nonexistent)
+++ include/libdragonfly/dio.h	(revision 1554)
@@ -0,0 +1,348 @@
+/**
+ * Copyright (c) 2007 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 dio.h
+ * @brief Definitions for digital input / output
+ *
+ * This file contains definitions and functions for dealing
+ * with digital input and output.
+ *
+ * @author Colony Project, CMU Robotics Club
+ * Based on Tom Lauwer's Firefly Library
+ **/
+
+#ifndef _DIO_H
+#define _DIO_H
+
+/*
+  these are ALL the pins
+  don't use unless you know what you're doing
+*/
+
+/*
+  DIO pins on new dragonfly boards are shown below:
+  -----------------------------------------------
+  | _PIN_E6 | _PIN_E7 | _PIN_D2 | _PIN_D3 | VCC |
+  -----------------------------------------------
+  | _PIN_E2 | _PIN_E3 | _PIN_E4 | _PIN_E5 | GND |
+  -----------------------------------------------
+*/
+
+/** @brief Port A **/
+#define _PORT_A 1
+/** @brief Port B **/
+#define _PORT_B 2
+/** @brief Port C **/
+#define _PORT_C 3
+/** @brief Port D **/
+#define _PORT_D 4
+/** @brief Port E **/
+#define _PORT_E 5
+/** @brief Port F **/
+#define _PORT_F 6
+/** @brief Port G **/
+#define _PORT_G 7
+
+/** @brief Pin A0 **/
+#define _PIN_A0 8
+/** @brief Pin A1 **/
+#define _PIN_A1 9
+/** @brief Pin A2 **/
+#define _PIN_A2 10
+/** @brief Pin A3 **/
+#define _PIN_A3 11
+/** @brief Pin A4 **/
+#define _PIN_A4 12
+/** @brief Pin A5 **/
+#define _PIN_A5 13
+/** @brief Pin A6 **/
+#define _PIN_A6 14 
+/** @brief Pin A7 **/
+#define _PIN_A7 15
+
+/** @brief Pin B0 **/
+#define _PIN_B0 16
+/** @brief Pin B1 **/
+#define _PIN_B1 17
+/** @brief Pin B2 **/
+#define _PIN_B2 18
+/** @brief Pin B3 **/
+#define _PIN_B3 19
+/** @brief Pin B4 **/
+#define _PIN_B4 20
+/** @brief Pin B5 **/
+#define _PIN_B5 21
+/** @brief Pin B6 **/
+#define _PIN_B6 22
+/** @brief Pin B7 **/
+#define _PIN_B7 23
+
+/** @brief Pin C0 **/
+#define _PIN_C0 24
+/** @brief Pin C1 **/
+#define _PIN_C1 25
+/** @brief Pin C2 **/
+#define _PIN_C2 26
+/** @brief Pin C3 **/
+#define _PIN_C3 27
+/** @brief Pin C4 **/
+#define _PIN_C4 28
+/** @brief Pin C5 **/
+#define _PIN_C5 29
+/** @brief Pin C6 **/
+#define _PIN_C6 30
+/** @brief Pin C7 **/
+#define _PIN_C7 31
+
+/** @brief Pin D0 **/
+#define _PIN_D0 32  // pin DIO6 on new dragonfly boards
+/** @brief Pin D1 **/
+#define _PIN_D1 33  // pin DIO7
+/** @brief Pin D2 **/
+#define _PIN_D2 34
+/** @brief Pin D3 **/
+#define _PIN_D3 35
+/** @brief Pin D4 **/
+#define _PIN_D4 36
+/** @brief Pin D5 **/
+#define _PIN_D5 37
+/** @brief Pin D6 **/
+#define _PIN_D6 38
+/** @brief Pin D7 **/
+#define _PIN_D7 39
+
+/** @brief Pin E0 **/
+#define _PIN_E0 40
+/** @brief Pin E1 **/
+#define _PIN_E1 41
+/** @brief Pin E2 **/
+#define _PIN_E2 42  // pin DIO0
+/** @brief Pin E3 **/
+#define _PIN_E3 43  // pin DIO1
+/** @brief Pin E4 **/
+#define _PIN_E4 44  // pin DIO2
+/** @brief Pin E5 **/
+#define _PIN_E5 45  // pin DIO3
+/** @brief Pin E6 **/
+#define _PIN_E6 46  // pin DIO4
+/** @brief Pin E7 **/
+#define _PIN_E7 47  // pin DIO5
+
+/** @brief Pin F0 **/
+#define _PIN_F0 48
+/** @brief Pin F1 **/
+#define _PIN_F1 49
+/** @brief Pin F2 **/
+#define _PIN_F2 50
+/** @brief Pin F3 **/
+#define _PIN_F3 51
+/** @brief Pin F4 **/
+#define _PIN_F4 52
+/** @brief Pin F5 **/
+#define _PIN_F5 53
+/** @brief Pin F6 **/
+#define _PIN_F6 54
+/** @brief Pin F7 **/
+#define _PIN_F7 55
+
+/** @brief Pin G0 **/
+#define _PIN_G0 56
+/** @brief Pin WR **/
+#define _PIN_WR 56
+/** @brief Pin G1 **/
+#define _PIN_G1 57
+/** @brief Pin RD **/
+#define _PIN_RD 57
+/** @brief Pin G2 **/
+#define _PIN_G2 58
+/** @brief Pin ALE **/
+#define _PIN_ALE 58
+/** @brief Pin G3 **/
+#define _PIN_G3 59
+/** @brief Pin TOSC2 **/
+#define _PIN_TOSC2 59
+/** @brief Pin G4 **/
+#define _PIN_G4 60
+/** @brief Pin TOSC1 **/
+#define _PIN_TOSC1 60
+//#define _PIN_G5 61
+//#define _PIN_G6 62
+//#define _PIN_G7 63
+
+/*
+  These are the header pins (the ones you can connect things to)
+  Feel free to use these
+*/
+
+/**
+ * @addtogroup dio
+ * @{
+ **/
+/** @brief Pin A0 **/
+#define PIN_A0 8
+/** @brief Pin A1 **/
+#define PIN_A1 9
+/** @brief Pin A2 **/
+#define PIN_A2 10
+/** @brief Pin A3 **/
+#define PIN_A3 11
+/** @brief Pin A4 **/
+#define PIN_A4 12
+/** @brief Pin A5 **/
+#define PIN_A5 13
+/** @brief Pin A6 **/
+#define PIN_A6 14 
+/** @brief Pin A7 **/
+#define PIN_A7 15
+
+/** @brief Pin SS **/
+#define PIN_SS 16
+/** @brief Pin SCK **/
+#define PIN_SCK 17
+/** @brief Pin MOSI **/
+#define PIN_MOSI 18
+/** @brief Pin MISO **/
+#define PIN_MISO 19
+/** @brief LCD Command Pin **/
+#define PIN_LCD_COMMAND 20
+
+/** @brief Pin C0 **/
+#define PIN_C0 24
+/** @brief Pin C1 **/
+#define PIN_C1 25
+/** @brief Pin C2 **/
+#define PIN_C2 26
+/** @brief Pin C3 **/
+#define PIN_C3 27
+/** @brief Pin C4 **/
+#define PIN_C4 28
+/** @brief Pin C5 **/
+#define PIN_C5 29
+/** @brief Pin C6 **/
+#define PIN_C6 30
+/** @brief Pin C7 **/
+#define PIN_C7 31
+
+/** @brief Pin SCL **/
+#define PIN_SCL 32
+/** @brief Pin SDA **/
+#define PIN_SDA 33
+
+/** @brief Pin RX0 **/
+#define PIN_RX0 40
+/** @brief Pin TX0 **/
+#define PIN_TX0 41
+/** @brief LCD Reset Pin **/
+#define PIN_LCD_RESET 42
+/** @brief Pin E6 **/
+#define PIN_E6 46
+/** @brief Pin EXT_DIO1 **/
+#define PIN_EXT_DIO1 46
+/** @brief Pin E7 **/
+#define PIN_E7 47
+/** @brief Pin EXT_DIO2 **/
+#define PIN_EXT_DIO2 48
+
+/** @brief Pin AN0 **/
+#define PIN_AN0 48
+/** @brief Pin ADC0 **/
+#define PIN_ADC0 48
+/** @brief Pin AN1 **/
+#define PIN_AN1 49
+/** @brief Pin ADC1 **/
+#define PIN_ADC1 49
+/** @brief Pin AN2 **/
+#define PIN_AN2 50
+/** @brief Pin ADC2 **/
+#define PIN_ADC2 50
+/** @brief Pin AN3 **/
+#define PIN_AN3 51
+/** @brief Pin ADC3 **/
+#define PIN_ADC3 51
+/** @brief Pin AN4 **/
+#define PIN_AN4 52
+/** @brief Pin ADC4 **/
+#define PIN_ADC4 52
+/** @brief Pin AN5 **/
+#define PIN_AN5 53
+/** @brief Pin ADC5 **/
+#define PIN_ADC5 53
+/** @brief Pin AN6 **/
+#define PIN_AN6 54
+/** @brief Pin ADC6 **/
+#define PIN_ADC6 54
+/** @brief Pin AN7 **/
+#define PIN_AN7 55
+/** @brief Pin ADC7 **/
+#define PIN_ADC7 55
+
+/** @brief Wheel Pin **/
+#define PIN_WHEEL 54
+/** @brief Battery Voltage Monitor Pin **/
+#define PIN_BATT 55
+
+/** @brief button1 Pin **/
+#define PIN_BTN1 56
+/** @brief button2 Pin **/
+#define PIN_BTN2 57
+
+/** @brief LED1 Pin **/
+#define PIN_LED1 58
+
+/* Buttons */
+/** @brief Button Pin **/
+#define PIN_BTN PING
+/** @brief button2 Pin **/
+#define BTN2 PING1
+/** @brief button1 Pin **/
+#define BTN1 PING0
+
+/** @brief Read a portpin. **/
+int digital_input(int);
+/** @brief Output to a portpin. **/
+void digital_output(int bit, int val);
+/** @brief Pullup a portpin. **/
+void digital_pull_up(int);
+
+/** @brief Check if button1 is pressed. **/
+int button1_read( void );
+/** @brief Check if button1 is clicked. **/
+int button1_click( void );
+/** @brief Wait until button1 is pressed. **/
+void button1_wait( void );
+
+/** @brief Check if button2 is pressed. **/
+int button2_read( void );
+/** @brief Check if button2 is clicked. **/
+int button2_click( void );
+/** @brief Wait until button2 is pressed. **/
+void button2_wait( void );
+
+/** @} **/ // end addtogroup
+
+#endif
+
Index: include/libdragonfly/atomic.h
===================================================================
--- include/libdragonfly/atomic.h	(nonexistent)
+++ include/libdragonfly/atomic.h	(revision 1554)
@@ -0,0 +1,309 @@
+/* This file is in the dragonfly library directory because it seems to be
+   missing from the AVR libc distribution */
+   
+/* Copyright (c) 2007 Dean Camera
+   All rights reserved.
+
+   Redistribution and use in source and binary forms, with or without
+   modification, are permitted provided that the following conditions are met:
+
+   * Redistributions of source code must retain the above copyright
+     notice, this list of conditions and the following disclaimer.
+
+   * Redistributions in binary form must reproduce the above copyright
+     notice, this list of conditions and the following disclaimer in
+     the documentation and/or other materials provided with the
+     distribution.
+
+   * Neither the name of the copyright holders nor the names of
+     contributors may be used to endorse or promote products derived
+     from this software without specific prior written permission.
+
+  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+  POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/* $Id: atomic.h,v 1.3 2007/12/20 14:17:56 joerg_wunsch Exp $ */
+
+#ifndef _UTIL_ATOMIC_H_
+#define _UTIL_ATOMIC_H_ 1
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#if !defined(__DOXYGEN__)
+/* Internal helper functions. */
+static __inline__ uint8_t __iSeiRetVal(void)
+{
+    sei();
+    return 1;
+}
+
+static __inline__ uint8_t __iCliRetVal(void)
+{
+    cli();
+    return 1;
+}
+
+static __inline__ void __iSeiParam(const uint8_t *__s)
+{
+    sei();
+    __asm__ volatile ("" ::: "memory");
+    (void)__s;
+}
+
+static __inline__ void __iCliParam(const uint8_t *__s)
+{
+    cli();
+    __asm__ volatile ("" ::: "memory");
+    (void)__s;
+}
+
+static __inline__ void __iRestore(const  uint8_t *__s)
+{
+    SREG = *__s;
+    __asm__ volatile ("" ::: "memory");
+}
+#endif	/* !__DOXYGEN__ */
+
+/** \file */
+/** \defgroup util_atomic <util/atomic.h> Atomically and Non-Atomically Executed Code Blocks
+
+    \code
+    #include <util/atomic.h>
+    \endcode
+
+    \note The macros in this header file require the ISO/IEC 9899:1999
+    ("ISO C99") feature of for loop variables that are declared inside
+    the for loop itself.  For that reason, this header file can only
+    be used if the standard level of the compiler (option --std=) is
+    set to either \c c99 or \c gnu99.
+
+    The macros in this header file deal with code blocks that are
+    guaranteed to be excuted Atomically or Non-Atmomically.  The term
+    "Atomic" in this context refers to the unability of the respective
+    code to be interrupted.
+
+    These macros operate via automatic manipulation of the Global
+    Interrupt Status (I) bit of the SREG register. Exit paths from
+    both block types are all managed automatically without the need
+    for special considerations, i. e. the interrupt status will be
+    restored to the same value it has been when entering the
+    respective block.
+
+    A typical example that requires atomic access is a 16 (or more)
+    bit variable that is shared between the main execution path and an
+    ISR.  While declaring such a variable as volatile ensures that the
+    compiler will not optimize accesses to it away, it does not
+    guarantee atomic access to it.  Assuming the following example:
+
+    \code
+#include <inttypes.h>
+#include <avr/interrupt.h>
+#include <avr/io.h>
+
+volatile uint16_t ctr;
+
+ISR(TIMER1_OVF_vect)
+{
+  ctr--;
+}
+
+...
+int
+main(void)
+{
+   ...
+   ctr = 0x200;
+   start_timer();
+   while (ctr != 0)
+     // wait
+       ;
+   ...
+}
+    \endcode
+
+    There is a chance where the main context will exit its wait loop
+    when the variable \c ctr just reached the value 0xFF.  This happens
+    because the compiler cannot natively access a 16-bit variable
+    atomically in an 8-bit CPU.  So the variable is for example at
+    0x100, the compiler then tests the low byte for 0, which succeeds.
+    It then proceeds to test the high byte, but that moment the ISR
+    triggers, and the main context is interrupted.  The ISR will
+    decrement the variable from 0x100 to 0xFF, and the main context
+    proceeds.  It now tests the high byte of the variable which is
+    (now) also 0, so it concludes the variable has reached 0, and
+    terminates the loop.
+
+    Using the macros from this header file, the above code can be
+    rewritten like:
+
+    \code
+#include <inttypes.h>
+#include <avr/interrupt.h>
+#include <avr/io.h>
+#include <util/atomic.h>
+
+volatile uint16_t ctr;
+
+ISR(TIMER1_OVF_vect)
+{
+  ctr--;
+}
+
+...
+int
+main(void)
+{
+   ...
+   ctr = 0x200;
+   start_timer();
+   sei();
+   uint16_t ctr_copy;
+   do
+   {
+     ATOMIC_BLOCK(ATOMIC_FORCEON)
+     {
+       ctr_copy = ctr;
+     }
+   }
+   while (ctr_copy != 0);
+   ...
+}
+    \endcode
+
+    This will install the appropriate interrupt protection before
+    accessing variable \c ctr, so it is guaranteed to be consistently
+    tested.  If the global interrupt state were uncertain before
+    entering the ATOMIC_BLOCK, it should be executed with the
+    parameter ATOMIC_RESTORESTATE rather than ATOMIC_FORCEON.
+
+*/
+
+/** \def ATOMIC_BLOCK(type)
+    \ingroup util_atomic
+
+    Creates a block of code that is guaranteed to be executed
+    atomically. Upon entering the block the Global Interrupt Status
+    flag in SREG is disabled, and re-enabled upon exiting the block
+    from any exit path.
+
+    Two possible macro parameters are permitted, ATOMIC_RESTORESTATE
+    and ATOMIC_FORCEON.
+*/
+#if defined(__DOXYGEN__)
+#define ATOMIC_BLOCK(type)
+#else
+#define ATOMIC_BLOCK(type) for ( type, __ToDo = __iCliRetVal(); \
+	                       __ToDo ; __ToDo = 0 )
+#endif	/* __DOXYGEN__ */
+
+/** \def NONATOMIC_BLOCK(type)
+    \ingroup util_atomic
+
+    Creates a block of code that is executed non-atomically. Upon
+    entering the block the Global Interrupt Status flag in SREG is
+    enabled, and disabled upon exiting the block from any exit
+    path. This is useful when nested inside ATOMIC_BLOCK sections,
+    allowing for non-atomic execution of small blocks of code while
+    maintaining the atomic access of the other sections of the parent
+    ATOMIC_BLOCK.
+
+    Two possible macro parameters are permitted,
+    NONATOMIC_RESTORESTATE and NONATOMIC_FORCEOFF.
+*/
+#if defined(__DOXYGEN__)
+#define NONATOMIC_BLOCK(type)
+#else
+#define NONATOMIC_BLOCK(type) for ( type, __ToDo = __iSeiRetVal(); \
+	                          __ToDo ;  __ToDo = 0 )
+#endif	/* __DOXYGEN__ */
+
+/** \def ATOMIC_RESTORESTATE
+    \ingroup util_atomic
+
+    This is a possible parameter for ATOMIC_BLOCK. When used, it will
+    cause the ATOMIC_BLOCK to restore the previous state of the SREG
+    register, saved before the Global Interrupt Status flag bit was
+    disabled. The net effect of this is to make the ATOMIC_BLOCK's
+    contents guaranteed atomic, without changing the state of the
+    Global Interrupt Status flag when execution of the block
+    completes.
+*/
+#if defined(__DOXYGEN__)
+#define ATOMIC_RESTORESTATE
+#else
+#define ATOMIC_RESTORESTATE uint8_t sreg_save \
+	__attribute__((__cleanup__(__iRestore))) = SREG
+#endif	/* __DOXYGEN__ */
+
+/** \def ATOMIC_FORCEON
+    \ingroup util_atomic
+
+    This is a possible parameter for ATOMIC_BLOCK. When used, it will
+    cause the ATOMIC_BLOCK to force the state of the SREG register on
+    exit, enabling the Global Interrupt Status flag bit. This saves on
+    flash space as the previous value of the SREG register does not
+    need to be saved at the start of the block.
+
+    Care should be taken that ATOMIC_FORCEON is only used when it is
+    known that interrupts are enabled before the block's execution or
+    when the side effects of enabling global interrupts at the block's
+    completion are known and understood.
+*/
+#if defined(__DOXYGEN__)
+#define ATOMIC_FORCEON
+#else
+#define ATOMIC_FORCEON uint8_t sreg_save \
+	__attribute__((__cleanup__(__iSeiParam))) = 0
+#endif	/* __DOXYGEN__ */
+
+/** \def NONATOMIC_RESTORESTATE
+    \ingroup util_atomic
+
+    This is a possible parameter for NONATOMIC_BLOCK. When used, it
+    will cause the NONATOMIC_BLOCK to restore the previous state of
+    the SREG register, saved before the Global Interrupt Status flag
+    bit was enabled. The net effect of this is to make the
+    NONATOMIC_BLOCK's contents guaranteed non-atomic, without changing
+    the state of the Global Interrupt Status flag when execution of
+    the block completes.
+*/
+#if defined(__DOXYGEN__)
+#define NONATOMIC_RESTORESTATE
+#else
+#define NONATOMIC_RESTORESTATE uint8_t sreg_save \
+	__attribute__((__cleanup__(__iRestore))) = SREG
+#endif	/* __DOXYGEN__ */
+
+/** \def NONATOMIC_FORCEOFF
+    \ingroup util_atomic
+
+    This is a possible parameter for NONATOMIC_BLOCK. When used, it
+    will cause the NONATOMIC_BLOCK to force the state of the SREG
+    register on exit, disabling the Global Interrupt Status flag
+    bit. This saves on flash space as the previous value of the SREG
+    register does not need to be saved at the start of the block.
+
+    Care should be taken that NONATOMIC_FORCEOFF is only used when it
+    is known that interrupts are disabled before the block's execution
+    or when the side effects of disabling global interrupts at the
+    block's completion are known and understood.
+*/
+#if defined(__DOXYGEN__)
+#define NONATOMIC_FORCEOFF
+#else
+#define NONATOMIC_FORCEOFF uint8_t sreg_save \
+	__attribute__((__cleanup__(__iCliParam))) = 0
+#endif	/* __DOXYGEN__ */
+
+#endif
Index: include/libdragonfly/i2c.h
===================================================================
--- include/libdragonfly/i2c.h	(nonexistent)
+++ include/libdragonfly/i2c.h	(revision 1554)
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) 2007 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 i2c.h
+ *  @brief Header file for I2C
+ *
+ *  Contains functions for I2C.
+ *
+ *  @author Kevin Woo and Suresh Nidhiry, Colony Project, CMU Robotics Club
+ **/
+
+
+#ifndef _I2C_H_
+#define _I2C_H_
+
+#include <stddef.h>
+
+/** @brief Address of slave receive handler function **/
+typedef void (*fun_srecv_t)(char);
+
+/** @brief Address of master receive handler function**/
+typedef int (*fun_mrecv_t)(char);
+
+/** @brief Address of slave send handler function**/
+typedef char (*fun_send_t)(void);
+
+int i2c_init(char addr, fun_mrecv_t master_recv, fun_srecv_t slave_recv, fun_send_t slave_send);
+int i2c_send(char dest, char* data, size_t bytes);
+int i2c_request(char dest);
+
+void i2c_packet_rec (char i2c_byte);
+void i2c_packet_sniff(char data);
+#endif
+
Index: include/libdragonfly/bom.h
===================================================================
--- include/libdragonfly/bom.h	(nonexistent)
+++ include/libdragonfly/bom.h	(revision 1554)
@@ -0,0 +1,86 @@
+/**
+ * Copyright (c) 2007 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 bom.h
+ * @brief Definitions for using the BOM
+ * 
+ * This file contains definitions for using the Bearing and 
+ * Orientation Module (BOM).
+ *
+ * @author Colony Project, CMU Robotics Club
+ *
+ **/
+
+#ifndef _BOM_H
+#define _BOM_H
+
+/**
+ * @addtogroup bom
+ * @{
+ **/
+ 
+/** @brief Include all elements in the 16-bit bitfield **/
+#define BOM_ALL 0xFFFF
+
+/** @brief Original BOM - No Range, No Individual LED control **/
+#define BOM10     0
+
+/** @brief BOM 1.5 - No Range, Individual LED control **/
+#define BOM15   1
+
+/** @brief RBOM - Range, Individual LED control **/
+#define RBOM    2
+
+
+/** @brief Initialize the bom according to bom type **/
+void bom_init(char type);
+
+/** @brief Refresh bom_val[] with new values from analog8.  analog_init and bom_init must be called for this to work. **/
+void bom_refresh(int bit_field);
+
+/** @brief Gets the bom reading from bom_val[which].  Call bom_refresh beforehand to read new bom values. **/
+int bom_get(int which);
+
+/** @brief Compares all the values in bom_val[] and returns the index to the highest value element. **/
+int bom_get_max(void);
+
+/** @brief Enables the selected bom leds on a BOM1.5 **/
+void bom_set_leds(int bit_field);
+
+/** @brief (DEPRECATED) Gets and compares all bom values.  Returns the index to the highest value element since last refresh. **/
+int get_max_bom(void);
+
+/** @brief Turns on all BOM leds, or turns on enabled leds on a BOM1.5. **/
+void bom_on(void);
+
+/** @brief Turns off all bom leds. **/
+void bom_off(void);
+
+/** @} **/
+
+#endif
+
Index: include/libdragonfly/serial.h
===================================================================
--- include/libdragonfly/serial.h	(nonexistent)
+++ include/libdragonfly/serial.h	(revision 1554)
@@ -0,0 +1,146 @@
+/**
+ * Copyright (c) 2007 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 serial.h
+ * @brief Contains declarations for serial input and output
+ *
+ * Contains definitions for serial input and output.
+ *
+ * @author Colony Project, CMU Robotics Club
+ * Based on Tom Lauwer's Firefly Library
+ *
+ **/
+
+/*
+  serial.h - Contains definitions and function prototypes for the RS232 serial port
+  author(s): pkv
+  
+  Directions:
+  Call the initialization function for the serial port you wish to use.  Then, use
+  either the provided functions or the stdio functions (fprintf, etc) to read and
+  write characters to the serial ports.
+  
+  UART Mapping:
+  usb_*() -> UART0
+  xbee_*() -> UART1
+  
+  Options: (Add the following defines to your code to configure this library)
+  #define USB_BAUD { 115200 | 9600 } <= pick ONE value from in here
+  #define XBEE_BAUD { 115200 | 9600 } <= pick ONE value from in here
+  #define USE_STDIO
+  
+  Note: If you enable USE_STDIO, the first init function that is called will 
+  automatically be linked to stdin, stdout, and stderr.  To use the baud rate 
+  commands, add something like the following to your code:
+  
+  #define FOO_BAUD 9600
+  
+  **UNLESS YOU KNOW WHAT YOU ARE DOING, PLEASE DO NOT CHANGE THIS FILE**
+  Many, many other people use this file in their code.  If you change it, you will
+  probably break all of their nice code.  You should not need to change anything in
+  here, except to accomodate new hardware.
+*/
+
+#ifndef _SERIAL_H
+#define _SERIAL_H
+
+#include <inttypes.h>
+#include <avr/pgmspace.h>
+
+/**
+ * @defgroup usb USB Input / Output
+ * @brief Functions for USB input / output
+ *
+ * Low level functions for USB input and output.
+ *
+ * @{
+ **/
+
+// if no baud rate is defined for usb, default is set here
+#ifndef USB_BAUD
+/** @brief the USB baud rate **/
+#define USB_BAUD 115200
+#endif
+
+/** @brief Initialize the USB **/
+void usb_init(void);
+/** @brief Print a character to USB **/
+int usb_putc(char c);
+/** @brief Read a character from USB **/
+int usb_getc(void);
+/** @brief Read a character from USB without blocking **/
+int usb_getc_nb(char *c);
+/** @brief Print a string to USB **/
+int usb_puts(char *s);
+/** @brief Print a string from program space to USB **/
+void usb_puts_P (PGM_P s);
+/** @brief Print an integer to USB **/
+int usb_puti(int value);
+/** @brief Determine a hexadecimal digit **/
+uint8_t hex_digit (uint8_t value);
+/** @brief Print a fixed width hexadecimal representation to USB **/
+void usb_puth16 (uint16_t value);
+/** @brief Print a fixed width hexadecimal representation to USB **/
+void usb_puth8(uint8_t value);
+/** @brief Alias for usb_puth16 **/
+static inline void usb_puth (uint16_t value) { usb_puth16 (value); };
+
+
+/** @} **/ //end addtogroup
+
+/**
+ * @defgroup xbee XBee Input / Output
+ * @brief Functions for XBee input / output
+ *
+ * Low level functions for XBee input and output.
+ *
+ * @{
+ **/
+
+// if no baud rate is defined for usb, default is set here
+
+// if no baud rate is defined for xbee, default is set here
+#ifndef XBEE_BAUD
+/** @brief the XBee baud rate **/
+#define XBEE_BAUD 9600
+#endif
+
+/** @brief Initialize the XBee **/
+void xbee_init(void);
+/** @brief Print a character to the XBee **/
+int xbee_putc(char c);
+/** @brief Read a character from the XBee **/
+int xbee_getc(void);
+/** @brief Read a character from the XBee without blocking **/
+int xbee_getc_nb(char *c);
+
+
+
+/** @} **/ //end addtogroup
+
+#endif
+
Index: include/libdragonfly/buzzer.h
===================================================================
--- include/libdragonfly/buzzer.h	(nonexistent)
+++ include/libdragonfly/buzzer.h	(revision 1554)
@@ -0,0 +1,88 @@
+/**
+ * Copyright (c) 2007 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 buzzer.h
+ * @brief Contains definitions for using the buzzer.
+ *
+ * Contains definitions for using the buzzer built into
+ * the colony robots.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef _BUZZER_H_
+#define _BUZZER_H_
+
+/**
+ * @addtogroup buzzer
+ * @{
+ **/
+
+//Musical note definitions
+//Source: http://www.answers.com/topic/piano-key-frequencies
+/** @brief Middle C **/
+#define	C4	260 //Middle C
+/** @brief C# **/
+#define	C4s	277 //C sharp
+/** @brief D **/
+#define	D4	294
+/** @brief D# **/
+#define	D4s	311
+/** @brief E **/
+#define	E4	330
+/** @brief F **/
+#define	F4	349
+/** @brief F# **/
+#define	F4s	370
+/** @brief G **/
+#define	G4	392
+/** @brief G# **/
+#define	G4s	415
+/** @brief A **/
+#define	A4	440
+/** @brief A# **/
+#define	A4s	466
+/** @brief B **/
+#define	B4	494
+/** @brief C **/
+#define	C5	523
+
+/** @brief Initialize the buzzer. **/
+void buzzer_init(void);
+/** @brief Set the value the buzzer plays. **/
+void buzzer_set_val(unsigned int buzz_value);
+/** @brief Set the frequency the buzzer plays. **/
+void buzzer_set_freq(unsigned int buzz_freq);
+/** @brief Play a frequency for a specified time. **/
+void buzzer_chirp(unsigned int ms, unsigned int buzz_freq);
+/** @brief Turn the buzzer off. **/
+void buzzer_off(void); 
+
+/** @} **/ //end addtogroup
+
+#endif
+
Index: include/libdragonfly/reset.h
===================================================================
--- include/libdragonfly/reset.h	(nonexistent)
+++ include/libdragonfly/reset.h	(revision 1554)
@@ -0,0 +1,49 @@
+/**
+ * Copyright (c) 2007 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 reset.h
+ * @brief Contains function(s) for resetting the robots
+ * 
+ * @author Colony Project, CMU Robotics Club, James Kong
+ */
+
+#ifndef _RESET_H_
+#define _RESET_H_
+
+/**
+ * @addtogroup reset
+ * @{
+ **/
+ 
+/** @brief Reset the robot **/
+void reset(void);
+
+/**@}**/ //end group
+
+#endif
+
Index: include/libdragonfly/rangefinder.h
===================================================================
--- include/libdragonfly/rangefinder.h	(nonexistent)
+++ include/libdragonfly/rangefinder.h	(revision 1554)
@@ -0,0 +1,70 @@
+/**
+ * Copyright (c) 2007 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 rangefinder.h
+ * @brief Contains rangefinder declarations and functions
+ * 
+ * Contains functions and definitions for the use of
+ * IR rangefinders.
+ *
+ * @author Colony Project, CMU Robotics Club
+ **/
+
+#ifndef _RANGEFINDER_H_
+#define _RANGEFINDER_H_
+
+/**
+ * @addtogroup rangefinder
+ * @{
+ **/
+
+/** @brief IR Rangefinder 1 **/
+#define IR1 6
+/** @brief IR Rangefinder 2 **/
+#define IR2 5
+/** @brief IR Rangefinder 3 **/
+#define IR3 4
+/** @brief IR Rangefinder 4 **/
+#define IR4 3
+/** @brief IR Rangefinder 5 **/
+#define IR5 2
+/** @brief smallest meaningful rangefinder reading (logarithmic scale) **/
+#define MIN_IR_ADC8 20
+/** @brief largest meaningful rangefinder reading (logarithmic scale) **/
+#define MAX_IR_ADC8 133
+
+/** @brief Initialize the rangefinders **/
+void range_init(void);
+/** @brief Read the distance from a rangefinder **/
+int range_read_distance(int range_id);
+/** @brief Convert logarithmic-scale distance readings to a linear scale **/
+int linearize_distance(int value);
+
+/** @} **/ //end addtogroup
+
+#endif
+
Index: include/libdragonfly/eeprom.h
===================================================================
--- include/libdragonfly/eeprom.h	(nonexistent)
+++ include/libdragonfly/eeprom.h	(revision 1554)
@@ -0,0 +1,49 @@
+/**
+ * @file eeprom.h
+ * @brief handles eeprom storage for persistent data
+ *
+ * Contains functions and definitions for reading and writing to eeprom
+ *
+ * @author Colony Project, Brad Neuman
+ */
+ 
+ #ifndef _EEPROM_H_
+ #define _EEPROM_H_
+ 
+ #include <bom.h>
+ 
+ #define EEPROM_ROBOT_ID_ADDR 0x10
+ #define EEPROM_BOM_TYPE_ADDR 0x14
+ 
+ /** @brief store a byte to eeproem
+  *  @return 0 if success, nonzero on failure
+  */
+ int eeprom_put_byte(unsigned int addr, unsigned char byte);
+ 
+ /** @brief reads a byte from eeprom
+  *
+  *  Pass it thge address and a pointer to a byte where the byte at the
+  *  address will be stored
+  *
+  *  @return 0 if successful (byte is set to the eeprom value at addr), 
+  *  nonzero if there was a problem
+   */
+ int eeprom_get_byte(unsigned int addr, unsigned char *byte);
+ 
+ /** @brief get stored robot ID
+  *
+  *  checks that EEPROM has been programed with an ID and returns it
+  *
+  *  @return the robot id, if it is stored. If it returns 0xFF it is probably invalid
+  */
+ unsigned char get_robotid(void);
+  
+   /** @brief get stored robot ID
+  *
+  * checks that EEPROM has been programed with an BOM type and returns it
+  *
+  *  @return the robot bom type as defined in bom.h, if it is stored. If it returns 0xFF it is probably invalid
+  */
+ unsigned char get_bom_type(void);
+ 
+ #endif
Index: include/libdragonfly/ring_buffer.h
===================================================================
--- include/libdragonfly/ring_buffer.h	(nonexistent)
+++ include/libdragonfly/ring_buffer.h	(revision 1554)
@@ -0,0 +1,142 @@
+/**
+ * Copyright (c) 2007 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 ring_buffer.h
+ * @brief Ring Buffer
+ *
+ * Include macros to create a ring buffer. Originally written for 15-410.
+ * Modified for use in ATMega128 serial driver
+ *
+ * @author Cornell Wright (cgwright)
+ * @author Jason P. Winters (jpwinter)
+ *
+ **/
+
+#ifndef _RING_BUFFER_H
+#define _RING_BUFFER_H
+
+/** @brief Creates the struct for a new ring buffer. This just expands to a
+ *	structure definition and thus should be invoked in the global context.
+ *
+ *	@param struct_name Name of the ring buffer struct.
+ *
+ *	@param size The size of the buffer to create.
+ *
+ *	@param type The type of object that the queue is to hold.
+ *
+ *	@param ... Name or names of the instance or instances of the ring buffer(s)
+ *	to be created.
+ */
+#define RING_BUFFER_NEW(struct_name, size, type, ...)	\
+	struct struct_name {	\
+		type queue[size];	\
+		uint8_t start;			\
+		uint8_t end;			\
+		uint8_t buffer_size;			\
+	} __VA_ARGS__
+
+
+/** @brief Initializes the ring buffer, setting its size to the correct value
+ *
+ *	@param buf The ring buffer to initialize.
+ *
+ *  @param size The size of the ring buffer (in array elements)
+ */
+#define RING_BUFFER_INIT(buf, size) 			\
+	do {										\
+		(buf).buffer_size = size;				\
+	} while(0)
+
+
+/** @brief Sets the specified ring buffer to be empty.
+ *
+ *	@param buf The ring buffer to make empty.
+ */
+#define RING_BUFFER_CLEAR(buf)	\
+	do {						\
+		(buf).start = 0;		\
+		(buf).end = 0;			\
+	} while (0)
+
+/** @brief Returns true if the ring buffer specified is empty.
+ *
+ *	@param buf The buffer to check emptiness of.
+ */
+#define RING_BUFFER_EMPTY(buf) ((buf).start == (buf).end)
+
+
+/** @brief Returns true if the ring buffer specified is full.
+ *
+ *	@param buf The buffer to check fullness of.
+ */
+#define RING_BUFFER_FULL(buf)	\
+		(((buf).end + 1) % (buf).buffer_size == (buf).start)
+
+
+/** @brief Adds val to ring buffer buf. Note that val must be of the type
+ *	used in creating the ring buffer to prevent the compiler from spewing
+ *	confusing errors. Also, this assumes that the ring buffer is not full.
+ *
+ *	@param buf The ring buffer to add to.
+ *	@param val The value to add.
+ */
+#define RING_BUFFER_ADD(buf, val)		\
+	do {								\
+		(buf).queue[(buf).end] = val;	\
+		(buf).end = ((buf).end + 1) % (buf).buffer_size;	\
+	} while (0)
+
+
+/** @brief Removes the value at the head of the ring buffer and puts it in
+ *	val_ret. Note that val_ret must be the same type used in creating the ring
+ *	buffer to prevent the compiler from spewing confusing errors. Also, this
+ *	assumes that the ring buffer is not empty.
+ *
+ *	@param buf The ring buffer to remove from.
+ *	@param val_ret Where to put the value removed from the head of the ring
+ *	buffer.
+ */
+#define RING_BUFFER_REMOVE(buf, val_ret)	\
+	do {	\
+		(val_ret) = (buf).queue[(buf).start];	\
+		(buf).start = ((buf).start + 1) % (buf).buffer_size;	\
+	} while (0)
+
+/** @brief Checks the value at the head of the ring buffer without removing it
+ *  and puts it into val_ret. Note that val_ret must be the same type used in
+ *  creating the ring buffer to prevent the compiler from spewing confusing
+ *  errors. Also, this assumes that the ring buffer is not empty.
+ *
+ *  @param buf The ring buffer to check from
+ *  @param val_ret where to put the value checked from the head of the ring
+ */
+ #define RING_BUFFER_PEEK(buf, val_ret)  \
+  do { \
+    (val_ret) = (buf).queue[(buf).start]; \
+  } while(0)
+
+#endif /* _RING_BUFFER_H */
+
