// Serial port control
#ifndef __SERIAL
#define __SERIAL

#include <wx/wx.h>
#include <wx/panel.h>
#include <wx/config.h>   // wxconfig
#include <termios.h>     // serial

#define ID_SERIAL        200
#define CMD_SERIAL_ONOFF   ID_SERIAL+1
#define TXT_SERIAL_PORT    ID_SERIAL+2
#define SERIAL_PORT        "/dev/ttyS0"
#define BAUDRATE           B9600

void dec2bin(long decimal, char* binary); // convert decimal to binary for display

class clsSerial: public wxPanel {
	public:
		clsSerial(wxPanel*);
		wxPanel*  m_panel;
		void        cmdSerialOnOff(wxCommandEvent&);   // connect/disconnect the serial
		void        SendSerial(unsigned char *val, int length); // send a char
		bool        SendServo(int servo_num, double val); // send a servo command
		void        txtSerialPort(wxCommandEvent&);   // text changes on the serial port

	private:
		wxConfigBase*  config;
		bool           serial_on;        // serial is on? 
		wxButton*      btn_serial_on;    // turn the serial on/off
		wxTextCtrl*    txt_serial_port;  // /dev/ttys0
		int            fd_serial;
		struct termios oldtty;        // save old port settings
};
#endif
