Skip to content

Commit a1f4d26

Browse files
committed
#21 fix to try and work with new Arduino core API, move all interrupt handling into base package. IN PROGRESS
1 parent 328ee0a commit a1f4d26

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

examples/marshalInterrupt/marshalInterrupt.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,30 @@
1010
*/
1111

1212
#include <TaskManagerIO.h>
13+
#include <BasicInterruptAbstraction.h>
1314

1415
// choose any pin on your board to register an interrupt against.
1516
const int interruptPin = 2;
1617

1718
// now we create an InterruptAbstraction, for this example we use the simple inbuilt ArduinoInterruptExample, but you
1819
// can also use any IoAbstractionRef from IoAbstraction library too.
19-
ArduinoInterruptAbstraction interruptAbstraction;
20+
BasicArduinoInterruptAbstraction interruptAbstraction;
2021

2122
//
2223
// Here we register the interrupt handler task, it will not be called in an ISR, so it's safe to call most functions
2324
// apart from delay here.
2425
//
25-
void interruptTask(pinid_t thePin) {
26+
void interruptTask(pintype_t thePin) {
2627
Serial.println("Interrupt triggered");
2728
}
2829

2930
//
3031
// Here we set the interrupt task handler, and add the interrupt, the syntax is very similar to attachInterrupt.
3132
//
3233
void setup() {
34+
Serial.begin(115200);
35+
Serial.println("Starting interrupt example");
36+
3337
taskManager.setInterruptCallback(interruptTask);
3438
taskManager.addInterrupt(&interruptAbstraction, interruptPin, CHANGE);
3539
}

examples/taskManagement/taskManagement.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Written by Dave Cherry of thecoderscorner.com in 2017
1515

1616
#include <Arduino.h>
1717
#include <TaskManagerIO.h>
18-
#include "../../src/TaskManagerIO.h"
18+
#include <BasicInterruptAbstraction.h>
1919

2020
// here we define an interrupt capable pin that will be varied in value during execution causing the
2121
// task manager interrupt handler to be executed. Task manager will marshal the interrupt back into

src/BasicInterruptAbstraction.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Created by dave on 23/12/2020.
3+
//
4+
5+
#ifndef TASKMANAGERIO_BASICINTERRUPTABSTRACTION_H
6+
#define TASKMANAGERIO_BASICINTERRUPTABSTRACTION_H
7+
8+
#include <TaskPlatformDeps.h>
9+
#include <TaskManagerIO.h>
10+
11+
#ifdef IOA_USE_ARDUINO
12+
13+
inline void internalHandleInterrupt(pintype_t pin, RawIntHandler fn, uint8_t mode) {
14+
#if defined(ARDUINO_MBED_MODE) || (ARDUINO_API_VERSION >= 10200)
15+
::attachInterrupt(pin, fn, (PinStatus)mode);
16+
#elif defined(PARTICLE)
17+
::attachInterrupt(pin, fn, (InterruptMode)mode);
18+
#else
19+
::attachInterrupt(pin, fn, mode);
20+
#endif // Interrupt mode conditionals
21+
}
22+
23+
/**
24+
* For Arduino devices when NOT using IoAbstraction, this is the minimum possible implementation that can call
25+
* through to the Arduino platform ::attachInterrupt call. You can pass a pointer to one of these to the task manager
26+
* interrupt functions. If you are using IoAbstraction, all IoAbstractionRef's implement InterruptAbstraction.
27+
*/
28+
class BasicArduinoInterruptAbstraction : public InterruptAbstraction {
29+
void attachInterrupt(pintype_t pin, RawIntHandler fn, uint8_t mode) override {
30+
internalHandleInterrupt(pin, fn, mode);
31+
}
32+
};
33+
#endif // IOA_USE_ARDUINO - Arduino Only
34+
35+
#endif //TASKMANAGERIO_BASICINTERRUPTABSTRACTION_H

src/TaskManagerIO.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ class InterruptAbstraction {
7070
virtual void attachInterrupt(pintype_t pin, RawIntHandler fn, uint8_t mode) = 0;
7171
};
7272

73-
#ifdef IOA_USE_ARDUINO
74-
/**
75-
* For Arduino devices when NOT using IoAbstraction, this is the minimum possible implementation that can call
76-
* through to the Arduino platform ::attachInterrupt call. You can pass a pointer to one of these to the task manager
77-
* interrupt functions. If you are using IoAbstraction, all IoAbstractionRef's implement InterruptAbstraction.
78-
*/
79-
class BasicArduinoInterruptAbstraction : public InterruptAbstraction {
80-
void attachInterrupt(pintype_t pin, RawIntHandler fn, uint8_t mode) override {
81-
#if defined(ARDUINO_MBED_MODE)
82-
::attachInterrupt(pin, fn, (PinStatus)mode);
83-
#elif defined(PARTICLE)
84-
::attachInterrupt(pin, fn, (InterruptMode)mode);
85-
#else
86-
::attachInterrupt(pin, fn, mode);
87-
#endif // ARDUINO_MBED_MODE
88-
}
89-
};
90-
#endif // IOA_USE_ARDUINO - Arduino Only
91-
9273
/**
9374
* TaskManager is a lightweight cooperative co-routine implementation for Arduino, it works by scheduling tasks to be
9475
* done either immediately, or at a future point in time. It is quite efficient at scheduling tasks as internally tasks

0 commit comments

Comments
 (0)