/*

Copyright © 2003, Russell C. Hay
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

i. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer. 

ii. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution. 

iii. Neither the name of the dead[protocol]society nor the names of its
     contributors may be used to endorse or promote products derived from this
     software without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/
#ifndef DEVICE_H
#define DEVICE_H

#define DEVICE_CMD_START		0xFE

#define DEVICE_CMD_HOME				72
#define DEVICE_CMD_BIGINT			35
#define DEVICE_CMD_HGRAPH			124
#define DEVICE_CMD_VGRAPH			61
#define DEVICE_CMD_INIT_BIGINT	110
#define DEVICE_CMD_INIT_HGRAPH	104
#define DEVICE_CMD_INIT_VGRAPH	115
#define DEVICE_CMD_GPOOFF			86
#define DEVICE_CMD_GPOON			87
#define DEVICE_CMD_CURSOR			71
#define DEVICE_CMD_BACKLIGHT_ON	66
#define DEVICE_CMD_BACKLIGHT_OFF	70
#define DEVICE_CMD_FORWARD			77
#define DEVICE_CMD_BACK				76
#define DEVICE_CMD_CLEAR			88
#define DEVICE_CMD_TYPE				55

#define DEVICE_MODE_EMPTY		0x00
#define DEVICE_MODE_HGRAPH		0x01
#define DEVICE_MODE_VGRAPH		0x02
#define DEVICE_MODE_BIGINT		0x03
#define DEVICE_MODE_CCHAR		0x04

class mtxtype;

class device
{
	public:
		device();
		device(const char *dev);
		device(const char *dev, int baud);
		device(const char *dev, int baud, int bits, char parity, int stopbit);

		~device();

		int Open();
		void Close();

		int Push(action act);
		int Process();
		int AddToFdSet(fd_set *fd, int *max);
		int IsSet(fd_set *fd);
		char HandleIncoming();
		void Backlight(int status);
		void Reset();
		int InPriority();
		void StartPriority();
		void StopPriority();

	protected:
		void BuildOptions();
		void SendCommand(action act);
		void ActiveMode(unsigned char mode);
		void SendSingleCommand(int cmd);
		void center(char *str, int line);

		action_queue_t m_action_queue;
		int m_priority_active;
		int m_screen_width, m_screen_height;
		int m_serial_fd;
		int m_serial_bits;
		int m_serial_baud;
		char m_serial_parity;
		int m_serial_stopbit;
		int m_status_flags;
		unsigned char m_serial_device_type;
		unsigned char m_serial_mode;
		struct termios m_serial_options;
		std::string m_serial_device_name;
		class mtxtype m_serial_device_constraints;
};

#endif // DEVICE_H


syntax highlighted by Code2HTML, v. 0.9.1