Changeset 54:fb6a875ea5d2 in xplra


Ignore:
Timestamp:
02/16/13 18:04:17 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added support for the hotkey functions in the C++ client and a test program as well

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/client/c/hu/varadiistvan/xplra/XPlane.cc

    r40 r54  
    5959using std::auto_ptr;
    6060using std::string;
     61using std::min;
    6162
    6263//------------------------------------------------------------------------------
     
    500501//------------------------------------------------------------------------------
    501502
     503void XPlane::registerHotkeys(const uint16_t* codes, size_t length)
     504    throw(Exception)
     505{
     506    stream->writeU8(Protocol::COMMAND_REGISTER_HOTKEYS);
     507    stream->writeU32(length);
     508    stream->write(codes, sizeof(uint16_t)*length);
     509    stream->flush();
     510    checkResult();
     511}
     512
     513//------------------------------------------------------------------------------
     514
     515void XPlane::queryHotkeys(uint8_t* states, size_t length) throw(Exception)
     516{
     517    stream->writeU8(Protocol::COMMAND_QUERY_HOTKEYS);
     518    stream->flush();
     519    checkResult();
     520
     521    size_t count = stream->readU32();
     522    checkStream();
     523    stream->read(states, min(length, count));
     524    if (length<count) {
     525        while(length<count) {
     526            stream->readU8();
     527            ++length;
     528        }
     529    } else if (length>count) {
     530        memset(states + count, 0, length - count);
     531    }
     532    checkStream();
     533}
     534
     535//------------------------------------------------------------------------------
     536
     537void XPlane::unregisterHotkeys()
     538{
     539    stream->writeU8(Protocol::COMMAND_UNREGISTER_HOTKEYS);
     540    stream->flush();
     541    checkResult();
     542}
     543
     544//------------------------------------------------------------------------------
     545
    502546// Local Variables:
    503547// mode: C++
  • src/client/c/hu/varadiistvan/xplra/XPlane.h

    r40 r54  
    282282    void showMessage(const char* message, float duration) throw(Exception);
    283283
     284    /**
     285     * Register the given hotkey codes for listening. If there is an
     286     * existing set of hotkeys registered, those will be overwritten.
     287     */
     288    void registerHotkeys(const uint16_t* codes, size_t length) throw(Exception);
     289
     290    /**
     291     * Query the registered hotkeys whether they were pressed.
     292     */
     293    void queryHotkeys(uint8_t* states, size_t length) throw(Exception);
     294
     295    /**
     296     * Unregister the hotkeys.
     297     */
     298    void unregisterHotkeys();
     299
    284300private:
    285301    /**
  • test/Makefile.am

    r31 r54  
    66endif
    77
    8 noinst_PROGRAMS=ctest basictest basicctest multigettest multigetctest multisettest multisetctest
     8noinst_PROGRAMS=ctest basictest basicctest multigettest multigetctest multisettest multisetctest hotkeytest
    99
    1010ctest_SOURCES=ctest.c
     
    3434endif
    3535
     36hotkeytest_SOURCES=hotkeytest.cc
     37
    3638EXTRA_DIST=\
    3739        runpy.sh                \
    38         basictest.py
     40        basictest.py            \
     41        multigettest.py         \
     42        multisettest.py         \
     43        hotkeytest.py
  • test/hotkeytest.py

    r53 r54  
    2121        xplane.registerHotkeys([0x0241, 0x0142, 0x0343, 0x0251])
    2222        print "Registered hotkeys..."
     23        print
    2324
    2425        print "Listening to hotkeys..."
     
    4546        print ">>>>>>>>>>>>>>>>>>>>>> Exception caught:", str(e)
    4647    finally:
     48        xplane.unregisterHotkeys()
    4749        xplane.disconnect()
Note: See TracChangeset for help on using the changeset viewer.