-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new PCI listener implementation.
- Loading branch information
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|