initial commit
authorPhilipp Wagner <mail@philipp-wagner.com>
Sun Jun 14 17:34:16 2009 +0200 (2009-06-14)
changeset 06de75f1eb56c
child 1 49e691731b34
initial commit
CMakeLists.txt
INSTALL
LICENCE
README
examples/CMakeLists.txt
examples/speechmike_dump.c
libspeechmike.c
libspeechmike.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/CMakeLists.txt	Sun Jun 14 17:34:16 2009 +0200
     1.3 @@ -0,0 +1,16 @@
     1.4 +cmake_minimum_required(VERSION 2.6)
     1.5 +
     1.6 +ADD_LIBRARY(speechmike STATIC
     1.7 +  libspeechmike.c
     1.8 +)
     1.9 +
    1.10 +TARGET_LINK_LIBRARIES(speechmike)
    1.11 +
    1.12 +SET(CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries")
    1.13 +
    1.14 +INSTALL(TARGETS speechmike 
    1.15 +  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    1.16 +  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    1.17 +)
    1.18 +
    1.19 +add_subdirectory(examples)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/INSTALL	Sun Jun 14 17:34:16 2009 +0200
     2.3 @@ -0,0 +1,19 @@
     2.4 +Building and installing libspeechmike
     2.5 +=====================================
     2.6 +
     2.7 +libspeechmike uses CMake. The following steps should give you a working 
     2.8 +(static) library as well as the example program speechmike_dump:
     2.9 +
    2.10 +$ cd /your/source/dir
    2.11 +$ mkdir build
    2.12 +$ cd build
    2.13 +$ cmake ..
    2.14 +$ make
    2.15 +
    2.16 +If you want to install the library, call
    2.17 +# make install
    2.18 +The example program is not installed.
    2.19 +
    2.20 +The makefiles don't support building a shared library for now, please link
    2.21 +libspeechmike statically until the API is more stable.
    2.22 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/LICENCE	Sun Jun 14 17:34:16 2009 +0200
     3.3 @@ -0,0 +1,166 @@
     3.4 +		   GNU LESSER GENERAL PUBLIC LICENSE
     3.5 +                       Version 3, 29 June 2007
     3.6 +
     3.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
     3.8 + Everyone is permitted to copy and distribute verbatim copies
     3.9 + of this license document, but changing it is not allowed.
    3.10 +
    3.11 +
    3.12 +  This version of the GNU Lesser General Public License incorporates
    3.13 +the terms and conditions of version 3 of the GNU General Public
    3.14 +License, supplemented by the additional permissions listed below.
    3.15 +
    3.16 +  0. Additional Definitions.
    3.17 +
    3.18 +  As used herein, "this License" refers to version 3 of the GNU Lesser
    3.19 +General Public License, and the "GNU GPL" refers to version 3 of the GNU
    3.20 +General Public License.
    3.21 +
    3.22 +  "The Library" refers to a covered work governed by this License,
    3.23 +other than an Application or a Combined Work as defined below.
    3.24 +
    3.25 +  An "Application" is any work that makes use of an interface provided
    3.26 +by the Library, but which is not otherwise based on the Library.
    3.27 +Defining a subclass of a class defined by the Library is deemed a mode
    3.28 +of using an interface provided by the Library.
    3.29 +
    3.30 +  A "Combined Work" is a work produced by combining or linking an
    3.31 +Application with the Library.  The particular version of the Library
    3.32 +with which the Combined Work was made is also called the "Linked
    3.33 +Version".
    3.34 +
    3.35 +  The "Minimal Corresponding Source" for a Combined Work means the
    3.36 +Corresponding Source for the Combined Work, excluding any source code
    3.37 +for portions of the Combined Work that, considered in isolation, are
    3.38 +based on the Application, and not on the Linked Version.
    3.39 +
    3.40 +  The "Corresponding Application Code" for a Combined Work means the
    3.41 +object code and/or source code for the Application, including any data
    3.42 +and utility programs needed for reproducing the Combined Work from the
    3.43 +Application, but excluding the System Libraries of the Combined Work.
    3.44 +
    3.45 +  1. Exception to Section 3 of the GNU GPL.
    3.46 +
    3.47 +  You may convey a covered work under sections 3 and 4 of this License
    3.48 +without being bound by section 3 of the GNU GPL.
    3.49 +
    3.50 +  2. Conveying Modified Versions.
    3.51 +
    3.52 +  If you modify a copy of the Library, and, in your modifications, a
    3.53 +facility refers to a function or data to be supplied by an Application
    3.54 +that uses the facility (other than as an argument passed when the
    3.55 +facility is invoked), then you may convey a copy of the modified
    3.56 +version:
    3.57 +
    3.58 +   a) under this License, provided that you make a good faith effort to
    3.59 +   ensure that, in the event an Application does not supply the
    3.60 +   function or data, the facility still operates, and performs
    3.61 +   whatever part of its purpose remains meaningful, or
    3.62 +
    3.63 +   b) under the GNU GPL, with none of the additional permissions of
    3.64 +   this License applicable to that copy.
    3.65 +
    3.66 +  3. Object Code Incorporating Material from Library Header Files.
    3.67 +
    3.68 +  The object code form of an Application may incorporate material from
    3.69 +a header file that is part of the Library.  You may convey such object
    3.70 +code under terms of your choice, provided that, if the incorporated
    3.71 +material is not limited to numerical parameters, data structure
    3.72 +layouts and accessors, or small macros, inline functions and templates
    3.73 +(ten or fewer lines in length), you do both of the following:
    3.74 +
    3.75 +   a) Give prominent notice with each copy of the object code that the
    3.76 +   Library is used in it and that the Library and its use are
    3.77 +   covered by this License.
    3.78 +
    3.79 +   b) Accompany the object code with a copy of the GNU GPL and this license
    3.80 +   document.
    3.81 +
    3.82 +  4. Combined Works.
    3.83 +
    3.84 +  You may convey a Combined Work under terms of your choice that,
    3.85 +taken together, effectively do not restrict modification of the
    3.86 +portions of the Library contained in the Combined Work and reverse
    3.87 +engineering for debugging such modifications, if you also do each of
    3.88 +the following:
    3.89 +
    3.90 +   a) Give prominent notice with each copy of the Combined Work that
    3.91 +   the Library is used in it and that the Library and its use are
    3.92 +   covered by this License.
    3.93 +
    3.94 +   b) Accompany the Combined Work with a copy of the GNU GPL and this license
    3.95 +   document.
    3.96 +
    3.97 +   c) For a Combined Work that displays copyright notices during
    3.98 +   execution, include the copyright notice for the Library among
    3.99 +   these notices, as well as a reference directing the user to the
   3.100 +   copies of the GNU GPL and this license document.
   3.101 +
   3.102 +   d) Do one of the following:
   3.103 +
   3.104 +       0) Convey the Minimal Corresponding Source under the terms of this
   3.105 +       License, and the Corresponding Application Code in a form
   3.106 +       suitable for, and under terms that permit, the user to
   3.107 +       recombine or relink the Application with a modified version of
   3.108 +       the Linked Version to produce a modified Combined Work, in the
   3.109 +       manner specified by section 6 of the GNU GPL for conveying
   3.110 +       Corresponding Source.
   3.111 +
   3.112 +       1) Use a suitable shared library mechanism for linking with the
   3.113 +       Library.  A suitable mechanism is one that (a) uses at run time
   3.114 +       a copy of the Library already present on the user's computer
   3.115 +       system, and (b) will operate properly with a modified version
   3.116 +       of the Library that is interface-compatible with the Linked
   3.117 +       Version.
   3.118 +
   3.119 +   e) Provide Installation Information, but only if you would otherwise
   3.120 +   be required to provide such information under section 6 of the
   3.121 +   GNU GPL, and only to the extent that such information is
   3.122 +   necessary to install and execute a modified version of the
   3.123 +   Combined Work produced by recombining or relinking the
   3.124 +   Application with a modified version of the Linked Version. (If
   3.125 +   you use option 4d0, the Installation Information must accompany
   3.126 +   the Minimal Corresponding Source and Corresponding Application
   3.127 +   Code. If you use option 4d1, you must provide the Installation
   3.128 +   Information in the manner specified by section 6 of the GNU GPL
   3.129 +   for conveying Corresponding Source.)
   3.130 +
   3.131 +  5. Combined Libraries.
   3.132 +
   3.133 +  You may place library facilities that are a work based on the
   3.134 +Library side by side in a single library together with other library
   3.135 +facilities that are not Applications and are not covered by this
   3.136 +License, and convey such a combined library under terms of your
   3.137 +choice, if you do both of the following:
   3.138 +
   3.139 +   a) Accompany the combined library with a copy of the same work based
   3.140 +   on the Library, uncombined with any other library facilities,
   3.141 +   conveyed under the terms of this License.
   3.142 +
   3.143 +   b) Give prominent notice with the combined library that part of it
   3.144 +   is a work based on the Library, and explaining where to find the
   3.145 +   accompanying uncombined form of the same work.
   3.146 +
   3.147 +  6. Revised Versions of the GNU Lesser General Public License.
   3.148 +
   3.149 +  The Free Software Foundation may publish revised and/or new versions
   3.150 +of the GNU Lesser General Public License from time to time. Such new
   3.151 +versions will be similar in spirit to the present version, but may
   3.152 +differ in detail to address new problems or concerns.
   3.153 +
   3.154 +  Each version is given a distinguishing version number. If the
   3.155 +Library as you received it specifies that a certain numbered version
   3.156 +of the GNU Lesser General Public License "or any later version"
   3.157 +applies to it, you have the option of following the terms and
   3.158 +conditions either of that published version or of any later version
   3.159 +published by the Free Software Foundation. If the Library as you
   3.160 +received it does not specify a version number of the GNU Lesser
   3.161 +General Public License, you may choose any version of the GNU Lesser
   3.162 +General Public License ever published by the Free Software Foundation.
   3.163 +
   3.164 +  If the Library as you received it specifies that a proxy can decide
   3.165 +whether future versions of the GNU Lesser General Public License shall
   3.166 +apply, that proxy's public statement of acceptance of any version is
   3.167 +permanent authorization for you to choose that version for the
   3.168 +Library.
   3.169 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/README	Sun Jun 14 17:34:16 2009 +0200
     4.3 @@ -0,0 +1,33 @@
     4.4 +Philips SpeechMike access library
     4.5 +=================================
     4.6 +
     4.7 +This library (libspeechmike) provides access to the buttons on Philips 
     4.8 +Speechmike devices. All other features of the device (trackpoint, 
     4.9 +speaker, microphone) are standard USB HID or USB audio devices and supported
    4.10 +by the default Linux kernel driver (snd_usb_audio, usbhid). 
    4.11 +The buttons don't use the standardized USB HID protocol but a proprietary 
    4.12 +protocol, as an arbitrary number of buttons can have "button pressed" status
    4.13 +at the same time. This is mainly useful for the slider variants 
    4.14 +SpeechMike Classic, but works for all buttons.
    4.15 +
    4.16 +libspeechmike uses the hiddev driver for accessing the device. When you 
    4.17 +plug the device in, this driver will create a device /dev/hiddevX (where
    4.18 +X is a number, usually 0). You need to pass this file name to 
    4.19 +speechmike_set_device().
    4.20 +
    4.21 +The library provides a method speechmike_read() that blocks until a button
    4.22 +press is recieved and returns it to the caller. A sample program 
    4.23 +(speechmike_dump) is included and built when your build the library.
    4.24 +
    4.25 +The LEDs don't work at the moment.
    4.26 +
    4.27 +The following devices were tested:
    4.28 + SpeechMike Classic (LFH 5260)
    4.29 + SpeechMike Pro Plus (LFH 5276)
    4.30 +
    4.31 +It is believed that the other device combinations should work, too.
    4.32 +
    4.33 +See the INSTALL files for building instructions.
    4.34 +
    4.35 +Please report bugs to <mail@philipp-wagner.com>.
    4.36 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/examples/CMakeLists.txt	Sun Jun 14 17:34:16 2009 +0200
     5.3 @@ -0,0 +1,6 @@
     5.4 +cmake_minimum_required(VERSION 2.6)
     5.5 +
     5.6 +LINK_DIRECTORIES( ../ ) 
     5.7 +INCLUDE_DIRECTORIES( ../ )
     5.8 +ADD_EXECUTABLE(speechmike_dump speechmike_dump.c)
     5.9 +TARGET_LINK_LIBRARIES(speechmike_dump libspeechmike.a)
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/examples/speechmike_dump.c	Sun Jun 14 17:34:16 2009 +0200
     6.3 @@ -0,0 +1,112 @@
     6.4 +/*
     6.5 + * Copyright (c) 2009 Philipp Wagner <mail@philipp-wagner.com>
     6.6 + *
     6.7 + * This program is free software: you can redistribute it and/or modify
     6.8 + * it under the terms of the GNU Lesser General Public License as published by
     6.9 + * the Free Software Foundation, either version 3 of the License, or
    6.10 + * (at your option) any later version.
    6.11 + *
    6.12 + * This program is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 + * GNU General Public License for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU General Public License
    6.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    6.19 + */
    6.20 +
    6.21 +#include "libspeechmike.h"
    6.22 +#include <stdio.h>
    6.23 +#include <stdint.h>
    6.24 +#include <string.h>
    6.25 +#include <stdlib.h>
    6.26 +
    6.27 +char* get_keyname(uint64_t key)
    6.28 +{
    6.29 +    switch (key) {
    6.30 +    case SPEECHMIKE_KEY_RECORD:
    6.31 +        return "RECORD";
    6.32 +        break;
    6.33 +    case SPEECHMIKE_KEY_STOP:
    6.34 +        return "STOP";
    6.35 +        break;
    6.36 +    case SPEECHMIKE_KEY_PLAY:
    6.37 +        return "PLAY";
    6.38 +        break;
    6.39 +    case SPEECHMIKE_KEY_FF:
    6.40 +        return "FF";
    6.41 +        break;
    6.42 +    case SPEECHMIKE_KEY_REWIND:
    6.43 +        return "REWIND";
    6.44 +        break;
    6.45 +    case SPEECHMIKE_KEY_EOL:
    6.46 +        return "EOL";
    6.47 +        break;
    6.48 +    case SPEECHMIKE_KEY_INSERT:
    6.49 +        return "INSERT";
    6.50 +        break;
    6.51 +    case SPEECHMIKE_KEY_INSTR:
    6.52 +        return "INSTR";
    6.53 +        break;
    6.54 +    case SPEECHMIKE_KEY_F1:
    6.55 +        return "F1";
    6.56 +        break;
    6.57 +    case SPEECHMIKE_KEY_F2:
    6.58 +        return "F2";
    6.59 +        break;
    6.60 +    case SPEECHMIKE_KEY_F3:
    6.61 +        return "F3";
    6.62 +        break;
    6.63 +    case SPEECHMIKE_KEY_F4:
    6.64 +        return "F4";
    6.65 +        break;
    6.66 +    case SPEECHMIKE_KEY_TRIGGER:
    6.67 +        return "TRIGGER";
    6.68 +        break;
    6.69 +    }
    6.70 +    return NULL;
    6.71 +}
    6.72 +
    6.73 +void print_keys(uint64_t keys)
    6.74 +{
    6.75 +    int i;
    6.76 +    char* keyname;
    6.77 +    for (i=0; i<32; i++) {
    6.78 +        keyname = get_keyname(keys & (1 << i));
    6.79 +        if (keyname != NULL) {
    6.80 +            printf("%s, ", keyname);
    6.81 +        }
    6.82 +    }
    6.83 +}
    6.84 +
    6.85 +int main(int argc, char **argv)
    6.86 +{
    6.87 +    struct speechmike_context *ctxt;
    6.88 +    char* file = "/dev/hiddev0";
    6.89 +    struct speechmike_key_event ev;
    6.90 +
    6.91 +    printf("libspeechmike version: %s\n", speechmike_version());
    6.92 +
    6.93 +    ctxt = speechmike_new();
    6.94 +    if (!ctxt) {
    6.95 +        printf("Unable to initialize libspeechmike.\n");
    6.96 +        return 1;
    6.97 +    }
    6.98 +    if (speechmike_set_device(ctxt, file) != 0) {
    6.99 +        printf("Unable to open device %s: %s\n", file, speechmike_get_error_message(ctxt));
   6.100 +        return 1;
   6.101 +    }
   6.102 +
   6.103 +    while (speechmike_read(ctxt, &ev) == 0) {
   6.104 +        printf("pressed:  ");
   6.105 +        print_keys(ev.pressed_keys);
   6.106 +        printf("\n");
   6.107 +        printf("released: ");
   6.108 +        print_keys(ev.released_keys);
   6.109 +        printf("\n\n");
   6.110 +    }
   6.111 +
   6.112 +    speechmike_free(ctxt);
   6.113 +    return 0;
   6.114 +}
   6.115 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/libspeechmike.c	Sun Jun 14 17:34:16 2009 +0200
     7.3 @@ -0,0 +1,155 @@
     7.4 +/*
     7.5 + * Copyright (c) 2009 Philipp Wagner <mail@philipp-wagner.com>
     7.6 + *
     7.7 + * This program is free software: you can redistribute it and/or modify
     7.8 + * it under the terms of the GNU Lesser General Public License as published by
     7.9 + * the Free Software Foundation, either version 3 of the License, or
    7.10 + * (at your option) any later version.
    7.11 + *
    7.12 + * This program is distributed in the hope that it will be useful,
    7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.15 + * GNU General Public License for more details.
    7.16 + *
    7.17 + * You should have received a copy of the GNU General Public License
    7.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    7.19 + */
    7.20 +
    7.21 +#include "libspeechmike.h"
    7.22 +#include <stdlib.h>
    7.23 +#include <stdio.h>
    7.24 +#include <sys/ioctl.h>
    7.25 +#include <sys/types.h>
    7.26 +#include <sys/stat.h>
    7.27 +#include <asm/types.h>
    7.28 +#include <fcntl.h>
    7.29 +#include <unistd.h>
    7.30 +#include <linux/hiddev.h>
    7.31 +#include <errno.h>
    7.32 +#include <string.h>
    7.33 +
    7.34 +
    7.35 +char* speechmike_version()
    7.36 +{
    7.37 +    return "0.1";
    7.38 +}
    7.39 +
    7.40 +int speechmike_read(struct speechmike_context* ctxt, struct speechmike_key_event* ev)
    7.41 +{
    7.42 +    struct hiddev_event event;
    7.43 +    int bytes_read;
    7.44 +    uint16_t usage_page;
    7.45 +    uint16_t usage_id;
    7.46 +
    7.47 +    uint64_t report = 0;
    7.48 +    uint8_t cnt;
    7.49 +    uint8_t value = 0;
    7.50 +
    7.51 +    while((bytes_read = read(ctxt->hiddev_fd, &event, sizeof(struct hiddev_event))) > 0) {
    7.52 +        if (bytes_read != sizeof(struct hiddev_event)) {
    7.53 +            ctxt->error_msg = "Invalid read size";
    7.54 +            return -1;
    7.55 +        }
    7.56 +
    7.57 +        /* event.hid is a 32 bit field, the first 16 bits are the usage page
    7.58 +         * and the second 16 bits are the usage id.
    7.59 +         */
    7.60 +        usage_page = event.hid >> 16;
    7.61 +        usage_id = event.hid & 0x0000FFFF;
    7.62 +
    7.63 +        /* Even though the event.value field is specified as "signed int"
    7.64 +         * only the first byte seems to be used.
    7.65 +         */
    7.66 +        value = event.value;
    7.67 +
    7.68 +        /* the speechmikes use a usage page from the "vendor defined" range */
    7.69 +        if (usage_page != 0xFFA1)
    7.70 +            continue;
    7.71 +
    7.72 +        /* A button press/release sequence always starts with a message with
    7.73 +         * usage_id == 0x03 and value = 0x80, followed by 8 messages with
    7.74 +         * usage_id == 0x04 and values with to the pressed keys.
    7.75 +         * The keys are ORed together. We store the 8 messages in a single
    7.76 +         * 64 bit variable for easier access.
    7.77 +         *
    7.78 +         * XXX: problems on 32 bit machines?
    7.79 +         */
    7.80 +        if (usage_id == 0x03 && value == 0x80) {
    7.81 +            /* sequence start */
    7.82 +            cnt = 7;
    7.83 +        } else if (usage_id == 0x04) {
    7.84 +            report |= (value << (cnt*8));
    7.85 +
    7.86 +            if (cnt == 0)
    7.87 +                break;
    7.88 +
    7.89 +            cnt--;
    7.90 +        }
    7.91 +
    7.92 +    }
    7.93 +
    7.94 +    ev->pressed_keys = report & ~ctxt->previous_event;
    7.95 +    ev->released_keys = ~report & ctxt->previous_event;
    7.96 +
    7.97 +    ctxt->previous_event = report;
    7.98 +
    7.99 +    return 0;
   7.100 +}
   7.101 +
   7.102 +struct speechmike_context* speechmike_new()
   7.103 +{
   7.104 +    struct speechmike_context *ctxt = (struct speechmike_context*) malloc(sizeof(struct speechmike_context));
   7.105 +    if (speechmike_init(ctxt) != 0) {
   7.106 +        free(ctxt);
   7.107 +        return NULL;
   7.108 +    }
   7.109 +    return ctxt;
   7.110 +}
   7.111 +
   7.112 +int speechmike_init(struct speechmike_context* ctxt)
   7.113 +{
   7.114 +    ctxt->previous_event = 0;
   7.115 +    ctxt->error_msg = NULL;
   7.116 +    return 0;
   7.117 +}
   7.118 +
   7.119 +int speechmike_deinit(struct speechmike_context *ctxt)
   7.120 +{
   7.121 +    close(ctxt->hiddev_fd);
   7.122 +    return 0;
   7.123 +}
   7.124 +
   7.125 +int speechmike_set_device(struct speechmike_context* ctxt, char* hiddev_file)
   7.126 +{
   7.127 +
   7.128 +    int fd = -1;
   7.129 +    struct hiddev_devinfo device_info;
   7.130 +
   7.131 +    if ((fd = open(hiddev_file, O_RDONLY)) < 0) {
   7.132 +        ctxt->error_msg = strerror(errno);
   7.133 +        return -1;
   7.134 +    }
   7.135 +    ctxt->hiddev_fd = fd;
   7.136 +
   7.137 +    /* check if we really got a speechmike here */
   7.138 +    ioctl(ctxt->hiddev_fd, HIDIOCGDEVINFO, &device_info);
   7.139 +    if (device_info.vendor != 0x0911 || device_info.product != 0x149a) {
   7.140 +        ctxt->error_msg = "Device is not a SpeechMike!";
   7.141 +        return -1;
   7.142 +    }
   7.143 +
   7.144 +    return 0;
   7.145 +}
   7.146 +
   7.147 +void speechmike_free(struct speechmike_context* ctxt)
   7.148 +{
   7.149 +    speechmike_deinit(ctxt);
   7.150 +    free(ctxt);
   7.151 +    ctxt = 0;
   7.152 +}
   7.153 +
   7.154 +char* speechmike_get_error_message(struct speechmike_context* ctxt)
   7.155 +{
   7.156 +    return ctxt->error_msg;
   7.157 +}
   7.158 +
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/libspeechmike.h	Sun Jun 14 17:34:16 2009 +0200
     8.3 @@ -0,0 +1,92 @@
     8.4 +/*
     8.5 + * Copyright (c) 2009 Philipp Wagner <mail@philipp-wagner.com>
     8.6 + *
     8.7 + * This program is free software: you can redistribute it and/or modify
     8.8 + * it under the terms of the GNU Lesser General Public License as published by
     8.9 + * the Free Software Foundation, either version 3 of the License, or
    8.10 + * (at your option) any later version.
    8.11 + *
    8.12 + * This program is distributed in the hope that it will be useful,
    8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 + * GNU General Public License for more details.
    8.16 + *
    8.17 + * You should have received a copy of the GNU General Public License
    8.18 + * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    8.19 + */
    8.20 +
    8.21 +#ifndef LIBSPEECHMIKE_H_
    8.22 +#define LIBSPEECHMIKE_H_
    8.23 +
    8.24 +#include <stdint.h>
    8.25 +
    8.26 +/* even though these keys look different on different speechmike versions,
    8.27 + * the keycodes are the same.
    8.28 + */
    8.29 +#define SPEECHMIKE_KEY_RECORD  0x01
    8.30 +#define SPEECHMIKE_KEY_STOP    0x02
    8.31 +#define SPEECHMIKE_KEY_PLAY    0x04
    8.32 +#define SPEECHMIKE_KEY_FF      0x08
    8.33 +#define SPEECHMIKE_KEY_REWIND  0x10
    8.34 +#define SPEECHMIKE_KEY_EOL     0x20
    8.35 +#define SPEECHMIKE_KEY_INSERT  0x40
    8.36 +#define SPEECHMIKE_KEY_INSTR   0x80
    8.37 +
    8.38 +/* function keys of SpeechMike Classic/Pro Plus */
    8.39 +#define SPEECHMIKE_KEY_F1      0x200
    8.40 +#define SPEECHMIKE_KEY_F2      0x400
    8.41 +#define SPEECHMIKE_KEY_F3      0x800
    8.42 +#define SPEECHMIKE_KEY_F4      0x1000
    8.43 +
    8.44 +/* trigger button at the back */
    8.45 +#define SPEECHMIKE_KEY_TRIGGER 0x2000
    8.46 +
    8.47 +struct speechmike_context {
    8.48 +    int hiddev_fd;
    8.49 +    uint64_t previous_event;
    8.50 +    char* error_msg;
    8.51 +};
    8.52 +
    8.53 +struct speechmike_key_event {
    8.54 +    uint64_t pressed_keys;
    8.55 +    uint64_t released_keys;
    8.56 +};
    8.57 +
    8.58 +/*!
    8.59 + * Get the library version
    8.60 + */
    8.61 +char* speechmike_version();
    8.62 +/*!
    8.63 + * Create a new speechmike_context (not yet initialized).
    8.64 + */
    8.65 +struct speechmike_context* speechmike_new();
    8.66 +/*!
    8.67 + * Initialize speechmike_context.
    8.68 + */
    8.69 +int speechmike_init(struct speechmike_context* ctxt);
    8.70 +/*!
    8.71 + * Set the hiddev file which represents the SpeechMike. Usually /dev/hiddev0
    8.72 + */
    8.73 +int speechmike_set_device(struct speechmike_context *ctxt, char* hiddev_file);
    8.74 +/*!
    8.75 + * Free the speechmike_context. This calls deinit() for you.
    8.76 + */
    8.77 +void speechmike_free(struct speechmike_context* ctxt);
    8.78 +/*!
    8.79 + * Get the error message if a function returned something else than 0.
    8.80 + */
    8.81 +char* speechmike_get_error_message(struct speechmike_context* ctxt);
    8.82 +/*!
    8.83 + * Cleanup. Close file descriptors, etc.
    8.84 + */
    8.85 +int speechmike_deinit(struct speechmike_context* ctxt);
    8.86 +/*!
    8.87 + * Read a single button event. This function blocks until it receives the event
    8.88 + * and returns it in \p keys.
    8.89 + *
    8.90 + * \param ctxt the context
    8.91 + * \param ev   the event structure containing information about pressed and released keys
    8.92 + */
    8.93 +int speechmike_read(struct speechmike_context* ctxt, struct speechmike_key_event* ev);
    8.94 +
    8.95 +#endif /* LIBSPEECHMIKE_H_ */