/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Core Library
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 *
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __DEVCOM_H
#define __DEVCOM_H

#include <usb.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#ifndef USB_REQ_SET_REPORT
#define USB_REQ_SET_REPORT 0x09
#endif
#ifndef USB_DIR_IN
#define USB_DIR_IN 0x80
#endif
#ifndef USB_REQ_GET_REPORT
#define USB_REQ_GET_REPORT 0x01
#endif

#define USB_VENDOR_ID_CODEMERCS 1984
/* low speed iowarrior */
#define USB_DEVICE_ID_CODEMERCS_IOW40 0x1500
#define USB_DEVICE_ID_CODEMERCS_IOW24 0x1501
/* full speed iowarrior */
#define USB_DEVICE_ID_CODEMERCS_IOW48 0x1502
#define USB_DEVICE_ID_CODEMERCS_IOW28 0x1503

namespace iwear {
namespace iowarrior {

/**
 * This class provides the interface for communicating with the IO Warrior hardware.
 * It provides functions for opening and closing the usb port and for sending and
 * receiving messages from/to the IO Warrior.
 */
class Devcom {
    
    public:

	/**
	 * Get an instance of this class
	 */
        Devcom();

	/**
	 * Delete an instance of this class
	 */
        ~Devcom();


	/**
	 * Represent the usb port the IO Warrior is connected at
	 */
        usb_dev_handle *myusb;


	/**
	 * Write a message to the IO Warrior
	 * @param ifnum the identifier for the connected IO Warrior
	 * @param val the message to set the ports
	 * @return error message
	 */
        int write_warrior(int ifnum, int val);

	/**
	 * Read a message from the IO Warrior
	 * @param ifnum the identifier for the connected IO Warrior
	 * @return the message containing the states of all ports
	 */
        int read_warrior(int ifnum);

	/**
	 * Test if the IO Warrior hardware is connected or not
	 * @return true, if it's connected, false otherwise
	 */
        bool isconnected_iowarrior();

	/**
	 * Open the usb port to the IO Warrior for communication
	 * @return error message
	 */
        int open_iowarrior();

	/**
	 * Close the usb port to the IO Warrior
	 * @return error message
	 */
        int close_iowarrior();
	
};

} // namespace iowarrior
} // namespace iwear

#endif // __DEVCOM_H

