/*************************************************************************** * Copyright (C) 2005-2007 Nicolas Hadacek * * Copyright (C) 2003-2004 Alain Gibaud * * Copyright (C) 2002-2003 Stephen Landamore * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/ #include "parallel.h" #include "common/global/global.h" #if defined(HAVE_PPDEV) # include # include # include # include # include // needed on some system # include #elif defined(HAVE_PPBUS) # include # include # include # include # include # include # include #endif #include "common/common/misc.h" //----------------------------------------------------------------------------- QStringList *Port::Parallel::_list = 0; Port::IODirs Port::Parallel::probe(const QString &device) { #if defined(HAVE_PPDEV) int fd = ::open(device.latin1(), O_RDWR); if ( fd<0) return NoIO; if ( ioctl(fd, PPCLAIM)<0 ) { ::close(fd) ; return In; } ioctl(fd, PPRELEASE); ::close(fd); return (In | Out); #elif defined(HAVE_PPBUS) int fd = ::open(device.latin1(), O_RDWR); if ( fd<0 ) return NoIO; ::close(fd); return In | Out; // #### can we detect read-only ? #else return NoIO; #endif } QStringList Port::Parallel::deviceList() { QStringList list; #if defined(HAVE_PPDEV) // standard parport in user space for(int i = 0; i<8; ++i) list.append(QString("/dev/parport%1").arg(i)); // new devfs parport flavour for(int i = 0; i<8; ++i) list.append(QString("/dev/parports/%1").arg(i)); #elif defined(HAVE_PPBUS) // FreeBSD for(int i = 0; i<8; ++i) list.append(QString("/dev/ppi%1").arg(i)); #endif return list; } const QStringList &Port::Parallel::probedDeviceList() { if ( _list==0 ) { QStringList all = deviceList(); _list = new QStringList; for (uint i=0; iappend(all[i]); } return *_list; } bool Port::Parallel::isAvailable() { #if defined(HAVE_PPDEV) || defined(HAVE_PPBUS) return true; #else return false; #endif } //----------------------------------------------------------------------------- const Port::Parallel::PPinData Port::Parallel::PIN_DATA[Nb_Pins] = { { Control, 0x01, Out, "/DS" }, // !strobe { Data, 0x01, Out, "D0" }, // data 0 { Data, 0x02, Out, "D1" }, // data 1 { Data, 0x04, Out, "D2" }, // data 2 { Data, 0x08, Out, "D3" }, // data 3 { Data, 0x10, Out, "D4" }, // data 4 { Data, 0x20, Out, "D5" }, // data 5 { Data, 0x40, Out, "D6" }, // data 6 { Data, 0x80, Out, "D7" }, // data 7 { Status, 0x40, In, "/ACK" }, // !ack { Status, 0x80, In, "BUSY" }, // busy { Status, 0x20, In, "PAPER" }, // pout { Status, 0x10, In, "SELin" }, // select { Control, 0x02, Out, "LF" }, // !feed { Status, 0x08, In, "/ERROR" }, // !error { Control, 0x04, Out, "PRIME" }, // !init { Control, 0x08, Out, "SELout" }, // !si { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND { Nb_RequestTypes, 0x00, NoIO, "GND" }, // GND { Nb_RequestTypes, 0x00, NoIO, "GND" } // GND }; QValueVector Port::Parallel::pinData(IODir dir) const { QValueVector v; for (uint i=0; i