| 1 | /* | 
|---|
| 2 | Copyright (C) 2004 by Jasem Mutlaq | 
|---|
| 3 |  | 
|---|
| 4 | This library is free software; you can redistribute it and/or | 
|---|
| 5 | modify it under the terms of the GNU Lesser General Public | 
|---|
| 6 | License as published by the Free Software Foundation; either | 
|---|
| 7 | version 2.1 of the License, or (at your option) any later version. | 
|---|
| 8 |  | 
|---|
| 9 | This library is distributed in the hope that it will be useful, | 
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 12 | Lesser General Public License for more details. | 
|---|
| 13 |  | 
|---|
| 14 | You should have received a copy of the GNU Lesser General Public | 
|---|
| 15 | License along with this library; if not, write to the Free Software | 
|---|
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA | 
|---|
| 17 |  | 
|---|
| 18 | */ | 
|---|
| 19 |  | 
|---|
| 20 | #ifndef _PPort_hpp_ | 
|---|
| 21 | #define _PPort_hpp_ | 
|---|
| 22 |  | 
|---|
| 23 | class port_t; | 
|---|
| 24 |  | 
|---|
| 25 | /** To access and share the parallel port | 
|---|
| 26 | between severa objects. */ | 
|---|
| 27 | class PPort { | 
|---|
| 28 | public: | 
|---|
| 29 | PPort(); | 
|---|
| 30 | PPort(int ioPort); | 
|---|
| 31 | ~PPort(); | 
|---|
| 32 | /** set the ioport associated to the // port. | 
|---|
| 33 | \return true if the binding was possible | 
|---|
| 34 | */ | 
|---|
| 35 | bool setPort(int ioPort); | 
|---|
| 36 | /** set a data bit of the // port. | 
|---|
| 37 | \return false if IO port not set, or bit not registered by ID. | 
|---|
| 38 | \param ID the identifier used to register the bit | 
|---|
| 39 | \param stat the stat wanted for the given bit | 
|---|
| 40 | \param bit the bit to set. They are numbered from 0 to 7. | 
|---|
| 41 |  | 
|---|
| 42 | */ | 
|---|
| 43 | bool setBit(const void * ID,int bit,bool stat); | 
|---|
| 44 | /** register a bit for object ID. | 
|---|
| 45 | \param ID the identifier used to register the bit it should be the 'this' pointer. | 
|---|
| 46 | \param bit the bit of the // port to register | 
|---|
| 47 | \return false if the bit is already register with an | 
|---|
| 48 | other ID, or if the // port is not initialised. | 
|---|
| 49 | */ | 
|---|
| 50 | bool registerBit(const void * ID,int bit); | 
|---|
| 51 | /** release a bit. | 
|---|
| 52 | \param ID the identifier used to register the bit | 
|---|
| 53 | \param bit the bit to register. | 
|---|
| 54 | \return false if the bit was not registered by ID or | 
|---|
| 55 | if the if the // port is not initialised. | 
|---|
| 56 | */ | 
|---|
| 57 | bool unregisterBit(const void * ID,int bit); | 
|---|
| 58 |  | 
|---|
| 59 | /** test if a bit is registerd. | 
|---|
| 60 | \param ID the identifier used to register the bit | 
|---|
| 61 | \param bit the bit to test. | 
|---|
| 62 | \return false if the bit was not registered by ID or | 
|---|
| 63 | if the if the // port is not initialised. | 
|---|
| 64 | */ | 
|---|
| 65 | bool isRegisterBit(const void * ID,int bit) const; | 
|---|
| 66 |  | 
|---|
| 67 | /** set the bits off the // port according to previous call to setBit(). | 
|---|
| 68 | */ | 
|---|
| 69 | bool commit(); | 
|---|
| 70 | private: | 
|---|
| 71 | void reset(); | 
|---|
| 72 | unsigned char bitArray; | 
|---|
| 73 | const void * assignedBit[8]; | 
|---|
| 74 | port_t * currentPort; | 
|---|
| 75 | }; | 
|---|
| 76 | #endif | 
|---|