A library that maps the functions used with the mbed microcontroller to be used on with the GPIO ports of a Raspberry pi.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DigitalIn.cc Source File

DigitalIn.cc

00001 namespace CPPToPigpio{
00002     //@TODO: Confirm that PinName is convertible to int
00003     DigitalIn::DigitalIn(PinName pin): _pinNumber(pin)
00004     {
00005         CPPToPigpio::_handlePigpioInitialisationIfNeeded();
00006         gpioSetMode(pin, PI_INPUT); //mode for gpio refers to input or output
00007         DigitalIn::mode(PullNone); 
00008     }
00009 
00010     DigitalIn::DigitalIn(PinName pin, PinMode pMode): _pinNumber(pin)
00011     {
00012         CPPToPigpio::_handlePigpioInitialisationIfNeeded();
00013         gpioSetMode(pin, PI_INPUT);
00014         DigitalIn::mode(pMode);
00015     }
00016 
00017     DigitalIn::DigitalIn(int pin): DigitalIn::DigitalIn(static_cast<PinName> (pin))
00018     {
00019         //Doesn't need _handlePigpioInitialisationIfNeeded() since calls other constructor  
00020     }
00021 
00022     DigitalIn::DigitalIn(int pin, PinMode pMode): DigitalIn::DigitalIn(static_cast<PinName> (pin), pMode)
00023     {
00024         //Doesn't need _handlePigpioInitialisationIfNeeded() since calls other constructor  
00025     }
00026 
00027     int DigitalIn::read()
00028     {
00029         return gpioRead(_pinNumber);
00030     }
00031 
00032     DigitalIn::operator int()
00033     {
00034         return DigitalIn::read();
00035     }
00036     
00037     void DigitalIn::mode(PinMode pMode){
00038         switch(pMode){
00039             case PullUp:
00040                 gpioSetPullUpDown(_pinNumber, PI_PUD_UP);
00041                 break;
00042             case PullDown:
00043                 gpioSetPullUpDown(_pinNumber, PI_PUD_DOWN); 
00044                 break;
00045             case PullNone:
00046                 gpioSetPullUpDown(_pinNumber, PI_PUD_OFF); 
00047                 break;
00048         }
00049     }
00050 
00051     bool DigitalIn::operator==(int in)
00052     {
00053         return _pinNumber == in;
00054     }
00055 
00056     bool DigitalIn::operator==(DigitalIn &other)
00057     {
00058         return _pinNumber == other._pinNumber;
00059     }
00060 
00061     DigitalIn::~DigitalIn()
00062     {
00063         CPPToPigpio::_handlePigpioTermination();
00064     }
00065 
00066 }
00067