8000 improvements (#33) · useful-esp8266-lib/Task@bd0c816 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd0c816

Browse files
authored
improvements (Makuna#33)
1 parent f2c6b68 commit bd0c816

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

examples/ButtonInterrupt/ButtonInterrupt.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ void OnBButtonChanged(ButtonState state);
5252
void OnUpdateTaskLedOn(uint32_t deltaTime);
5353
void OnUpdateTaskLedOff(uint32_t deltaTime);
5454
void OnAutoSleep(uint32_t deltaTime);
55+
void ISR_ATTR OnExtIntLow();
56+
void ISR_ATTR OnExtIntHigh();
5557

5658
ButtonTask AButtonTask(OnAButtonChanged, AButtonPin);
5759
ButtonTask BButtonTask(OnBButtonChanged, BButtonPin);
@@ -92,7 +94,7 @@ void loop()
9294
taskManager.Loop();
9395
}
9496

95-
void OnExtIntLow()
97+
void ISR_ATTR OnExtIntLow()
9698
{
9799
// required due to Mega Level to wake up
98100
// so we toggle it off when it happens and setup
@@ -101,7 +103,7 @@ void OnExtIntLow()
101103
attachInterrupt(WakeInterruptNumber, OnExtIntHigh, HIGH);
102104
}
103105

104-
void OnExtIntHigh()
106+
void ISR_ATTR OnExtIntHigh()
105107
{
106108
// required due to Mega Level to wake up
107109
// so we toggle it off when it happens and setup

examples/ButtonInterrupt/ButtonTask.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ class ButtonTask : public Task
103103
_timer -= deltaTimeMs;
104104
}
105105
break;
106+
107+
case ButtonState_Released:
108+
break;
106109
}
107110
}
108111
}

src/Task.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ See GNU Lesser General Public License at <http://www.gnu.org/licenses/>.
1919
#define countof(a) (sizeof(a) / sizeof(a[0]))
2020
#endif
2121

22+
// Arduino has no standard for attributing methods used for ISRs
23+
// even though some platforms require it, so to simplify the problem
24+
// for end users, this provides a standard ISR_ATTR
25+
#if !defined(ISR_ATTR)
26+
27+
#if defined(ARDUINO_ARCH_ESP8266)
28+
#define ISR_ATTR ICACHE_RAM_ATTR
29+
#elif defined(ARDUINO_ARCH_ESP32)
30+
#define ISR_ATTR ICACHE_RAM_ATTR
31+
#else
32+
#define ISR_ATTR
33+
#endif
34+
35+
#endif // !defined(ISR_ATTR)
36+
2237
// if you need finer timing resolution than a millisecond
2338
// then enable the below, but this will limit the max interval
2439
// to just over 70 minutes

src/TaskManager.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ void TaskManager::EnterSleep(uint32_t microSeconds,
166166
{
167167
system_rtc_mem_write(RTC_MEM_SLEEP_ADDR, state, sizeofState);
168168
}
169+
if (microSeconds == 0)
170+
{
171+
microSeconds = ESP.deepSleepMax();
172+
}
169173
ESP.deepSleep(microSeconds, mode);
170174
}
171175

src/TaskManager.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,17 @@ class TaskManager
4242

4343
#if defined(ARDUINO_ARCH_ESP8266)
4444
// must have GPIO16 tied to RST
45-
void EnterSleep(uint32_t microSeconds,
45+
void EnterSleep(uint32_t microSeconds = 0,
4646
void* state = NULL,
4747
uint16_t sizeofState = 0,
4848
WakeMode mode = WAKE_RF_DEFAULT);
4949
bool RestartedFromSleep(void* state = NULL,
5050
uint16_t sizeofState = 0 );
51+
#elif defined(ARDUINO_ARCH_ESP32)
52+
#error "ESP32 support for sleep not implemented yet"
5153
#elif defined(__arm__)
5254
// Arm support for sleep not implemented yet
55+
#error "Arm support for sleep not implemented yet"
5356
#elif defined(ARDUINO_ARCH_AVR)
5457
void EnterSleep(uint8_t sleepMode = SLEEP_MODE_PWR_DOWN);
5558
#endif

0 commit comments

Comments
 (0)
0