• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xid_device_t.cpp

Go to the documentation of this file.
00001 /* Copyright (c) 2010, Cedrus Corporation
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are
00006  * met:
00007  *
00008  * Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.  
00010  *
00011  * Redistributions in binary form must reproduce the above copyright
00012  * notice, this list of conditions and the following disclaimer in the
00013  * documentation and/or other materials provided with the distribution.
00014  *
00015  * Neither the name of Cedrus Corporation nor the names of its
00016  * contributors may be used to endorse or promote products derived from
00017  * this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #include "xid_device_t.h"
00033 #include "xid_device_config_t.h"
00034 #include "xid_con_t.h"
00035 #include "constants.h"
00036 
00037 cedrus::xid_device_t::xid_device_t(
00038     boost::shared_ptr<xid_con_t> xid_con,
00039     const std::wstring &devconfig_path)
00040     : base_device_t(xid_con, devconfig_path),
00041       button_count_(8),
00042       input_name_prefix_(L"Button")
00043 {
00044     init_response_device();
00045 }
00046 
00047 cedrus::xid_device_t::~xid_device_t(void)
00048 {
00049 }
00050 
00051 int cedrus::xid_device_t::get_button_count() const
00052 {
00053     if(config_)
00054         return config_->number_of_lines();
00055     else
00056         return 8;
00057 }
00058 
00059 void cedrus::xid_device_t::poll_for_response()
00060 {
00061     cedrus::key_state state = xid_con_->check_for_keypress();
00062 
00063     if(state != cedrus::NO_KEY_DETECTED)
00064     {
00065         int port = -1;
00066         int key  = -1;
00067         bool was_pressed = false;
00068         int response_time = -1;
00069 
00070         xid_con_->get_current_response(port, key, was_pressed, response_time);
00071         
00072         if(config_)
00073         {
00074             key = config_->get_mapped_key(key);
00075         }
00076         else
00077         {
00078             // RB series response pads respond with a 1 based button index.  
00079             // Users of the API should expect a 0 based index.  Subtract 1 
00080             // from the key to give the user the correct button number.
00081             key -= 1;
00082         }
00083 
00084         response res;
00085         res.port = port;
00086         res.button = key;
00087         res.pressed = was_pressed;
00088         res.reaction_time = response_time;
00089         res.key_state = state;
00090  
00091         response_queue_.push(res);
00092     }
00093 }
00094 
00095 std::size_t cedrus::xid_device_t::response_queue_size() const
00096 {
00097     return response_queue_.size();
00098 }
00099 
00100 bool cedrus::xid_device_t::has_queued_responses() const
00101 {
00102     return !response_queue_.empty();
00103 }
00104 
00105 void cedrus::xid_device_t::clear_response_queue()
00106 {
00107     while(response_queue_.size() > 0)
00108     {
00109         response_queue_.pop();
00110     }
00111 }
00112 
00113 cedrus::response cedrus::xid_device_t::get_next_response()
00114 {
00115     response res = response_queue_.front();
00116     response_queue_.pop();
00117     return res;
00118 }
00119 
00120 std::wstring cedrus::xid_device_t::input_name_prefix() const
00121 {
00122     return input_name_prefix_;
00123 }
00124 
00125 void cedrus::xid_device_t::init_response_device()
00126 {
00127     switch(get_product_id())
00128     {
00129     case 1:
00130         {
00131             input_name_prefix_ = L"Voice Response";
00132             break;
00133         }
00134     default:
00135         {
00136             input_name_prefix_ = L"Button";
00137             break;
00138         }
00139     }
00140 }

Generated on Wed Dec 15 2010 13:17:12 for XID device library by  doxygen 1.7.2