Skip to content

Commit

Permalink
Adding new PCI listener implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
prampec committed Oct 26, 2015
1 parent 4e4281a commit 3cd0b81
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
4 changes: 4 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ PciListener KEYWORD1
pciHandleInterrupt KEYWORD2

PciListenerImp KEYWORD1

PciListenerImp2 KEYWORD1
init KEYWORD2
lastVal KEYWORD2
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=PciManager
version=2.0.0
version=2.1.0
author=Balazs Kelemen <prampec+arduino@gmail.com>
maintainer=Balazs Kelemen <prampec+arduino@gmail.com>
sentence=This library helps you manage Pin Change Interrupts: subscribe and receive change events.
Expand Down
46 changes: 46 additions & 0 deletions src/IPciChangeHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* File: IPciHandler.h
* Description:
* PciManager library is an easy to use Pin Change Interrupt manager for Arduino.
*
* Author: Balazs Kelemen
* Contact: prampec+arduino@gmail.com
* Copyright: 2012 Balazs Kelemen
* Copying permission statement:
This file is part of PciManager.
PciManager 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PCI_IPCICHANGEHANDLER_H
#define PCI_IPCICHANGEHANDLER_H

#include <Arduino.h>

/**
* PinChangeInterrupt listener abstract class. Please override this class with a custom pciHandleInterrupt() callback
* to be used in PciListenerImpl2.
*/
class IPciChangeHandler {
public:
/**
* This method will be called by the PciManager on pin change. The function will be fired only when to corresponding pin
* was changed. See PciListenerImpl2 for details.
*/
virtual void pciHandleChange(byte changedTo, PciListenerImp2* listener);
};

#endif

52 changes: 52 additions & 0 deletions src/PciListenerImp2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* File: PciListenerImp2.cpp
* Description:
* PciManager library is an easy to use Pin Change Interrupt manager for Arduino.
*
* Author: Balazs Kelemen
* Contact: prampec+arduino@gmail.com
* Copyright: 2012 Balazs Kelemen
* Copying permission statement:
This file is part of PciManager.
PciManager 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Arduino.h"
#include "PciListenerImp2.h"
#include <IPciChangeHandler.h>

PciListenerImp2::PciListenerImp2() {
}

void PciListenerImp2::init(byte pin, IPciChangeHandler* handler, bool pullUp) {
this->pciPin = pin;
this->_pciChangeHandler = handler;
this->lastVal = digitalRead(this->pciPin);

if(pullUp) {
pinMode(pin, INPUT_PULLUP);
} else {
pinMode(pin, INPUT);
}
}

void PciListenerImp2::pciHandleInterrupt(byte vect) {
byte val = digitalRead(this->pciPin);
if(val != this->lastVal) {
this->lastVal = val;
this->_pciChangeHandler->pciHandleChange(val, this);
}
}
57 changes: 57 additions & 0 deletions src/PciListenerImp2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* File: PciListenerImp2.h
* Description:
* PciManager library is an easy to use Pin Change Interrupt manager for Arduino.
*
* Author: Balazs Kelemen
* Contact: prampec+arduino@gmail.com
* Copyright: 2012 Balazs Kelemen
* Copying permission statement:
This file is part of PciManager.
PciManager 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PCI_LISTENERIMP2_H
#define PCI_LISTENERIMP2_H

#include <Arduino.h>
#include <PciListener.h>

class IPciChangeHandler;

/**
* An extended PinChangeInterrupt listener implementation.
* The difference between this, and PciListenerImpl, is that this also passes the listener instance to the handler on event.
*/
class PciListenerImp2 : public PciListener
{
public:
PciListenerImp2();
/**
* Initialize the listener.
* - pin - Pin to listen
* - handler - Handler
* - puppUp - Set true, to have the pin set in pullup mode.
*/
void init(byte pin, IPciChangeHandler* handler, bool pullUp = false);
virtual void pciHandleInterrupt(byte vector);
byte lastVal;
private:
IPciChangeHandler* _pciChangeHandler;
};

#endif

0 comments on commit 3cd0b81

Please sign in to comment.