Arduino: separated interrupt callbacks
Java: fixed TC
This commit is contained in:
parent
17e50573d6
commit
15555ea7eb
5 changed files with 34 additions and 30 deletions
|
|
@ -61,7 +61,7 @@ void setup()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DEBUG("Setup INTERRUPT");
|
DEBUG("Setup INTERRUPT");
|
||||||
Interrupt::setCallback(timerInterruptFunc);
|
Interrupt::setWatchDogCallback(timerInterruptFunc);
|
||||||
Interrupt::setupWatchDogInterrupt(TIMER_MILLISECOND); // one minute scheduled interrupt
|
Interrupt::setupWatchDogInterrupt(TIMER_MILLISECOND); // one minute scheduled interrupt
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,25 +6,15 @@
|
||||||
#include "HalInterfaces.h"
|
#include "HalInterfaces.h"
|
||||||
|
|
||||||
void emptyFunc(){}
|
void emptyFunc(){}
|
||||||
InterruptFunction Interrupt::callback = emptyFunc;
|
|
||||||
bool Interrupt::wakeUpNow = false;
|
bool Interrupt::wakeUpNow = false;
|
||||||
|
InterruptFunction Interrupt::pinCallback = emptyFunc;
|
||||||
|
InterruptFunction Interrupt::wdtCallback = emptyFunc;
|
||||||
|
|
||||||
|
|
||||||
void __interruptHandler__() // the interrupt is handled here after wakeup
|
void Interrupt::handlePinInterrupt() // the interrupt is handled here after wakeup
|
||||||
{
|
{
|
||||||
// execute code here after wake-up before returning to the loop() function
|
(*Interrupt::pinCallback) ();
|
||||||
// timers and code using timers (serial.print and more...) will not work here.
|
//Interrupt::wakeUp();
|
||||||
|
|
||||||
noInterrupts(); // disable all interrupts
|
|
||||||
(Interrupt::getCallback()) ();
|
|
||||||
interrupts(); // enable all interrupts
|
|
||||||
Interrupt::wakeUp();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Interrupt::wakeUp()
|
|
||||||
{
|
|
||||||
wakeUpNow = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Interrupt::sleep()
|
void Interrupt::sleep()
|
||||||
|
|
@ -81,7 +71,7 @@ void Interrupt::setupPinInterrupt(int pin)
|
||||||
*
|
*
|
||||||
* In all but the IDLE sleep modes only LOW can be used.
|
* In all but the IDLE sleep modes only LOW can be used.
|
||||||
*/
|
*/
|
||||||
attachInterrupt((pin == PIND2 ? 0 : 1), __interruptHandler__, LOW);
|
attachInterrupt((pin == PIND2 ? 0 : 1), Interrupt::handlePinInterrupt, LOW);
|
||||||
|
|
||||||
//detachInterrupt(0); // disables interrupt 0 on pin 2 so the
|
//detachInterrupt(0); // disables interrupt 0 on pin 2 so the
|
||||||
// wakeUpNow code will not be executed
|
// wakeUpNow code will not be executed
|
||||||
|
|
@ -93,9 +83,9 @@ void Interrupt::setupPinInterrupt(int pin)
|
||||||
// Watchdog timer
|
// Watchdog timer
|
||||||
unsigned int wdtTime;
|
unsigned int wdtTime;
|
||||||
long wdtTimeLeft;
|
long wdtTimeLeft;
|
||||||
void __setWatchDogInterrupt();
|
|
||||||
|
|
||||||
ISR(WDT_vect)
|
|
||||||
|
void Interrupt::handleWatchDogInterrupt()
|
||||||
{
|
{
|
||||||
//DEBUG("WDT Interrupt");
|
//DEBUG("WDT Interrupt");
|
||||||
wdt_disable();
|
wdt_disable();
|
||||||
|
|
@ -103,19 +93,24 @@ ISR(WDT_vect)
|
||||||
{
|
{
|
||||||
DEBUG("WDT interrupt");
|
DEBUG("WDT interrupt");
|
||||||
Interrupt::wakeUp();
|
Interrupt::wakeUp();
|
||||||
__interruptHandler__();
|
(*Interrupt::wdtCallback) ();
|
||||||
wdtTimeLeft = wdtTime;
|
wdtTimeLeft = wdtTime;
|
||||||
}
|
}
|
||||||
__setWatchDogInterrupt();
|
setupWatchDogInterrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(WDT_vect)
|
||||||
|
{
|
||||||
|
Interrupt::handleWatchDogInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Interrupt::setupWatchDogInterrupt(unsigned int milliseconds)
|
void Interrupt::setupWatchDogInterrupt(unsigned int milliseconds)
|
||||||
{
|
{
|
||||||
wdtTimeLeft = wdtTime = milliseconds;
|
wdtTimeLeft = wdtTime = milliseconds;
|
||||||
__setWatchDogInterrupt();
|
setupWatchDogInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __setWatchDogInterrupt()
|
void Interrupt::setupWatchDogInterrupt()
|
||||||
{
|
{
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
|
|
||||||
|
|
@ -194,7 +189,7 @@ void __setWatchDogInterrupt()
|
||||||
ISR(Timer1_COMPA_vect) // timer compare interrupt service routine
|
ISR(Timer1_COMPA_vect) // timer compare interrupt service routine
|
||||||
{
|
{
|
||||||
//DEBUG("Timer1e Interrupt");
|
//DEBUG("Timer1e Interrupt");
|
||||||
__interruptHandler__();
|
__pinInterruptHandler__();
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -7,22 +7,31 @@ typedef void (*InterruptFunction) ();
|
||||||
class Interrupt
|
class Interrupt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void wakeUp();
|
static void wakeUp() { wakeUpNow = true; };
|
||||||
static void sleep();
|
static void sleep();
|
||||||
static void setupPinInterrupt(int pin);
|
static void setupPinInterrupt(int pin);
|
||||||
static void setupWatchDogInterrupt(unsigned int milliseconds);
|
static void setupWatchDogInterrupt(unsigned int milliseconds);
|
||||||
//static void setupTimerInterrupt(unsigned int milliseconds);
|
//static void setupTimerInterrupt(unsigned int milliseconds);
|
||||||
|
|
||||||
static void setCallback(InterruptFunction callback){ Interrupt::callback = callback;}
|
static void setPinCallback(InterruptFunction callback){ Interrupt::pinCallback = callback;}
|
||||||
static InterruptFunction getCallback(){ return Interrupt::callback;}
|
static void setWatchDogCallback(InterruptFunction callback){ Interrupt::wdtCallback = callback;}
|
||||||
|
|
||||||
|
/* Should not be called externally, used as triggering functions */
|
||||||
|
static void handlePinInterrupt();
|
||||||
|
static void handleWatchDogInterrupt();
|
||||||
private:
|
private:
|
||||||
static InterruptFunction callback;
|
|
||||||
static bool wakeUpNow;
|
static bool wakeUpNow;
|
||||||
|
|
||||||
|
static InterruptFunction pinCallback;
|
||||||
|
static InterruptFunction wdtCallback;
|
||||||
|
|
||||||
|
static void setupWatchDogInterrupt();
|
||||||
|
|
||||||
|
// Disable constructors and copy operators
|
||||||
Interrupt() {};
|
Interrupt() {};
|
||||||
Interrupt(Interrupt const&);
|
Interrupt(Interrupt const&);
|
||||||
void operator=(Interrupt const&);
|
void operator=(Interrupt const&);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ void SensorPhotocell::interruptHandler()
|
||||||
|
|
||||||
void SensorPhotocell::setup()
|
void SensorPhotocell::setup()
|
||||||
{
|
{
|
||||||
Interrupt::setCallback(SensorPhotocell::interruptHandler);
|
Interrupt::setPinCallback(SensorPhotocell::interruptHandler);
|
||||||
Interrupt::setupPinInterrupt(PC2); //PC3
|
Interrupt::setupPinInterrupt(PC2); //PC3
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class NexaSelfLearningTest {
|
||||||
127, 255, 24, 0, // timings
|
127, 255, 24, 0, // timings
|
||||||
134, // length
|
134, // length
|
||||||
|
|
||||||
0xF9, // preamble
|
0x09, // preamble
|
||||||
168, 168, 138, 168, 138, 138, 168, 168, 138, 138,
|
168, 168, 138, 168, 138, 138, 168, 168, 138, 138,
|
||||||
138, 168, 138, 168, 168, 168, 168, 168, 168, 138,
|
138, 168, 138, 168, 168, 168, 168, 168, 168, 138,
|
||||||
138, 168, 168, 138, 138, 168, 168, 138, 168, 168,
|
138, 168, 168, 138, 138, 168, 168, 138, 168, 168,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue