include/liblpfk.h

changeset 0
745037d69d81
child 1
3e775df109e6
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/liblpfk.h	Tue Aug 26 12:45:33 2008 +0100
     1.3 @@ -0,0 +1,135 @@
     1.4 +/****************************************************************************
     1.5 + * Project:		liblpfk
     1.6 + * Purpose:		Driver library for the IBM 6094-020 Lighted Program Function
     1.7 + * 				Keyboard.
     1.8 + * Version:		1.0
     1.9 + * Author:		Philip Pemberton <philpem@philpem.me.uk>
    1.10 + *
    1.11 + * The latest version of this library is available from
    1.12 + * <http://www.philpem.me.uk/code/liblpfk/>.
    1.13 + *
    1.14 + * Copyright (c) 2008, Philip Pemberton
    1.15 + * All rights reserved.
    1.16 + *
    1.17 + * Redistribution and use in source and binary forms, with or without
    1.18 + * modification, are permitted provided that the following conditions
    1.19 + * are met:
    1.20 + *
    1.21 + *  * Redistributions of source code must retain the above copyright
    1.22 + *    notice, this list of conditions and the following disclaimer.
    1.23 + *  * Redistributions in binary form must reproduce the above copyright
    1.24 + *    notice, this list of conditions and the following disclaimer in
    1.25 + *    the documentation and/or other materials provided with the
    1.26 + *    distribution.
    1.27 + *  * Neither the name of the project nor the names of its
    1.28 + *    contributors may be used to endorse or promote products derived
    1.29 + *    from this software without specific prior written permission.
    1.30 + *
    1.31 + *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.32 + *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.33 + *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    1.34 + *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    1.35 + *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
    1.36 + *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
    1.37 + *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
    1.38 + *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    1.39 + *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
    1.40 + *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
    1.41 + *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.42 + ****************************************************************************/
    1.43 +
    1.44 +/**
    1.45 + * @file	liblpfk.h
    1.46 + * @brief	liblpfk library header
    1.47 + */
    1.48 +
    1.49 +#ifndef _liblpfk_h_included
    1.50 +#define _liblpfk_h_included
    1.51 +
    1.52 +#include <termios.h>
    1.53 +
    1.54 +/**
    1.55 + * @brief	LPFK context
    1.56 + *
    1.57 + * Do not change any variables inside this struct, they are for liblpfk's
    1.58 + * internal use only.
    1.59 + */
    1.60 +typedef struct {
    1.61 +	int				fd;			///< serial port file descriptor
    1.62 +	struct termios	oldtio;		///< old termios setup
    1.63 +	int				enabled;	///< LPFK enabled
    1.64 +	unsigned long	led_mask;	///< lit LEDs mask
    1.65 +} LPFK_CTX;
    1.66 +
    1.67 +/**
    1.68 + * @brief	liblpfk error codes
    1.69 + */
    1.70 +enum {
    1.71 +	LPFK_E_OK = 0,				///< No error, success.
    1.72 +	LPFK_E_PORT_OPEN,			///< Could not open comm port.
    1.73 +	LPFK_E_NOT_PRESENT,			///< LPFK not present on specified port.
    1.74 +	LPFK_E_COMMS,				///< Communication error.
    1.75 +	LPFK_E_PARAM				///< Invalid function parameter.
    1.76 +};
    1.77 +
    1.78 +/**
    1.79 + * @brief	Open a serial port and attempt to connecct to an LPFK on that
    1.80 + * 			port.
    1.81 + * @param	port	Serial port path (e.g. /dev/ttyS0).
    1.82 + * @param	ctx		Pointer to an LPFK_CTX struct where LPFK context will be
    1.83 + * 					stored.
    1.84 + * @return	LPFK_E_OK on success, LPFK_E_PORT_OPEN if port could not be
    1.85 + * 			opened, LPFK_E_NOT_PRESENT if no LPFK present on specified port.
    1.86 + */
    1.87 +int lpfk_open(const char *port, LPFK_CTX *ctx);
    1.88 +
    1.89 +/**
    1.90 + * @brief	Close the LPFK.
    1.91 + * @param	ctx		Pointer to an LPFK_CTX struct initialised by lpfk_open().
    1.92 + * @return	LPFK_E_OK
    1.93 + */
    1.94 +int lpfk_close(LPFK_CTX *ctx);
    1.95 +
    1.96 +/**
    1.97 + * @brief	Enable or disable LPFK input
    1.98 + * @param	ctx		Pointer to an LPFK_CTX struct initialised by lpfk_open().
    1.99 + * @param	val		true to enable the LPFK's keys, false to disable.
   1.100 + * @return	LPFK_E_OK on success, LPFK_E_COMMS on comms error.
   1.101 + */
   1.102 +int lpfk_enable(LPFK_CTX *ctx, int val);
   1.103 +
   1.104 +/**
   1.105 + * @brief	Set or clear an LED on the LPFK.
   1.106 + * @param	ctx		Pointer to an LPFK_CTX struct initialised by lpfk_open().
   1.107 + * @param	num		LED/key number, from 0 to 31.
   1.108 + * @param	state	State, true for on, false for off.
   1.109 + * @return	LPFK_E_OK on success, LPFK_E_PARAM on bad parameter, LPFK_E_COMMS
   1.110 + * 			on comms error.
   1.111 + */
   1.112 +int lpfk_set_led(LPFK_CTX *ctx, const int num, const int state);
   1.113 +
   1.114 +/**
   1.115 + * @brief	Set or clear all the LEDs on the LPFK.
   1.116 + * @param	ctx		Pointer to an LPFK_CTX struct initialised by lpfk_open().
   1.117 + * @param	state	State, true for on, false for off.
   1.118 + * @return	LPFK_E_OK on success, LPFK_E_PARAM on bad parameter, LPFK_E_COMMS
   1.119 + * 			on comms error.
   1.120 + */
   1.121 +int lpfk_set_leds(LPFK_CTX *ctx, const int state);
   1.122 +
   1.123 +/**
   1.124 + * @brief	Get the status of an LED on the LPFK.
   1.125 + * @param	ctx		Pointer to an LPFK_CTX struct initialised by lpfk_open().
   1.126 + * @param	num		LED/key number, from 0 to 31.
   1.127 + * @return	true if LED is on, false otherwise.
   1.128 + */
   1.129 +int lpfk_get_led(LPFK_CTX *ctx, const int num);
   1.130 +
   1.131 +/**
   1.132 + * @brief	Read a key from the LPFK
   1.133 + * @param	ctx		Pointer to an LPFK_CTX struct initialised by lpfk_open().
   1.134 + * @return	-1 if no keys in buffer, 0-31 for key 1-32 down.
   1.135 + */
   1.136 +int lpfk_read(LPFK_CTX *ctx);
   1.137 +
   1.138 +#endif // _liblpfk_h_included